import { CODE_POINTS, REPLACEMENT_CHARACTER } from "../common/unicode.js";
import { ERR } from "../common/error-codes.js";
import { TokenType, getTokenAttr } from "../common/token.js";
import { ATTRS, DOCUMENT_MODE, NS, NUMBERED_HEADERS, SPECIAL_ELEMENTS, TAG_ID, TAG_NAMES, getTagID } from "../common/html.js";
import { Tokenizer, TokenizerMode } from "../tokenizer/index.js";
import { OpenElementStack } from "./open-element-stack.js";
import { EntryType, FormattingElementList } from "./formatting-element-list.js";
import { defaultTreeAdapter } from "../tree-adapters/default.js";
import { getDocumentMode, isConforming } from "../common/doctype.js";
import { adjustTokenMathMLAttrs, adjustTokenSVGAttrs, adjustTokenSVGTagName, adjustTokenXMLAttrs, causesExit, isIntegrationPoint } from "../common/foreign-content.js";
var HIDDEN_INPUT_TYPE = "hidden", AA_OUTER_LOOP_ITER = 8, AA_INNER_LOOP_ITER = 3, InsertionMode;
(function(v) {
	v[v.INITIAL = 0] = "INITIAL", v[v.BEFORE_HTML = 1] = "BEFORE_HTML", v[v.BEFORE_HEAD = 2] = "BEFORE_HEAD", v[v.IN_HEAD = 3] = "IN_HEAD", v[v.IN_HEAD_NO_SCRIPT = 4] = "IN_HEAD_NO_SCRIPT", v[v.AFTER_HEAD = 5] = "AFTER_HEAD", v[v.IN_BODY = 6] = "IN_BODY", v[v.TEXT = 7] = "TEXT", v[v.IN_TABLE = 8] = "IN_TABLE", v[v.IN_TABLE_TEXT = 9] = "IN_TABLE_TEXT", v[v.IN_CAPTION = 10] = "IN_CAPTION", v[v.IN_COLUMN_GROUP = 11] = "IN_COLUMN_GROUP", v[v.IN_TABLE_BODY = 12] = "IN_TABLE_BODY", v[v.IN_ROW = 13] = "IN_ROW", v[v.IN_CELL = 14] = "IN_CELL", v[v.IN_SELECT = 15] = "IN_SELECT", v[v.IN_SELECT_IN_TABLE = 16] = "IN_SELECT_IN_TABLE", v[v.IN_TEMPLATE = 17] = "IN_TEMPLATE", v[v.AFTER_BODY = 18] = "AFTER_BODY", v[v.IN_FRAMESET = 19] = "IN_FRAMESET", v[v.AFTER_FRAMESET = 20] = "AFTER_FRAMESET", v[v.AFTER_AFTER_BODY = 21] = "AFTER_AFTER_BODY", v[v.AFTER_AFTER_FRAMESET = 22] = "AFTER_AFTER_FRAMESET";
})(InsertionMode ||= {});
var BASE_LOC = {
	startLine: -1,
	startCol: -1,
	startOffset: -1,
	endLine: -1,
	endCol: -1,
	endOffset: -1
}, TABLE_STRUCTURE_TAGS = new Set([
	TAG_ID.TABLE,
	TAG_ID.TBODY,
	TAG_ID.TFOOT,
	TAG_ID.THEAD,
	TAG_ID.TR
]), defaultParserOptions = {
	scriptingEnabled: !0,
	sourceCodeLocationInfo: !1,
	treeAdapter: defaultTreeAdapter,
	onParseError: null
}, Parser = class {
	constructor(v, q, J = null, Y = null) {
		this.fragmentContext = J, this.scriptHandler = Y, this.currentToken = null, this.stopped = !1, this.insertionMode = InsertionMode.INITIAL, this.originalInsertionMode = InsertionMode.INITIAL, this.headElement = null, this.formElement = null, this.currentNotInHTML = !1, this.tmplInsertionModeStack = [], this.pendingCharacterTokens = [], this.hasNonWhitespacePendingCharacterToken = !1, this.framesetOk = !0, this.skipNextNewLine = !1, this.fosterParentingEnabled = !1, this.options = {
			...defaultParserOptions,
			...v
		}, this.treeAdapter = this.options.treeAdapter, this.onParseError = this.options.onParseError, this.onParseError && (this.options.sourceCodeLocationInfo = !0), this.document = q ?? this.treeAdapter.createDocument(), this.tokenizer = new Tokenizer(this.options, this), this.activeFormattingElements = new FormattingElementList(this.treeAdapter), this.fragmentContextID = J ? getTagID(this.treeAdapter.getTagName(J)) : TAG_ID.UNKNOWN, this._setContextModes(J ?? this.document, this.fragmentContextID), this.openElements = new OpenElementStack(this.document, this.treeAdapter, this);
	}
	static parse(v, q) {
		let J = new this(q);
		return J.tokenizer.write(v, !0), J.document;
	}
	static getFragmentParser(v, q) {
		let J = {
			...defaultParserOptions,
			...q
		};
		v ??= J.treeAdapter.createElement(TAG_NAMES.TEMPLATE, NS.HTML, []);
		let Y = J.treeAdapter.createElement("documentmock", NS.HTML, []), X = new this(J, Y, v);
		return X.fragmentContextID === TAG_ID.TEMPLATE && X.tmplInsertionModeStack.unshift(InsertionMode.IN_TEMPLATE), X._initTokenizerForFragmentParsing(), X._insertFakeRootElement(), X._resetInsertionMode(), X._findFormInFragmentContext(), X;
	}
	getFragment() {
		let v = this.treeAdapter.getFirstChild(this.document), q = this.treeAdapter.createDocumentFragment();
		return this._adoptNodes(v, q), q;
	}
	_err(v, q, J) {
		if (!this.onParseError) return;
		let Y = v.location ?? BASE_LOC, X = {
			code: q,
			startLine: Y.startLine,
			startCol: Y.startCol,
			startOffset: Y.startOffset,
			endLine: J ? Y.startLine : Y.endLine,
			endCol: J ? Y.startCol : Y.endCol,
			endOffset: J ? Y.startOffset : Y.endOffset
		};
		this.onParseError(X);
	}
	onItemPush(v, q, J) {
		var Y, X;
		(X = (Y = this.treeAdapter).onItemPush) == null || X.call(Y, v), J && this.openElements.stackTop > 0 && this._setContextModes(v, q);
	}
	onItemPop(v, q) {
		var J, Y;
		if (this.options.sourceCodeLocationInfo && this._setEndLocation(v, this.currentToken), (Y = (J = this.treeAdapter).onItemPop) == null || Y.call(J, v, this.openElements.current), q) {
			let v, q;
			this.openElements.stackTop === 0 && this.fragmentContext ? (v = this.fragmentContext, q = this.fragmentContextID) : {current: v, currentTagId: q} = this.openElements, this._setContextModes(v, q);
		}
	}
	_setContextModes(v, q) {
		let J = v === this.document || v && this.treeAdapter.getNamespaceURI(v) === NS.HTML;
		this.currentNotInHTML = !J, this.tokenizer.inForeignNode = !J && v !== void 0 && q !== void 0 && !this._isIntegrationPoint(q, v);
	}
	_switchToTextParsing(v, q) {
		this._insertElement(v, NS.HTML), this.tokenizer.state = q, this.originalInsertionMode = this.insertionMode, this.insertionMode = InsertionMode.TEXT;
	}
	switchToPlaintextParsing() {
		this.insertionMode = InsertionMode.TEXT, this.originalInsertionMode = InsertionMode.IN_BODY, this.tokenizer.state = TokenizerMode.PLAINTEXT;
	}
	_getAdjustedCurrentElement() {
		return this.openElements.stackTop === 0 && this.fragmentContext ? this.fragmentContext : this.openElements.current;
	}
	_findFormInFragmentContext() {
		let v = this.fragmentContext;
		for (; v;) {
			if (this.treeAdapter.getTagName(v) === TAG_NAMES.FORM) {
				this.formElement = v;
				break;
			}
			v = this.treeAdapter.getParentNode(v);
		}
	}
	_initTokenizerForFragmentParsing() {
		if (!(!this.fragmentContext || this.treeAdapter.getNamespaceURI(this.fragmentContext) !== NS.HTML)) switch (this.fragmentContextID) {
			case TAG_ID.TITLE:
			case TAG_ID.TEXTAREA:
				this.tokenizer.state = TokenizerMode.RCDATA;
				break;
			case TAG_ID.STYLE:
			case TAG_ID.XMP:
			case TAG_ID.IFRAME:
			case TAG_ID.NOEMBED:
			case TAG_ID.NOFRAMES:
			case TAG_ID.NOSCRIPT:
				this.tokenizer.state = TokenizerMode.RAWTEXT;
				break;
			case TAG_ID.SCRIPT:
				this.tokenizer.state = TokenizerMode.SCRIPT_DATA;
				break;
			case TAG_ID.PLAINTEXT:
				this.tokenizer.state = TokenizerMode.PLAINTEXT;
				break;
			default:
		}
	}
	_setDocumentType(v) {
		let q = v.name || "", J = v.publicId || "", Y = v.systemId || "";
		if (this.treeAdapter.setDocumentType(this.document, q, J, Y), v.location) {
			let q = this.treeAdapter.getChildNodes(this.document).find((v) => this.treeAdapter.isDocumentTypeNode(v));
			q && this.treeAdapter.setNodeSourceCodeLocation(q, v.location);
		}
	}
	_attachElementToTree(v, q) {
		if (this.options.sourceCodeLocationInfo) {
			let J = q && {
				...q,
				startTag: q
			};
			this.treeAdapter.setNodeSourceCodeLocation(v, J);
		}
		if (this._shouldFosterParentOnInsertion()) this._fosterParentElement(v);
		else {
			let q = this.openElements.currentTmplContentOrNode;
			this.treeAdapter.appendChild(q ?? this.document, v);
		}
	}
	_appendElement(v, q) {
		let J = this.treeAdapter.createElement(v.tagName, q, v.attrs);
		this._attachElementToTree(J, v.location);
	}
	_insertElement(v, q) {
		let J = this.treeAdapter.createElement(v.tagName, q, v.attrs);
		this._attachElementToTree(J, v.location), this.openElements.push(J, v.tagID);
	}
	_insertFakeElement(v, q) {
		let J = this.treeAdapter.createElement(v, NS.HTML, []);
		this._attachElementToTree(J, null), this.openElements.push(J, q);
	}
	_insertTemplate(v) {
		let q = this.treeAdapter.createElement(v.tagName, NS.HTML, v.attrs), J = this.treeAdapter.createDocumentFragment();
		this.treeAdapter.setTemplateContent(q, J), this._attachElementToTree(q, v.location), this.openElements.push(q, v.tagID), this.options.sourceCodeLocationInfo && this.treeAdapter.setNodeSourceCodeLocation(J, null);
	}
	_insertFakeRootElement() {
		let v = this.treeAdapter.createElement(TAG_NAMES.HTML, NS.HTML, []);
		this.options.sourceCodeLocationInfo && this.treeAdapter.setNodeSourceCodeLocation(v, null), this.treeAdapter.appendChild(this.openElements.current, v), this.openElements.push(v, TAG_ID.HTML);
	}
	_appendCommentNode(v, q) {
		let J = this.treeAdapter.createCommentNode(v.data);
		this.treeAdapter.appendChild(q, J), this.options.sourceCodeLocationInfo && this.treeAdapter.setNodeSourceCodeLocation(J, v.location);
	}
	_insertCharacters(v) {
		let q, J;
		if (this._shouldFosterParentOnInsertion() ? ({parent: q, beforeElement: J} = this._findFosterParentingLocation(), J ? this.treeAdapter.insertTextBefore(q, v.chars, J) : this.treeAdapter.insertText(q, v.chars)) : (q = this.openElements.currentTmplContentOrNode, this.treeAdapter.insertText(q, v.chars)), !v.location) return;
		let Y = this.treeAdapter.getChildNodes(q), X = Y[(J ? Y.lastIndexOf(J) : Y.length) - 1];
		if (this.treeAdapter.getNodeSourceCodeLocation(X)) {
			let { endLine: q, endCol: J, endOffset: Y } = v.location;
			this.treeAdapter.updateNodeSourceCodeLocation(X, {
				endLine: q,
				endCol: J,
				endOffset: Y
			});
		} else this.options.sourceCodeLocationInfo && this.treeAdapter.setNodeSourceCodeLocation(X, v.location);
	}
	_adoptNodes(v, q) {
		for (let J = this.treeAdapter.getFirstChild(v); J; J = this.treeAdapter.getFirstChild(v)) this.treeAdapter.detachNode(J), this.treeAdapter.appendChild(q, J);
	}
	_setEndLocation(v, q) {
		if (this.treeAdapter.getNodeSourceCodeLocation(v) && q.location) {
			let J = q.location, X = this.treeAdapter.getTagName(v), Z = q.type === TokenType.END_TAG && X === q.tagName ? {
				endTag: { ...J },
				endLine: J.endLine,
				endCol: J.endCol,
				endOffset: J.endOffset
			} : {
				endLine: J.startLine,
				endCol: J.startCol,
				endOffset: J.startOffset
			};
			this.treeAdapter.updateNodeSourceCodeLocation(v, Z);
		}
	}
	shouldProcessStartTagTokenInForeignContent(v) {
		if (!this.currentNotInHTML) return !1;
		let q, J;
		return this.openElements.stackTop === 0 && this.fragmentContext ? (q = this.fragmentContext, J = this.fragmentContextID) : {current: q, currentTagId: J} = this.openElements, v.tagID === TAG_ID.SVG && this.treeAdapter.getTagName(q) === TAG_NAMES.ANNOTATION_XML && this.treeAdapter.getNamespaceURI(q) === NS.MATHML ? !1 : this.tokenizer.inForeignNode || (v.tagID === TAG_ID.MGLYPH || v.tagID === TAG_ID.MALIGNMARK) && J !== void 0 && !this._isIntegrationPoint(J, q, NS.HTML);
	}
	_processToken(v) {
		switch (v.type) {
			case TokenType.CHARACTER:
				this.onCharacter(v);
				break;
			case TokenType.NULL_CHARACTER:
				this.onNullCharacter(v);
				break;
			case TokenType.COMMENT:
				this.onComment(v);
				break;
			case TokenType.DOCTYPE:
				this.onDoctype(v);
				break;
			case TokenType.START_TAG:
				this._processStartTag(v);
				break;
			case TokenType.END_TAG:
				this.onEndTag(v);
				break;
			case TokenType.EOF:
				this.onEof(v);
				break;
			case TokenType.WHITESPACE_CHARACTER:
				this.onWhitespaceCharacter(v);
				break;
		}
	}
	_isIntegrationPoint(v, q, J) {
		return isIntegrationPoint(v, this.treeAdapter.getNamespaceURI(q), this.treeAdapter.getAttrList(q), J);
	}
	_reconstructActiveFormattingElements() {
		let v = this.activeFormattingElements.entries.length;
		if (v) {
			let q = this.activeFormattingElements.entries.findIndex((v) => v.type === EntryType.Marker || this.openElements.contains(v.element)), J = q === -1 ? v - 1 : q - 1;
			for (let v = J; v >= 0; v--) {
				let q = this.activeFormattingElements.entries[v];
				this._insertElement(q.token, this.treeAdapter.getNamespaceURI(q.element)), q.element = this.openElements.current;
			}
		}
	}
	_closeTableCell() {
		this.openElements.generateImpliedEndTags(), this.openElements.popUntilTableCellPopped(), this.activeFormattingElements.clearToLastMarker(), this.insertionMode = InsertionMode.IN_ROW;
	}
	_closePElement() {
		this.openElements.generateImpliedEndTagsWithExclusion(TAG_ID.P), this.openElements.popUntilTagNamePopped(TAG_ID.P);
	}
	_resetInsertionMode() {
		for (let v = this.openElements.stackTop; v >= 0; v--) switch (v === 0 && this.fragmentContext ? this.fragmentContextID : this.openElements.tagIDs[v]) {
			case TAG_ID.TR:
				this.insertionMode = InsertionMode.IN_ROW;
				return;
			case TAG_ID.TBODY:
			case TAG_ID.THEAD:
			case TAG_ID.TFOOT:
				this.insertionMode = InsertionMode.IN_TABLE_BODY;
				return;
			case TAG_ID.CAPTION:
				this.insertionMode = InsertionMode.IN_CAPTION;
				return;
			case TAG_ID.COLGROUP:
				this.insertionMode = InsertionMode.IN_COLUMN_GROUP;
				return;
			case TAG_ID.TABLE:
				this.insertionMode = InsertionMode.IN_TABLE;
				return;
			case TAG_ID.BODY:
				this.insertionMode = InsertionMode.IN_BODY;
				return;
			case TAG_ID.FRAMESET:
				this.insertionMode = InsertionMode.IN_FRAMESET;
				return;
			case TAG_ID.SELECT:
				this._resetInsertionModeForSelect(v);
				return;
			case TAG_ID.TEMPLATE:
				this.insertionMode = this.tmplInsertionModeStack[0];
				return;
			case TAG_ID.HTML:
				this.insertionMode = this.headElement ? InsertionMode.AFTER_HEAD : InsertionMode.BEFORE_HEAD;
				return;
			case TAG_ID.TD:
			case TAG_ID.TH:
				if (v > 0) {
					this.insertionMode = InsertionMode.IN_CELL;
					return;
				}
				break;
			case TAG_ID.HEAD:
				if (v > 0) {
					this.insertionMode = InsertionMode.IN_HEAD;
					return;
				}
				break;
		}
		this.insertionMode = InsertionMode.IN_BODY;
	}
	_resetInsertionModeForSelect(v) {
		if (v > 0) for (let q = v - 1; q > 0; q--) {
			let v = this.openElements.tagIDs[q];
			if (v === TAG_ID.TEMPLATE) break;
			if (v === TAG_ID.TABLE) {
				this.insertionMode = InsertionMode.IN_SELECT_IN_TABLE;
				return;
			}
		}
		this.insertionMode = InsertionMode.IN_SELECT;
	}
	_isElementCausesFosterParenting(v) {
		return TABLE_STRUCTURE_TAGS.has(v);
	}
	_shouldFosterParentOnInsertion() {
		return this.fosterParentingEnabled && this.openElements.currentTagId !== void 0 && this._isElementCausesFosterParenting(this.openElements.currentTagId);
	}
	_findFosterParentingLocation() {
		for (let v = this.openElements.stackTop; v >= 0; v--) {
			let q = this.openElements.items[v];
			switch (this.openElements.tagIDs[v]) {
				case TAG_ID.TEMPLATE:
					if (this.treeAdapter.getNamespaceURI(q) === NS.HTML) return {
						parent: this.treeAdapter.getTemplateContent(q),
						beforeElement: null
					};
					break;
				case TAG_ID.TABLE: {
					let J = this.treeAdapter.getParentNode(q);
					return J ? {
						parent: J,
						beforeElement: q
					} : {
						parent: this.openElements.items[v - 1],
						beforeElement: null
					};
				}
				default:
			}
		}
		return {
			parent: this.openElements.items[0],
			beforeElement: null
		};
	}
	_fosterParentElement(v) {
		let q = this._findFosterParentingLocation();
		q.beforeElement ? this.treeAdapter.insertBefore(q.parent, v, q.beforeElement) : this.treeAdapter.appendChild(q.parent, v);
	}
	_isSpecialElement(v, q) {
		return SPECIAL_ELEMENTS[this.treeAdapter.getNamespaceURI(v)].has(q);
	}
	onCharacter(v) {
		if (this.skipNextNewLine = !1, this.tokenizer.inForeignNode) {
			characterInForeignContent(this, v);
			return;
		}
		switch (this.insertionMode) {
			case InsertionMode.INITIAL:
				tokenInInitialMode(this, v);
				break;
			case InsertionMode.BEFORE_HTML:
				tokenBeforeHtml(this, v);
				break;
			case InsertionMode.BEFORE_HEAD:
				tokenBeforeHead(this, v);
				break;
			case InsertionMode.IN_HEAD:
				tokenInHead(this, v);
				break;
			case InsertionMode.IN_HEAD_NO_SCRIPT:
				tokenInHeadNoScript(this, v);
				break;
			case InsertionMode.AFTER_HEAD:
				tokenAfterHead(this, v);
				break;
			case InsertionMode.IN_BODY:
			case InsertionMode.IN_CAPTION:
			case InsertionMode.IN_CELL:
			case InsertionMode.IN_TEMPLATE:
				characterInBody(this, v);
				break;
			case InsertionMode.TEXT:
			case InsertionMode.IN_SELECT:
			case InsertionMode.IN_SELECT_IN_TABLE:
				this._insertCharacters(v);
				break;
			case InsertionMode.IN_TABLE:
			case InsertionMode.IN_TABLE_BODY:
			case InsertionMode.IN_ROW:
				characterInTable(this, v);
				break;
			case InsertionMode.IN_TABLE_TEXT:
				characterInTableText(this, v);
				break;
			case InsertionMode.IN_COLUMN_GROUP:
				tokenInColumnGroup(this, v);
				break;
			case InsertionMode.AFTER_BODY:
				tokenAfterBody(this, v);
				break;
			case InsertionMode.AFTER_AFTER_BODY:
				tokenAfterAfterBody(this, v);
				break;
			default:
		}
	}
	onNullCharacter(v) {
		if (this.skipNextNewLine = !1, this.tokenizer.inForeignNode) {
			nullCharacterInForeignContent(this, v);
			return;
		}
		switch (this.insertionMode) {
			case InsertionMode.INITIAL:
				tokenInInitialMode(this, v);
				break;
			case InsertionMode.BEFORE_HTML:
				tokenBeforeHtml(this, v);
				break;
			case InsertionMode.BEFORE_HEAD:
				tokenBeforeHead(this, v);
				break;
			case InsertionMode.IN_HEAD:
				tokenInHead(this, v);
				break;
			case InsertionMode.IN_HEAD_NO_SCRIPT:
				tokenInHeadNoScript(this, v);
				break;
			case InsertionMode.AFTER_HEAD:
				tokenAfterHead(this, v);
				break;
			case InsertionMode.TEXT:
				this._insertCharacters(v);
				break;
			case InsertionMode.IN_TABLE:
			case InsertionMode.IN_TABLE_BODY:
			case InsertionMode.IN_ROW:
				characterInTable(this, v);
				break;
			case InsertionMode.IN_COLUMN_GROUP:
				tokenInColumnGroup(this, v);
				break;
			case InsertionMode.AFTER_BODY:
				tokenAfterBody(this, v);
				break;
			case InsertionMode.AFTER_AFTER_BODY:
				tokenAfterAfterBody(this, v);
				break;
			default:
		}
	}
	onComment(v) {
		if (this.skipNextNewLine = !1, this.currentNotInHTML) {
			appendComment(this, v);
			return;
		}
		switch (this.insertionMode) {
			case InsertionMode.INITIAL:
			case InsertionMode.BEFORE_HTML:
			case InsertionMode.BEFORE_HEAD:
			case InsertionMode.IN_HEAD:
			case InsertionMode.IN_HEAD_NO_SCRIPT:
			case InsertionMode.AFTER_HEAD:
			case InsertionMode.IN_BODY:
			case InsertionMode.IN_TABLE:
			case InsertionMode.IN_CAPTION:
			case InsertionMode.IN_COLUMN_GROUP:
			case InsertionMode.IN_TABLE_BODY:
			case InsertionMode.IN_ROW:
			case InsertionMode.IN_CELL:
			case InsertionMode.IN_SELECT:
			case InsertionMode.IN_SELECT_IN_TABLE:
			case InsertionMode.IN_TEMPLATE:
			case InsertionMode.IN_FRAMESET:
			case InsertionMode.AFTER_FRAMESET:
				appendComment(this, v);
				break;
			case InsertionMode.IN_TABLE_TEXT:
				tokenInTableText(this, v);
				break;
			case InsertionMode.AFTER_BODY:
				appendCommentToRootHtmlElement(this, v);
				break;
			case InsertionMode.AFTER_AFTER_BODY:
			case InsertionMode.AFTER_AFTER_FRAMESET:
				appendCommentToDocument(this, v);
				break;
			default:
		}
	}
	onDoctype(v) {
		switch (this.skipNextNewLine = !1, this.insertionMode) {
			case InsertionMode.INITIAL:
				doctypeInInitialMode(this, v);
				break;
			case InsertionMode.BEFORE_HEAD:
			case InsertionMode.IN_HEAD:
			case InsertionMode.IN_HEAD_NO_SCRIPT:
			case InsertionMode.AFTER_HEAD:
				this._err(v, ERR.misplacedDoctype);
				break;
			case InsertionMode.IN_TABLE_TEXT:
				tokenInTableText(this, v);
				break;
			default:
		}
	}
	onStartTag(v) {
		this.skipNextNewLine = !1, this.currentToken = v, this._processStartTag(v), v.selfClosing && !v.ackSelfClosing && this._err(v, ERR.nonVoidHtmlElementStartTagWithTrailingSolidus);
	}
	_processStartTag(v) {
		this.shouldProcessStartTagTokenInForeignContent(v) ? startTagInForeignContent(this, v) : this._startTagOutsideForeignContent(v);
	}
	_startTagOutsideForeignContent(v) {
		switch (this.insertionMode) {
			case InsertionMode.INITIAL:
				tokenInInitialMode(this, v);
				break;
			case InsertionMode.BEFORE_HTML:
				startTagBeforeHtml(this, v);
				break;
			case InsertionMode.BEFORE_HEAD:
				startTagBeforeHead(this, v);
				break;
			case InsertionMode.IN_HEAD:
				startTagInHead(this, v);
				break;
			case InsertionMode.IN_HEAD_NO_SCRIPT:
				startTagInHeadNoScript(this, v);
				break;
			case InsertionMode.AFTER_HEAD:
				startTagAfterHead(this, v);
				break;
			case InsertionMode.IN_BODY:
				startTagInBody(this, v);
				break;
			case InsertionMode.IN_TABLE:
				startTagInTable(this, v);
				break;
			case InsertionMode.IN_TABLE_TEXT:
				tokenInTableText(this, v);
				break;
			case InsertionMode.IN_CAPTION:
				startTagInCaption(this, v);
				break;
			case InsertionMode.IN_COLUMN_GROUP:
				startTagInColumnGroup(this, v);
				break;
			case InsertionMode.IN_TABLE_BODY:
				startTagInTableBody(this, v);
				break;
			case InsertionMode.IN_ROW:
				startTagInRow(this, v);
				break;
			case InsertionMode.IN_CELL:
				startTagInCell(this, v);
				break;
			case InsertionMode.IN_SELECT:
				startTagInSelect(this, v);
				break;
			case InsertionMode.IN_SELECT_IN_TABLE:
				startTagInSelectInTable(this, v);
				break;
			case InsertionMode.IN_TEMPLATE:
				startTagInTemplate(this, v);
				break;
			case InsertionMode.AFTER_BODY:
				startTagAfterBody(this, v);
				break;
			case InsertionMode.IN_FRAMESET:
				startTagInFrameset(this, v);
				break;
			case InsertionMode.AFTER_FRAMESET:
				startTagAfterFrameset(this, v);
				break;
			case InsertionMode.AFTER_AFTER_BODY:
				startTagAfterAfterBody(this, v);
				break;
			case InsertionMode.AFTER_AFTER_FRAMESET:
				startTagAfterAfterFrameset(this, v);
				break;
			default:
		}
	}
	onEndTag(v) {
		this.skipNextNewLine = !1, this.currentToken = v, this.currentNotInHTML ? endTagInForeignContent(this, v) : this._endTagOutsideForeignContent(v);
	}
	_endTagOutsideForeignContent(v) {
		switch (this.insertionMode) {
			case InsertionMode.INITIAL:
				tokenInInitialMode(this, v);
				break;
			case InsertionMode.BEFORE_HTML:
				endTagBeforeHtml(this, v);
				break;
			case InsertionMode.BEFORE_HEAD:
				endTagBeforeHead(this, v);
				break;
			case InsertionMode.IN_HEAD:
				endTagInHead(this, v);
				break;
			case InsertionMode.IN_HEAD_NO_SCRIPT:
				endTagInHeadNoScript(this, v);
				break;
			case InsertionMode.AFTER_HEAD:
				endTagAfterHead(this, v);
				break;
			case InsertionMode.IN_BODY:
				endTagInBody(this, v);
				break;
			case InsertionMode.TEXT:
				endTagInText(this, v);
				break;
			case InsertionMode.IN_TABLE:
				endTagInTable(this, v);
				break;
			case InsertionMode.IN_TABLE_TEXT:
				tokenInTableText(this, v);
				break;
			case InsertionMode.IN_CAPTION:
				endTagInCaption(this, v);
				break;
			case InsertionMode.IN_COLUMN_GROUP:
				endTagInColumnGroup(this, v);
				break;
			case InsertionMode.IN_TABLE_BODY:
				endTagInTableBody(this, v);
				break;
			case InsertionMode.IN_ROW:
				endTagInRow(this, v);
				break;
			case InsertionMode.IN_CELL:
				endTagInCell(this, v);
				break;
			case InsertionMode.IN_SELECT:
				endTagInSelect(this, v);
				break;
			case InsertionMode.IN_SELECT_IN_TABLE:
				endTagInSelectInTable(this, v);
				break;
			case InsertionMode.IN_TEMPLATE:
				endTagInTemplate(this, v);
				break;
			case InsertionMode.AFTER_BODY:
				endTagAfterBody(this, v);
				break;
			case InsertionMode.IN_FRAMESET:
				endTagInFrameset(this, v);
				break;
			case InsertionMode.AFTER_FRAMESET:
				endTagAfterFrameset(this, v);
				break;
			case InsertionMode.AFTER_AFTER_BODY:
				tokenAfterAfterBody(this, v);
				break;
			default:
		}
	}
	onEof(v) {
		switch (this.insertionMode) {
			case InsertionMode.INITIAL:
				tokenInInitialMode(this, v);
				break;
			case InsertionMode.BEFORE_HTML:
				tokenBeforeHtml(this, v);
				break;
			case InsertionMode.BEFORE_HEAD:
				tokenBeforeHead(this, v);
				break;
			case InsertionMode.IN_HEAD:
				tokenInHead(this, v);
				break;
			case InsertionMode.IN_HEAD_NO_SCRIPT:
				tokenInHeadNoScript(this, v);
				break;
			case InsertionMode.AFTER_HEAD:
				tokenAfterHead(this, v);
				break;
			case InsertionMode.IN_BODY:
			case InsertionMode.IN_TABLE:
			case InsertionMode.IN_CAPTION:
			case InsertionMode.IN_COLUMN_GROUP:
			case InsertionMode.IN_TABLE_BODY:
			case InsertionMode.IN_ROW:
			case InsertionMode.IN_CELL:
			case InsertionMode.IN_SELECT:
			case InsertionMode.IN_SELECT_IN_TABLE:
				eofInBody(this, v);
				break;
			case InsertionMode.TEXT:
				eofInText(this, v);
				break;
			case InsertionMode.IN_TABLE_TEXT:
				tokenInTableText(this, v);
				break;
			case InsertionMode.IN_TEMPLATE:
				eofInTemplate(this, v);
				break;
			case InsertionMode.AFTER_BODY:
			case InsertionMode.IN_FRAMESET:
			case InsertionMode.AFTER_FRAMESET:
			case InsertionMode.AFTER_AFTER_BODY:
			case InsertionMode.AFTER_AFTER_FRAMESET:
				stopParsing(this, v);
				break;
			default:
		}
	}
	onWhitespaceCharacter(q) {
		if (this.skipNextNewLine && (this.skipNextNewLine = !1, q.chars.charCodeAt(0) === CODE_POINTS.LINE_FEED)) {
			if (q.chars.length === 1) return;
			q.chars = q.chars.substr(1);
		}
		if (this.tokenizer.inForeignNode) {
			this._insertCharacters(q);
			return;
		}
		switch (this.insertionMode) {
			case InsertionMode.IN_HEAD:
			case InsertionMode.IN_HEAD_NO_SCRIPT:
			case InsertionMode.AFTER_HEAD:
			case InsertionMode.TEXT:
			case InsertionMode.IN_COLUMN_GROUP:
			case InsertionMode.IN_SELECT:
			case InsertionMode.IN_SELECT_IN_TABLE:
			case InsertionMode.IN_FRAMESET:
			case InsertionMode.AFTER_FRAMESET:
				this._insertCharacters(q);
				break;
			case InsertionMode.IN_BODY:
			case InsertionMode.IN_CAPTION:
			case InsertionMode.IN_CELL:
			case InsertionMode.IN_TEMPLATE:
			case InsertionMode.AFTER_BODY:
			case InsertionMode.AFTER_AFTER_BODY:
			case InsertionMode.AFTER_AFTER_FRAMESET:
				whitespaceCharacterInBody(this, q);
				break;
			case InsertionMode.IN_TABLE:
			case InsertionMode.IN_TABLE_BODY:
			case InsertionMode.IN_ROW:
				characterInTable(this, q);
				break;
			case InsertionMode.IN_TABLE_TEXT:
				whitespaceCharacterInTableText(this, q);
				break;
			default:
		}
	}
};
function aaObtainFormattingElementEntry(v, q) {
	let J = v.activeFormattingElements.getElementEntryInScopeWithTagName(q.tagName);
	return J ? v.openElements.contains(J.element) ? v.openElements.hasInScope(q.tagID) || (J = null) : (v.activeFormattingElements.removeEntry(J), J = null) : genericEndTagInBody(v, q), J;
}
function aaObtainFurthestBlock(v, q) {
	let J = null, Y = v.openElements.stackTop;
	for (; Y >= 0; Y--) {
		let X = v.openElements.items[Y];
		if (X === q.element) break;
		v._isSpecialElement(X, v.openElements.tagIDs[Y]) && (J = X);
	}
	return J || (v.openElements.shortenToLength(Math.max(Y, 0)), v.activeFormattingElements.removeEntry(q)), J;
}
function aaInnerLoop(v, q, J) {
	let Y = q, X = v.openElements.getCommonAncestor(q);
	for (let Z = 0, Q = X; Q !== J; Z++, Q = X) {
		X = v.openElements.getCommonAncestor(Q);
		let J = v.activeFormattingElements.getElementEntry(Q), $ = J && Z >= AA_INNER_LOOP_ITER;
		!J || $ ? ($ && v.activeFormattingElements.removeEntry(J), v.openElements.remove(Q)) : (Q = aaRecreateElementFromEntry(v, J), Y === q && (v.activeFormattingElements.bookmark = J), v.treeAdapter.detachNode(Y), v.treeAdapter.appendChild(Q, Y), Y = Q);
	}
	return Y;
}
function aaRecreateElementFromEntry(v, q) {
	let J = v.treeAdapter.getNamespaceURI(q.element), Y = v.treeAdapter.createElement(q.token.tagName, J, q.token.attrs);
	return v.openElements.replace(q.element, Y), q.element = Y, Y;
}
function aaInsertLastNodeInCommonAncestor(v, q, J) {
	let Y = getTagID(v.treeAdapter.getTagName(q));
	if (v._isElementCausesFosterParenting(Y)) v._fosterParentElement(J);
	else {
		let X = v.treeAdapter.getNamespaceURI(q);
		Y === TAG_ID.TEMPLATE && X === NS.HTML && (q = v.treeAdapter.getTemplateContent(q)), v.treeAdapter.appendChild(q, J);
	}
}
function aaReplaceFormattingElement(v, q, J) {
	let Y = v.treeAdapter.getNamespaceURI(J.element), { token: X } = J, Z = v.treeAdapter.createElement(X.tagName, Y, X.attrs);
	v._adoptNodes(q, Z), v.treeAdapter.appendChild(q, Z), v.activeFormattingElements.insertElementAfterBookmark(Z, X), v.activeFormattingElements.removeEntry(J), v.openElements.remove(J.element), v.openElements.insertAfter(q, Z, X.tagID);
}
function callAdoptionAgency(v, q) {
	for (let J = 0; J < AA_OUTER_LOOP_ITER; J++) {
		let J = aaObtainFormattingElementEntry(v, q);
		if (!J) break;
		let Y = aaObtainFurthestBlock(v, J);
		if (!Y) break;
		v.activeFormattingElements.bookmark = J;
		let X = aaInnerLoop(v, Y, J.element), Z = v.openElements.getCommonAncestor(J.element);
		v.treeAdapter.detachNode(X), Z && aaInsertLastNodeInCommonAncestor(v, Z, X), aaReplaceFormattingElement(v, Y, J);
	}
}
function appendComment(v, q) {
	v._appendCommentNode(q, v.openElements.currentTmplContentOrNode);
}
function appendCommentToRootHtmlElement(v, q) {
	v._appendCommentNode(q, v.openElements.items[0]);
}
function appendCommentToDocument(v, q) {
	v._appendCommentNode(q, v.document);
}
function stopParsing(v, q) {
	if (v.stopped = !0, q.location) {
		let J = v.fragmentContext ? 0 : 2;
		for (let Y = v.openElements.stackTop; Y >= J; Y--) v._setEndLocation(v.openElements.items[Y], q);
		if (!v.fragmentContext && v.openElements.stackTop >= 0) {
			let J = v.openElements.items[0], Y = v.treeAdapter.getNodeSourceCodeLocation(J);
			if (Y && !Y.endTag && (v._setEndLocation(J, q), v.openElements.stackTop >= 1)) {
				let J = v.openElements.items[1], Y = v.treeAdapter.getNodeSourceCodeLocation(J);
				Y && !Y.endTag && v._setEndLocation(J, q);
			}
		}
	}
}
function doctypeInInitialMode(v, q) {
	v._setDocumentType(q);
	let Y = q.forceQuirks ? DOCUMENT_MODE.QUIRKS : getDocumentMode(q);
	isConforming(q) || v._err(q, ERR.nonConformingDoctype), v.treeAdapter.setDocumentMode(v.document, Y), v.insertionMode = InsertionMode.BEFORE_HTML;
}
function tokenInInitialMode(v, q) {
	v._err(q, ERR.missingDoctype, !0), v.treeAdapter.setDocumentMode(v.document, DOCUMENT_MODE.QUIRKS), v.insertionMode = InsertionMode.BEFORE_HTML, v._processToken(q);
}
function startTagBeforeHtml(v, q) {
	q.tagID === TAG_ID.HTML ? (v._insertElement(q, NS.HTML), v.insertionMode = InsertionMode.BEFORE_HEAD) : tokenBeforeHtml(v, q);
}
function endTagBeforeHtml(v, q) {
	let J = q.tagID;
	(J === TAG_ID.HTML || J === TAG_ID.HEAD || J === TAG_ID.BODY || J === TAG_ID.BR) && tokenBeforeHtml(v, q);
}
function tokenBeforeHtml(v, q) {
	v._insertFakeRootElement(), v.insertionMode = InsertionMode.BEFORE_HEAD, v._processToken(q);
}
function startTagBeforeHead(v, q) {
	switch (q.tagID) {
		case TAG_ID.HTML:
			startTagInBody(v, q);
			break;
		case TAG_ID.HEAD:
			v._insertElement(q, NS.HTML), v.headElement = v.openElements.current, v.insertionMode = InsertionMode.IN_HEAD;
			break;
		default: tokenBeforeHead(v, q);
	}
}
function endTagBeforeHead(v, q) {
	let Y = q.tagID;
	Y === TAG_ID.HEAD || Y === TAG_ID.BODY || Y === TAG_ID.HTML || Y === TAG_ID.BR ? tokenBeforeHead(v, q) : v._err(q, ERR.endTagWithoutMatchingOpenElement);
}
function tokenBeforeHead(v, q) {
	v._insertFakeElement(TAG_NAMES.HEAD, TAG_ID.HEAD), v.headElement = v.openElements.current, v.insertionMode = InsertionMode.IN_HEAD, v._processToken(q);
}
function startTagInHead(v, q) {
	switch (q.tagID) {
		case TAG_ID.HTML:
			startTagInBody(v, q);
			break;
		case TAG_ID.BASE:
		case TAG_ID.BASEFONT:
		case TAG_ID.BGSOUND:
		case TAG_ID.LINK:
		case TAG_ID.META:
			v._appendElement(q, NS.HTML), q.ackSelfClosing = !0;
			break;
		case TAG_ID.TITLE:
			v._switchToTextParsing(q, TokenizerMode.RCDATA);
			break;
		case TAG_ID.NOSCRIPT:
			v.options.scriptingEnabled ? v._switchToTextParsing(q, TokenizerMode.RAWTEXT) : (v._insertElement(q, NS.HTML), v.insertionMode = InsertionMode.IN_HEAD_NO_SCRIPT);
			break;
		case TAG_ID.NOFRAMES:
		case TAG_ID.STYLE:
			v._switchToTextParsing(q, TokenizerMode.RAWTEXT);
			break;
		case TAG_ID.SCRIPT:
			v._switchToTextParsing(q, TokenizerMode.SCRIPT_DATA);
			break;
		case TAG_ID.TEMPLATE:
			v._insertTemplate(q), v.activeFormattingElements.insertMarker(), v.framesetOk = !1, v.insertionMode = InsertionMode.IN_TEMPLATE, v.tmplInsertionModeStack.unshift(InsertionMode.IN_TEMPLATE);
			break;
		case TAG_ID.HEAD:
			v._err(q, ERR.misplacedStartTagForHeadElement);
			break;
		default: tokenInHead(v, q);
	}
}
function endTagInHead(v, q) {
	switch (q.tagID) {
		case TAG_ID.HEAD:
			v.openElements.pop(), v.insertionMode = InsertionMode.AFTER_HEAD;
			break;
		case TAG_ID.BODY:
		case TAG_ID.BR:
		case TAG_ID.HTML:
			tokenInHead(v, q);
			break;
		case TAG_ID.TEMPLATE:
			templateEndTagInHead(v, q);
			break;
		default: v._err(q, ERR.endTagWithoutMatchingOpenElement);
	}
}
function templateEndTagInHead(v, q) {
	v.openElements.tmplCount > 0 ? (v.openElements.generateImpliedEndTagsThoroughly(), v.openElements.currentTagId !== TAG_ID.TEMPLATE && v._err(q, ERR.closingOfElementWithOpenChildElements), v.openElements.popUntilTagNamePopped(TAG_ID.TEMPLATE), v.activeFormattingElements.clearToLastMarker(), v.tmplInsertionModeStack.shift(), v._resetInsertionMode()) : v._err(q, ERR.endTagWithoutMatchingOpenElement);
}
function tokenInHead(v, q) {
	v.openElements.pop(), v.insertionMode = InsertionMode.AFTER_HEAD, v._processToken(q);
}
function startTagInHeadNoScript(v, q) {
	switch (q.tagID) {
		case TAG_ID.HTML:
			startTagInBody(v, q);
			break;
		case TAG_ID.BASEFONT:
		case TAG_ID.BGSOUND:
		case TAG_ID.HEAD:
		case TAG_ID.LINK:
		case TAG_ID.META:
		case TAG_ID.NOFRAMES:
		case TAG_ID.STYLE:
			startTagInHead(v, q);
			break;
		case TAG_ID.NOSCRIPT:
			v._err(q, ERR.nestedNoscriptInHead);
			break;
		default: tokenInHeadNoScript(v, q);
	}
}
function endTagInHeadNoScript(v, q) {
	switch (q.tagID) {
		case TAG_ID.NOSCRIPT:
			v.openElements.pop(), v.insertionMode = InsertionMode.IN_HEAD;
			break;
		case TAG_ID.BR:
			tokenInHeadNoScript(v, q);
			break;
		default: v._err(q, ERR.endTagWithoutMatchingOpenElement);
	}
}
function tokenInHeadNoScript(v, q) {
	let X = q.type === TokenType.EOF ? ERR.openElementsLeftAfterEof : ERR.disallowedContentInNoscriptInHead;
	v._err(q, X), v.openElements.pop(), v.insertionMode = InsertionMode.IN_HEAD, v._processToken(q);
}
function startTagAfterHead(v, q) {
	switch (q.tagID) {
		case TAG_ID.HTML:
			startTagInBody(v, q);
			break;
		case TAG_ID.BODY:
			v._insertElement(q, NS.HTML), v.framesetOk = !1, v.insertionMode = InsertionMode.IN_BODY;
			break;
		case TAG_ID.FRAMESET:
			v._insertElement(q, NS.HTML), v.insertionMode = InsertionMode.IN_FRAMESET;
			break;
		case TAG_ID.BASE:
		case TAG_ID.BASEFONT:
		case TAG_ID.BGSOUND:
		case TAG_ID.LINK:
		case TAG_ID.META:
		case TAG_ID.NOFRAMES:
		case TAG_ID.SCRIPT:
		case TAG_ID.STYLE:
		case TAG_ID.TEMPLATE:
		case TAG_ID.TITLE:
			v._err(q, ERR.abandonedHeadElementChild), v.openElements.push(v.headElement, TAG_ID.HEAD), startTagInHead(v, q), v.openElements.remove(v.headElement);
			break;
		case TAG_ID.HEAD:
			v._err(q, ERR.misplacedStartTagForHeadElement);
			break;
		default: tokenAfterHead(v, q);
	}
}
function endTagAfterHead(v, q) {
	switch (q.tagID) {
		case TAG_ID.BODY:
		case TAG_ID.HTML:
		case TAG_ID.BR:
			tokenAfterHead(v, q);
			break;
		case TAG_ID.TEMPLATE:
			templateEndTagInHead(v, q);
			break;
		default: v._err(q, ERR.endTagWithoutMatchingOpenElement);
	}
}
function tokenAfterHead(v, q) {
	v._insertFakeElement(TAG_NAMES.BODY, TAG_ID.BODY), v.insertionMode = InsertionMode.IN_BODY, modeInBody(v, q);
}
function modeInBody(v, q) {
	switch (q.type) {
		case TokenType.CHARACTER:
			characterInBody(v, q);
			break;
		case TokenType.WHITESPACE_CHARACTER:
			whitespaceCharacterInBody(v, q);
			break;
		case TokenType.COMMENT:
			appendComment(v, q);
			break;
		case TokenType.START_TAG:
			startTagInBody(v, q);
			break;
		case TokenType.END_TAG:
			endTagInBody(v, q);
			break;
		case TokenType.EOF:
			eofInBody(v, q);
			break;
		default:
	}
}
function whitespaceCharacterInBody(v, q) {
	v._reconstructActiveFormattingElements(), v._insertCharacters(q);
}
function characterInBody(v, q) {
	v._reconstructActiveFormattingElements(), v._insertCharacters(q), v.framesetOk = !1;
}
function htmlStartTagInBody(v, q) {
	v.openElements.tmplCount === 0 && v.treeAdapter.adoptAttributes(v.openElements.items[0], q.attrs);
}
function bodyStartTagInBody(v, q) {
	let J = v.openElements.tryPeekProperlyNestedBodyElement();
	J && v.openElements.tmplCount === 0 && (v.framesetOk = !1, v.treeAdapter.adoptAttributes(J, q.attrs));
}
function framesetStartTagInBody(v, q) {
	let J = v.openElements.tryPeekProperlyNestedBodyElement();
	v.framesetOk && J && (v.treeAdapter.detachNode(J), v.openElements.popAllUpToHtmlElement(), v._insertElement(q, NS.HTML), v.insertionMode = InsertionMode.IN_FRAMESET);
}
function addressStartTagInBody(v, q) {
	v.openElements.hasInButtonScope(TAG_ID.P) && v._closePElement(), v._insertElement(q, NS.HTML);
}
function numberedHeaderStartTagInBody(v, q) {
	v.openElements.hasInButtonScope(TAG_ID.P) && v._closePElement(), v.openElements.currentTagId !== void 0 && NUMBERED_HEADERS.has(v.openElements.currentTagId) && v.openElements.pop(), v._insertElement(q, NS.HTML);
}
function preStartTagInBody(v, q) {
	v.openElements.hasInButtonScope(TAG_ID.P) && v._closePElement(), v._insertElement(q, NS.HTML), v.skipNextNewLine = !0, v.framesetOk = !1;
}
function formStartTagInBody(v, q) {
	let J = v.openElements.tmplCount > 0;
	(!v.formElement || J) && (v.openElements.hasInButtonScope(TAG_ID.P) && v._closePElement(), v._insertElement(q, NS.HTML), J || (v.formElement = v.openElements.current));
}
function listItemStartTagInBody(v, q) {
	v.framesetOk = !1;
	let J = q.tagID;
	for (let q = v.openElements.stackTop; q >= 0; q--) {
		let Y = v.openElements.tagIDs[q];
		if (J === TAG_ID.LI && Y === TAG_ID.LI || (J === TAG_ID.DD || J === TAG_ID.DT) && (Y === TAG_ID.DD || Y === TAG_ID.DT)) {
			v.openElements.generateImpliedEndTagsWithExclusion(Y), v.openElements.popUntilTagNamePopped(Y);
			break;
		}
		if (Y !== TAG_ID.ADDRESS && Y !== TAG_ID.DIV && Y !== TAG_ID.P && v._isSpecialElement(v.openElements.items[q], Y)) break;
	}
	v.openElements.hasInButtonScope(TAG_ID.P) && v._closePElement(), v._insertElement(q, NS.HTML);
}
function plaintextStartTagInBody(v, q) {
	v.openElements.hasInButtonScope(TAG_ID.P) && v._closePElement(), v._insertElement(q, NS.HTML), v.tokenizer.state = TokenizerMode.PLAINTEXT;
}
function buttonStartTagInBody(v, q) {
	v.openElements.hasInScope(TAG_ID.BUTTON) && (v.openElements.generateImpliedEndTags(), v.openElements.popUntilTagNamePopped(TAG_ID.BUTTON)), v._reconstructActiveFormattingElements(), v._insertElement(q, NS.HTML), v.framesetOk = !1;
}
function aStartTagInBody(v, q) {
	let J = v.activeFormattingElements.getElementEntryInScopeWithTagName(TAG_NAMES.A);
	J && (callAdoptionAgency(v, q), v.openElements.remove(J.element), v.activeFormattingElements.removeEntry(J)), v._reconstructActiveFormattingElements(), v._insertElement(q, NS.HTML), v.activeFormattingElements.pushElement(v.openElements.current, q);
}
function bStartTagInBody(v, q) {
	v._reconstructActiveFormattingElements(), v._insertElement(q, NS.HTML), v.activeFormattingElements.pushElement(v.openElements.current, q);
}
function nobrStartTagInBody(v, q) {
	v._reconstructActiveFormattingElements(), v.openElements.hasInScope(TAG_ID.NOBR) && (callAdoptionAgency(v, q), v._reconstructActiveFormattingElements()), v._insertElement(q, NS.HTML), v.activeFormattingElements.pushElement(v.openElements.current, q);
}
function appletStartTagInBody(v, q) {
	v._reconstructActiveFormattingElements(), v._insertElement(q, NS.HTML), v.activeFormattingElements.insertMarker(), v.framesetOk = !1;
}
function tableStartTagInBody(v, q) {
	v.treeAdapter.getDocumentMode(v.document) !== DOCUMENT_MODE.QUIRKS && v.openElements.hasInButtonScope(TAG_ID.P) && v._closePElement(), v._insertElement(q, NS.HTML), v.framesetOk = !1, v.insertionMode = InsertionMode.IN_TABLE;
}
function areaStartTagInBody(v, q) {
	v._reconstructActiveFormattingElements(), v._appendElement(q, NS.HTML), v.framesetOk = !1, q.ackSelfClosing = !0;
}
function isHiddenInput(v) {
	let q = getTokenAttr(v, ATTRS.TYPE);
	return q != null && q.toLowerCase() === HIDDEN_INPUT_TYPE;
}
function inputStartTagInBody(v, q) {
	v._reconstructActiveFormattingElements(), v._appendElement(q, NS.HTML), isHiddenInput(q) || (v.framesetOk = !1), q.ackSelfClosing = !0;
}
function paramStartTagInBody(v, q) {
	v._appendElement(q, NS.HTML), q.ackSelfClosing = !0;
}
function hrStartTagInBody(v, q) {
	v.openElements.hasInButtonScope(TAG_ID.P) && v._closePElement(), v._appendElement(q, NS.HTML), v.framesetOk = !1, q.ackSelfClosing = !0;
}
function imageStartTagInBody(v, q) {
	q.tagName = TAG_NAMES.IMG, q.tagID = TAG_ID.IMG, areaStartTagInBody(v, q);
}
function textareaStartTagInBody(v, q) {
	v._insertElement(q, NS.HTML), v.skipNextNewLine = !0, v.tokenizer.state = TokenizerMode.RCDATA, v.originalInsertionMode = v.insertionMode, v.framesetOk = !1, v.insertionMode = InsertionMode.TEXT;
}
function xmpStartTagInBody(v, q) {
	v.openElements.hasInButtonScope(TAG_ID.P) && v._closePElement(), v._reconstructActiveFormattingElements(), v.framesetOk = !1, v._switchToTextParsing(q, TokenizerMode.RAWTEXT);
}
function iframeStartTagInBody(v, q) {
	v.framesetOk = !1, v._switchToTextParsing(q, TokenizerMode.RAWTEXT);
}
function rawTextStartTagInBody(v, q) {
	v._switchToTextParsing(q, TokenizerMode.RAWTEXT);
}
function selectStartTagInBody(v, q) {
	v._reconstructActiveFormattingElements(), v._insertElement(q, NS.HTML), v.framesetOk = !1, v.insertionMode = v.insertionMode === InsertionMode.IN_TABLE || v.insertionMode === InsertionMode.IN_CAPTION || v.insertionMode === InsertionMode.IN_TABLE_BODY || v.insertionMode === InsertionMode.IN_ROW || v.insertionMode === InsertionMode.IN_CELL ? InsertionMode.IN_SELECT_IN_TABLE : InsertionMode.IN_SELECT;
}
function optgroupStartTagInBody(v, q) {
	v.openElements.currentTagId === TAG_ID.OPTION && v.openElements.pop(), v._reconstructActiveFormattingElements(), v._insertElement(q, NS.HTML);
}
function rbStartTagInBody(v, q) {
	v.openElements.hasInScope(TAG_ID.RUBY) && v.openElements.generateImpliedEndTags(), v._insertElement(q, NS.HTML);
}
function rtStartTagInBody(v, q) {
	v.openElements.hasInScope(TAG_ID.RUBY) && v.openElements.generateImpliedEndTagsWithExclusion(TAG_ID.RTC), v._insertElement(q, NS.HTML);
}
function mathStartTagInBody(v, q) {
	v._reconstructActiveFormattingElements(), adjustTokenMathMLAttrs(q), adjustTokenXMLAttrs(q), q.selfClosing ? v._appendElement(q, NS.MATHML) : v._insertElement(q, NS.MATHML), q.ackSelfClosing = !0;
}
function svgStartTagInBody(v, q) {
	v._reconstructActiveFormattingElements(), adjustTokenSVGAttrs(q), adjustTokenXMLAttrs(q), q.selfClosing ? v._appendElement(q, NS.SVG) : v._insertElement(q, NS.SVG), q.ackSelfClosing = !0;
}
function genericStartTagInBody(v, q) {
	v._reconstructActiveFormattingElements(), v._insertElement(q, NS.HTML);
}
function startTagInBody(v, q) {
	switch (q.tagID) {
		case TAG_ID.I:
		case TAG_ID.S:
		case TAG_ID.B:
		case TAG_ID.U:
		case TAG_ID.EM:
		case TAG_ID.TT:
		case TAG_ID.BIG:
		case TAG_ID.CODE:
		case TAG_ID.FONT:
		case TAG_ID.SMALL:
		case TAG_ID.STRIKE:
		case TAG_ID.STRONG:
			bStartTagInBody(v, q);
			break;
		case TAG_ID.A:
			aStartTagInBody(v, q);
			break;
		case TAG_ID.H1:
		case TAG_ID.H2:
		case TAG_ID.H3:
		case TAG_ID.H4:
		case TAG_ID.H5:
		case TAG_ID.H6:
			numberedHeaderStartTagInBody(v, q);
			break;
		case TAG_ID.P:
		case TAG_ID.DL:
		case TAG_ID.OL:
		case TAG_ID.UL:
		case TAG_ID.DIV:
		case TAG_ID.DIR:
		case TAG_ID.NAV:
		case TAG_ID.MAIN:
		case TAG_ID.MENU:
		case TAG_ID.ASIDE:
		case TAG_ID.CENTER:
		case TAG_ID.FIGURE:
		case TAG_ID.FOOTER:
		case TAG_ID.HEADER:
		case TAG_ID.HGROUP:
		case TAG_ID.DIALOG:
		case TAG_ID.DETAILS:
		case TAG_ID.ADDRESS:
		case TAG_ID.ARTICLE:
		case TAG_ID.SEARCH:
		case TAG_ID.SECTION:
		case TAG_ID.SUMMARY:
		case TAG_ID.FIELDSET:
		case TAG_ID.BLOCKQUOTE:
		case TAG_ID.FIGCAPTION:
			addressStartTagInBody(v, q);
			break;
		case TAG_ID.LI:
		case TAG_ID.DD:
		case TAG_ID.DT:
			listItemStartTagInBody(v, q);
			break;
		case TAG_ID.BR:
		case TAG_ID.IMG:
		case TAG_ID.WBR:
		case TAG_ID.AREA:
		case TAG_ID.EMBED:
		case TAG_ID.KEYGEN:
			areaStartTagInBody(v, q);
			break;
		case TAG_ID.HR:
			hrStartTagInBody(v, q);
			break;
		case TAG_ID.RB:
		case TAG_ID.RTC:
			rbStartTagInBody(v, q);
			break;
		case TAG_ID.RT:
		case TAG_ID.RP:
			rtStartTagInBody(v, q);
			break;
		case TAG_ID.PRE:
		case TAG_ID.LISTING:
			preStartTagInBody(v, q);
			break;
		case TAG_ID.XMP:
			xmpStartTagInBody(v, q);
			break;
		case TAG_ID.SVG:
			svgStartTagInBody(v, q);
			break;
		case TAG_ID.HTML:
			htmlStartTagInBody(v, q);
			break;
		case TAG_ID.BASE:
		case TAG_ID.LINK:
		case TAG_ID.META:
		case TAG_ID.STYLE:
		case TAG_ID.TITLE:
		case TAG_ID.SCRIPT:
		case TAG_ID.BGSOUND:
		case TAG_ID.BASEFONT:
		case TAG_ID.TEMPLATE:
			startTagInHead(v, q);
			break;
		case TAG_ID.BODY:
			bodyStartTagInBody(v, q);
			break;
		case TAG_ID.FORM:
			formStartTagInBody(v, q);
			break;
		case TAG_ID.NOBR:
			nobrStartTagInBody(v, q);
			break;
		case TAG_ID.MATH:
			mathStartTagInBody(v, q);
			break;
		case TAG_ID.TABLE:
			tableStartTagInBody(v, q);
			break;
		case TAG_ID.INPUT:
			inputStartTagInBody(v, q);
			break;
		case TAG_ID.PARAM:
		case TAG_ID.TRACK:
		case TAG_ID.SOURCE:
			paramStartTagInBody(v, q);
			break;
		case TAG_ID.IMAGE:
			imageStartTagInBody(v, q);
			break;
		case TAG_ID.BUTTON:
			buttonStartTagInBody(v, q);
			break;
		case TAG_ID.APPLET:
		case TAG_ID.OBJECT:
		case TAG_ID.MARQUEE:
			appletStartTagInBody(v, q);
			break;
		case TAG_ID.IFRAME:
			iframeStartTagInBody(v, q);
			break;
		case TAG_ID.SELECT:
			selectStartTagInBody(v, q);
			break;
		case TAG_ID.OPTION:
		case TAG_ID.OPTGROUP:
			optgroupStartTagInBody(v, q);
			break;
		case TAG_ID.NOEMBED:
		case TAG_ID.NOFRAMES:
			rawTextStartTagInBody(v, q);
			break;
		case TAG_ID.FRAMESET:
			framesetStartTagInBody(v, q);
			break;
		case TAG_ID.TEXTAREA:
			textareaStartTagInBody(v, q);
			break;
		case TAG_ID.NOSCRIPT:
			v.options.scriptingEnabled ? rawTextStartTagInBody(v, q) : genericStartTagInBody(v, q);
			break;
		case TAG_ID.PLAINTEXT:
			plaintextStartTagInBody(v, q);
			break;
		case TAG_ID.COL:
		case TAG_ID.TH:
		case TAG_ID.TD:
		case TAG_ID.TR:
		case TAG_ID.HEAD:
		case TAG_ID.FRAME:
		case TAG_ID.TBODY:
		case TAG_ID.TFOOT:
		case TAG_ID.THEAD:
		case TAG_ID.CAPTION:
		case TAG_ID.COLGROUP: break;
		default: genericStartTagInBody(v, q);
	}
}
function bodyEndTagInBody(v, q) {
	if (v.openElements.hasInScope(TAG_ID.BODY) && (v.insertionMode = InsertionMode.AFTER_BODY, v.options.sourceCodeLocationInfo)) {
		let J = v.openElements.tryPeekProperlyNestedBodyElement();
		J && v._setEndLocation(J, q);
	}
}
function htmlEndTagInBody(v, q) {
	v.openElements.hasInScope(TAG_ID.BODY) && (v.insertionMode = InsertionMode.AFTER_BODY, endTagAfterBody(v, q));
}
function addressEndTagInBody(v, q) {
	let J = q.tagID;
	v.openElements.hasInScope(J) && (v.openElements.generateImpliedEndTags(), v.openElements.popUntilTagNamePopped(J));
}
function formEndTagInBody(v) {
	let q = v.openElements.tmplCount > 0, { formElement: J } = v;
	q || (v.formElement = null), (J || q) && v.openElements.hasInScope(TAG_ID.FORM) && (v.openElements.generateImpliedEndTags(), q ? v.openElements.popUntilTagNamePopped(TAG_ID.FORM) : J && v.openElements.remove(J));
}
function pEndTagInBody(v) {
	v.openElements.hasInButtonScope(TAG_ID.P) || v._insertFakeElement(TAG_NAMES.P, TAG_ID.P), v._closePElement();
}
function liEndTagInBody(v) {
	v.openElements.hasInListItemScope(TAG_ID.LI) && (v.openElements.generateImpliedEndTagsWithExclusion(TAG_ID.LI), v.openElements.popUntilTagNamePopped(TAG_ID.LI));
}
function ddEndTagInBody(v, q) {
	let J = q.tagID;
	v.openElements.hasInScope(J) && (v.openElements.generateImpliedEndTagsWithExclusion(J), v.openElements.popUntilTagNamePopped(J));
}
function numberedHeaderEndTagInBody(v) {
	v.openElements.hasNumberedHeaderInScope() && (v.openElements.generateImpliedEndTags(), v.openElements.popUntilNumberedHeaderPopped());
}
function appletEndTagInBody(v, q) {
	let J = q.tagID;
	v.openElements.hasInScope(J) && (v.openElements.generateImpliedEndTags(), v.openElements.popUntilTagNamePopped(J), v.activeFormattingElements.clearToLastMarker());
}
function brEndTagInBody(v) {
	v._reconstructActiveFormattingElements(), v._insertFakeElement(TAG_NAMES.BR, TAG_ID.BR), v.openElements.pop(), v.framesetOk = !1;
}
function genericEndTagInBody(v, q) {
	let J = q.tagName, Y = q.tagID;
	for (let q = v.openElements.stackTop; q > 0; q--) {
		let X = v.openElements.items[q], Z = v.openElements.tagIDs[q];
		if (Y === Z && (Y !== TAG_ID.UNKNOWN || v.treeAdapter.getTagName(X) === J)) {
			v.openElements.generateImpliedEndTagsWithExclusion(Y), v.openElements.stackTop >= q && v.openElements.shortenToLength(q);
			break;
		}
		if (v._isSpecialElement(X, Z)) break;
	}
}
function endTagInBody(v, q) {
	switch (q.tagID) {
		case TAG_ID.A:
		case TAG_ID.B:
		case TAG_ID.I:
		case TAG_ID.S:
		case TAG_ID.U:
		case TAG_ID.EM:
		case TAG_ID.TT:
		case TAG_ID.BIG:
		case TAG_ID.CODE:
		case TAG_ID.FONT:
		case TAG_ID.NOBR:
		case TAG_ID.SMALL:
		case TAG_ID.STRIKE:
		case TAG_ID.STRONG:
			callAdoptionAgency(v, q);
			break;
		case TAG_ID.P:
			pEndTagInBody(v);
			break;
		case TAG_ID.DL:
		case TAG_ID.UL:
		case TAG_ID.OL:
		case TAG_ID.DIR:
		case TAG_ID.DIV:
		case TAG_ID.NAV:
		case TAG_ID.PRE:
		case TAG_ID.MAIN:
		case TAG_ID.MENU:
		case TAG_ID.ASIDE:
		case TAG_ID.BUTTON:
		case TAG_ID.CENTER:
		case TAG_ID.FIGURE:
		case TAG_ID.FOOTER:
		case TAG_ID.HEADER:
		case TAG_ID.HGROUP:
		case TAG_ID.DIALOG:
		case TAG_ID.ADDRESS:
		case TAG_ID.ARTICLE:
		case TAG_ID.DETAILS:
		case TAG_ID.SEARCH:
		case TAG_ID.SECTION:
		case TAG_ID.SUMMARY:
		case TAG_ID.LISTING:
		case TAG_ID.FIELDSET:
		case TAG_ID.BLOCKQUOTE:
		case TAG_ID.FIGCAPTION:
			addressEndTagInBody(v, q);
			break;
		case TAG_ID.LI:
			liEndTagInBody(v);
			break;
		case TAG_ID.DD:
		case TAG_ID.DT:
			ddEndTagInBody(v, q);
			break;
		case TAG_ID.H1:
		case TAG_ID.H2:
		case TAG_ID.H3:
		case TAG_ID.H4:
		case TAG_ID.H5:
		case TAG_ID.H6:
			numberedHeaderEndTagInBody(v);
			break;
		case TAG_ID.BR:
			brEndTagInBody(v);
			break;
		case TAG_ID.BODY:
			bodyEndTagInBody(v, q);
			break;
		case TAG_ID.HTML:
			htmlEndTagInBody(v, q);
			break;
		case TAG_ID.FORM:
			formEndTagInBody(v);
			break;
		case TAG_ID.APPLET:
		case TAG_ID.OBJECT:
		case TAG_ID.MARQUEE:
			appletEndTagInBody(v, q);
			break;
		case TAG_ID.TEMPLATE:
			templateEndTagInHead(v, q);
			break;
		default: genericEndTagInBody(v, q);
	}
}
function eofInBody(v, q) {
	v.tmplInsertionModeStack.length > 0 ? eofInTemplate(v, q) : stopParsing(v, q);
}
function endTagInText(v, q) {
	var J;
	q.tagID === TAG_ID.SCRIPT && ((J = v.scriptHandler) == null || J.call(v, v.openElements.current)), v.openElements.pop(), v.insertionMode = v.originalInsertionMode;
}
function eofInText(v, q) {
	v._err(q, ERR.eofInElementThatCanContainOnlyText), v.openElements.pop(), v.insertionMode = v.originalInsertionMode, v.onEof(q);
}
function characterInTable(v, q) {
	if (v.openElements.currentTagId !== void 0 && TABLE_STRUCTURE_TAGS.has(v.openElements.currentTagId)) switch (v.pendingCharacterTokens.length = 0, v.hasNonWhitespacePendingCharacterToken = !1, v.originalInsertionMode = v.insertionMode, v.insertionMode = InsertionMode.IN_TABLE_TEXT, q.type) {
		case TokenType.CHARACTER:
			characterInTableText(v, q);
			break;
		case TokenType.WHITESPACE_CHARACTER:
			whitespaceCharacterInTableText(v, q);
			break;
	}
	else tokenInTable(v, q);
}
function captionStartTagInTable(v, q) {
	v.openElements.clearBackToTableContext(), v.activeFormattingElements.insertMarker(), v._insertElement(q, NS.HTML), v.insertionMode = InsertionMode.IN_CAPTION;
}
function colgroupStartTagInTable(v, q) {
	v.openElements.clearBackToTableContext(), v._insertElement(q, NS.HTML), v.insertionMode = InsertionMode.IN_COLUMN_GROUP;
}
function colStartTagInTable(v, q) {
	v.openElements.clearBackToTableContext(), v._insertFakeElement(TAG_NAMES.COLGROUP, TAG_ID.COLGROUP), v.insertionMode = InsertionMode.IN_COLUMN_GROUP, startTagInColumnGroup(v, q);
}
function tbodyStartTagInTable(v, q) {
	v.openElements.clearBackToTableContext(), v._insertElement(q, NS.HTML), v.insertionMode = InsertionMode.IN_TABLE_BODY;
}
function tdStartTagInTable(v, q) {
	v.openElements.clearBackToTableContext(), v._insertFakeElement(TAG_NAMES.TBODY, TAG_ID.TBODY), v.insertionMode = InsertionMode.IN_TABLE_BODY, startTagInTableBody(v, q);
}
function tableStartTagInTable(v, q) {
	v.openElements.hasInTableScope(TAG_ID.TABLE) && (v.openElements.popUntilTagNamePopped(TAG_ID.TABLE), v._resetInsertionMode(), v._processStartTag(q));
}
function inputStartTagInTable(v, q) {
	isHiddenInput(q) ? v._appendElement(q, NS.HTML) : tokenInTable(v, q), q.ackSelfClosing = !0;
}
function formStartTagInTable(v, q) {
	!v.formElement && v.openElements.tmplCount === 0 && (v._insertElement(q, NS.HTML), v.formElement = v.openElements.current, v.openElements.pop());
}
function startTagInTable(v, q) {
	switch (q.tagID) {
		case TAG_ID.TD:
		case TAG_ID.TH:
		case TAG_ID.TR:
			tdStartTagInTable(v, q);
			break;
		case TAG_ID.STYLE:
		case TAG_ID.SCRIPT:
		case TAG_ID.TEMPLATE:
			startTagInHead(v, q);
			break;
		case TAG_ID.COL:
			colStartTagInTable(v, q);
			break;
		case TAG_ID.FORM:
			formStartTagInTable(v, q);
			break;
		case TAG_ID.TABLE:
			tableStartTagInTable(v, q);
			break;
		case TAG_ID.TBODY:
		case TAG_ID.TFOOT:
		case TAG_ID.THEAD:
			tbodyStartTagInTable(v, q);
			break;
		case TAG_ID.INPUT:
			inputStartTagInTable(v, q);
			break;
		case TAG_ID.CAPTION:
			captionStartTagInTable(v, q);
			break;
		case TAG_ID.COLGROUP:
			colgroupStartTagInTable(v, q);
			break;
		default: tokenInTable(v, q);
	}
}
function endTagInTable(v, q) {
	switch (q.tagID) {
		case TAG_ID.TABLE:
			v.openElements.hasInTableScope(TAG_ID.TABLE) && (v.openElements.popUntilTagNamePopped(TAG_ID.TABLE), v._resetInsertionMode());
			break;
		case TAG_ID.TEMPLATE:
			templateEndTagInHead(v, q);
			break;
		case TAG_ID.BODY:
		case TAG_ID.CAPTION:
		case TAG_ID.COL:
		case TAG_ID.COLGROUP:
		case TAG_ID.HTML:
		case TAG_ID.TBODY:
		case TAG_ID.TD:
		case TAG_ID.TFOOT:
		case TAG_ID.TH:
		case TAG_ID.THEAD:
		case TAG_ID.TR: break;
		default: tokenInTable(v, q);
	}
}
function tokenInTable(v, q) {
	let J = v.fosterParentingEnabled;
	v.fosterParentingEnabled = !0, modeInBody(v, q), v.fosterParentingEnabled = J;
}
function whitespaceCharacterInTableText(v, q) {
	v.pendingCharacterTokens.push(q);
}
function characterInTableText(v, q) {
	v.pendingCharacterTokens.push(q), v.hasNonWhitespacePendingCharacterToken = !0;
}
function tokenInTableText(v, q) {
	let J = 0;
	if (v.hasNonWhitespacePendingCharacterToken) for (; J < v.pendingCharacterTokens.length; J++) tokenInTable(v, v.pendingCharacterTokens[J]);
	else for (; J < v.pendingCharacterTokens.length; J++) v._insertCharacters(v.pendingCharacterTokens[J]);
	v.insertionMode = v.originalInsertionMode, v._processToken(q);
}
var TABLE_VOID_ELEMENTS = new Set([
	TAG_ID.CAPTION,
	TAG_ID.COL,
	TAG_ID.COLGROUP,
	TAG_ID.TBODY,
	TAG_ID.TD,
	TAG_ID.TFOOT,
	TAG_ID.TH,
	TAG_ID.THEAD,
	TAG_ID.TR
]);
function startTagInCaption(v, q) {
	let J = q.tagID;
	TABLE_VOID_ELEMENTS.has(J) ? v.openElements.hasInTableScope(TAG_ID.CAPTION) && (v.openElements.generateImpliedEndTags(), v.openElements.popUntilTagNamePopped(TAG_ID.CAPTION), v.activeFormattingElements.clearToLastMarker(), v.insertionMode = InsertionMode.IN_TABLE, startTagInTable(v, q)) : startTagInBody(v, q);
}
function endTagInCaption(v, q) {
	let J = q.tagID;
	switch (J) {
		case TAG_ID.CAPTION:
		case TAG_ID.TABLE:
			v.openElements.hasInTableScope(TAG_ID.CAPTION) && (v.openElements.generateImpliedEndTags(), v.openElements.popUntilTagNamePopped(TAG_ID.CAPTION), v.activeFormattingElements.clearToLastMarker(), v.insertionMode = InsertionMode.IN_TABLE, J === TAG_ID.TABLE && endTagInTable(v, q));
			break;
		case TAG_ID.BODY:
		case TAG_ID.COL:
		case TAG_ID.COLGROUP:
		case TAG_ID.HTML:
		case TAG_ID.TBODY:
		case TAG_ID.TD:
		case TAG_ID.TFOOT:
		case TAG_ID.TH:
		case TAG_ID.THEAD:
		case TAG_ID.TR: break;
		default: endTagInBody(v, q);
	}
}
function startTagInColumnGroup(v, q) {
	switch (q.tagID) {
		case TAG_ID.HTML:
			startTagInBody(v, q);
			break;
		case TAG_ID.COL:
			v._appendElement(q, NS.HTML), q.ackSelfClosing = !0;
			break;
		case TAG_ID.TEMPLATE:
			startTagInHead(v, q);
			break;
		default: tokenInColumnGroup(v, q);
	}
}
function endTagInColumnGroup(v, q) {
	switch (q.tagID) {
		case TAG_ID.COLGROUP:
			v.openElements.currentTagId === TAG_ID.COLGROUP && (v.openElements.pop(), v.insertionMode = InsertionMode.IN_TABLE);
			break;
		case TAG_ID.TEMPLATE:
			templateEndTagInHead(v, q);
			break;
		case TAG_ID.COL: break;
		default: tokenInColumnGroup(v, q);
	}
}
function tokenInColumnGroup(v, q) {
	v.openElements.currentTagId === TAG_ID.COLGROUP && (v.openElements.pop(), v.insertionMode = InsertionMode.IN_TABLE, v._processToken(q));
}
function startTagInTableBody(v, q) {
	switch (q.tagID) {
		case TAG_ID.TR:
			v.openElements.clearBackToTableBodyContext(), v._insertElement(q, NS.HTML), v.insertionMode = InsertionMode.IN_ROW;
			break;
		case TAG_ID.TH:
		case TAG_ID.TD:
			v.openElements.clearBackToTableBodyContext(), v._insertFakeElement(TAG_NAMES.TR, TAG_ID.TR), v.insertionMode = InsertionMode.IN_ROW, startTagInRow(v, q);
			break;
		case TAG_ID.CAPTION:
		case TAG_ID.COL:
		case TAG_ID.COLGROUP:
		case TAG_ID.TBODY:
		case TAG_ID.TFOOT:
		case TAG_ID.THEAD:
			v.openElements.hasTableBodyContextInTableScope() && (v.openElements.clearBackToTableBodyContext(), v.openElements.pop(), v.insertionMode = InsertionMode.IN_TABLE, startTagInTable(v, q));
			break;
		default: startTagInTable(v, q);
	}
}
function endTagInTableBody(v, q) {
	let J = q.tagID;
	switch (q.tagID) {
		case TAG_ID.TBODY:
		case TAG_ID.TFOOT:
		case TAG_ID.THEAD:
			v.openElements.hasInTableScope(J) && (v.openElements.clearBackToTableBodyContext(), v.openElements.pop(), v.insertionMode = InsertionMode.IN_TABLE);
			break;
		case TAG_ID.TABLE:
			v.openElements.hasTableBodyContextInTableScope() && (v.openElements.clearBackToTableBodyContext(), v.openElements.pop(), v.insertionMode = InsertionMode.IN_TABLE, endTagInTable(v, q));
			break;
		case TAG_ID.BODY:
		case TAG_ID.CAPTION:
		case TAG_ID.COL:
		case TAG_ID.COLGROUP:
		case TAG_ID.HTML:
		case TAG_ID.TD:
		case TAG_ID.TH:
		case TAG_ID.TR: break;
		default: endTagInTable(v, q);
	}
}
function startTagInRow(v, q) {
	switch (q.tagID) {
		case TAG_ID.TH:
		case TAG_ID.TD:
			v.openElements.clearBackToTableRowContext(), v._insertElement(q, NS.HTML), v.insertionMode = InsertionMode.IN_CELL, v.activeFormattingElements.insertMarker();
			break;
		case TAG_ID.CAPTION:
		case TAG_ID.COL:
		case TAG_ID.COLGROUP:
		case TAG_ID.TBODY:
		case TAG_ID.TFOOT:
		case TAG_ID.THEAD:
		case TAG_ID.TR:
			v.openElements.hasInTableScope(TAG_ID.TR) && (v.openElements.clearBackToTableRowContext(), v.openElements.pop(), v.insertionMode = InsertionMode.IN_TABLE_BODY, startTagInTableBody(v, q));
			break;
		default: startTagInTable(v, q);
	}
}
function endTagInRow(v, q) {
	switch (q.tagID) {
		case TAG_ID.TR:
			v.openElements.hasInTableScope(TAG_ID.TR) && (v.openElements.clearBackToTableRowContext(), v.openElements.pop(), v.insertionMode = InsertionMode.IN_TABLE_BODY);
			break;
		case TAG_ID.TABLE:
			v.openElements.hasInTableScope(TAG_ID.TR) && (v.openElements.clearBackToTableRowContext(), v.openElements.pop(), v.insertionMode = InsertionMode.IN_TABLE_BODY, endTagInTableBody(v, q));
			break;
		case TAG_ID.TBODY:
		case TAG_ID.TFOOT:
		case TAG_ID.THEAD:
			(v.openElements.hasInTableScope(q.tagID) || v.openElements.hasInTableScope(TAG_ID.TR)) && (v.openElements.clearBackToTableRowContext(), v.openElements.pop(), v.insertionMode = InsertionMode.IN_TABLE_BODY, endTagInTableBody(v, q));
			break;
		case TAG_ID.BODY:
		case TAG_ID.CAPTION:
		case TAG_ID.COL:
		case TAG_ID.COLGROUP:
		case TAG_ID.HTML:
		case TAG_ID.TD:
		case TAG_ID.TH: break;
		default: endTagInTable(v, q);
	}
}
function startTagInCell(v, q) {
	let J = q.tagID;
	TABLE_VOID_ELEMENTS.has(J) ? (v.openElements.hasInTableScope(TAG_ID.TD) || v.openElements.hasInTableScope(TAG_ID.TH)) && (v._closeTableCell(), startTagInRow(v, q)) : startTagInBody(v, q);
}
function endTagInCell(v, q) {
	let J = q.tagID;
	switch (J) {
		case TAG_ID.TD:
		case TAG_ID.TH:
			v.openElements.hasInTableScope(J) && (v.openElements.generateImpliedEndTags(), v.openElements.popUntilTagNamePopped(J), v.activeFormattingElements.clearToLastMarker(), v.insertionMode = InsertionMode.IN_ROW);
			break;
		case TAG_ID.TABLE:
		case TAG_ID.TBODY:
		case TAG_ID.TFOOT:
		case TAG_ID.THEAD:
		case TAG_ID.TR:
			v.openElements.hasInTableScope(J) && (v._closeTableCell(), endTagInRow(v, q));
			break;
		case TAG_ID.BODY:
		case TAG_ID.CAPTION:
		case TAG_ID.COL:
		case TAG_ID.COLGROUP:
		case TAG_ID.HTML: break;
		default: endTagInBody(v, q);
	}
}
function startTagInSelect(v, q) {
	switch (q.tagID) {
		case TAG_ID.HTML:
			startTagInBody(v, q);
			break;
		case TAG_ID.OPTION:
			v.openElements.currentTagId === TAG_ID.OPTION && v.openElements.pop(), v._insertElement(q, NS.HTML);
			break;
		case TAG_ID.OPTGROUP:
			v.openElements.currentTagId === TAG_ID.OPTION && v.openElements.pop(), v.openElements.currentTagId === TAG_ID.OPTGROUP && v.openElements.pop(), v._insertElement(q, NS.HTML);
			break;
		case TAG_ID.HR:
			v.openElements.currentTagId === TAG_ID.OPTION && v.openElements.pop(), v.openElements.currentTagId === TAG_ID.OPTGROUP && v.openElements.pop(), v._appendElement(q, NS.HTML), q.ackSelfClosing = !0;
			break;
		case TAG_ID.INPUT:
		case TAG_ID.KEYGEN:
		case TAG_ID.TEXTAREA:
		case TAG_ID.SELECT:
			v.openElements.hasInSelectScope(TAG_ID.SELECT) && (v.openElements.popUntilTagNamePopped(TAG_ID.SELECT), v._resetInsertionMode(), q.tagID !== TAG_ID.SELECT && v._processStartTag(q));
			break;
		case TAG_ID.SCRIPT:
		case TAG_ID.TEMPLATE:
			startTagInHead(v, q);
			break;
		default:
	}
}
function endTagInSelect(v, q) {
	switch (q.tagID) {
		case TAG_ID.OPTGROUP:
			v.openElements.stackTop > 0 && v.openElements.currentTagId === TAG_ID.OPTION && v.openElements.tagIDs[v.openElements.stackTop - 1] === TAG_ID.OPTGROUP && v.openElements.pop(), v.openElements.currentTagId === TAG_ID.OPTGROUP && v.openElements.pop();
			break;
		case TAG_ID.OPTION:
			v.openElements.currentTagId === TAG_ID.OPTION && v.openElements.pop();
			break;
		case TAG_ID.SELECT:
			v.openElements.hasInSelectScope(TAG_ID.SELECT) && (v.openElements.popUntilTagNamePopped(TAG_ID.SELECT), v._resetInsertionMode());
			break;
		case TAG_ID.TEMPLATE:
			templateEndTagInHead(v, q);
			break;
		default:
	}
}
function startTagInSelectInTable(v, q) {
	let J = q.tagID;
	J === TAG_ID.CAPTION || J === TAG_ID.TABLE || J === TAG_ID.TBODY || J === TAG_ID.TFOOT || J === TAG_ID.THEAD || J === TAG_ID.TR || J === TAG_ID.TD || J === TAG_ID.TH ? (v.openElements.popUntilTagNamePopped(TAG_ID.SELECT), v._resetInsertionMode(), v._processStartTag(q)) : startTagInSelect(v, q);
}
function endTagInSelectInTable(v, q) {
	let J = q.tagID;
	J === TAG_ID.CAPTION || J === TAG_ID.TABLE || J === TAG_ID.TBODY || J === TAG_ID.TFOOT || J === TAG_ID.THEAD || J === TAG_ID.TR || J === TAG_ID.TD || J === TAG_ID.TH ? v.openElements.hasInTableScope(J) && (v.openElements.popUntilTagNamePopped(TAG_ID.SELECT), v._resetInsertionMode(), v.onEndTag(q)) : endTagInSelect(v, q);
}
function startTagInTemplate(v, q) {
	switch (q.tagID) {
		case TAG_ID.BASE:
		case TAG_ID.BASEFONT:
		case TAG_ID.BGSOUND:
		case TAG_ID.LINK:
		case TAG_ID.META:
		case TAG_ID.NOFRAMES:
		case TAG_ID.SCRIPT:
		case TAG_ID.STYLE:
		case TAG_ID.TEMPLATE:
		case TAG_ID.TITLE:
			startTagInHead(v, q);
			break;
		case TAG_ID.CAPTION:
		case TAG_ID.COLGROUP:
		case TAG_ID.TBODY:
		case TAG_ID.TFOOT:
		case TAG_ID.THEAD:
			v.tmplInsertionModeStack[0] = InsertionMode.IN_TABLE, v.insertionMode = InsertionMode.IN_TABLE, startTagInTable(v, q);
			break;
		case TAG_ID.COL:
			v.tmplInsertionModeStack[0] = InsertionMode.IN_COLUMN_GROUP, v.insertionMode = InsertionMode.IN_COLUMN_GROUP, startTagInColumnGroup(v, q);
			break;
		case TAG_ID.TR:
			v.tmplInsertionModeStack[0] = InsertionMode.IN_TABLE_BODY, v.insertionMode = InsertionMode.IN_TABLE_BODY, startTagInTableBody(v, q);
			break;
		case TAG_ID.TD:
		case TAG_ID.TH:
			v.tmplInsertionModeStack[0] = InsertionMode.IN_ROW, v.insertionMode = InsertionMode.IN_ROW, startTagInRow(v, q);
			break;
		default: v.tmplInsertionModeStack[0] = InsertionMode.IN_BODY, v.insertionMode = InsertionMode.IN_BODY, startTagInBody(v, q);
	}
}
function endTagInTemplate(v, q) {
	q.tagID === TAG_ID.TEMPLATE && templateEndTagInHead(v, q);
}
function eofInTemplate(v, q) {
	v.openElements.tmplCount > 0 ? (v.openElements.popUntilTagNamePopped(TAG_ID.TEMPLATE), v.activeFormattingElements.clearToLastMarker(), v.tmplInsertionModeStack.shift(), v._resetInsertionMode(), v.onEof(q)) : stopParsing(v, q);
}
function startTagAfterBody(v, q) {
	q.tagID === TAG_ID.HTML ? startTagInBody(v, q) : tokenAfterBody(v, q);
}
function endTagAfterBody(v, q) {
	if (q.tagID === TAG_ID.HTML) {
		if (v.fragmentContext || (v.insertionMode = InsertionMode.AFTER_AFTER_BODY), v.options.sourceCodeLocationInfo && v.openElements.tagIDs[0] === TAG_ID.HTML) {
			v._setEndLocation(v.openElements.items[0], q);
			let J = v.openElements.items[1];
			J && !v.treeAdapter.getNodeSourceCodeLocation(J)?.endTag && v._setEndLocation(J, q);
		}
	} else tokenAfterBody(v, q);
}
function tokenAfterBody(v, q) {
	v.insertionMode = InsertionMode.IN_BODY, modeInBody(v, q);
}
function startTagInFrameset(v, q) {
	switch (q.tagID) {
		case TAG_ID.HTML:
			startTagInBody(v, q);
			break;
		case TAG_ID.FRAMESET:
			v._insertElement(q, NS.HTML);
			break;
		case TAG_ID.FRAME:
			v._appendElement(q, NS.HTML), q.ackSelfClosing = !0;
			break;
		case TAG_ID.NOFRAMES:
			startTagInHead(v, q);
			break;
		default:
	}
}
function endTagInFrameset(v, q) {
	q.tagID === TAG_ID.FRAMESET && !v.openElements.isRootHtmlElementCurrent() && (v.openElements.pop(), !v.fragmentContext && v.openElements.currentTagId !== TAG_ID.FRAMESET && (v.insertionMode = InsertionMode.AFTER_FRAMESET));
}
function startTagAfterFrameset(v, q) {
	switch (q.tagID) {
		case TAG_ID.HTML:
			startTagInBody(v, q);
			break;
		case TAG_ID.NOFRAMES:
			startTagInHead(v, q);
			break;
		default:
	}
}
function endTagAfterFrameset(v, q) {
	q.tagID === TAG_ID.HTML && (v.insertionMode = InsertionMode.AFTER_AFTER_FRAMESET);
}
function startTagAfterAfterBody(v, q) {
	q.tagID === TAG_ID.HTML ? startTagInBody(v, q) : tokenAfterAfterBody(v, q);
}
function tokenAfterAfterBody(v, q) {
	v.insertionMode = InsertionMode.IN_BODY, modeInBody(v, q);
}
function startTagAfterAfterFrameset(v, q) {
	switch (q.tagID) {
		case TAG_ID.HTML:
			startTagInBody(v, q);
			break;
		case TAG_ID.NOFRAMES:
			startTagInHead(v, q);
			break;
		default:
	}
}
function nullCharacterInForeignContent(v, q) {
	q.chars = "�", v._insertCharacters(q);
}
function characterInForeignContent(v, q) {
	v._insertCharacters(q), v.framesetOk = !1;
}
function popUntilHtmlOrIntegrationPoint(v) {
	for (; v.treeAdapter.getNamespaceURI(v.openElements.current) !== NS.HTML && v.openElements.currentTagId !== void 0 && !v._isIntegrationPoint(v.openElements.currentTagId, v.openElements.current);) v.openElements.pop();
}
function startTagInForeignContent(v, q) {
	if (causesExit(q)) popUntilHtmlOrIntegrationPoint(v), v._startTagOutsideForeignContent(q);
	else {
		let J = v._getAdjustedCurrentElement(), Y = v.treeAdapter.getNamespaceURI(J);
		Y === NS.MATHML ? adjustTokenMathMLAttrs(q) : Y === NS.SVG && (adjustTokenSVGTagName(q), adjustTokenSVGAttrs(q)), adjustTokenXMLAttrs(q), q.selfClosing ? v._appendElement(q, Y) : v._insertElement(q, Y), q.ackSelfClosing = !0;
	}
}
function endTagInForeignContent(v, q) {
	if (q.tagID === TAG_ID.P || q.tagID === TAG_ID.BR) {
		popUntilHtmlOrIntegrationPoint(v), v._endTagOutsideForeignContent(q);
		return;
	}
	for (let J = v.openElements.stackTop; J > 0; J--) {
		let Y = v.openElements.items[J];
		if (v.treeAdapter.getNamespaceURI(Y) === NS.HTML) {
			v._endTagOutsideForeignContent(q);
			break;
		}
		let X = v.treeAdapter.getTagName(Y);
		if (X.toLowerCase() === q.tagName) {
			q.tagName = X, v.openElements.shortenToLength(J);
			break;
		}
	}
}
export { Parser };
