"use client";
import { Preprocessor as u } from "./preprocessor.js";
import { CODE_POINTS as t, REPLACEMENT_CHARACTER as _, SEQUENCES as T, isSurrogate as O, isUndefinedCodePoint as R, isControlCodePoint as m } from "../common/unicode.js";
import { TokenType as A, getTokenAttr as P } from "../common/token.js";
import { EntityDecoder as k, DecodingMode as D } from "../../../entities/dist/esm/decode.js";
import { ERR as i } from "../common/error-codes.js";
import { TAG_ID as C, getTagID as l } from "../common/html.js";
import { htmlDecodeTree as d } from "../../../entities/dist/esm/generated/decode-data-html.js";
var s;
(function(a) {
  a[a.DATA = 0] = "DATA", a[a.RCDATA = 1] = "RCDATA", a[a.RAWTEXT = 2] = "RAWTEXT", a[a.SCRIPT_DATA = 3] = "SCRIPT_DATA", a[a.PLAINTEXT = 4] = "PLAINTEXT", a[a.TAG_OPEN = 5] = "TAG_OPEN", a[a.END_TAG_OPEN = 6] = "END_TAG_OPEN", a[a.TAG_NAME = 7] = "TAG_NAME", a[a.RCDATA_LESS_THAN_SIGN = 8] = "RCDATA_LESS_THAN_SIGN", a[a.RCDATA_END_TAG_OPEN = 9] = "RCDATA_END_TAG_OPEN", a[a.RCDATA_END_TAG_NAME = 10] = "RCDATA_END_TAG_NAME", a[a.RAWTEXT_LESS_THAN_SIGN = 11] = "RAWTEXT_LESS_THAN_SIGN", a[a.RAWTEXT_END_TAG_OPEN = 12] = "RAWTEXT_END_TAG_OPEN", a[a.RAWTEXT_END_TAG_NAME = 13] = "RAWTEXT_END_TAG_NAME", a[a.SCRIPT_DATA_LESS_THAN_SIGN = 14] = "SCRIPT_DATA_LESS_THAN_SIGN", a[a.SCRIPT_DATA_END_TAG_OPEN = 15] = "SCRIPT_DATA_END_TAG_OPEN", a[a.SCRIPT_DATA_END_TAG_NAME = 16] = "SCRIPT_DATA_END_TAG_NAME", a[a.SCRIPT_DATA_ESCAPE_START = 17] = "SCRIPT_DATA_ESCAPE_START", a[a.SCRIPT_DATA_ESCAPE_START_DASH = 18] = "SCRIPT_DATA_ESCAPE_START_DASH", a[a.SCRIPT_DATA_ESCAPED = 19] = "SCRIPT_DATA_ESCAPED", a[a.SCRIPT_DATA_ESCAPED_DASH = 20] = "SCRIPT_DATA_ESCAPED_DASH", a[a.SCRIPT_DATA_ESCAPED_DASH_DASH = 21] = "SCRIPT_DATA_ESCAPED_DASH_DASH", a[a.SCRIPT_DATA_ESCAPED_LESS_THAN_SIGN = 22] = "SCRIPT_DATA_ESCAPED_LESS_THAN_SIGN", a[a.SCRIPT_DATA_ESCAPED_END_TAG_OPEN = 23] = "SCRIPT_DATA_ESCAPED_END_TAG_OPEN", a[a.SCRIPT_DATA_ESCAPED_END_TAG_NAME = 24] = "SCRIPT_DATA_ESCAPED_END_TAG_NAME", a[a.SCRIPT_DATA_DOUBLE_ESCAPE_START = 25] = "SCRIPT_DATA_DOUBLE_ESCAPE_START", a[a.SCRIPT_DATA_DOUBLE_ESCAPED = 26] = "SCRIPT_DATA_DOUBLE_ESCAPED", a[a.SCRIPT_DATA_DOUBLE_ESCAPED_DASH = 27] = "SCRIPT_DATA_DOUBLE_ESCAPED_DASH", a[a.SCRIPT_DATA_DOUBLE_ESCAPED_DASH_DASH = 28] = "SCRIPT_DATA_DOUBLE_ESCAPED_DASH_DASH", a[a.SCRIPT_DATA_DOUBLE_ESCAPED_LESS_THAN_SIGN = 29] = "SCRIPT_DATA_DOUBLE_ESCAPED_LESS_THAN_SIGN", a[a.SCRIPT_DATA_DOUBLE_ESCAPE_END = 30] = "SCRIPT_DATA_DOUBLE_ESCAPE_END", a[a.BEFORE_ATTRIBUTE_NAME = 31] = "BEFORE_ATTRIBUTE_NAME", a[a.ATTRIBUTE_NAME = 32] = "ATTRIBUTE_NAME", a[a.AFTER_ATTRIBUTE_NAME = 33] = "AFTER_ATTRIBUTE_NAME", a[a.BEFORE_ATTRIBUTE_VALUE = 34] = "BEFORE_ATTRIBUTE_VALUE", a[a.ATTRIBUTE_VALUE_DOUBLE_QUOTED = 35] = "ATTRIBUTE_VALUE_DOUBLE_QUOTED", a[a.ATTRIBUTE_VALUE_SINGLE_QUOTED = 36] = "ATTRIBUTE_VALUE_SINGLE_QUOTED", a[a.ATTRIBUTE_VALUE_UNQUOTED = 37] = "ATTRIBUTE_VALUE_UNQUOTED", a[a.AFTER_ATTRIBUTE_VALUE_QUOTED = 38] = "AFTER_ATTRIBUTE_VALUE_QUOTED", a[a.SELF_CLOSING_START_TAG = 39] = "SELF_CLOSING_START_TAG", a[a.BOGUS_COMMENT = 40] = "BOGUS_COMMENT", a[a.MARKUP_DECLARATION_OPEN = 41] = "MARKUP_DECLARATION_OPEN", a[a.COMMENT_START = 42] = "COMMENT_START", a[a.COMMENT_START_DASH = 43] = "COMMENT_START_DASH", a[a.COMMENT = 44] = "COMMENT", a[a.COMMENT_LESS_THAN_SIGN = 45] = "COMMENT_LESS_THAN_SIGN", a[a.COMMENT_LESS_THAN_SIGN_BANG = 46] = "COMMENT_LESS_THAN_SIGN_BANG", a[a.COMMENT_LESS_THAN_SIGN_BANG_DASH = 47] = "COMMENT_LESS_THAN_SIGN_BANG_DASH", a[a.COMMENT_LESS_THAN_SIGN_BANG_DASH_DASH = 48] = "COMMENT_LESS_THAN_SIGN_BANG_DASH_DASH", a[a.COMMENT_END_DASH = 49] = "COMMENT_END_DASH", a[a.COMMENT_END = 50] = "COMMENT_END", a[a.COMMENT_END_BANG = 51] = "COMMENT_END_BANG", a[a.DOCTYPE = 52] = "DOCTYPE", a[a.BEFORE_DOCTYPE_NAME = 53] = "BEFORE_DOCTYPE_NAME", a[a.DOCTYPE_NAME = 54] = "DOCTYPE_NAME", a[a.AFTER_DOCTYPE_NAME = 55] = "AFTER_DOCTYPE_NAME", a[a.AFTER_DOCTYPE_PUBLIC_KEYWORD = 56] = "AFTER_DOCTYPE_PUBLIC_KEYWORD", a[a.BEFORE_DOCTYPE_PUBLIC_IDENTIFIER = 57] = "BEFORE_DOCTYPE_PUBLIC_IDENTIFIER", a[a.DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED = 58] = "DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED", a[a.DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED = 59] = "DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED", a[a.AFTER_DOCTYPE_PUBLIC_IDENTIFIER = 60] = "AFTER_DOCTYPE_PUBLIC_IDENTIFIER", a[a.BETWEEN_DOCTYPE_PUBLIC_AND_SYSTEM_IDENTIFIERS = 61] = "BETWEEN_DOCTYPE_PUBLIC_AND_SYSTEM_IDENTIFIERS", a[a.AFTER_DOCTYPE_SYSTEM_KEYWORD = 62] = "AFTER_DOCTYPE_SYSTEM_KEYWORD", a[a.BEFORE_DOCTYPE_SYSTEM_IDENTIFIER = 63] = "BEFORE_DOCTYPE_SYSTEM_IDENTIFIER", a[a.DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED = 64] = "DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED", a[a.DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED = 65] = "DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED", a[a.AFTER_DOCTYPE_SYSTEM_IDENTIFIER = 66] = "AFTER_DOCTYPE_SYSTEM_IDENTIFIER", a[a.BOGUS_DOCTYPE = 67] = "BOGUS_DOCTYPE", a[a.CDATA_SECTION = 68] = "CDATA_SECTION", a[a.CDATA_SECTION_BRACKET = 69] = "CDATA_SECTION_BRACKET", a[a.CDATA_SECTION_END = 70] = "CDATA_SECTION_END", a[a.CHARACTER_REFERENCE = 71] = "CHARACTER_REFERENCE", a[a.AMBIGUOUS_AMPERSAND = 72] = "AMBIGUOUS_AMPERSAND";
})(s || (s = {}));
const H = {
  DATA: s.DATA,
  RCDATA: s.RCDATA,
  RAWTEXT: s.RAWTEXT,
  SCRIPT_DATA: s.SCRIPT_DATA,
  PLAINTEXT: s.PLAINTEXT,
  CDATA_SECTION: s.CDATA_SECTION
};
function f(a) {
  return a >= t.DIGIT_0 && a <= t.DIGIT_9;
}
function o(a) {
  return a >= t.LATIN_CAPITAL_A && a <= t.LATIN_CAPITAL_Z;
}
function L(a) {
  return a >= t.LATIN_SMALL_A && a <= t.LATIN_SMALL_Z;
}
function n(a) {
  return L(a) || o(a);
}
function S(a) {
  return n(a) || f(a);
}
function c(a) {
  return a + 32;
}
function I(a) {
  return a === t.SPACE || a === t.LINE_FEED || a === t.TABULATION || a === t.FORM_FEED;
}
function N(a) {
  return I(a) || a === t.SOLIDUS || a === t.GREATER_THAN_SIGN;
}
function b(a) {
  return a === t.NULL ? i.nullCharacterReference : a > 1114111 ? i.characterReferenceOutsideUnicodeRange : O(a) ? i.surrogateCharacterReference : R(a) ? i.noncharacterCharacterReference : m(a) || a === t.CARRIAGE_RETURN ? i.controlCharacterReference : null;
}
class y {
  constructor(e, r) {
    this.options = e, this.handler = r, this.paused = !1, this.inLoop = !1, this.inForeignNode = !1, this.lastStartTagName = "", this.active = !1, this.state = s.DATA, this.returnState = s.DATA, this.entityStartPos = 0, this.consumedAfterSnapshot = -1, this.currentCharacterToken = null, this.currentToken = null, this.currentAttr = { name: "", value: "" }, this.preprocessor = new u(r), this.currentLocation = this.getCurrentLocation(-1), this.entityDecoder = new k(d, (E, h) => {
      this.preprocessor.pos = this.entityStartPos + h - 1, this._flushCodePointConsumedAsCharacterReference(E);
    }, r.onParseError ? {
      missingSemicolonAfterCharacterReference: () => {
        this._err(i.missingSemicolonAfterCharacterReference, 1);
      },
      absenceOfDigitsInNumericCharacterReference: (E) => {
        this._err(i.absenceOfDigitsInNumericCharacterReference, this.entityStartPos - this.preprocessor.pos + E);
      },
      validateNumericCharacterReference: (E) => {
        const h = b(E);
        h && this._err(h, 1);
      }
    } : void 0);
  }
  //Errors
  _err(e, r = 0) {
    var E, h;
    (h = (E = this.handler).onParseError) === null || h === void 0 || h.call(E, this.preprocessor.getError(e, r));
  }
  // NOTE: `offset` may never run across line boundaries.
  getCurrentLocation(e) {
    return this.options.sourceCodeLocationInfo ? {
      startLine: this.preprocessor.line,
      startCol: this.preprocessor.col - e,
      startOffset: this.preprocessor.offset - e,
      endLine: -1,
      endCol: -1,
      endOffset: -1
    } : null;
  }
  _runParsingLoop() {
    if (!this.inLoop) {
      for (this.inLoop = !0; this.active && !this.paused; ) {
        this.consumedAfterSnapshot = 0;
        const e = this._consume();
        this._ensureHibernation() || this._callState(e);
      }
      this.inLoop = !1;
    }
  }
  //API
  pause() {
    this.paused = !0;
  }
  resume(e) {
    if (!this.paused)
      throw new Error("Parser was already resumed");
    this.paused = !1, !this.inLoop && (this._runParsingLoop(), this.paused || e?.());
  }
  write(e, r, E) {
    this.active = !0, this.preprocessor.write(e, r), this._runParsingLoop(), this.paused || E?.();
  }
  insertHtmlAtCurrentPos(e) {
    this.active = !0, this.preprocessor.insertHtmlAtCurrentPos(e), this._runParsingLoop();
  }
  //Hibernation
  _ensureHibernation() {
    return this.preprocessor.endOfChunkHit ? (this.preprocessor.retreat(this.consumedAfterSnapshot), this.consumedAfterSnapshot = 0, this.active = !1, !0) : !1;
  }
  //Consumption
  _consume() {
    return this.consumedAfterSnapshot++, this.preprocessor.advance();
  }
  _advanceBy(e) {
    this.consumedAfterSnapshot += e;
    for (let r = 0; r < e; r++)
      this.preprocessor.advance();
  }
  _consumeSequenceIfMatch(e, r) {
    return this.preprocessor.startsWith(e, r) ? (this._advanceBy(e.length - 1), !0) : !1;
  }
  //Token creation
  _createStartTagToken() {
    this.currentToken = {
      type: A.START_TAG,
      tagName: "",
      tagID: C.UNKNOWN,
      selfClosing: !1,
      ackSelfClosing: !1,
      attrs: [],
      location: this.getCurrentLocation(1)
    };
  }
  _createEndTagToken() {
    this.currentToken = {
      type: A.END_TAG,
      tagName: "",
      tagID: C.UNKNOWN,
      selfClosing: !1,
      ackSelfClosing: !1,
      attrs: [],
      location: this.getCurrentLocation(2)
    };
  }
  _createCommentToken(e) {
    this.currentToken = {
      type: A.COMMENT,
      data: "",
      location: this.getCurrentLocation(e)
    };
  }
  _createDoctypeToken(e) {
    this.currentToken = {
      type: A.DOCTYPE,
      name: e,
      forceQuirks: !1,
      publicId: null,
      systemId: null,
      location: this.currentLocation
    };
  }
  _createCharacterToken(e, r) {
    this.currentCharacterToken = {
      type: e,
      chars: r,
      location: this.currentLocation
    };
  }
  //Tag attributes
  _createAttr(e) {
    this.currentAttr = {
      name: e,
      value: ""
    }, this.currentLocation = this.getCurrentLocation(0);
  }
  _leaveAttrName() {
    var e, r;
    const E = this.currentToken;
    if (P(E, this.currentAttr.name) === null) {
      if (E.attrs.push(this.currentAttr), E.location && this.currentLocation) {
        const h = (e = (r = E.location).attrs) !== null && e !== void 0 ? e : r.attrs = /* @__PURE__ */ Object.create(null);
        h[this.currentAttr.name] = this.currentLocation, this._leaveAttrValue();
      }
    } else
      this._err(i.duplicateAttribute);
  }
  _leaveAttrValue() {
    this.currentLocation && (this.currentLocation.endLine = this.preprocessor.line, this.currentLocation.endCol = this.preprocessor.col, this.currentLocation.endOffset = this.preprocessor.offset);
  }
  //Token emission
  prepareToken(e) {
    this._emitCurrentCharacterToken(e.location), this.currentToken = null, e.location && (e.location.endLine = this.preprocessor.line, e.location.endCol = this.preprocessor.col + 1, e.location.endOffset = this.preprocessor.offset + 1), this.currentLocation = this.getCurrentLocation(-1);
  }
  emitCurrentTagToken() {
    const e = this.currentToken;
    this.prepareToken(e), e.tagID = l(e.tagName), e.type === A.START_TAG ? (this.lastStartTagName = e.tagName, this.handler.onStartTag(e)) : (e.attrs.length > 0 && this._err(i.endTagWithAttributes), e.selfClosing && this._err(i.endTagWithTrailingSolidus), this.handler.onEndTag(e)), this.preprocessor.dropParsedChunk();
  }
  emitCurrentComment(e) {
    this.prepareToken(e), this.handler.onComment(e), this.preprocessor.dropParsedChunk();
  }
  emitCurrentDoctype(e) {
    this.prepareToken(e), this.handler.onDoctype(e), this.preprocessor.dropParsedChunk();
  }
  _emitCurrentCharacterToken(e) {
    if (this.currentCharacterToken) {
      switch (e && this.currentCharacterToken.location && (this.currentCharacterToken.location.endLine = e.startLine, this.currentCharacterToken.location.endCol = e.startCol, this.currentCharacterToken.location.endOffset = e.startOffset), this.currentCharacterToken.type) {
        case A.CHARACTER: {
          this.handler.onCharacter(this.currentCharacterToken);
          break;
        }
        case A.NULL_CHARACTER: {
          this.handler.onNullCharacter(this.currentCharacterToken);
          break;
        }
        case A.WHITESPACE_CHARACTER: {
          this.handler.onWhitespaceCharacter(this.currentCharacterToken);
          break;
        }
      }
      this.currentCharacterToken = null;
    }
  }
  _emitEOFToken() {
    const e = this.getCurrentLocation(0);
    e && (e.endLine = e.startLine, e.endCol = e.startCol, e.endOffset = e.startOffset), this._emitCurrentCharacterToken(e), this.handler.onEof({ type: A.EOF, location: e }), this.active = !1;
  }
  //Characters emission
  //OPTIMIZATION: The specification uses only one type of character token (one token per character).
  //This causes a huge memory overhead and a lot of unnecessary parser loops. parse5 uses 3 groups of characters.
  //If we have a sequence of characters that belong to the same group, the parser can process it
  //as a single solid character token.
  //So, there are 3 types of character tokens in parse5:
  //1)TokenType.NULL_CHARACTER - \u0000-character sequences (e.g. '\u0000\u0000\u0000')
  //2)TokenType.WHITESPACE_CHARACTER - any whitespace/new-line character sequences (e.g. '\n  \r\t   \f')
  //3)TokenType.CHARACTER - any character sequence which don't belong to groups 1 and 2 (e.g. 'abcdef1234@@#$%^')
  _appendCharToCurrentCharacterToken(e, r) {
    if (this.currentCharacterToken)
      if (this.currentCharacterToken.type === e) {
        this.currentCharacterToken.chars += r;
        return;
      } else
        this.currentLocation = this.getCurrentLocation(0), this._emitCurrentCharacterToken(this.currentLocation), this.preprocessor.dropParsedChunk();
    this._createCharacterToken(e, r);
  }
  _emitCodePoint(e) {
    const r = I(e) ? A.WHITESPACE_CHARACTER : e === t.NULL ? A.NULL_CHARACTER : A.CHARACTER;
    this._appendCharToCurrentCharacterToken(r, String.fromCodePoint(e));
  }
  //NOTE: used when we emit characters explicitly.
  //This is always for non-whitespace and non-null characters, which allows us to avoid additional checks.
  _emitChars(e) {
    this._appendCharToCurrentCharacterToken(A.CHARACTER, e);
  }
  // Character reference helpers
  _startCharacterReference() {
    this.returnState = this.state, this.state = s.CHARACTER_REFERENCE, this.entityStartPos = this.preprocessor.pos, this.entityDecoder.startEntity(this._isCharacterReferenceInAttribute() ? D.Attribute : D.Legacy);
  }
  _isCharacterReferenceInAttribute() {
    return this.returnState === s.ATTRIBUTE_VALUE_DOUBLE_QUOTED || this.returnState === s.ATTRIBUTE_VALUE_SINGLE_QUOTED || this.returnState === s.ATTRIBUTE_VALUE_UNQUOTED;
  }
  _flushCodePointConsumedAsCharacterReference(e) {
    this._isCharacterReferenceInAttribute() ? this.currentAttr.value += String.fromCodePoint(e) : this._emitCodePoint(e);
  }
  // Calling states this way turns out to be much faster than any other approach.
  _callState(e) {
    switch (this.state) {
      case s.DATA: {
        this._stateData(e);
        break;
      }
      case s.RCDATA: {
        this._stateRcdata(e);
        break;
      }
      case s.RAWTEXT: {
        this._stateRawtext(e);
        break;
      }
      case s.SCRIPT_DATA: {
        this._stateScriptData(e);
        break;
      }
      case s.PLAINTEXT: {
        this._statePlaintext(e);
        break;
      }
      case s.TAG_OPEN: {
        this._stateTagOpen(e);
        break;
      }
      case s.END_TAG_OPEN: {
        this._stateEndTagOpen(e);
        break;
      }
      case s.TAG_NAME: {
        this._stateTagName(e);
        break;
      }
      case s.RCDATA_LESS_THAN_SIGN: {
        this._stateRcdataLessThanSign(e);
        break;
      }
      case s.RCDATA_END_TAG_OPEN: {
        this._stateRcdataEndTagOpen(e);
        break;
      }
      case s.RCDATA_END_TAG_NAME: {
        this._stateRcdataEndTagName(e);
        break;
      }
      case s.RAWTEXT_LESS_THAN_SIGN: {
        this._stateRawtextLessThanSign(e);
        break;
      }
      case s.RAWTEXT_END_TAG_OPEN: {
        this._stateRawtextEndTagOpen(e);
        break;
      }
      case s.RAWTEXT_END_TAG_NAME: {
        this._stateRawtextEndTagName(e);
        break;
      }
      case s.SCRIPT_DATA_LESS_THAN_SIGN: {
        this._stateScriptDataLessThanSign(e);
        break;
      }
      case s.SCRIPT_DATA_END_TAG_OPEN: {
        this._stateScriptDataEndTagOpen(e);
        break;
      }
      case s.SCRIPT_DATA_END_TAG_NAME: {
        this._stateScriptDataEndTagName(e);
        break;
      }
      case s.SCRIPT_DATA_ESCAPE_START: {
        this._stateScriptDataEscapeStart(e);
        break;
      }
      case s.SCRIPT_DATA_ESCAPE_START_DASH: {
        this._stateScriptDataEscapeStartDash(e);
        break;
      }
      case s.SCRIPT_DATA_ESCAPED: {
        this._stateScriptDataEscaped(e);
        break;
      }
      case s.SCRIPT_DATA_ESCAPED_DASH: {
        this._stateScriptDataEscapedDash(e);
        break;
      }
      case s.SCRIPT_DATA_ESCAPED_DASH_DASH: {
        this._stateScriptDataEscapedDashDash(e);
        break;
      }
      case s.SCRIPT_DATA_ESCAPED_LESS_THAN_SIGN: {
        this._stateScriptDataEscapedLessThanSign(e);
        break;
      }
      case s.SCRIPT_DATA_ESCAPED_END_TAG_OPEN: {
        this._stateScriptDataEscapedEndTagOpen(e);
        break;
      }
      case s.SCRIPT_DATA_ESCAPED_END_TAG_NAME: {
        this._stateScriptDataEscapedEndTagName(e);
        break;
      }
      case s.SCRIPT_DATA_DOUBLE_ESCAPE_START: {
        this._stateScriptDataDoubleEscapeStart(e);
        break;
      }
      case s.SCRIPT_DATA_DOUBLE_ESCAPED: {
        this._stateScriptDataDoubleEscaped(e);
        break;
      }
      case s.SCRIPT_DATA_DOUBLE_ESCAPED_DASH: {
        this._stateScriptDataDoubleEscapedDash(e);
        break;
      }
      case s.SCRIPT_DATA_DOUBLE_ESCAPED_DASH_DASH: {
        this._stateScriptDataDoubleEscapedDashDash(e);
        break;
      }
      case s.SCRIPT_DATA_DOUBLE_ESCAPED_LESS_THAN_SIGN: {
        this._stateScriptDataDoubleEscapedLessThanSign(e);
        break;
      }
      case s.SCRIPT_DATA_DOUBLE_ESCAPE_END: {
        this._stateScriptDataDoubleEscapeEnd(e);
        break;
      }
      case s.BEFORE_ATTRIBUTE_NAME: {
        this._stateBeforeAttributeName(e);
        break;
      }
      case s.ATTRIBUTE_NAME: {
        this._stateAttributeName(e);
        break;
      }
      case s.AFTER_ATTRIBUTE_NAME: {
        this._stateAfterAttributeName(e);
        break;
      }
      case s.BEFORE_ATTRIBUTE_VALUE: {
        this._stateBeforeAttributeValue(e);
        break;
      }
      case s.ATTRIBUTE_VALUE_DOUBLE_QUOTED: {
        this._stateAttributeValueDoubleQuoted(e);
        break;
      }
      case s.ATTRIBUTE_VALUE_SINGLE_QUOTED: {
        this._stateAttributeValueSingleQuoted(e);
        break;
      }
      case s.ATTRIBUTE_VALUE_UNQUOTED: {
        this._stateAttributeValueUnquoted(e);
        break;
      }
      case s.AFTER_ATTRIBUTE_VALUE_QUOTED: {
        this._stateAfterAttributeValueQuoted(e);
        break;
      }
      case s.SELF_CLOSING_START_TAG: {
        this._stateSelfClosingStartTag(e);
        break;
      }
      case s.BOGUS_COMMENT: {
        this._stateBogusComment(e);
        break;
      }
      case s.MARKUP_DECLARATION_OPEN: {
        this._stateMarkupDeclarationOpen(e);
        break;
      }
      case s.COMMENT_START: {
        this._stateCommentStart(e);
        break;
      }
      case s.COMMENT_START_DASH: {
        this._stateCommentStartDash(e);
        break;
      }
      case s.COMMENT: {
        this._stateComment(e);
        break;
      }
      case s.COMMENT_LESS_THAN_SIGN: {
        this._stateCommentLessThanSign(e);
        break;
      }
      case s.COMMENT_LESS_THAN_SIGN_BANG: {
        this._stateCommentLessThanSignBang(e);
        break;
      }
      case s.COMMENT_LESS_THAN_SIGN_BANG_DASH: {
        this._stateCommentLessThanSignBangDash(e);
        break;
      }
      case s.COMMENT_LESS_THAN_SIGN_BANG_DASH_DASH: {
        this._stateCommentLessThanSignBangDashDash(e);
        break;
      }
      case s.COMMENT_END_DASH: {
        this._stateCommentEndDash(e);
        break;
      }
      case s.COMMENT_END: {
        this._stateCommentEnd(e);
        break;
      }
      case s.COMMENT_END_BANG: {
        this._stateCommentEndBang(e);
        break;
      }
      case s.DOCTYPE: {
        this._stateDoctype(e);
        break;
      }
      case s.BEFORE_DOCTYPE_NAME: {
        this._stateBeforeDoctypeName(e);
        break;
      }
      case s.DOCTYPE_NAME: {
        this._stateDoctypeName(e);
        break;
      }
      case s.AFTER_DOCTYPE_NAME: {
        this._stateAfterDoctypeName(e);
        break;
      }
      case s.AFTER_DOCTYPE_PUBLIC_KEYWORD: {
        this._stateAfterDoctypePublicKeyword(e);
        break;
      }
      case s.BEFORE_DOCTYPE_PUBLIC_IDENTIFIER: {
        this._stateBeforeDoctypePublicIdentifier(e);
        break;
      }
      case s.DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED: {
        this._stateDoctypePublicIdentifierDoubleQuoted(e);
        break;
      }
      case s.DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED: {
        this._stateDoctypePublicIdentifierSingleQuoted(e);
        break;
      }
      case s.AFTER_DOCTYPE_PUBLIC_IDENTIFIER: {
        this._stateAfterDoctypePublicIdentifier(e);
        break;
      }
      case s.BETWEEN_DOCTYPE_PUBLIC_AND_SYSTEM_IDENTIFIERS: {
        this._stateBetweenDoctypePublicAndSystemIdentifiers(e);
        break;
      }
      case s.AFTER_DOCTYPE_SYSTEM_KEYWORD: {
        this._stateAfterDoctypeSystemKeyword(e);
        break;
      }
      case s.BEFORE_DOCTYPE_SYSTEM_IDENTIFIER: {
        this._stateBeforeDoctypeSystemIdentifier(e);
        break;
      }
      case s.DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED: {
        this._stateDoctypeSystemIdentifierDoubleQuoted(e);
        break;
      }
      case s.DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED: {
        this._stateDoctypeSystemIdentifierSingleQuoted(e);
        break;
      }
      case s.AFTER_DOCTYPE_SYSTEM_IDENTIFIER: {
        this._stateAfterDoctypeSystemIdentifier(e);
        break;
      }
      case s.BOGUS_DOCTYPE: {
        this._stateBogusDoctype(e);
        break;
      }
      case s.CDATA_SECTION: {
        this._stateCdataSection(e);
        break;
      }
      case s.CDATA_SECTION_BRACKET: {
        this._stateCdataSectionBracket(e);
        break;
      }
      case s.CDATA_SECTION_END: {
        this._stateCdataSectionEnd(e);
        break;
      }
      case s.CHARACTER_REFERENCE: {
        this._stateCharacterReference();
        break;
      }
      case s.AMBIGUOUS_AMPERSAND: {
        this._stateAmbiguousAmpersand(e);
        break;
      }
      default:
        throw new Error("Unknown state");
    }
  }
  // State machine
  // Data state
  //------------------------------------------------------------------
  _stateData(e) {
    switch (e) {
      case t.LESS_THAN_SIGN: {
        this.state = s.TAG_OPEN;
        break;
      }
      case t.AMPERSAND: {
        this._startCharacterReference();
        break;
      }
      case t.NULL: {
        this._err(i.unexpectedNullCharacter), this._emitCodePoint(e);
        break;
      }
      case t.EOF: {
        this._emitEOFToken();
        break;
      }
      default:
        this._emitCodePoint(e);
    }
  }
  //  RCDATA state
  //------------------------------------------------------------------
  _stateRcdata(e) {
    switch (e) {
      case t.AMPERSAND: {
        this._startCharacterReference();
        break;
      }
      case t.LESS_THAN_SIGN: {
        this.state = s.RCDATA_LESS_THAN_SIGN;
        break;
      }
      case t.NULL: {
        this._err(i.unexpectedNullCharacter), this._emitChars(_);
        break;
      }
      case t.EOF: {
        this._emitEOFToken();
        break;
      }
      default:
        this._emitCodePoint(e);
    }
  }
  // RAWTEXT state
  //------------------------------------------------------------------
  _stateRawtext(e) {
    switch (e) {
      case t.LESS_THAN_SIGN: {
        this.state = s.RAWTEXT_LESS_THAN_SIGN;
        break;
      }
      case t.NULL: {
        this._err(i.unexpectedNullCharacter), this._emitChars(_);
        break;
      }
      case t.EOF: {
        this._emitEOFToken();
        break;
      }
      default:
        this._emitCodePoint(e);
    }
  }
  // Script data state
  //------------------------------------------------------------------
  _stateScriptData(e) {
    switch (e) {
      case t.LESS_THAN_SIGN: {
        this.state = s.SCRIPT_DATA_LESS_THAN_SIGN;
        break;
      }
      case t.NULL: {
        this._err(i.unexpectedNullCharacter), this._emitChars(_);
        break;
      }
      case t.EOF: {
        this._emitEOFToken();
        break;
      }
      default:
        this._emitCodePoint(e);
    }
  }
  // PLAINTEXT state
  //------------------------------------------------------------------
  _statePlaintext(e) {
    switch (e) {
      case t.NULL: {
        this._err(i.unexpectedNullCharacter), this._emitChars(_);
        break;
      }
      case t.EOF: {
        this._emitEOFToken();
        break;
      }
      default:
        this._emitCodePoint(e);
    }
  }
  // Tag open state
  //------------------------------------------------------------------
  _stateTagOpen(e) {
    if (n(e))
      this._createStartTagToken(), this.state = s.TAG_NAME, this._stateTagName(e);
    else
      switch (e) {
        case t.EXCLAMATION_MARK: {
          this.state = s.MARKUP_DECLARATION_OPEN;
          break;
        }
        case t.SOLIDUS: {
          this.state = s.END_TAG_OPEN;
          break;
        }
        case t.QUESTION_MARK: {
          this._err(i.unexpectedQuestionMarkInsteadOfTagName), this._createCommentToken(1), this.state = s.BOGUS_COMMENT, this._stateBogusComment(e);
          break;
        }
        case t.EOF: {
          this._err(i.eofBeforeTagName), this._emitChars("<"), this._emitEOFToken();
          break;
        }
        default:
          this._err(i.invalidFirstCharacterOfTagName), this._emitChars("<"), this.state = s.DATA, this._stateData(e);
      }
  }
  // End tag open state
  //------------------------------------------------------------------
  _stateEndTagOpen(e) {
    if (n(e))
      this._createEndTagToken(), this.state = s.TAG_NAME, this._stateTagName(e);
    else
      switch (e) {
        case t.GREATER_THAN_SIGN: {
          this._err(i.missingEndTagName), this.state = s.DATA;
          break;
        }
        case t.EOF: {
          this._err(i.eofBeforeTagName), this._emitChars("</"), this._emitEOFToken();
          break;
        }
        default:
          this._err(i.invalidFirstCharacterOfTagName), this._createCommentToken(2), this.state = s.BOGUS_COMMENT, this._stateBogusComment(e);
      }
  }
  // Tag name state
  //------------------------------------------------------------------
  _stateTagName(e) {
    const r = this.currentToken;
    switch (e) {
      case t.SPACE:
      case t.LINE_FEED:
      case t.TABULATION:
      case t.FORM_FEED: {
        this.state = s.BEFORE_ATTRIBUTE_NAME;
        break;
      }
      case t.SOLIDUS: {
        this.state = s.SELF_CLOSING_START_TAG;
        break;
      }
      case t.GREATER_THAN_SIGN: {
        this.state = s.DATA, this.emitCurrentTagToken();
        break;
      }
      case t.NULL: {
        this._err(i.unexpectedNullCharacter), r.tagName += _;
        break;
      }
      case t.EOF: {
        this._err(i.eofInTag), this._emitEOFToken();
        break;
      }
      default:
        r.tagName += String.fromCodePoint(o(e) ? c(e) : e);
    }
  }
  // RCDATA less-than sign state
  //------------------------------------------------------------------
  _stateRcdataLessThanSign(e) {
    e === t.SOLIDUS ? this.state = s.RCDATA_END_TAG_OPEN : (this._emitChars("<"), this.state = s.RCDATA, this._stateRcdata(e));
  }
  // RCDATA end tag open state
  //------------------------------------------------------------------
  _stateRcdataEndTagOpen(e) {
    n(e) ? (this.state = s.RCDATA_END_TAG_NAME, this._stateRcdataEndTagName(e)) : (this._emitChars("</"), this.state = s.RCDATA, this._stateRcdata(e));
  }
  handleSpecialEndTag(e) {
    if (!this.preprocessor.startsWith(this.lastStartTagName, !1))
      return !this._ensureHibernation();
    this._createEndTagToken();
    const r = this.currentToken;
    switch (r.tagName = this.lastStartTagName, this.preprocessor.peek(this.lastStartTagName.length)) {
      case t.SPACE:
      case t.LINE_FEED:
      case t.TABULATION:
      case t.FORM_FEED:
        return this._advanceBy(this.lastStartTagName.length), this.state = s.BEFORE_ATTRIBUTE_NAME, !1;
      case t.SOLIDUS:
        return this._advanceBy(this.lastStartTagName.length), this.state = s.SELF_CLOSING_START_TAG, !1;
      case t.GREATER_THAN_SIGN:
        return this._advanceBy(this.lastStartTagName.length), this.emitCurrentTagToken(), this.state = s.DATA, !1;
      default:
        return !this._ensureHibernation();
    }
  }
  // RCDATA end tag name state
  //------------------------------------------------------------------
  _stateRcdataEndTagName(e) {
    this.handleSpecialEndTag(e) && (this._emitChars("</"), this.state = s.RCDATA, this._stateRcdata(e));
  }
  // RAWTEXT less-than sign state
  //------------------------------------------------------------------
  _stateRawtextLessThanSign(e) {
    e === t.SOLIDUS ? this.state = s.RAWTEXT_END_TAG_OPEN : (this._emitChars("<"), this.state = s.RAWTEXT, this._stateRawtext(e));
  }
  // RAWTEXT end tag open state
  //------------------------------------------------------------------
  _stateRawtextEndTagOpen(e) {
    n(e) ? (this.state = s.RAWTEXT_END_TAG_NAME, this._stateRawtextEndTagName(e)) : (this._emitChars("</"), this.state = s.RAWTEXT, this._stateRawtext(e));
  }
  // RAWTEXT end tag name state
  //------------------------------------------------------------------
  _stateRawtextEndTagName(e) {
    this.handleSpecialEndTag(e) && (this._emitChars("</"), this.state = s.RAWTEXT, this._stateRawtext(e));
  }
  // Script data less-than sign state
  //------------------------------------------------------------------
  _stateScriptDataLessThanSign(e) {
    switch (e) {
      case t.SOLIDUS: {
        this.state = s.SCRIPT_DATA_END_TAG_OPEN;
        break;
      }
      case t.EXCLAMATION_MARK: {
        this.state = s.SCRIPT_DATA_ESCAPE_START, this._emitChars("<!");
        break;
      }
      default:
        this._emitChars("<"), this.state = s.SCRIPT_DATA, this._stateScriptData(e);
    }
  }
  // Script data end tag open state
  //------------------------------------------------------------------
  _stateScriptDataEndTagOpen(e) {
    n(e) ? (this.state = s.SCRIPT_DATA_END_TAG_NAME, this._stateScriptDataEndTagName(e)) : (this._emitChars("</"), this.state = s.SCRIPT_DATA, this._stateScriptData(e));
  }
  // Script data end tag name state
  //------------------------------------------------------------------
  _stateScriptDataEndTagName(e) {
    this.handleSpecialEndTag(e) && (this._emitChars("</"), this.state = s.SCRIPT_DATA, this._stateScriptData(e));
  }
  // Script data escape start state
  //------------------------------------------------------------------
  _stateScriptDataEscapeStart(e) {
    e === t.HYPHEN_MINUS ? (this.state = s.SCRIPT_DATA_ESCAPE_START_DASH, this._emitChars("-")) : (this.state = s.SCRIPT_DATA, this._stateScriptData(e));
  }
  // Script data escape start dash state
  //------------------------------------------------------------------
  _stateScriptDataEscapeStartDash(e) {
    e === t.HYPHEN_MINUS ? (this.state = s.SCRIPT_DATA_ESCAPED_DASH_DASH, this._emitChars("-")) : (this.state = s.SCRIPT_DATA, this._stateScriptData(e));
  }
  // Script data escaped state
  //------------------------------------------------------------------
  _stateScriptDataEscaped(e) {
    switch (e) {
      case t.HYPHEN_MINUS: {
        this.state = s.SCRIPT_DATA_ESCAPED_DASH, this._emitChars("-");
        break;
      }
      case t.LESS_THAN_SIGN: {
        this.state = s.SCRIPT_DATA_ESCAPED_LESS_THAN_SIGN;
        break;
      }
      case t.NULL: {
        this._err(i.unexpectedNullCharacter), this._emitChars(_);
        break;
      }
      case t.EOF: {
        this._err(i.eofInScriptHtmlCommentLikeText), this._emitEOFToken();
        break;
      }
      default:
        this._emitCodePoint(e);
    }
  }
  // Script data escaped dash state
  //------------------------------------------------------------------
  _stateScriptDataEscapedDash(e) {
    switch (e) {
      case t.HYPHEN_MINUS: {
        this.state = s.SCRIPT_DATA_ESCAPED_DASH_DASH, this._emitChars("-");
        break;
      }
      case t.LESS_THAN_SIGN: {
        this.state = s.SCRIPT_DATA_ESCAPED_LESS_THAN_SIGN;
        break;
      }
      case t.NULL: {
        this._err(i.unexpectedNullCharacter), this.state = s.SCRIPT_DATA_ESCAPED, this._emitChars(_);
        break;
      }
      case t.EOF: {
        this._err(i.eofInScriptHtmlCommentLikeText), this._emitEOFToken();
        break;
      }
      default:
        this.state = s.SCRIPT_DATA_ESCAPED, this._emitCodePoint(e);
    }
  }
  // Script data escaped dash dash state
  //------------------------------------------------------------------
  _stateScriptDataEscapedDashDash(e) {
    switch (e) {
      case t.HYPHEN_MINUS: {
        this._emitChars("-");
        break;
      }
      case t.LESS_THAN_SIGN: {
        this.state = s.SCRIPT_DATA_ESCAPED_LESS_THAN_SIGN;
        break;
      }
      case t.GREATER_THAN_SIGN: {
        this.state = s.SCRIPT_DATA, this._emitChars(">");
        break;
      }
      case t.NULL: {
        this._err(i.unexpectedNullCharacter), this.state = s.SCRIPT_DATA_ESCAPED, this._emitChars(_);
        break;
      }
      case t.EOF: {
        this._err(i.eofInScriptHtmlCommentLikeText), this._emitEOFToken();
        break;
      }
      default:
        this.state = s.SCRIPT_DATA_ESCAPED, this._emitCodePoint(e);
    }
  }
  // Script data escaped less-than sign state
  //------------------------------------------------------------------
  _stateScriptDataEscapedLessThanSign(e) {
    e === t.SOLIDUS ? this.state = s.SCRIPT_DATA_ESCAPED_END_TAG_OPEN : n(e) ? (this._emitChars("<"), this.state = s.SCRIPT_DATA_DOUBLE_ESCAPE_START, this._stateScriptDataDoubleEscapeStart(e)) : (this._emitChars("<"), this.state = s.SCRIPT_DATA_ESCAPED, this._stateScriptDataEscaped(e));
  }
  // Script data escaped end tag open state
  //------------------------------------------------------------------
  _stateScriptDataEscapedEndTagOpen(e) {
    n(e) ? (this.state = s.SCRIPT_DATA_ESCAPED_END_TAG_NAME, this._stateScriptDataEscapedEndTagName(e)) : (this._emitChars("</"), this.state = s.SCRIPT_DATA_ESCAPED, this._stateScriptDataEscaped(e));
  }
  // Script data escaped end tag name state
  //------------------------------------------------------------------
  _stateScriptDataEscapedEndTagName(e) {
    this.handleSpecialEndTag(e) && (this._emitChars("</"), this.state = s.SCRIPT_DATA_ESCAPED, this._stateScriptDataEscaped(e));
  }
  // Script data double escape start state
  //------------------------------------------------------------------
  _stateScriptDataDoubleEscapeStart(e) {
    if (this.preprocessor.startsWith(T.SCRIPT, !1) && N(this.preprocessor.peek(T.SCRIPT.length))) {
      this._emitCodePoint(e);
      for (let r = 0; r < T.SCRIPT.length; r++)
        this._emitCodePoint(this._consume());
      this.state = s.SCRIPT_DATA_DOUBLE_ESCAPED;
    } else this._ensureHibernation() || (this.state = s.SCRIPT_DATA_ESCAPED, this._stateScriptDataEscaped(e));
  }
  // Script data double escaped state
  //------------------------------------------------------------------
  _stateScriptDataDoubleEscaped(e) {
    switch (e) {
      case t.HYPHEN_MINUS: {
        this.state = s.SCRIPT_DATA_DOUBLE_ESCAPED_DASH, this._emitChars("-");
        break;
      }
      case t.LESS_THAN_SIGN: {
        this.state = s.SCRIPT_DATA_DOUBLE_ESCAPED_LESS_THAN_SIGN, this._emitChars("<");
        break;
      }
      case t.NULL: {
        this._err(i.unexpectedNullCharacter), this._emitChars(_);
        break;
      }
      case t.EOF: {
        this._err(i.eofInScriptHtmlCommentLikeText), this._emitEOFToken();
        break;
      }
      default:
        this._emitCodePoint(e);
    }
  }
  // Script data double escaped dash state
  //------------------------------------------------------------------
  _stateScriptDataDoubleEscapedDash(e) {
    switch (e) {
      case t.HYPHEN_MINUS: {
        this.state = s.SCRIPT_DATA_DOUBLE_ESCAPED_DASH_DASH, this._emitChars("-");
        break;
      }
      case t.LESS_THAN_SIGN: {
        this.state = s.SCRIPT_DATA_DOUBLE_ESCAPED_LESS_THAN_SIGN, this._emitChars("<");
        break;
      }
      case t.NULL: {
        this._err(i.unexpectedNullCharacter), this.state = s.SCRIPT_DATA_DOUBLE_ESCAPED, this._emitChars(_);
        break;
      }
      case t.EOF: {
        this._err(i.eofInScriptHtmlCommentLikeText), this._emitEOFToken();
        break;
      }
      default:
        this.state = s.SCRIPT_DATA_DOUBLE_ESCAPED, this._emitCodePoint(e);
    }
  }
  // Script data double escaped dash dash state
  //------------------------------------------------------------------
  _stateScriptDataDoubleEscapedDashDash(e) {
    switch (e) {
      case t.HYPHEN_MINUS: {
        this._emitChars("-");
        break;
      }
      case t.LESS_THAN_SIGN: {
        this.state = s.SCRIPT_DATA_DOUBLE_ESCAPED_LESS_THAN_SIGN, this._emitChars("<");
        break;
      }
      case t.GREATER_THAN_SIGN: {
        this.state = s.SCRIPT_DATA, this._emitChars(">");
        break;
      }
      case t.NULL: {
        this._err(i.unexpectedNullCharacter), this.state = s.SCRIPT_DATA_DOUBLE_ESCAPED, this._emitChars(_);
        break;
      }
      case t.EOF: {
        this._err(i.eofInScriptHtmlCommentLikeText), this._emitEOFToken();
        break;
      }
      default:
        this.state = s.SCRIPT_DATA_DOUBLE_ESCAPED, this._emitCodePoint(e);
    }
  }
  // Script data double escaped less-than sign state
  //------------------------------------------------------------------
  _stateScriptDataDoubleEscapedLessThanSign(e) {
    e === t.SOLIDUS ? (this.state = s.SCRIPT_DATA_DOUBLE_ESCAPE_END, this._emitChars("/")) : (this.state = s.SCRIPT_DATA_DOUBLE_ESCAPED, this._stateScriptDataDoubleEscaped(e));
  }
  // Script data double escape end state
  //------------------------------------------------------------------
  _stateScriptDataDoubleEscapeEnd(e) {
    if (this.preprocessor.startsWith(T.SCRIPT, !1) && N(this.preprocessor.peek(T.SCRIPT.length))) {
      this._emitCodePoint(e);
      for (let r = 0; r < T.SCRIPT.length; r++)
        this._emitCodePoint(this._consume());
      this.state = s.SCRIPT_DATA_ESCAPED;
    } else this._ensureHibernation() || (this.state = s.SCRIPT_DATA_DOUBLE_ESCAPED, this._stateScriptDataDoubleEscaped(e));
  }
  // Before attribute name state
  //------------------------------------------------------------------
  _stateBeforeAttributeName(e) {
    switch (e) {
      case t.SPACE:
      case t.LINE_FEED:
      case t.TABULATION:
      case t.FORM_FEED:
        break;
      case t.SOLIDUS:
      case t.GREATER_THAN_SIGN:
      case t.EOF: {
        this.state = s.AFTER_ATTRIBUTE_NAME, this._stateAfterAttributeName(e);
        break;
      }
      case t.EQUALS_SIGN: {
        this._err(i.unexpectedEqualsSignBeforeAttributeName), this._createAttr("="), this.state = s.ATTRIBUTE_NAME;
        break;
      }
      default:
        this._createAttr(""), this.state = s.ATTRIBUTE_NAME, this._stateAttributeName(e);
    }
  }
  // Attribute name state
  //------------------------------------------------------------------
  _stateAttributeName(e) {
    switch (e) {
      case t.SPACE:
      case t.LINE_FEED:
      case t.TABULATION:
      case t.FORM_FEED:
      case t.SOLIDUS:
      case t.GREATER_THAN_SIGN:
      case t.EOF: {
        this._leaveAttrName(), this.state = s.AFTER_ATTRIBUTE_NAME, this._stateAfterAttributeName(e);
        break;
      }
      case t.EQUALS_SIGN: {
        this._leaveAttrName(), this.state = s.BEFORE_ATTRIBUTE_VALUE;
        break;
      }
      case t.QUOTATION_MARK:
      case t.APOSTROPHE:
      case t.LESS_THAN_SIGN: {
        this._err(i.unexpectedCharacterInAttributeName), this.currentAttr.name += String.fromCodePoint(e);
        break;
      }
      case t.NULL: {
        this._err(i.unexpectedNullCharacter), this.currentAttr.name += _;
        break;
      }
      default:
        this.currentAttr.name += String.fromCodePoint(o(e) ? c(e) : e);
    }
  }
  // After attribute name state
  //------------------------------------------------------------------
  _stateAfterAttributeName(e) {
    switch (e) {
      case t.SPACE:
      case t.LINE_FEED:
      case t.TABULATION:
      case t.FORM_FEED:
        break;
      case t.SOLIDUS: {
        this.state = s.SELF_CLOSING_START_TAG;
        break;
      }
      case t.EQUALS_SIGN: {
        this.state = s.BEFORE_ATTRIBUTE_VALUE;
        break;
      }
      case t.GREATER_THAN_SIGN: {
        this.state = s.DATA, this.emitCurrentTagToken();
        break;
      }
      case t.EOF: {
        this._err(i.eofInTag), this._emitEOFToken();
        break;
      }
      default:
        this._createAttr(""), this.state = s.ATTRIBUTE_NAME, this._stateAttributeName(e);
    }
  }
  // Before attribute value state
  //------------------------------------------------------------------
  _stateBeforeAttributeValue(e) {
    switch (e) {
      case t.SPACE:
      case t.LINE_FEED:
      case t.TABULATION:
      case t.FORM_FEED:
        break;
      case t.QUOTATION_MARK: {
        this.state = s.ATTRIBUTE_VALUE_DOUBLE_QUOTED;
        break;
      }
      case t.APOSTROPHE: {
        this.state = s.ATTRIBUTE_VALUE_SINGLE_QUOTED;
        break;
      }
      case t.GREATER_THAN_SIGN: {
        this._err(i.missingAttributeValue), this.state = s.DATA, this.emitCurrentTagToken();
        break;
      }
      default:
        this.state = s.ATTRIBUTE_VALUE_UNQUOTED, this._stateAttributeValueUnquoted(e);
    }
  }
  // Attribute value (double-quoted) state
  //------------------------------------------------------------------
  _stateAttributeValueDoubleQuoted(e) {
    switch (e) {
      case t.QUOTATION_MARK: {
        this.state = s.AFTER_ATTRIBUTE_VALUE_QUOTED;
        break;
      }
      case t.AMPERSAND: {
        this._startCharacterReference();
        break;
      }
      case t.NULL: {
        this._err(i.unexpectedNullCharacter), this.currentAttr.value += _;
        break;
      }
      case t.EOF: {
        this._err(i.eofInTag), this._emitEOFToken();
        break;
      }
      default:
        this.currentAttr.value += String.fromCodePoint(e);
    }
  }
  // Attribute value (single-quoted) state
  //------------------------------------------------------------------
  _stateAttributeValueSingleQuoted(e) {
    switch (e) {
      case t.APOSTROPHE: {
        this.state = s.AFTER_ATTRIBUTE_VALUE_QUOTED;
        break;
      }
      case t.AMPERSAND: {
        this._startCharacterReference();
        break;
      }
      case t.NULL: {
        this._err(i.unexpectedNullCharacter), this.currentAttr.value += _;
        break;
      }
      case t.EOF: {
        this._err(i.eofInTag), this._emitEOFToken();
        break;
      }
      default:
        this.currentAttr.value += String.fromCodePoint(e);
    }
  }
  // Attribute value (unquoted) state
  //------------------------------------------------------------------
  _stateAttributeValueUnquoted(e) {
    switch (e) {
      case t.SPACE:
      case t.LINE_FEED:
      case t.TABULATION:
      case t.FORM_FEED: {
        this._leaveAttrValue(), this.state = s.BEFORE_ATTRIBUTE_NAME;
        break;
      }
      case t.AMPERSAND: {
        this._startCharacterReference();
        break;
      }
      case t.GREATER_THAN_SIGN: {
        this._leaveAttrValue(), this.state = s.DATA, this.emitCurrentTagToken();
        break;
      }
      case t.NULL: {
        this._err(i.unexpectedNullCharacter), this.currentAttr.value += _;
        break;
      }
      case t.QUOTATION_MARK:
      case t.APOSTROPHE:
      case t.LESS_THAN_SIGN:
      case t.EQUALS_SIGN:
      case t.GRAVE_ACCENT: {
        this._err(i.unexpectedCharacterInUnquotedAttributeValue), this.currentAttr.value += String.fromCodePoint(e);
        break;
      }
      case t.EOF: {
        this._err(i.eofInTag), this._emitEOFToken();
        break;
      }
      default:
        this.currentAttr.value += String.fromCodePoint(e);
    }
  }
  // After attribute value (quoted) state
  //------------------------------------------------------------------
  _stateAfterAttributeValueQuoted(e) {
    switch (e) {
      case t.SPACE:
      case t.LINE_FEED:
      case t.TABULATION:
      case t.FORM_FEED: {
        this._leaveAttrValue(), this.state = s.BEFORE_ATTRIBUTE_NAME;
        break;
      }
      case t.SOLIDUS: {
        this._leaveAttrValue(), this.state = s.SELF_CLOSING_START_TAG;
        break;
      }
      case t.GREATER_THAN_SIGN: {
        this._leaveAttrValue(), this.state = s.DATA, this.emitCurrentTagToken();
        break;
      }
      case t.EOF: {
        this._err(i.eofInTag), this._emitEOFToken();
        break;
      }
      default:
        this._err(i.missingWhitespaceBetweenAttributes), this.state = s.BEFORE_ATTRIBUTE_NAME, this._stateBeforeAttributeName(e);
    }
  }
  // Self-closing start tag state
  //------------------------------------------------------------------
  _stateSelfClosingStartTag(e) {
    switch (e) {
      case t.GREATER_THAN_SIGN: {
        const r = this.currentToken;
        r.selfClosing = !0, this.state = s.DATA, this.emitCurrentTagToken();
        break;
      }
      case t.EOF: {
        this._err(i.eofInTag), this._emitEOFToken();
        break;
      }
      default:
        this._err(i.unexpectedSolidusInTag), this.state = s.BEFORE_ATTRIBUTE_NAME, this._stateBeforeAttributeName(e);
    }
  }
  // Bogus comment state
  //------------------------------------------------------------------
  _stateBogusComment(e) {
    const r = this.currentToken;
    switch (e) {
      case t.GREATER_THAN_SIGN: {
        this.state = s.DATA, this.emitCurrentComment(r);
        break;
      }
      case t.EOF: {
        this.emitCurrentComment(r), this._emitEOFToken();
        break;
      }
      case t.NULL: {
        this._err(i.unexpectedNullCharacter), r.data += _;
        break;
      }
      default:
        r.data += String.fromCodePoint(e);
    }
  }
  // Markup declaration open state
  //------------------------------------------------------------------
  _stateMarkupDeclarationOpen(e) {
    this._consumeSequenceIfMatch(T.DASH_DASH, !0) ? (this._createCommentToken(T.DASH_DASH.length + 1), this.state = s.COMMENT_START) : this._consumeSequenceIfMatch(T.DOCTYPE, !1) ? (this.currentLocation = this.getCurrentLocation(T.DOCTYPE.length + 1), this.state = s.DOCTYPE) : this._consumeSequenceIfMatch(T.CDATA_START, !0) ? this.inForeignNode ? this.state = s.CDATA_SECTION : (this._err(i.cdataInHtmlContent), this._createCommentToken(T.CDATA_START.length + 1), this.currentToken.data = "[CDATA[", this.state = s.BOGUS_COMMENT) : this._ensureHibernation() || (this._err(i.incorrectlyOpenedComment), this._createCommentToken(2), this.state = s.BOGUS_COMMENT, this._stateBogusComment(e));
  }
  // Comment start state
  //------------------------------------------------------------------
  _stateCommentStart(e) {
    switch (e) {
      case t.HYPHEN_MINUS: {
        this.state = s.COMMENT_START_DASH;
        break;
      }
      case t.GREATER_THAN_SIGN: {
        this._err(i.abruptClosingOfEmptyComment), this.state = s.DATA;
        const r = this.currentToken;
        this.emitCurrentComment(r);
        break;
      }
      default:
        this.state = s.COMMENT, this._stateComment(e);
    }
  }
  // Comment start dash state
  //------------------------------------------------------------------
  _stateCommentStartDash(e) {
    const r = this.currentToken;
    switch (e) {
      case t.HYPHEN_MINUS: {
        this.state = s.COMMENT_END;
        break;
      }
      case t.GREATER_THAN_SIGN: {
        this._err(i.abruptClosingOfEmptyComment), this.state = s.DATA, this.emitCurrentComment(r);
        break;
      }
      case t.EOF: {
        this._err(i.eofInComment), this.emitCurrentComment(r), this._emitEOFToken();
        break;
      }
      default:
        r.data += "-", this.state = s.COMMENT, this._stateComment(e);
    }
  }
  // Comment state
  //------------------------------------------------------------------
  _stateComment(e) {
    const r = this.currentToken;
    switch (e) {
      case t.HYPHEN_MINUS: {
        this.state = s.COMMENT_END_DASH;
        break;
      }
      case t.LESS_THAN_SIGN: {
        r.data += "<", this.state = s.COMMENT_LESS_THAN_SIGN;
        break;
      }
      case t.NULL: {
        this._err(i.unexpectedNullCharacter), r.data += _;
        break;
      }
      case t.EOF: {
        this._err(i.eofInComment), this.emitCurrentComment(r), this._emitEOFToken();
        break;
      }
      default:
        r.data += String.fromCodePoint(e);
    }
  }
  // Comment less-than sign state
  //------------------------------------------------------------------
  _stateCommentLessThanSign(e) {
    const r = this.currentToken;
    switch (e) {
      case t.EXCLAMATION_MARK: {
        r.data += "!", this.state = s.COMMENT_LESS_THAN_SIGN_BANG;
        break;
      }
      case t.LESS_THAN_SIGN: {
        r.data += "<";
        break;
      }
      default:
        this.state = s.COMMENT, this._stateComment(e);
    }
  }
  // Comment less-than sign bang state
  //------------------------------------------------------------------
  _stateCommentLessThanSignBang(e) {
    e === t.HYPHEN_MINUS ? this.state = s.COMMENT_LESS_THAN_SIGN_BANG_DASH : (this.state = s.COMMENT, this._stateComment(e));
  }
  // Comment less-than sign bang dash state
  //------------------------------------------------------------------
  _stateCommentLessThanSignBangDash(e) {
    e === t.HYPHEN_MINUS ? this.state = s.COMMENT_LESS_THAN_SIGN_BANG_DASH_DASH : (this.state = s.COMMENT_END_DASH, this._stateCommentEndDash(e));
  }
  // Comment less-than sign bang dash dash state
  //------------------------------------------------------------------
  _stateCommentLessThanSignBangDashDash(e) {
    e !== t.GREATER_THAN_SIGN && e !== t.EOF && this._err(i.nestedComment), this.state = s.COMMENT_END, this._stateCommentEnd(e);
  }
  // Comment end dash state
  //------------------------------------------------------------------
  _stateCommentEndDash(e) {
    const r = this.currentToken;
    switch (e) {
      case t.HYPHEN_MINUS: {
        this.state = s.COMMENT_END;
        break;
      }
      case t.EOF: {
        this._err(i.eofInComment), this.emitCurrentComment(r), this._emitEOFToken();
        break;
      }
      default:
        r.data += "-", this.state = s.COMMENT, this._stateComment(e);
    }
  }
  // Comment end state
  //------------------------------------------------------------------
  _stateCommentEnd(e) {
    const r = this.currentToken;
    switch (e) {
      case t.GREATER_THAN_SIGN: {
        this.state = s.DATA, this.emitCurrentComment(r);
        break;
      }
      case t.EXCLAMATION_MARK: {
        this.state = s.COMMENT_END_BANG;
        break;
      }
      case t.HYPHEN_MINUS: {
        r.data += "-";
        break;
      }
      case t.EOF: {
        this._err(i.eofInComment), this.emitCurrentComment(r), this._emitEOFToken();
        break;
      }
      default:
        r.data += "--", this.state = s.COMMENT, this._stateComment(e);
    }
  }
  // Comment end bang state
  //------------------------------------------------------------------
  _stateCommentEndBang(e) {
    const r = this.currentToken;
    switch (e) {
      case t.HYPHEN_MINUS: {
        r.data += "--!", this.state = s.COMMENT_END_DASH;
        break;
      }
      case t.GREATER_THAN_SIGN: {
        this._err(i.incorrectlyClosedComment), this.state = s.DATA, this.emitCurrentComment(r);
        break;
      }
      case t.EOF: {
        this._err(i.eofInComment), this.emitCurrentComment(r), this._emitEOFToken();
        break;
      }
      default:
        r.data += "--!", this.state = s.COMMENT, this._stateComment(e);
    }
  }
  // DOCTYPE state
  //------------------------------------------------------------------
  _stateDoctype(e) {
    switch (e) {
      case t.SPACE:
      case t.LINE_FEED:
      case t.TABULATION:
      case t.FORM_FEED: {
        this.state = s.BEFORE_DOCTYPE_NAME;
        break;
      }
      case t.GREATER_THAN_SIGN: {
        this.state = s.BEFORE_DOCTYPE_NAME, this._stateBeforeDoctypeName(e);
        break;
      }
      case t.EOF: {
        this._err(i.eofInDoctype), this._createDoctypeToken(null);
        const r = this.currentToken;
        r.forceQuirks = !0, this.emitCurrentDoctype(r), this._emitEOFToken();
        break;
      }
      default:
        this._err(i.missingWhitespaceBeforeDoctypeName), this.state = s.BEFORE_DOCTYPE_NAME, this._stateBeforeDoctypeName(e);
    }
  }
  // Before DOCTYPE name state
  //------------------------------------------------------------------
  _stateBeforeDoctypeName(e) {
    if (o(e))
      this._createDoctypeToken(String.fromCharCode(c(e))), this.state = s.DOCTYPE_NAME;
    else
      switch (e) {
        case t.SPACE:
        case t.LINE_FEED:
        case t.TABULATION:
        case t.FORM_FEED:
          break;
        case t.NULL: {
          this._err(i.unexpectedNullCharacter), this._createDoctypeToken(_), this.state = s.DOCTYPE_NAME;
          break;
        }
        case t.GREATER_THAN_SIGN: {
          this._err(i.missingDoctypeName), this._createDoctypeToken(null);
          const r = this.currentToken;
          r.forceQuirks = !0, this.emitCurrentDoctype(r), this.state = s.DATA;
          break;
        }
        case t.EOF: {
          this._err(i.eofInDoctype), this._createDoctypeToken(null);
          const r = this.currentToken;
          r.forceQuirks = !0, this.emitCurrentDoctype(r), this._emitEOFToken();
          break;
        }
        default:
          this._createDoctypeToken(String.fromCodePoint(e)), this.state = s.DOCTYPE_NAME;
      }
  }
  // DOCTYPE name state
  //------------------------------------------------------------------
  _stateDoctypeName(e) {
    const r = this.currentToken;
    switch (e) {
      case t.SPACE:
      case t.LINE_FEED:
      case t.TABULATION:
      case t.FORM_FEED: {
        this.state = s.AFTER_DOCTYPE_NAME;
        break;
      }
      case t.GREATER_THAN_SIGN: {
        this.state = s.DATA, this.emitCurrentDoctype(r);
        break;
      }
      case t.NULL: {
        this._err(i.unexpectedNullCharacter), r.name += _;
        break;
      }
      case t.EOF: {
        this._err(i.eofInDoctype), r.forceQuirks = !0, this.emitCurrentDoctype(r), this._emitEOFToken();
        break;
      }
      default:
        r.name += String.fromCodePoint(o(e) ? c(e) : e);
    }
  }
  // After DOCTYPE name state
  //------------------------------------------------------------------
  _stateAfterDoctypeName(e) {
    const r = this.currentToken;
    switch (e) {
      case t.SPACE:
      case t.LINE_FEED:
      case t.TABULATION:
      case t.FORM_FEED:
        break;
      case t.GREATER_THAN_SIGN: {
        this.state = s.DATA, this.emitCurrentDoctype(r);
        break;
      }
      case t.EOF: {
        this._err(i.eofInDoctype), r.forceQuirks = !0, this.emitCurrentDoctype(r), this._emitEOFToken();
        break;
      }
      default:
        this._consumeSequenceIfMatch(T.PUBLIC, !1) ? this.state = s.AFTER_DOCTYPE_PUBLIC_KEYWORD : this._consumeSequenceIfMatch(T.SYSTEM, !1) ? this.state = s.AFTER_DOCTYPE_SYSTEM_KEYWORD : this._ensureHibernation() || (this._err(i.invalidCharacterSequenceAfterDoctypeName), r.forceQuirks = !0, this.state = s.BOGUS_DOCTYPE, this._stateBogusDoctype(e));
    }
  }
  // After DOCTYPE public keyword state
  //------------------------------------------------------------------
  _stateAfterDoctypePublicKeyword(e) {
    const r = this.currentToken;
    switch (e) {
      case t.SPACE:
      case t.LINE_FEED:
      case t.TABULATION:
      case t.FORM_FEED: {
        this.state = s.BEFORE_DOCTYPE_PUBLIC_IDENTIFIER;
        break;
      }
      case t.QUOTATION_MARK: {
        this._err(i.missingWhitespaceAfterDoctypePublicKeyword), r.publicId = "", this.state = s.DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED;
        break;
      }
      case t.APOSTROPHE: {
        this._err(i.missingWhitespaceAfterDoctypePublicKeyword), r.publicId = "", this.state = s.DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED;
        break;
      }
      case t.GREATER_THAN_SIGN: {
        this._err(i.missingDoctypePublicIdentifier), r.forceQuirks = !0, this.state = s.DATA, this.emitCurrentDoctype(r);
        break;
      }
      case t.EOF: {
        this._err(i.eofInDoctype), r.forceQuirks = !0, this.emitCurrentDoctype(r), this._emitEOFToken();
        break;
      }
      default:
        this._err(i.missingQuoteBeforeDoctypePublicIdentifier), r.forceQuirks = !0, this.state = s.BOGUS_DOCTYPE, this._stateBogusDoctype(e);
    }
  }
  // Before DOCTYPE public identifier state
  //------------------------------------------------------------------
  _stateBeforeDoctypePublicIdentifier(e) {
    const r = this.currentToken;
    switch (e) {
      case t.SPACE:
      case t.LINE_FEED:
      case t.TABULATION:
      case t.FORM_FEED:
        break;
      case t.QUOTATION_MARK: {
        r.publicId = "", this.state = s.DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED;
        break;
      }
      case t.APOSTROPHE: {
        r.publicId = "", this.state = s.DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED;
        break;
      }
      case t.GREATER_THAN_SIGN: {
        this._err(i.missingDoctypePublicIdentifier), r.forceQuirks = !0, this.state = s.DATA, this.emitCurrentDoctype(r);
        break;
      }
      case t.EOF: {
        this._err(i.eofInDoctype), r.forceQuirks = !0, this.emitCurrentDoctype(r), this._emitEOFToken();
        break;
      }
      default:
        this._err(i.missingQuoteBeforeDoctypePublicIdentifier), r.forceQuirks = !0, this.state = s.BOGUS_DOCTYPE, this._stateBogusDoctype(e);
    }
  }
  // DOCTYPE public identifier (double-quoted) state
  //------------------------------------------------------------------
  _stateDoctypePublicIdentifierDoubleQuoted(e) {
    const r = this.currentToken;
    switch (e) {
      case t.QUOTATION_MARK: {
        this.state = s.AFTER_DOCTYPE_PUBLIC_IDENTIFIER;
        break;
      }
      case t.NULL: {
        this._err(i.unexpectedNullCharacter), r.publicId += _;
        break;
      }
      case t.GREATER_THAN_SIGN: {
        this._err(i.abruptDoctypePublicIdentifier), r.forceQuirks = !0, this.emitCurrentDoctype(r), this.state = s.DATA;
        break;
      }
      case t.EOF: {
        this._err(i.eofInDoctype), r.forceQuirks = !0, this.emitCurrentDoctype(r), this._emitEOFToken();
        break;
      }
      default:
        r.publicId += String.fromCodePoint(e);
    }
  }
  // DOCTYPE public identifier (single-quoted) state
  //------------------------------------------------------------------
  _stateDoctypePublicIdentifierSingleQuoted(e) {
    const r = this.currentToken;
    switch (e) {
      case t.APOSTROPHE: {
        this.state = s.AFTER_DOCTYPE_PUBLIC_IDENTIFIER;
        break;
      }
      case t.NULL: {
        this._err(i.unexpectedNullCharacter), r.publicId += _;
        break;
      }
      case t.GREATER_THAN_SIGN: {
        this._err(i.abruptDoctypePublicIdentifier), r.forceQuirks = !0, this.emitCurrentDoctype(r), this.state = s.DATA;
        break;
      }
      case t.EOF: {
        this._err(i.eofInDoctype), r.forceQuirks = !0, this.emitCurrentDoctype(r), this._emitEOFToken();
        break;
      }
      default:
        r.publicId += String.fromCodePoint(e);
    }
  }
  // After DOCTYPE public identifier state
  //------------------------------------------------------------------
  _stateAfterDoctypePublicIdentifier(e) {
    const r = this.currentToken;
    switch (e) {
      case t.SPACE:
      case t.LINE_FEED:
      case t.TABULATION:
      case t.FORM_FEED: {
        this.state = s.BETWEEN_DOCTYPE_PUBLIC_AND_SYSTEM_IDENTIFIERS;
        break;
      }
      case t.GREATER_THAN_SIGN: {
        this.state = s.DATA, this.emitCurrentDoctype(r);
        break;
      }
      case t.QUOTATION_MARK: {
        this._err(i.missingWhitespaceBetweenDoctypePublicAndSystemIdentifiers), r.systemId = "", this.state = s.DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED;
        break;
      }
      case t.APOSTROPHE: {
        this._err(i.missingWhitespaceBetweenDoctypePublicAndSystemIdentifiers), r.systemId = "", this.state = s.DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED;
        break;
      }
      case t.EOF: {
        this._err(i.eofInDoctype), r.forceQuirks = !0, this.emitCurrentDoctype(r), this._emitEOFToken();
        break;
      }
      default:
        this._err(i.missingQuoteBeforeDoctypeSystemIdentifier), r.forceQuirks = !0, this.state = s.BOGUS_DOCTYPE, this._stateBogusDoctype(e);
    }
  }
  // Between DOCTYPE public and system identifiers state
  //------------------------------------------------------------------
  _stateBetweenDoctypePublicAndSystemIdentifiers(e) {
    const r = this.currentToken;
    switch (e) {
      case t.SPACE:
      case t.LINE_FEED:
      case t.TABULATION:
      case t.FORM_FEED:
        break;
      case t.GREATER_THAN_SIGN: {
        this.emitCurrentDoctype(r), this.state = s.DATA;
        break;
      }
      case t.QUOTATION_MARK: {
        r.systemId = "", this.state = s.DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED;
        break;
      }
      case t.APOSTROPHE: {
        r.systemId = "", this.state = s.DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED;
        break;
      }
      case t.EOF: {
        this._err(i.eofInDoctype), r.forceQuirks = !0, this.emitCurrentDoctype(r), this._emitEOFToken();
        break;
      }
      default:
        this._err(i.missingQuoteBeforeDoctypeSystemIdentifier), r.forceQuirks = !0, this.state = s.BOGUS_DOCTYPE, this._stateBogusDoctype(e);
    }
  }
  // After DOCTYPE system keyword state
  //------------------------------------------------------------------
  _stateAfterDoctypeSystemKeyword(e) {
    const r = this.currentToken;
    switch (e) {
      case t.SPACE:
      case t.LINE_FEED:
      case t.TABULATION:
      case t.FORM_FEED: {
        this.state = s.BEFORE_DOCTYPE_SYSTEM_IDENTIFIER;
        break;
      }
      case t.QUOTATION_MARK: {
        this._err(i.missingWhitespaceAfterDoctypeSystemKeyword), r.systemId = "", this.state = s.DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED;
        break;
      }
      case t.APOSTROPHE: {
        this._err(i.missingWhitespaceAfterDoctypeSystemKeyword), r.systemId = "", this.state = s.DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED;
        break;
      }
      case t.GREATER_THAN_SIGN: {
        this._err(i.missingDoctypeSystemIdentifier), r.forceQuirks = !0, this.state = s.DATA, this.emitCurrentDoctype(r);
        break;
      }
      case t.EOF: {
        this._err(i.eofInDoctype), r.forceQuirks = !0, this.emitCurrentDoctype(r), this._emitEOFToken();
        break;
      }
      default:
        this._err(i.missingQuoteBeforeDoctypeSystemIdentifier), r.forceQuirks = !0, this.state = s.BOGUS_DOCTYPE, this._stateBogusDoctype(e);
    }
  }
  // Before DOCTYPE system identifier state
  //------------------------------------------------------------------
  _stateBeforeDoctypeSystemIdentifier(e) {
    const r = this.currentToken;
    switch (e) {
      case t.SPACE:
      case t.LINE_FEED:
      case t.TABULATION:
      case t.FORM_FEED:
        break;
      case t.QUOTATION_MARK: {
        r.systemId = "", this.state = s.DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED;
        break;
      }
      case t.APOSTROPHE: {
        r.systemId = "", this.state = s.DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED;
        break;
      }
      case t.GREATER_THAN_SIGN: {
        this._err(i.missingDoctypeSystemIdentifier), r.forceQuirks = !0, this.state = s.DATA, this.emitCurrentDoctype(r);
        break;
      }
      case t.EOF: {
        this._err(i.eofInDoctype), r.forceQuirks = !0, this.emitCurrentDoctype(r), this._emitEOFToken();
        break;
      }
      default:
        this._err(i.missingQuoteBeforeDoctypeSystemIdentifier), r.forceQuirks = !0, this.state = s.BOGUS_DOCTYPE, this._stateBogusDoctype(e);
    }
  }
  // DOCTYPE system identifier (double-quoted) state
  //------------------------------------------------------------------
  _stateDoctypeSystemIdentifierDoubleQuoted(e) {
    const r = this.currentToken;
    switch (e) {
      case t.QUOTATION_MARK: {
        this.state = s.AFTER_DOCTYPE_SYSTEM_IDENTIFIER;
        break;
      }
      case t.NULL: {
        this._err(i.unexpectedNullCharacter), r.systemId += _;
        break;
      }
      case t.GREATER_THAN_SIGN: {
        this._err(i.abruptDoctypeSystemIdentifier), r.forceQuirks = !0, this.emitCurrentDoctype(r), this.state = s.DATA;
        break;
      }
      case t.EOF: {
        this._err(i.eofInDoctype), r.forceQuirks = !0, this.emitCurrentDoctype(r), this._emitEOFToken();
        break;
      }
      default:
        r.systemId += String.fromCodePoint(e);
    }
  }
  // DOCTYPE system identifier (single-quoted) state
  //------------------------------------------------------------------
  _stateDoctypeSystemIdentifierSingleQuoted(e) {
    const r = this.currentToken;
    switch (e) {
      case t.APOSTROPHE: {
        this.state = s.AFTER_DOCTYPE_SYSTEM_IDENTIFIER;
        break;
      }
      case t.NULL: {
        this._err(i.unexpectedNullCharacter), r.systemId += _;
        break;
      }
      case t.GREATER_THAN_SIGN: {
        this._err(i.abruptDoctypeSystemIdentifier), r.forceQuirks = !0, this.emitCurrentDoctype(r), this.state = s.DATA;
        break;
      }
      case t.EOF: {
        this._err(i.eofInDoctype), r.forceQuirks = !0, this.emitCurrentDoctype(r), this._emitEOFToken();
        break;
      }
      default:
        r.systemId += String.fromCodePoint(e);
    }
  }
  // After DOCTYPE system identifier state
  //------------------------------------------------------------------
  _stateAfterDoctypeSystemIdentifier(e) {
    const r = this.currentToken;
    switch (e) {
      case t.SPACE:
      case t.LINE_FEED:
      case t.TABULATION:
      case t.FORM_FEED:
        break;
      case t.GREATER_THAN_SIGN: {
        this.emitCurrentDoctype(r), this.state = s.DATA;
        break;
      }
      case t.EOF: {
        this._err(i.eofInDoctype), r.forceQuirks = !0, this.emitCurrentDoctype(r), this._emitEOFToken();
        break;
      }
      default:
        this._err(i.unexpectedCharacterAfterDoctypeSystemIdentifier), this.state = s.BOGUS_DOCTYPE, this._stateBogusDoctype(e);
    }
  }
  // Bogus DOCTYPE state
  //------------------------------------------------------------------
  _stateBogusDoctype(e) {
    const r = this.currentToken;
    switch (e) {
      case t.GREATER_THAN_SIGN: {
        this.emitCurrentDoctype(r), this.state = s.DATA;
        break;
      }
      case t.NULL: {
        this._err(i.unexpectedNullCharacter);
        break;
      }
      case t.EOF: {
        this.emitCurrentDoctype(r), this._emitEOFToken();
        break;
      }
    }
  }
  // CDATA section state
  //------------------------------------------------------------------
  _stateCdataSection(e) {
    switch (e) {
      case t.RIGHT_SQUARE_BRACKET: {
        this.state = s.CDATA_SECTION_BRACKET;
        break;
      }
      case t.EOF: {
        this._err(i.eofInCdata), this._emitEOFToken();
        break;
      }
      default:
        this._emitCodePoint(e);
    }
  }
  // CDATA section bracket state
  //------------------------------------------------------------------
  _stateCdataSectionBracket(e) {
    e === t.RIGHT_SQUARE_BRACKET ? this.state = s.CDATA_SECTION_END : (this._emitChars("]"), this.state = s.CDATA_SECTION, this._stateCdataSection(e));
  }
  // CDATA section end state
  //------------------------------------------------------------------
  _stateCdataSectionEnd(e) {
    switch (e) {
      case t.GREATER_THAN_SIGN: {
        this.state = s.DATA;
        break;
      }
      case t.RIGHT_SQUARE_BRACKET: {
        this._emitChars("]");
        break;
      }
      default:
        this._emitChars("]]"), this.state = s.CDATA_SECTION, this._stateCdataSection(e);
    }
  }
  // Character reference state
  //------------------------------------------------------------------
  _stateCharacterReference() {
    let e = this.entityDecoder.write(this.preprocessor.html, this.preprocessor.pos);
    if (e < 0)
      if (this.preprocessor.lastChunkWritten)
        e = this.entityDecoder.end();
      else {
        this.active = !1, this.preprocessor.pos = this.preprocessor.html.length - 1, this.consumedAfterSnapshot = 0, this.preprocessor.endOfChunkHit = !0;
        return;
      }
    e === 0 ? (this.preprocessor.pos = this.entityStartPos, this._flushCodePointConsumedAsCharacterReference(t.AMPERSAND), this.state = !this._isCharacterReferenceInAttribute() && S(this.preprocessor.peek(1)) ? s.AMBIGUOUS_AMPERSAND : this.returnState) : this.state = this.returnState;
  }
  // Ambiguos ampersand state
  //------------------------------------------------------------------
  _stateAmbiguousAmpersand(e) {
    S(e) ? this._flushCodePointConsumedAsCharacterReference(e) : (e === t.SEMICOLON && this._err(i.unknownNamedCharacterReference), this.state = this.returnState, this._callState(e));
  }
}
export {
  y as Tokenizer,
  H as TokenizerMode
};
