import { CODE_POINTS as e, SEQUENCES as t, isControlCodePoint as n, isSurrogate as r, isUndefinedCodePoint as i } from "../common/unicode.js";
import { ERR as a } from "../common/error-codes.js";
import { Preprocessor as o } from "./preprocessor.js";
import { TokenType as s, getTokenAttr as c } from "../common/token.js";
import { htmlDecodeTree as l } from "../../../../../entities/dist/esm/generated/decode-data-html.js";
import { DecodingMode as u, EntityDecoder as d } from "../../../../../entities/dist/esm/decode.js";
import { TAG_ID as f, getTagID as p } from "../common/html.js";
//#region ../../node_modules/hast-util-raw/node_modules/parse5/dist/tokenizer/index.js
var m;
(function(e) {
	e[e.DATA = 0] = "DATA", e[e.RCDATA = 1] = "RCDATA", e[e.RAWTEXT = 2] = "RAWTEXT", e[e.SCRIPT_DATA = 3] = "SCRIPT_DATA", e[e.PLAINTEXT = 4] = "PLAINTEXT", e[e.TAG_OPEN = 5] = "TAG_OPEN", e[e.END_TAG_OPEN = 6] = "END_TAG_OPEN", e[e.TAG_NAME = 7] = "TAG_NAME", e[e.RCDATA_LESS_THAN_SIGN = 8] = "RCDATA_LESS_THAN_SIGN", e[e.RCDATA_END_TAG_OPEN = 9] = "RCDATA_END_TAG_OPEN", e[e.RCDATA_END_TAG_NAME = 10] = "RCDATA_END_TAG_NAME", e[e.RAWTEXT_LESS_THAN_SIGN = 11] = "RAWTEXT_LESS_THAN_SIGN", e[e.RAWTEXT_END_TAG_OPEN = 12] = "RAWTEXT_END_TAG_OPEN", e[e.RAWTEXT_END_TAG_NAME = 13] = "RAWTEXT_END_TAG_NAME", e[e.SCRIPT_DATA_LESS_THAN_SIGN = 14] = "SCRIPT_DATA_LESS_THAN_SIGN", e[e.SCRIPT_DATA_END_TAG_OPEN = 15] = "SCRIPT_DATA_END_TAG_OPEN", e[e.SCRIPT_DATA_END_TAG_NAME = 16] = "SCRIPT_DATA_END_TAG_NAME", e[e.SCRIPT_DATA_ESCAPE_START = 17] = "SCRIPT_DATA_ESCAPE_START", e[e.SCRIPT_DATA_ESCAPE_START_DASH = 18] = "SCRIPT_DATA_ESCAPE_START_DASH", e[e.SCRIPT_DATA_ESCAPED = 19] = "SCRIPT_DATA_ESCAPED", e[e.SCRIPT_DATA_ESCAPED_DASH = 20] = "SCRIPT_DATA_ESCAPED_DASH", e[e.SCRIPT_DATA_ESCAPED_DASH_DASH = 21] = "SCRIPT_DATA_ESCAPED_DASH_DASH", e[e.SCRIPT_DATA_ESCAPED_LESS_THAN_SIGN = 22] = "SCRIPT_DATA_ESCAPED_LESS_THAN_SIGN", e[e.SCRIPT_DATA_ESCAPED_END_TAG_OPEN = 23] = "SCRIPT_DATA_ESCAPED_END_TAG_OPEN", e[e.SCRIPT_DATA_ESCAPED_END_TAG_NAME = 24] = "SCRIPT_DATA_ESCAPED_END_TAG_NAME", e[e.SCRIPT_DATA_DOUBLE_ESCAPE_START = 25] = "SCRIPT_DATA_DOUBLE_ESCAPE_START", e[e.SCRIPT_DATA_DOUBLE_ESCAPED = 26] = "SCRIPT_DATA_DOUBLE_ESCAPED", e[e.SCRIPT_DATA_DOUBLE_ESCAPED_DASH = 27] = "SCRIPT_DATA_DOUBLE_ESCAPED_DASH", e[e.SCRIPT_DATA_DOUBLE_ESCAPED_DASH_DASH = 28] = "SCRIPT_DATA_DOUBLE_ESCAPED_DASH_DASH", e[e.SCRIPT_DATA_DOUBLE_ESCAPED_LESS_THAN_SIGN = 29] = "SCRIPT_DATA_DOUBLE_ESCAPED_LESS_THAN_SIGN", e[e.SCRIPT_DATA_DOUBLE_ESCAPE_END = 30] = "SCRIPT_DATA_DOUBLE_ESCAPE_END", e[e.BEFORE_ATTRIBUTE_NAME = 31] = "BEFORE_ATTRIBUTE_NAME", e[e.ATTRIBUTE_NAME = 32] = "ATTRIBUTE_NAME", e[e.AFTER_ATTRIBUTE_NAME = 33] = "AFTER_ATTRIBUTE_NAME", e[e.BEFORE_ATTRIBUTE_VALUE = 34] = "BEFORE_ATTRIBUTE_VALUE", e[e.ATTRIBUTE_VALUE_DOUBLE_QUOTED = 35] = "ATTRIBUTE_VALUE_DOUBLE_QUOTED", e[e.ATTRIBUTE_VALUE_SINGLE_QUOTED = 36] = "ATTRIBUTE_VALUE_SINGLE_QUOTED", e[e.ATTRIBUTE_VALUE_UNQUOTED = 37] = "ATTRIBUTE_VALUE_UNQUOTED", e[e.AFTER_ATTRIBUTE_VALUE_QUOTED = 38] = "AFTER_ATTRIBUTE_VALUE_QUOTED", e[e.SELF_CLOSING_START_TAG = 39] = "SELF_CLOSING_START_TAG", e[e.BOGUS_COMMENT = 40] = "BOGUS_COMMENT", e[e.MARKUP_DECLARATION_OPEN = 41] = "MARKUP_DECLARATION_OPEN", e[e.COMMENT_START = 42] = "COMMENT_START", e[e.COMMENT_START_DASH = 43] = "COMMENT_START_DASH", e[e.COMMENT = 44] = "COMMENT", e[e.COMMENT_LESS_THAN_SIGN = 45] = "COMMENT_LESS_THAN_SIGN", e[e.COMMENT_LESS_THAN_SIGN_BANG = 46] = "COMMENT_LESS_THAN_SIGN_BANG", e[e.COMMENT_LESS_THAN_SIGN_BANG_DASH = 47] = "COMMENT_LESS_THAN_SIGN_BANG_DASH", e[e.COMMENT_LESS_THAN_SIGN_BANG_DASH_DASH = 48] = "COMMENT_LESS_THAN_SIGN_BANG_DASH_DASH", e[e.COMMENT_END_DASH = 49] = "COMMENT_END_DASH", e[e.COMMENT_END = 50] = "COMMENT_END", e[e.COMMENT_END_BANG = 51] = "COMMENT_END_BANG", e[e.DOCTYPE = 52] = "DOCTYPE", e[e.BEFORE_DOCTYPE_NAME = 53] = "BEFORE_DOCTYPE_NAME", e[e.DOCTYPE_NAME = 54] = "DOCTYPE_NAME", e[e.AFTER_DOCTYPE_NAME = 55] = "AFTER_DOCTYPE_NAME", e[e.AFTER_DOCTYPE_PUBLIC_KEYWORD = 56] = "AFTER_DOCTYPE_PUBLIC_KEYWORD", e[e.BEFORE_DOCTYPE_PUBLIC_IDENTIFIER = 57] = "BEFORE_DOCTYPE_PUBLIC_IDENTIFIER", e[e.DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED = 58] = "DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED", e[e.DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED = 59] = "DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED", e[e.AFTER_DOCTYPE_PUBLIC_IDENTIFIER = 60] = "AFTER_DOCTYPE_PUBLIC_IDENTIFIER", e[e.BETWEEN_DOCTYPE_PUBLIC_AND_SYSTEM_IDENTIFIERS = 61] = "BETWEEN_DOCTYPE_PUBLIC_AND_SYSTEM_IDENTIFIERS", e[e.AFTER_DOCTYPE_SYSTEM_KEYWORD = 62] = "AFTER_DOCTYPE_SYSTEM_KEYWORD", e[e.BEFORE_DOCTYPE_SYSTEM_IDENTIFIER = 63] = "BEFORE_DOCTYPE_SYSTEM_IDENTIFIER", e[e.DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED = 64] = "DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED", e[e.DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED = 65] = "DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED", e[e.AFTER_DOCTYPE_SYSTEM_IDENTIFIER = 66] = "AFTER_DOCTYPE_SYSTEM_IDENTIFIER", e[e.BOGUS_DOCTYPE = 67] = "BOGUS_DOCTYPE", e[e.CDATA_SECTION = 68] = "CDATA_SECTION", e[e.CDATA_SECTION_BRACKET = 69] = "CDATA_SECTION_BRACKET", e[e.CDATA_SECTION_END = 70] = "CDATA_SECTION_END", e[e.CHARACTER_REFERENCE = 71] = "CHARACTER_REFERENCE", e[e.AMBIGUOUS_AMPERSAND = 72] = "AMBIGUOUS_AMPERSAND";
})(m ||= {});
var h = {
	DATA: m.DATA,
	RCDATA: m.RCDATA,
	RAWTEXT: m.RAWTEXT,
	SCRIPT_DATA: m.SCRIPT_DATA,
	PLAINTEXT: m.PLAINTEXT,
	CDATA_SECTION: m.CDATA_SECTION
};
function g(t) {
	return t >= e.DIGIT_0 && t <= e.DIGIT_9;
}
function _(t) {
	return t >= e.LATIN_CAPITAL_A && t <= e.LATIN_CAPITAL_Z;
}
function v(t) {
	return t >= e.LATIN_SMALL_A && t <= e.LATIN_SMALL_Z;
}
function y(e) {
	return v(e) || _(e);
}
function b(e) {
	return y(e) || g(e);
}
function x(e) {
	return e + 32;
}
function S(t) {
	return t === e.SPACE || t === e.LINE_FEED || t === e.TABULATION || t === e.FORM_FEED;
}
function C(t) {
	return S(t) || t === e.SOLIDUS || t === e.GREATER_THAN_SIGN;
}
function w(t) {
	return t === e.NULL ? a.nullCharacterReference : t > 1114111 ? a.characterReferenceOutsideUnicodeRange : r(t) ? a.surrogateCharacterReference : i(t) ? a.noncharacterCharacterReference : n(t) || t === e.CARRIAGE_RETURN ? a.controlCharacterReference : null;
}
var T = class {
	constructor(e, t) {
		this.options = e, this.handler = t, this.paused = !1, this.inLoop = !1, this.inForeignNode = !1, this.lastStartTagName = "", this.active = !1, this.state = m.DATA, this.returnState = m.DATA, this.entityStartPos = 0, this.consumedAfterSnapshot = -1, this.currentCharacterToken = null, this.currentToken = null, this.currentAttr = {
			name: "",
			value: ""
		}, this.preprocessor = new o(t), this.currentLocation = this.getCurrentLocation(-1), this.entityDecoder = new d(l, (e, t) => {
			this.preprocessor.pos = this.entityStartPos + t - 1, this._flushCodePointConsumedAsCharacterReference(e);
		}, t.onParseError ? {
			missingSemicolonAfterCharacterReference: () => {
				this._err(a.missingSemicolonAfterCharacterReference, 1);
			},
			absenceOfDigitsInNumericCharacterReference: (e) => {
				this._err(a.absenceOfDigitsInNumericCharacterReference, this.entityStartPos - this.preprocessor.pos + e);
			},
			validateNumericCharacterReference: (e) => {
				let t = w(e);
				t && this._err(t, 1);
			}
		} : void 0);
	}
	_err(e, t = 0) {
		var n, r;
		(r = (n = this.handler).onParseError) == null || r.call(n, this.preprocessor.getError(e, t));
	}
	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;
				let e = this._consume();
				this._ensureHibernation() || this._callState(e);
			}
			this.inLoop = !1;
		}
	}
	pause() {
		this.paused = !0;
	}
	resume(e) {
		if (!this.paused) throw Error("Parser was already resumed");
		this.paused = !1, !this.inLoop && (this._runParsingLoop(), this.paused || e?.());
	}
	write(e, t, n) {
		this.active = !0, this.preprocessor.write(e, t), this._runParsingLoop(), this.paused || n?.();
	}
	insertHtmlAtCurrentPos(e) {
		this.active = !0, this.preprocessor.insertHtmlAtCurrentPos(e), this._runParsingLoop();
	}
	_ensureHibernation() {
		return this.preprocessor.endOfChunkHit ? (this.preprocessor.retreat(this.consumedAfterSnapshot), this.consumedAfterSnapshot = 0, this.active = !1, !0) : !1;
	}
	_consume() {
		return this.consumedAfterSnapshot++, this.preprocessor.advance();
	}
	_advanceBy(e) {
		this.consumedAfterSnapshot += e;
		for (let t = 0; t < e; t++) this.preprocessor.advance();
	}
	_consumeSequenceIfMatch(e, t) {
		return this.preprocessor.startsWith(e, t) ? (this._advanceBy(e.length - 1), !0) : !1;
	}
	_createStartTagToken() {
		this.currentToken = {
			type: s.START_TAG,
			tagName: "",
			tagID: f.UNKNOWN,
			selfClosing: !1,
			ackSelfClosing: !1,
			attrs: [],
			location: this.getCurrentLocation(1)
		};
	}
	_createEndTagToken() {
		this.currentToken = {
			type: s.END_TAG,
			tagName: "",
			tagID: f.UNKNOWN,
			selfClosing: !1,
			ackSelfClosing: !1,
			attrs: [],
			location: this.getCurrentLocation(2)
		};
	}
	_createCommentToken(e) {
		this.currentToken = {
			type: s.COMMENT,
			data: "",
			location: this.getCurrentLocation(e)
		};
	}
	_createDoctypeToken(e) {
		this.currentToken = {
			type: s.DOCTYPE,
			name: e,
			forceQuirks: !1,
			publicId: null,
			systemId: null,
			location: this.currentLocation
		};
	}
	_createCharacterToken(e, t) {
		this.currentCharacterToken = {
			type: e,
			chars: t,
			location: this.currentLocation
		};
	}
	_createAttr(e) {
		this.currentAttr = {
			name: e,
			value: ""
		}, this.currentLocation = this.getCurrentLocation(0);
	}
	_leaveAttrName() {
		var e;
		let t = this.currentToken;
		if (c(t, this.currentAttr.name) === null) {
			if (t.attrs.push(this.currentAttr), t.location && this.currentLocation) {
				let n = (e = t.location).attrs ?? (e.attrs = Object.create(null));
				n[this.currentAttr.name] = this.currentLocation, this._leaveAttrValue();
			}
		} else this._err(a.duplicateAttribute);
	}
	_leaveAttrValue() {
		this.currentLocation && (this.currentLocation.endLine = this.preprocessor.line, this.currentLocation.endCol = this.preprocessor.col, this.currentLocation.endOffset = this.preprocessor.offset);
	}
	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() {
		let e = this.currentToken;
		this.prepareToken(e), e.tagID = p(e.tagName), e.type === s.START_TAG ? (this.lastStartTagName = e.tagName, this.handler.onStartTag(e)) : (e.attrs.length > 0 && this._err(a.endTagWithAttributes), e.selfClosing && this._err(a.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 s.CHARACTER:
					this.handler.onCharacter(this.currentCharacterToken);
					break;
				case s.NULL_CHARACTER:
					this.handler.onNullCharacter(this.currentCharacterToken);
					break;
				case s.WHITESPACE_CHARACTER:
					this.handler.onWhitespaceCharacter(this.currentCharacterToken);
					break;
			}
			this.currentCharacterToken = null;
		}
	}
	_emitEOFToken() {
		let e = this.getCurrentLocation(0);
		e && (e.endLine = e.startLine, e.endCol = e.startCol, e.endOffset = e.startOffset), this._emitCurrentCharacterToken(e), this.handler.onEof({
			type: s.EOF,
			location: e
		}), this.active = !1;
	}
	_appendCharToCurrentCharacterToken(e, t) {
		if (this.currentCharacterToken) if (this.currentCharacterToken.type === e) {
			this.currentCharacterToken.chars += t;
			return;
		} else this.currentLocation = this.getCurrentLocation(0), this._emitCurrentCharacterToken(this.currentLocation), this.preprocessor.dropParsedChunk();
		this._createCharacterToken(e, t);
	}
	_emitCodePoint(t) {
		let n = S(t) ? s.WHITESPACE_CHARACTER : t === e.NULL ? s.NULL_CHARACTER : s.CHARACTER;
		this._appendCharToCurrentCharacterToken(n, String.fromCodePoint(t));
	}
	_emitChars(e) {
		this._appendCharToCurrentCharacterToken(s.CHARACTER, e);
	}
	_startCharacterReference() {
		this.returnState = this.state, this.state = m.CHARACTER_REFERENCE, this.entityStartPos = this.preprocessor.pos, this.entityDecoder.startEntity(this._isCharacterReferenceInAttribute() ? u.Attribute : u.Legacy);
	}
	_isCharacterReferenceInAttribute() {
		return this.returnState === m.ATTRIBUTE_VALUE_DOUBLE_QUOTED || this.returnState === m.ATTRIBUTE_VALUE_SINGLE_QUOTED || this.returnState === m.ATTRIBUTE_VALUE_UNQUOTED;
	}
	_flushCodePointConsumedAsCharacterReference(e) {
		this._isCharacterReferenceInAttribute() ? this.currentAttr.value += String.fromCodePoint(e) : this._emitCodePoint(e);
	}
	_callState(e) {
		switch (this.state) {
			case m.DATA:
				this._stateData(e);
				break;
			case m.RCDATA:
				this._stateRcdata(e);
				break;
			case m.RAWTEXT:
				this._stateRawtext(e);
				break;
			case m.SCRIPT_DATA:
				this._stateScriptData(e);
				break;
			case m.PLAINTEXT:
				this._statePlaintext(e);
				break;
			case m.TAG_OPEN:
				this._stateTagOpen(e);
				break;
			case m.END_TAG_OPEN:
				this._stateEndTagOpen(e);
				break;
			case m.TAG_NAME:
				this._stateTagName(e);
				break;
			case m.RCDATA_LESS_THAN_SIGN:
				this._stateRcdataLessThanSign(e);
				break;
			case m.RCDATA_END_TAG_OPEN:
				this._stateRcdataEndTagOpen(e);
				break;
			case m.RCDATA_END_TAG_NAME:
				this._stateRcdataEndTagName(e);
				break;
			case m.RAWTEXT_LESS_THAN_SIGN:
				this._stateRawtextLessThanSign(e);
				break;
			case m.RAWTEXT_END_TAG_OPEN:
				this._stateRawtextEndTagOpen(e);
				break;
			case m.RAWTEXT_END_TAG_NAME:
				this._stateRawtextEndTagName(e);
				break;
			case m.SCRIPT_DATA_LESS_THAN_SIGN:
				this._stateScriptDataLessThanSign(e);
				break;
			case m.SCRIPT_DATA_END_TAG_OPEN:
				this._stateScriptDataEndTagOpen(e);
				break;
			case m.SCRIPT_DATA_END_TAG_NAME:
				this._stateScriptDataEndTagName(e);
				break;
			case m.SCRIPT_DATA_ESCAPE_START:
				this._stateScriptDataEscapeStart(e);
				break;
			case m.SCRIPT_DATA_ESCAPE_START_DASH:
				this._stateScriptDataEscapeStartDash(e);
				break;
			case m.SCRIPT_DATA_ESCAPED:
				this._stateScriptDataEscaped(e);
				break;
			case m.SCRIPT_DATA_ESCAPED_DASH:
				this._stateScriptDataEscapedDash(e);
				break;
			case m.SCRIPT_DATA_ESCAPED_DASH_DASH:
				this._stateScriptDataEscapedDashDash(e);
				break;
			case m.SCRIPT_DATA_ESCAPED_LESS_THAN_SIGN:
				this._stateScriptDataEscapedLessThanSign(e);
				break;
			case m.SCRIPT_DATA_ESCAPED_END_TAG_OPEN:
				this._stateScriptDataEscapedEndTagOpen(e);
				break;
			case m.SCRIPT_DATA_ESCAPED_END_TAG_NAME:
				this._stateScriptDataEscapedEndTagName(e);
				break;
			case m.SCRIPT_DATA_DOUBLE_ESCAPE_START:
				this._stateScriptDataDoubleEscapeStart(e);
				break;
			case m.SCRIPT_DATA_DOUBLE_ESCAPED:
				this._stateScriptDataDoubleEscaped(e);
				break;
			case m.SCRIPT_DATA_DOUBLE_ESCAPED_DASH:
				this._stateScriptDataDoubleEscapedDash(e);
				break;
			case m.SCRIPT_DATA_DOUBLE_ESCAPED_DASH_DASH:
				this._stateScriptDataDoubleEscapedDashDash(e);
				break;
			case m.SCRIPT_DATA_DOUBLE_ESCAPED_LESS_THAN_SIGN:
				this._stateScriptDataDoubleEscapedLessThanSign(e);
				break;
			case m.SCRIPT_DATA_DOUBLE_ESCAPE_END:
				this._stateScriptDataDoubleEscapeEnd(e);
				break;
			case m.BEFORE_ATTRIBUTE_NAME:
				this._stateBeforeAttributeName(e);
				break;
			case m.ATTRIBUTE_NAME:
				this._stateAttributeName(e);
				break;
			case m.AFTER_ATTRIBUTE_NAME:
				this._stateAfterAttributeName(e);
				break;
			case m.BEFORE_ATTRIBUTE_VALUE:
				this._stateBeforeAttributeValue(e);
				break;
			case m.ATTRIBUTE_VALUE_DOUBLE_QUOTED:
				this._stateAttributeValueDoubleQuoted(e);
				break;
			case m.ATTRIBUTE_VALUE_SINGLE_QUOTED:
				this._stateAttributeValueSingleQuoted(e);
				break;
			case m.ATTRIBUTE_VALUE_UNQUOTED:
				this._stateAttributeValueUnquoted(e);
				break;
			case m.AFTER_ATTRIBUTE_VALUE_QUOTED:
				this._stateAfterAttributeValueQuoted(e);
				break;
			case m.SELF_CLOSING_START_TAG:
				this._stateSelfClosingStartTag(e);
				break;
			case m.BOGUS_COMMENT:
				this._stateBogusComment(e);
				break;
			case m.MARKUP_DECLARATION_OPEN:
				this._stateMarkupDeclarationOpen(e);
				break;
			case m.COMMENT_START:
				this._stateCommentStart(e);
				break;
			case m.COMMENT_START_DASH:
				this._stateCommentStartDash(e);
				break;
			case m.COMMENT:
				this._stateComment(e);
				break;
			case m.COMMENT_LESS_THAN_SIGN:
				this._stateCommentLessThanSign(e);
				break;
			case m.COMMENT_LESS_THAN_SIGN_BANG:
				this._stateCommentLessThanSignBang(e);
				break;
			case m.COMMENT_LESS_THAN_SIGN_BANG_DASH:
				this._stateCommentLessThanSignBangDash(e);
				break;
			case m.COMMENT_LESS_THAN_SIGN_BANG_DASH_DASH:
				this._stateCommentLessThanSignBangDashDash(e);
				break;
			case m.COMMENT_END_DASH:
				this._stateCommentEndDash(e);
				break;
			case m.COMMENT_END:
				this._stateCommentEnd(e);
				break;
			case m.COMMENT_END_BANG:
				this._stateCommentEndBang(e);
				break;
			case m.DOCTYPE:
				this._stateDoctype(e);
				break;
			case m.BEFORE_DOCTYPE_NAME:
				this._stateBeforeDoctypeName(e);
				break;
			case m.DOCTYPE_NAME:
				this._stateDoctypeName(e);
				break;
			case m.AFTER_DOCTYPE_NAME:
				this._stateAfterDoctypeName(e);
				break;
			case m.AFTER_DOCTYPE_PUBLIC_KEYWORD:
				this._stateAfterDoctypePublicKeyword(e);
				break;
			case m.BEFORE_DOCTYPE_PUBLIC_IDENTIFIER:
				this._stateBeforeDoctypePublicIdentifier(e);
				break;
			case m.DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED:
				this._stateDoctypePublicIdentifierDoubleQuoted(e);
				break;
			case m.DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED:
				this._stateDoctypePublicIdentifierSingleQuoted(e);
				break;
			case m.AFTER_DOCTYPE_PUBLIC_IDENTIFIER:
				this._stateAfterDoctypePublicIdentifier(e);
				break;
			case m.BETWEEN_DOCTYPE_PUBLIC_AND_SYSTEM_IDENTIFIERS:
				this._stateBetweenDoctypePublicAndSystemIdentifiers(e);
				break;
			case m.AFTER_DOCTYPE_SYSTEM_KEYWORD:
				this._stateAfterDoctypeSystemKeyword(e);
				break;
			case m.BEFORE_DOCTYPE_SYSTEM_IDENTIFIER:
				this._stateBeforeDoctypeSystemIdentifier(e);
				break;
			case m.DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED:
				this._stateDoctypeSystemIdentifierDoubleQuoted(e);
				break;
			case m.DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED:
				this._stateDoctypeSystemIdentifierSingleQuoted(e);
				break;
			case m.AFTER_DOCTYPE_SYSTEM_IDENTIFIER:
				this._stateAfterDoctypeSystemIdentifier(e);
				break;
			case m.BOGUS_DOCTYPE:
				this._stateBogusDoctype(e);
				break;
			case m.CDATA_SECTION:
				this._stateCdataSection(e);
				break;
			case m.CDATA_SECTION_BRACKET:
				this._stateCdataSectionBracket(e);
				break;
			case m.CDATA_SECTION_END:
				this._stateCdataSectionEnd(e);
				break;
			case m.CHARACTER_REFERENCE:
				this._stateCharacterReference();
				break;
			case m.AMBIGUOUS_AMPERSAND:
				this._stateAmbiguousAmpersand(e);
				break;
			default: throw Error("Unknown state");
		}
	}
	_stateData(t) {
		switch (t) {
			case e.LESS_THAN_SIGN:
				this.state = m.TAG_OPEN;
				break;
			case e.AMPERSAND:
				this._startCharacterReference();
				break;
			case e.NULL:
				this._err(a.unexpectedNullCharacter), this._emitCodePoint(t);
				break;
			case e.EOF:
				this._emitEOFToken();
				break;
			default: this._emitCodePoint(t);
		}
	}
	_stateRcdata(t) {
		switch (t) {
			case e.AMPERSAND:
				this._startCharacterReference();
				break;
			case e.LESS_THAN_SIGN:
				this.state = m.RCDATA_LESS_THAN_SIGN;
				break;
			case e.NULL:
				this._err(a.unexpectedNullCharacter), this._emitChars("�");
				break;
			case e.EOF:
				this._emitEOFToken();
				break;
			default: this._emitCodePoint(t);
		}
	}
	_stateRawtext(t) {
		switch (t) {
			case e.LESS_THAN_SIGN:
				this.state = m.RAWTEXT_LESS_THAN_SIGN;
				break;
			case e.NULL:
				this._err(a.unexpectedNullCharacter), this._emitChars("�");
				break;
			case e.EOF:
				this._emitEOFToken();
				break;
			default: this._emitCodePoint(t);
		}
	}
	_stateScriptData(t) {
		switch (t) {
			case e.LESS_THAN_SIGN:
				this.state = m.SCRIPT_DATA_LESS_THAN_SIGN;
				break;
			case e.NULL:
				this._err(a.unexpectedNullCharacter), this._emitChars("�");
				break;
			case e.EOF:
				this._emitEOFToken();
				break;
			default: this._emitCodePoint(t);
		}
	}
	_statePlaintext(t) {
		switch (t) {
			case e.NULL:
				this._err(a.unexpectedNullCharacter), this._emitChars("�");
				break;
			case e.EOF:
				this._emitEOFToken();
				break;
			default: this._emitCodePoint(t);
		}
	}
	_stateTagOpen(t) {
		if (y(t)) this._createStartTagToken(), this.state = m.TAG_NAME, this._stateTagName(t);
		else switch (t) {
			case e.EXCLAMATION_MARK:
				this.state = m.MARKUP_DECLARATION_OPEN;
				break;
			case e.SOLIDUS:
				this.state = m.END_TAG_OPEN;
				break;
			case e.QUESTION_MARK:
				this._err(a.unexpectedQuestionMarkInsteadOfTagName), this._createCommentToken(1), this.state = m.BOGUS_COMMENT, this._stateBogusComment(t);
				break;
			case e.EOF:
				this._err(a.eofBeforeTagName), this._emitChars("<"), this._emitEOFToken();
				break;
			default: this._err(a.invalidFirstCharacterOfTagName), this._emitChars("<"), this.state = m.DATA, this._stateData(t);
		}
	}
	_stateEndTagOpen(t) {
		if (y(t)) this._createEndTagToken(), this.state = m.TAG_NAME, this._stateTagName(t);
		else switch (t) {
			case e.GREATER_THAN_SIGN:
				this._err(a.missingEndTagName), this.state = m.DATA;
				break;
			case e.EOF:
				this._err(a.eofBeforeTagName), this._emitChars("</"), this._emitEOFToken();
				break;
			default: this._err(a.invalidFirstCharacterOfTagName), this._createCommentToken(2), this.state = m.BOGUS_COMMENT, this._stateBogusComment(t);
		}
	}
	_stateTagName(t) {
		let n = this.currentToken;
		switch (t) {
			case e.SPACE:
			case e.LINE_FEED:
			case e.TABULATION:
			case e.FORM_FEED:
				this.state = m.BEFORE_ATTRIBUTE_NAME;
				break;
			case e.SOLIDUS:
				this.state = m.SELF_CLOSING_START_TAG;
				break;
			case e.GREATER_THAN_SIGN:
				this.state = m.DATA, this.emitCurrentTagToken();
				break;
			case e.NULL:
				this._err(a.unexpectedNullCharacter), n.tagName += "�";
				break;
			case e.EOF:
				this._err(a.eofInTag), this._emitEOFToken();
				break;
			default: n.tagName += String.fromCodePoint(_(t) ? x(t) : t);
		}
	}
	_stateRcdataLessThanSign(t) {
		t === e.SOLIDUS ? this.state = m.RCDATA_END_TAG_OPEN : (this._emitChars("<"), this.state = m.RCDATA, this._stateRcdata(t));
	}
	_stateRcdataEndTagOpen(e) {
		y(e) ? (this.state = m.RCDATA_END_TAG_NAME, this._stateRcdataEndTagName(e)) : (this._emitChars("</"), this.state = m.RCDATA, this._stateRcdata(e));
	}
	handleSpecialEndTag(t) {
		if (!this.preprocessor.startsWith(this.lastStartTagName, !1)) return !this._ensureHibernation();
		this._createEndTagToken();
		let n = this.currentToken;
		switch (n.tagName = this.lastStartTagName, this.preprocessor.peek(this.lastStartTagName.length)) {
			case e.SPACE:
			case e.LINE_FEED:
			case e.TABULATION:
			case e.FORM_FEED: return this._advanceBy(this.lastStartTagName.length), this.state = m.BEFORE_ATTRIBUTE_NAME, !1;
			case e.SOLIDUS: return this._advanceBy(this.lastStartTagName.length), this.state = m.SELF_CLOSING_START_TAG, !1;
			case e.GREATER_THAN_SIGN: return this._advanceBy(this.lastStartTagName.length), this.emitCurrentTagToken(), this.state = m.DATA, !1;
			default: return !this._ensureHibernation();
		}
	}
	_stateRcdataEndTagName(e) {
		this.handleSpecialEndTag(e) && (this._emitChars("</"), this.state = m.RCDATA, this._stateRcdata(e));
	}
	_stateRawtextLessThanSign(t) {
		t === e.SOLIDUS ? this.state = m.RAWTEXT_END_TAG_OPEN : (this._emitChars("<"), this.state = m.RAWTEXT, this._stateRawtext(t));
	}
	_stateRawtextEndTagOpen(e) {
		y(e) ? (this.state = m.RAWTEXT_END_TAG_NAME, this._stateRawtextEndTagName(e)) : (this._emitChars("</"), this.state = m.RAWTEXT, this._stateRawtext(e));
	}
	_stateRawtextEndTagName(e) {
		this.handleSpecialEndTag(e) && (this._emitChars("</"), this.state = m.RAWTEXT, this._stateRawtext(e));
	}
	_stateScriptDataLessThanSign(t) {
		switch (t) {
			case e.SOLIDUS:
				this.state = m.SCRIPT_DATA_END_TAG_OPEN;
				break;
			case e.EXCLAMATION_MARK:
				this.state = m.SCRIPT_DATA_ESCAPE_START, this._emitChars("<!");
				break;
			default: this._emitChars("<"), this.state = m.SCRIPT_DATA, this._stateScriptData(t);
		}
	}
	_stateScriptDataEndTagOpen(e) {
		y(e) ? (this.state = m.SCRIPT_DATA_END_TAG_NAME, this._stateScriptDataEndTagName(e)) : (this._emitChars("</"), this.state = m.SCRIPT_DATA, this._stateScriptData(e));
	}
	_stateScriptDataEndTagName(e) {
		this.handleSpecialEndTag(e) && (this._emitChars("</"), this.state = m.SCRIPT_DATA, this._stateScriptData(e));
	}
	_stateScriptDataEscapeStart(t) {
		t === e.HYPHEN_MINUS ? (this.state = m.SCRIPT_DATA_ESCAPE_START_DASH, this._emitChars("-")) : (this.state = m.SCRIPT_DATA, this._stateScriptData(t));
	}
	_stateScriptDataEscapeStartDash(t) {
		t === e.HYPHEN_MINUS ? (this.state = m.SCRIPT_DATA_ESCAPED_DASH_DASH, this._emitChars("-")) : (this.state = m.SCRIPT_DATA, this._stateScriptData(t));
	}
	_stateScriptDataEscaped(t) {
		switch (t) {
			case e.HYPHEN_MINUS:
				this.state = m.SCRIPT_DATA_ESCAPED_DASH, this._emitChars("-");
				break;
			case e.LESS_THAN_SIGN:
				this.state = m.SCRIPT_DATA_ESCAPED_LESS_THAN_SIGN;
				break;
			case e.NULL:
				this._err(a.unexpectedNullCharacter), this._emitChars("�");
				break;
			case e.EOF:
				this._err(a.eofInScriptHtmlCommentLikeText), this._emitEOFToken();
				break;
			default: this._emitCodePoint(t);
		}
	}
	_stateScriptDataEscapedDash(t) {
		switch (t) {
			case e.HYPHEN_MINUS:
				this.state = m.SCRIPT_DATA_ESCAPED_DASH_DASH, this._emitChars("-");
				break;
			case e.LESS_THAN_SIGN:
				this.state = m.SCRIPT_DATA_ESCAPED_LESS_THAN_SIGN;
				break;
			case e.NULL:
				this._err(a.unexpectedNullCharacter), this.state = m.SCRIPT_DATA_ESCAPED, this._emitChars("�");
				break;
			case e.EOF:
				this._err(a.eofInScriptHtmlCommentLikeText), this._emitEOFToken();
				break;
			default: this.state = m.SCRIPT_DATA_ESCAPED, this._emitCodePoint(t);
		}
	}
	_stateScriptDataEscapedDashDash(t) {
		switch (t) {
			case e.HYPHEN_MINUS:
				this._emitChars("-");
				break;
			case e.LESS_THAN_SIGN:
				this.state = m.SCRIPT_DATA_ESCAPED_LESS_THAN_SIGN;
				break;
			case e.GREATER_THAN_SIGN:
				this.state = m.SCRIPT_DATA, this._emitChars(">");
				break;
			case e.NULL:
				this._err(a.unexpectedNullCharacter), this.state = m.SCRIPT_DATA_ESCAPED, this._emitChars("�");
				break;
			case e.EOF:
				this._err(a.eofInScriptHtmlCommentLikeText), this._emitEOFToken();
				break;
			default: this.state = m.SCRIPT_DATA_ESCAPED, this._emitCodePoint(t);
		}
	}
	_stateScriptDataEscapedLessThanSign(t) {
		t === e.SOLIDUS ? this.state = m.SCRIPT_DATA_ESCAPED_END_TAG_OPEN : y(t) ? (this._emitChars("<"), this.state = m.SCRIPT_DATA_DOUBLE_ESCAPE_START, this._stateScriptDataDoubleEscapeStart(t)) : (this._emitChars("<"), this.state = m.SCRIPT_DATA_ESCAPED, this._stateScriptDataEscaped(t));
	}
	_stateScriptDataEscapedEndTagOpen(e) {
		y(e) ? (this.state = m.SCRIPT_DATA_ESCAPED_END_TAG_NAME, this._stateScriptDataEscapedEndTagName(e)) : (this._emitChars("</"), this.state = m.SCRIPT_DATA_ESCAPED, this._stateScriptDataEscaped(e));
	}
	_stateScriptDataEscapedEndTagName(e) {
		this.handleSpecialEndTag(e) && (this._emitChars("</"), this.state = m.SCRIPT_DATA_ESCAPED, this._stateScriptDataEscaped(e));
	}
	_stateScriptDataDoubleEscapeStart(e) {
		if (this.preprocessor.startsWith(t.SCRIPT, !1) && C(this.preprocessor.peek(t.SCRIPT.length))) {
			this._emitCodePoint(e);
			for (let e = 0; e < t.SCRIPT.length; e++) this._emitCodePoint(this._consume());
			this.state = m.SCRIPT_DATA_DOUBLE_ESCAPED;
		} else this._ensureHibernation() || (this.state = m.SCRIPT_DATA_ESCAPED, this._stateScriptDataEscaped(e));
	}
	_stateScriptDataDoubleEscaped(t) {
		switch (t) {
			case e.HYPHEN_MINUS:
				this.state = m.SCRIPT_DATA_DOUBLE_ESCAPED_DASH, this._emitChars("-");
				break;
			case e.LESS_THAN_SIGN:
				this.state = m.SCRIPT_DATA_DOUBLE_ESCAPED_LESS_THAN_SIGN, this._emitChars("<");
				break;
			case e.NULL:
				this._err(a.unexpectedNullCharacter), this._emitChars("�");
				break;
			case e.EOF:
				this._err(a.eofInScriptHtmlCommentLikeText), this._emitEOFToken();
				break;
			default: this._emitCodePoint(t);
		}
	}
	_stateScriptDataDoubleEscapedDash(t) {
		switch (t) {
			case e.HYPHEN_MINUS:
				this.state = m.SCRIPT_DATA_DOUBLE_ESCAPED_DASH_DASH, this._emitChars("-");
				break;
			case e.LESS_THAN_SIGN:
				this.state = m.SCRIPT_DATA_DOUBLE_ESCAPED_LESS_THAN_SIGN, this._emitChars("<");
				break;
			case e.NULL:
				this._err(a.unexpectedNullCharacter), this.state = m.SCRIPT_DATA_DOUBLE_ESCAPED, this._emitChars("�");
				break;
			case e.EOF:
				this._err(a.eofInScriptHtmlCommentLikeText), this._emitEOFToken();
				break;
			default: this.state = m.SCRIPT_DATA_DOUBLE_ESCAPED, this._emitCodePoint(t);
		}
	}
	_stateScriptDataDoubleEscapedDashDash(t) {
		switch (t) {
			case e.HYPHEN_MINUS:
				this._emitChars("-");
				break;
			case e.LESS_THAN_SIGN:
				this.state = m.SCRIPT_DATA_DOUBLE_ESCAPED_LESS_THAN_SIGN, this._emitChars("<");
				break;
			case e.GREATER_THAN_SIGN:
				this.state = m.SCRIPT_DATA, this._emitChars(">");
				break;
			case e.NULL:
				this._err(a.unexpectedNullCharacter), this.state = m.SCRIPT_DATA_DOUBLE_ESCAPED, this._emitChars("�");
				break;
			case e.EOF:
				this._err(a.eofInScriptHtmlCommentLikeText), this._emitEOFToken();
				break;
			default: this.state = m.SCRIPT_DATA_DOUBLE_ESCAPED, this._emitCodePoint(t);
		}
	}
	_stateScriptDataDoubleEscapedLessThanSign(t) {
		t === e.SOLIDUS ? (this.state = m.SCRIPT_DATA_DOUBLE_ESCAPE_END, this._emitChars("/")) : (this.state = m.SCRIPT_DATA_DOUBLE_ESCAPED, this._stateScriptDataDoubleEscaped(t));
	}
	_stateScriptDataDoubleEscapeEnd(e) {
		if (this.preprocessor.startsWith(t.SCRIPT, !1) && C(this.preprocessor.peek(t.SCRIPT.length))) {
			this._emitCodePoint(e);
			for (let e = 0; e < t.SCRIPT.length; e++) this._emitCodePoint(this._consume());
			this.state = m.SCRIPT_DATA_ESCAPED;
		} else this._ensureHibernation() || (this.state = m.SCRIPT_DATA_DOUBLE_ESCAPED, this._stateScriptDataDoubleEscaped(e));
	}
	_stateBeforeAttributeName(t) {
		switch (t) {
			case e.SPACE:
			case e.LINE_FEED:
			case e.TABULATION:
			case e.FORM_FEED: break;
			case e.SOLIDUS:
			case e.GREATER_THAN_SIGN:
			case e.EOF:
				this.state = m.AFTER_ATTRIBUTE_NAME, this._stateAfterAttributeName(t);
				break;
			case e.EQUALS_SIGN:
				this._err(a.unexpectedEqualsSignBeforeAttributeName), this._createAttr("="), this.state = m.ATTRIBUTE_NAME;
				break;
			default: this._createAttr(""), this.state = m.ATTRIBUTE_NAME, this._stateAttributeName(t);
		}
	}
	_stateAttributeName(t) {
		switch (t) {
			case e.SPACE:
			case e.LINE_FEED:
			case e.TABULATION:
			case e.FORM_FEED:
			case e.SOLIDUS:
			case e.GREATER_THAN_SIGN:
			case e.EOF:
				this._leaveAttrName(), this.state = m.AFTER_ATTRIBUTE_NAME, this._stateAfterAttributeName(t);
				break;
			case e.EQUALS_SIGN:
				this._leaveAttrName(), this.state = m.BEFORE_ATTRIBUTE_VALUE;
				break;
			case e.QUOTATION_MARK:
			case e.APOSTROPHE:
			case e.LESS_THAN_SIGN:
				this._err(a.unexpectedCharacterInAttributeName), this.currentAttr.name += String.fromCodePoint(t);
				break;
			case e.NULL:
				this._err(a.unexpectedNullCharacter), this.currentAttr.name += "�";
				break;
			default: this.currentAttr.name += String.fromCodePoint(_(t) ? x(t) : t);
		}
	}
	_stateAfterAttributeName(t) {
		switch (t) {
			case e.SPACE:
			case e.LINE_FEED:
			case e.TABULATION:
			case e.FORM_FEED: break;
			case e.SOLIDUS:
				this.state = m.SELF_CLOSING_START_TAG;
				break;
			case e.EQUALS_SIGN:
				this.state = m.BEFORE_ATTRIBUTE_VALUE;
				break;
			case e.GREATER_THAN_SIGN:
				this.state = m.DATA, this.emitCurrentTagToken();
				break;
			case e.EOF:
				this._err(a.eofInTag), this._emitEOFToken();
				break;
			default: this._createAttr(""), this.state = m.ATTRIBUTE_NAME, this._stateAttributeName(t);
		}
	}
	_stateBeforeAttributeValue(t) {
		switch (t) {
			case e.SPACE:
			case e.LINE_FEED:
			case e.TABULATION:
			case e.FORM_FEED: break;
			case e.QUOTATION_MARK:
				this.state = m.ATTRIBUTE_VALUE_DOUBLE_QUOTED;
				break;
			case e.APOSTROPHE:
				this.state = m.ATTRIBUTE_VALUE_SINGLE_QUOTED;
				break;
			case e.GREATER_THAN_SIGN:
				this._err(a.missingAttributeValue), this.state = m.DATA, this.emitCurrentTagToken();
				break;
			default: this.state = m.ATTRIBUTE_VALUE_UNQUOTED, this._stateAttributeValueUnquoted(t);
		}
	}
	_stateAttributeValueDoubleQuoted(t) {
		switch (t) {
			case e.QUOTATION_MARK:
				this.state = m.AFTER_ATTRIBUTE_VALUE_QUOTED;
				break;
			case e.AMPERSAND:
				this._startCharacterReference();
				break;
			case e.NULL:
				this._err(a.unexpectedNullCharacter), this.currentAttr.value += "�";
				break;
			case e.EOF:
				this._err(a.eofInTag), this._emitEOFToken();
				break;
			default: this.currentAttr.value += String.fromCodePoint(t);
		}
	}
	_stateAttributeValueSingleQuoted(t) {
		switch (t) {
			case e.APOSTROPHE:
				this.state = m.AFTER_ATTRIBUTE_VALUE_QUOTED;
				break;
			case e.AMPERSAND:
				this._startCharacterReference();
				break;
			case e.NULL:
				this._err(a.unexpectedNullCharacter), this.currentAttr.value += "�";
				break;
			case e.EOF:
				this._err(a.eofInTag), this._emitEOFToken();
				break;
			default: this.currentAttr.value += String.fromCodePoint(t);
		}
	}
	_stateAttributeValueUnquoted(t) {
		switch (t) {
			case e.SPACE:
			case e.LINE_FEED:
			case e.TABULATION:
			case e.FORM_FEED:
				this._leaveAttrValue(), this.state = m.BEFORE_ATTRIBUTE_NAME;
				break;
			case e.AMPERSAND:
				this._startCharacterReference();
				break;
			case e.GREATER_THAN_SIGN:
				this._leaveAttrValue(), this.state = m.DATA, this.emitCurrentTagToken();
				break;
			case e.NULL:
				this._err(a.unexpectedNullCharacter), this.currentAttr.value += "�";
				break;
			case e.QUOTATION_MARK:
			case e.APOSTROPHE:
			case e.LESS_THAN_SIGN:
			case e.EQUALS_SIGN:
			case e.GRAVE_ACCENT:
				this._err(a.unexpectedCharacterInUnquotedAttributeValue), this.currentAttr.value += String.fromCodePoint(t);
				break;
			case e.EOF:
				this._err(a.eofInTag), this._emitEOFToken();
				break;
			default: this.currentAttr.value += String.fromCodePoint(t);
		}
	}
	_stateAfterAttributeValueQuoted(t) {
		switch (t) {
			case e.SPACE:
			case e.LINE_FEED:
			case e.TABULATION:
			case e.FORM_FEED:
				this._leaveAttrValue(), this.state = m.BEFORE_ATTRIBUTE_NAME;
				break;
			case e.SOLIDUS:
				this._leaveAttrValue(), this.state = m.SELF_CLOSING_START_TAG;
				break;
			case e.GREATER_THAN_SIGN:
				this._leaveAttrValue(), this.state = m.DATA, this.emitCurrentTagToken();
				break;
			case e.EOF:
				this._err(a.eofInTag), this._emitEOFToken();
				break;
			default: this._err(a.missingWhitespaceBetweenAttributes), this.state = m.BEFORE_ATTRIBUTE_NAME, this._stateBeforeAttributeName(t);
		}
	}
	_stateSelfClosingStartTag(t) {
		switch (t) {
			case e.GREATER_THAN_SIGN: {
				let e = this.currentToken;
				e.selfClosing = !0, this.state = m.DATA, this.emitCurrentTagToken();
				break;
			}
			case e.EOF:
				this._err(a.eofInTag), this._emitEOFToken();
				break;
			default: this._err(a.unexpectedSolidusInTag), this.state = m.BEFORE_ATTRIBUTE_NAME, this._stateBeforeAttributeName(t);
		}
	}
	_stateBogusComment(t) {
		let n = this.currentToken;
		switch (t) {
			case e.GREATER_THAN_SIGN:
				this.state = m.DATA, this.emitCurrentComment(n);
				break;
			case e.EOF:
				this.emitCurrentComment(n), this._emitEOFToken();
				break;
			case e.NULL:
				this._err(a.unexpectedNullCharacter), n.data += "�";
				break;
			default: n.data += String.fromCodePoint(t);
		}
	}
	_stateMarkupDeclarationOpen(e) {
		this._consumeSequenceIfMatch(t.DASH_DASH, !0) ? (this._createCommentToken(t.DASH_DASH.length + 1), this.state = m.COMMENT_START) : this._consumeSequenceIfMatch(t.DOCTYPE, !1) ? (this.currentLocation = this.getCurrentLocation(t.DOCTYPE.length + 1), this.state = m.DOCTYPE) : this._consumeSequenceIfMatch(t.CDATA_START, !0) ? this.inForeignNode ? this.state = m.CDATA_SECTION : (this._err(a.cdataInHtmlContent), this._createCommentToken(t.CDATA_START.length + 1), this.currentToken.data = "[CDATA[", this.state = m.BOGUS_COMMENT) : this._ensureHibernation() || (this._err(a.incorrectlyOpenedComment), this._createCommentToken(2), this.state = m.BOGUS_COMMENT, this._stateBogusComment(e));
	}
	_stateCommentStart(t) {
		switch (t) {
			case e.HYPHEN_MINUS:
				this.state = m.COMMENT_START_DASH;
				break;
			case e.GREATER_THAN_SIGN: {
				this._err(a.abruptClosingOfEmptyComment), this.state = m.DATA;
				let e = this.currentToken;
				this.emitCurrentComment(e);
				break;
			}
			default: this.state = m.COMMENT, this._stateComment(t);
		}
	}
	_stateCommentStartDash(t) {
		let n = this.currentToken;
		switch (t) {
			case e.HYPHEN_MINUS:
				this.state = m.COMMENT_END;
				break;
			case e.GREATER_THAN_SIGN:
				this._err(a.abruptClosingOfEmptyComment), this.state = m.DATA, this.emitCurrentComment(n);
				break;
			case e.EOF:
				this._err(a.eofInComment), this.emitCurrentComment(n), this._emitEOFToken();
				break;
			default: n.data += "-", this.state = m.COMMENT, this._stateComment(t);
		}
	}
	_stateComment(t) {
		let n = this.currentToken;
		switch (t) {
			case e.HYPHEN_MINUS:
				this.state = m.COMMENT_END_DASH;
				break;
			case e.LESS_THAN_SIGN:
				n.data += "<", this.state = m.COMMENT_LESS_THAN_SIGN;
				break;
			case e.NULL:
				this._err(a.unexpectedNullCharacter), n.data += "�";
				break;
			case e.EOF:
				this._err(a.eofInComment), this.emitCurrentComment(n), this._emitEOFToken();
				break;
			default: n.data += String.fromCodePoint(t);
		}
	}
	_stateCommentLessThanSign(t) {
		let n = this.currentToken;
		switch (t) {
			case e.EXCLAMATION_MARK:
				n.data += "!", this.state = m.COMMENT_LESS_THAN_SIGN_BANG;
				break;
			case e.LESS_THAN_SIGN:
				n.data += "<";
				break;
			default: this.state = m.COMMENT, this._stateComment(t);
		}
	}
	_stateCommentLessThanSignBang(t) {
		t === e.HYPHEN_MINUS ? this.state = m.COMMENT_LESS_THAN_SIGN_BANG_DASH : (this.state = m.COMMENT, this._stateComment(t));
	}
	_stateCommentLessThanSignBangDash(t) {
		t === e.HYPHEN_MINUS ? this.state = m.COMMENT_LESS_THAN_SIGN_BANG_DASH_DASH : (this.state = m.COMMENT_END_DASH, this._stateCommentEndDash(t));
	}
	_stateCommentLessThanSignBangDashDash(t) {
		t !== e.GREATER_THAN_SIGN && t !== e.EOF && this._err(a.nestedComment), this.state = m.COMMENT_END, this._stateCommentEnd(t);
	}
	_stateCommentEndDash(t) {
		let n = this.currentToken;
		switch (t) {
			case e.HYPHEN_MINUS:
				this.state = m.COMMENT_END;
				break;
			case e.EOF:
				this._err(a.eofInComment), this.emitCurrentComment(n), this._emitEOFToken();
				break;
			default: n.data += "-", this.state = m.COMMENT, this._stateComment(t);
		}
	}
	_stateCommentEnd(t) {
		let n = this.currentToken;
		switch (t) {
			case e.GREATER_THAN_SIGN:
				this.state = m.DATA, this.emitCurrentComment(n);
				break;
			case e.EXCLAMATION_MARK:
				this.state = m.COMMENT_END_BANG;
				break;
			case e.HYPHEN_MINUS:
				n.data += "-";
				break;
			case e.EOF:
				this._err(a.eofInComment), this.emitCurrentComment(n), this._emitEOFToken();
				break;
			default: n.data += "--", this.state = m.COMMENT, this._stateComment(t);
		}
	}
	_stateCommentEndBang(t) {
		let n = this.currentToken;
		switch (t) {
			case e.HYPHEN_MINUS:
				n.data += "--!", this.state = m.COMMENT_END_DASH;
				break;
			case e.GREATER_THAN_SIGN:
				this._err(a.incorrectlyClosedComment), this.state = m.DATA, this.emitCurrentComment(n);
				break;
			case e.EOF:
				this._err(a.eofInComment), this.emitCurrentComment(n), this._emitEOFToken();
				break;
			default: n.data += "--!", this.state = m.COMMENT, this._stateComment(t);
		}
	}
	_stateDoctype(t) {
		switch (t) {
			case e.SPACE:
			case e.LINE_FEED:
			case e.TABULATION:
			case e.FORM_FEED:
				this.state = m.BEFORE_DOCTYPE_NAME;
				break;
			case e.GREATER_THAN_SIGN:
				this.state = m.BEFORE_DOCTYPE_NAME, this._stateBeforeDoctypeName(t);
				break;
			case e.EOF: {
				this._err(a.eofInDoctype), this._createDoctypeToken(null);
				let e = this.currentToken;
				e.forceQuirks = !0, this.emitCurrentDoctype(e), this._emitEOFToken();
				break;
			}
			default: this._err(a.missingWhitespaceBeforeDoctypeName), this.state = m.BEFORE_DOCTYPE_NAME, this._stateBeforeDoctypeName(t);
		}
	}
	_stateBeforeDoctypeName(t) {
		if (_(t)) this._createDoctypeToken(String.fromCharCode(x(t))), this.state = m.DOCTYPE_NAME;
		else switch (t) {
			case e.SPACE:
			case e.LINE_FEED:
			case e.TABULATION:
			case e.FORM_FEED: break;
			case e.NULL:
				this._err(a.unexpectedNullCharacter), this._createDoctypeToken("�"), this.state = m.DOCTYPE_NAME;
				break;
			case e.GREATER_THAN_SIGN: {
				this._err(a.missingDoctypeName), this._createDoctypeToken(null);
				let e = this.currentToken;
				e.forceQuirks = !0, this.emitCurrentDoctype(e), this.state = m.DATA;
				break;
			}
			case e.EOF: {
				this._err(a.eofInDoctype), this._createDoctypeToken(null);
				let e = this.currentToken;
				e.forceQuirks = !0, this.emitCurrentDoctype(e), this._emitEOFToken();
				break;
			}
			default: this._createDoctypeToken(String.fromCodePoint(t)), this.state = m.DOCTYPE_NAME;
		}
	}
	_stateDoctypeName(t) {
		let n = this.currentToken;
		switch (t) {
			case e.SPACE:
			case e.LINE_FEED:
			case e.TABULATION:
			case e.FORM_FEED:
				this.state = m.AFTER_DOCTYPE_NAME;
				break;
			case e.GREATER_THAN_SIGN:
				this.state = m.DATA, this.emitCurrentDoctype(n);
				break;
			case e.NULL:
				this._err(a.unexpectedNullCharacter), n.name += "�";
				break;
			case e.EOF:
				this._err(a.eofInDoctype), n.forceQuirks = !0, this.emitCurrentDoctype(n), this._emitEOFToken();
				break;
			default: n.name += String.fromCodePoint(_(t) ? x(t) : t);
		}
	}
	_stateAfterDoctypeName(n) {
		let r = this.currentToken;
		switch (n) {
			case e.SPACE:
			case e.LINE_FEED:
			case e.TABULATION:
			case e.FORM_FEED: break;
			case e.GREATER_THAN_SIGN:
				this.state = m.DATA, this.emitCurrentDoctype(r);
				break;
			case e.EOF:
				this._err(a.eofInDoctype), r.forceQuirks = !0, this.emitCurrentDoctype(r), this._emitEOFToken();
				break;
			default: this._consumeSequenceIfMatch(t.PUBLIC, !1) ? this.state = m.AFTER_DOCTYPE_PUBLIC_KEYWORD : this._consumeSequenceIfMatch(t.SYSTEM, !1) ? this.state = m.AFTER_DOCTYPE_SYSTEM_KEYWORD : this._ensureHibernation() || (this._err(a.invalidCharacterSequenceAfterDoctypeName), r.forceQuirks = !0, this.state = m.BOGUS_DOCTYPE, this._stateBogusDoctype(n));
		}
	}
	_stateAfterDoctypePublicKeyword(t) {
		let n = this.currentToken;
		switch (t) {
			case e.SPACE:
			case e.LINE_FEED:
			case e.TABULATION:
			case e.FORM_FEED:
				this.state = m.BEFORE_DOCTYPE_PUBLIC_IDENTIFIER;
				break;
			case e.QUOTATION_MARK:
				this._err(a.missingWhitespaceAfterDoctypePublicKeyword), n.publicId = "", this.state = m.DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED;
				break;
			case e.APOSTROPHE:
				this._err(a.missingWhitespaceAfterDoctypePublicKeyword), n.publicId = "", this.state = m.DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED;
				break;
			case e.GREATER_THAN_SIGN:
				this._err(a.missingDoctypePublicIdentifier), n.forceQuirks = !0, this.state = m.DATA, this.emitCurrentDoctype(n);
				break;
			case e.EOF:
				this._err(a.eofInDoctype), n.forceQuirks = !0, this.emitCurrentDoctype(n), this._emitEOFToken();
				break;
			default: this._err(a.missingQuoteBeforeDoctypePublicIdentifier), n.forceQuirks = !0, this.state = m.BOGUS_DOCTYPE, this._stateBogusDoctype(t);
		}
	}
	_stateBeforeDoctypePublicIdentifier(t) {
		let n = this.currentToken;
		switch (t) {
			case e.SPACE:
			case e.LINE_FEED:
			case e.TABULATION:
			case e.FORM_FEED: break;
			case e.QUOTATION_MARK:
				n.publicId = "", this.state = m.DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED;
				break;
			case e.APOSTROPHE:
				n.publicId = "", this.state = m.DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED;
				break;
			case e.GREATER_THAN_SIGN:
				this._err(a.missingDoctypePublicIdentifier), n.forceQuirks = !0, this.state = m.DATA, this.emitCurrentDoctype(n);
				break;
			case e.EOF:
				this._err(a.eofInDoctype), n.forceQuirks = !0, this.emitCurrentDoctype(n), this._emitEOFToken();
				break;
			default: this._err(a.missingQuoteBeforeDoctypePublicIdentifier), n.forceQuirks = !0, this.state = m.BOGUS_DOCTYPE, this._stateBogusDoctype(t);
		}
	}
	_stateDoctypePublicIdentifierDoubleQuoted(t) {
		let n = this.currentToken;
		switch (t) {
			case e.QUOTATION_MARK:
				this.state = m.AFTER_DOCTYPE_PUBLIC_IDENTIFIER;
				break;
			case e.NULL:
				this._err(a.unexpectedNullCharacter), n.publicId += "�";
				break;
			case e.GREATER_THAN_SIGN:
				this._err(a.abruptDoctypePublicIdentifier), n.forceQuirks = !0, this.emitCurrentDoctype(n), this.state = m.DATA;
				break;
			case e.EOF:
				this._err(a.eofInDoctype), n.forceQuirks = !0, this.emitCurrentDoctype(n), this._emitEOFToken();
				break;
			default: n.publicId += String.fromCodePoint(t);
		}
	}
	_stateDoctypePublicIdentifierSingleQuoted(t) {
		let n = this.currentToken;
		switch (t) {
			case e.APOSTROPHE:
				this.state = m.AFTER_DOCTYPE_PUBLIC_IDENTIFIER;
				break;
			case e.NULL:
				this._err(a.unexpectedNullCharacter), n.publicId += "�";
				break;
			case e.GREATER_THAN_SIGN:
				this._err(a.abruptDoctypePublicIdentifier), n.forceQuirks = !0, this.emitCurrentDoctype(n), this.state = m.DATA;
				break;
			case e.EOF:
				this._err(a.eofInDoctype), n.forceQuirks = !0, this.emitCurrentDoctype(n), this._emitEOFToken();
				break;
			default: n.publicId += String.fromCodePoint(t);
		}
	}
	_stateAfterDoctypePublicIdentifier(t) {
		let n = this.currentToken;
		switch (t) {
			case e.SPACE:
			case e.LINE_FEED:
			case e.TABULATION:
			case e.FORM_FEED:
				this.state = m.BETWEEN_DOCTYPE_PUBLIC_AND_SYSTEM_IDENTIFIERS;
				break;
			case e.GREATER_THAN_SIGN:
				this.state = m.DATA, this.emitCurrentDoctype(n);
				break;
			case e.QUOTATION_MARK:
				this._err(a.missingWhitespaceBetweenDoctypePublicAndSystemIdentifiers), n.systemId = "", this.state = m.DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED;
				break;
			case e.APOSTROPHE:
				this._err(a.missingWhitespaceBetweenDoctypePublicAndSystemIdentifiers), n.systemId = "", this.state = m.DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED;
				break;
			case e.EOF:
				this._err(a.eofInDoctype), n.forceQuirks = !0, this.emitCurrentDoctype(n), this._emitEOFToken();
				break;
			default: this._err(a.missingQuoteBeforeDoctypeSystemIdentifier), n.forceQuirks = !0, this.state = m.BOGUS_DOCTYPE, this._stateBogusDoctype(t);
		}
	}
	_stateBetweenDoctypePublicAndSystemIdentifiers(t) {
		let n = this.currentToken;
		switch (t) {
			case e.SPACE:
			case e.LINE_FEED:
			case e.TABULATION:
			case e.FORM_FEED: break;
			case e.GREATER_THAN_SIGN:
				this.emitCurrentDoctype(n), this.state = m.DATA;
				break;
			case e.QUOTATION_MARK:
				n.systemId = "", this.state = m.DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED;
				break;
			case e.APOSTROPHE:
				n.systemId = "", this.state = m.DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED;
				break;
			case e.EOF:
				this._err(a.eofInDoctype), n.forceQuirks = !0, this.emitCurrentDoctype(n), this._emitEOFToken();
				break;
			default: this._err(a.missingQuoteBeforeDoctypeSystemIdentifier), n.forceQuirks = !0, this.state = m.BOGUS_DOCTYPE, this._stateBogusDoctype(t);
		}
	}
	_stateAfterDoctypeSystemKeyword(t) {
		let n = this.currentToken;
		switch (t) {
			case e.SPACE:
			case e.LINE_FEED:
			case e.TABULATION:
			case e.FORM_FEED:
				this.state = m.BEFORE_DOCTYPE_SYSTEM_IDENTIFIER;
				break;
			case e.QUOTATION_MARK:
				this._err(a.missingWhitespaceAfterDoctypeSystemKeyword), n.systemId = "", this.state = m.DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED;
				break;
			case e.APOSTROPHE:
				this._err(a.missingWhitespaceAfterDoctypeSystemKeyword), n.systemId = "", this.state = m.DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED;
				break;
			case e.GREATER_THAN_SIGN:
				this._err(a.missingDoctypeSystemIdentifier), n.forceQuirks = !0, this.state = m.DATA, this.emitCurrentDoctype(n);
				break;
			case e.EOF:
				this._err(a.eofInDoctype), n.forceQuirks = !0, this.emitCurrentDoctype(n), this._emitEOFToken();
				break;
			default: this._err(a.missingQuoteBeforeDoctypeSystemIdentifier), n.forceQuirks = !0, this.state = m.BOGUS_DOCTYPE, this._stateBogusDoctype(t);
		}
	}
	_stateBeforeDoctypeSystemIdentifier(t) {
		let n = this.currentToken;
		switch (t) {
			case e.SPACE:
			case e.LINE_FEED:
			case e.TABULATION:
			case e.FORM_FEED: break;
			case e.QUOTATION_MARK:
				n.systemId = "", this.state = m.DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED;
				break;
			case e.APOSTROPHE:
				n.systemId = "", this.state = m.DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED;
				break;
			case e.GREATER_THAN_SIGN:
				this._err(a.missingDoctypeSystemIdentifier), n.forceQuirks = !0, this.state = m.DATA, this.emitCurrentDoctype(n);
				break;
			case e.EOF:
				this._err(a.eofInDoctype), n.forceQuirks = !0, this.emitCurrentDoctype(n), this._emitEOFToken();
				break;
			default: this._err(a.missingQuoteBeforeDoctypeSystemIdentifier), n.forceQuirks = !0, this.state = m.BOGUS_DOCTYPE, this._stateBogusDoctype(t);
		}
	}
	_stateDoctypeSystemIdentifierDoubleQuoted(t) {
		let n = this.currentToken;
		switch (t) {
			case e.QUOTATION_MARK:
				this.state = m.AFTER_DOCTYPE_SYSTEM_IDENTIFIER;
				break;
			case e.NULL:
				this._err(a.unexpectedNullCharacter), n.systemId += "�";
				break;
			case e.GREATER_THAN_SIGN:
				this._err(a.abruptDoctypeSystemIdentifier), n.forceQuirks = !0, this.emitCurrentDoctype(n), this.state = m.DATA;
				break;
			case e.EOF:
				this._err(a.eofInDoctype), n.forceQuirks = !0, this.emitCurrentDoctype(n), this._emitEOFToken();
				break;
			default: n.systemId += String.fromCodePoint(t);
		}
	}
	_stateDoctypeSystemIdentifierSingleQuoted(t) {
		let n = this.currentToken;
		switch (t) {
			case e.APOSTROPHE:
				this.state = m.AFTER_DOCTYPE_SYSTEM_IDENTIFIER;
				break;
			case e.NULL:
				this._err(a.unexpectedNullCharacter), n.systemId += "�";
				break;
			case e.GREATER_THAN_SIGN:
				this._err(a.abruptDoctypeSystemIdentifier), n.forceQuirks = !0, this.emitCurrentDoctype(n), this.state = m.DATA;
				break;
			case e.EOF:
				this._err(a.eofInDoctype), n.forceQuirks = !0, this.emitCurrentDoctype(n), this._emitEOFToken();
				break;
			default: n.systemId += String.fromCodePoint(t);
		}
	}
	_stateAfterDoctypeSystemIdentifier(t) {
		let n = this.currentToken;
		switch (t) {
			case e.SPACE:
			case e.LINE_FEED:
			case e.TABULATION:
			case e.FORM_FEED: break;
			case e.GREATER_THAN_SIGN:
				this.emitCurrentDoctype(n), this.state = m.DATA;
				break;
			case e.EOF:
				this._err(a.eofInDoctype), n.forceQuirks = !0, this.emitCurrentDoctype(n), this._emitEOFToken();
				break;
			default: this._err(a.unexpectedCharacterAfterDoctypeSystemIdentifier), this.state = m.BOGUS_DOCTYPE, this._stateBogusDoctype(t);
		}
	}
	_stateBogusDoctype(t) {
		let n = this.currentToken;
		switch (t) {
			case e.GREATER_THAN_SIGN:
				this.emitCurrentDoctype(n), this.state = m.DATA;
				break;
			case e.NULL:
				this._err(a.unexpectedNullCharacter);
				break;
			case e.EOF:
				this.emitCurrentDoctype(n), this._emitEOFToken();
				break;
			default:
		}
	}
	_stateCdataSection(t) {
		switch (t) {
			case e.RIGHT_SQUARE_BRACKET:
				this.state = m.CDATA_SECTION_BRACKET;
				break;
			case e.EOF:
				this._err(a.eofInCdata), this._emitEOFToken();
				break;
			default: this._emitCodePoint(t);
		}
	}
	_stateCdataSectionBracket(t) {
		t === e.RIGHT_SQUARE_BRACKET ? this.state = m.CDATA_SECTION_END : (this._emitChars("]"), this.state = m.CDATA_SECTION, this._stateCdataSection(t));
	}
	_stateCdataSectionEnd(t) {
		switch (t) {
			case e.GREATER_THAN_SIGN:
				this.state = m.DATA;
				break;
			case e.RIGHT_SQUARE_BRACKET:
				this._emitChars("]");
				break;
			default: this._emitChars("]]"), this.state = m.CDATA_SECTION, this._stateCdataSection(t);
		}
	}
	_stateCharacterReference() {
		let t = this.entityDecoder.write(this.preprocessor.html, this.preprocessor.pos);
		if (t < 0) if (this.preprocessor.lastChunkWritten) t = this.entityDecoder.end();
		else {
			this.active = !1, this.preprocessor.pos = this.preprocessor.html.length - 1, this.consumedAfterSnapshot = 0, this.preprocessor.endOfChunkHit = !0;
			return;
		}
		t === 0 ? (this.preprocessor.pos = this.entityStartPos, this._flushCodePointConsumedAsCharacterReference(e.AMPERSAND), this.state = !this._isCharacterReferenceInAttribute() && b(this.preprocessor.peek(1)) ? m.AMBIGUOUS_AMPERSAND : this.returnState) : this.state = this.returnState;
	}
	_stateAmbiguousAmpersand(t) {
		b(t) ? this._flushCodePointConsumedAsCharacterReference(t) : (t === e.SEMICOLON && this._err(a.unknownNamedCharacterReference), this.state = this.returnState, this._callState(t));
	}
};
//#endregion
export { T as Tokenizer, h as TokenizerMode };
