import { CODE_POINTS as e } from "../common/unicode.js";
import { ERR as t } from "../common/error-codes.js";
import { TokenType as n, getTokenAttr as r } from "../common/token.js";
import { ATTRS as i, DOCUMENT_MODE as a, NS as o, NUMBERED_HEADERS as s, SPECIAL_ELEMENTS as ee, TAG_ID as c, TAG_NAMES as l, getTagID as u } from "../common/html.js";
import { Tokenizer as te, TokenizerMode as d } from "../tokenizer/index.js";
import { OpenElementStack as ne } from "./open-element-stack.js";
import { EntryType as re, FormattingElementList as ie } from "./formatting-element-list.js";
import { defaultTreeAdapter as ae } from "../tree-adapters/default.js";
import { getDocumentMode as oe, isConforming as se } from "../common/doctype.js";
import { adjustTokenMathMLAttrs as f, adjustTokenSVGAttrs as p, adjustTokenSVGTagName as ce, adjustTokenXMLAttrs as m, causesExit as le, isIntegrationPoint as ue } from "../common/foreign-content.js";
//#region ../../node_modules/hast-util-raw/node_modules/parse5/dist/parser/index.js
var de = "hidden", fe = 8, pe = 3, h;
(function(e) {
	e[e.INITIAL = 0] = "INITIAL", e[e.BEFORE_HTML = 1] = "BEFORE_HTML", e[e.BEFORE_HEAD = 2] = "BEFORE_HEAD", e[e.IN_HEAD = 3] = "IN_HEAD", e[e.IN_HEAD_NO_SCRIPT = 4] = "IN_HEAD_NO_SCRIPT", e[e.AFTER_HEAD = 5] = "AFTER_HEAD", e[e.IN_BODY = 6] = "IN_BODY", e[e.TEXT = 7] = "TEXT", e[e.IN_TABLE = 8] = "IN_TABLE", e[e.IN_TABLE_TEXT = 9] = "IN_TABLE_TEXT", e[e.IN_CAPTION = 10] = "IN_CAPTION", e[e.IN_COLUMN_GROUP = 11] = "IN_COLUMN_GROUP", e[e.IN_TABLE_BODY = 12] = "IN_TABLE_BODY", e[e.IN_ROW = 13] = "IN_ROW", e[e.IN_CELL = 14] = "IN_CELL", e[e.IN_SELECT = 15] = "IN_SELECT", e[e.IN_SELECT_IN_TABLE = 16] = "IN_SELECT_IN_TABLE", e[e.IN_TEMPLATE = 17] = "IN_TEMPLATE", e[e.AFTER_BODY = 18] = "AFTER_BODY", e[e.IN_FRAMESET = 19] = "IN_FRAMESET", e[e.AFTER_FRAMESET = 20] = "AFTER_FRAMESET", e[e.AFTER_AFTER_BODY = 21] = "AFTER_AFTER_BODY", e[e.AFTER_AFTER_FRAMESET = 22] = "AFTER_AFTER_FRAMESET";
})(h ||= {});
var me = {
	startLine: -1,
	startCol: -1,
	startOffset: -1,
	endLine: -1,
	endCol: -1,
	endOffset: -1
}, g = new Set([
	c.TABLE,
	c.TBODY,
	c.TFOOT,
	c.THEAD,
	c.TR
]), _ = {
	scriptingEnabled: !0,
	sourceCodeLocationInfo: !1,
	treeAdapter: ae,
	onParseError: null
}, he = class {
	constructor(e, t, n = null, r = null) {
		this.fragmentContext = n, this.scriptHandler = r, this.currentToken = null, this.stopped = !1, this.insertionMode = h.INITIAL, this.originalInsertionMode = h.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 = {
			..._,
			...e
		}, this.treeAdapter = this.options.treeAdapter, this.onParseError = this.options.onParseError, this.onParseError && (this.options.sourceCodeLocationInfo = !0), this.document = t ?? this.treeAdapter.createDocument(), this.tokenizer = new te(this.options, this), this.activeFormattingElements = new ie(this.treeAdapter), this.fragmentContextID = n ? u(this.treeAdapter.getTagName(n)) : c.UNKNOWN, this._setContextModes(n ?? this.document, this.fragmentContextID), this.openElements = new ne(this.document, this.treeAdapter, this);
	}
	static parse(e, t) {
		let n = new this(t);
		return n.tokenizer.write(e, !0), n.document;
	}
	static getFragmentParser(e, t) {
		let n = {
			..._,
			...t
		};
		e ??= n.treeAdapter.createElement(l.TEMPLATE, o.HTML, []);
		let r = n.treeAdapter.createElement("documentmock", o.HTML, []), i = new this(n, r, e);
		return i.fragmentContextID === c.TEMPLATE && i.tmplInsertionModeStack.unshift(h.IN_TEMPLATE), i._initTokenizerForFragmentParsing(), i._insertFakeRootElement(), i._resetInsertionMode(), i._findFormInFragmentContext(), i;
	}
	getFragment() {
		let e = this.treeAdapter.getFirstChild(this.document), t = this.treeAdapter.createDocumentFragment();
		return this._adoptNodes(e, t), t;
	}
	_err(e, t, n) {
		if (!this.onParseError) return;
		let r = e.location ?? me, i = {
			code: t,
			startLine: r.startLine,
			startCol: r.startCol,
			startOffset: r.startOffset,
			endLine: n ? r.startLine : r.endLine,
			endCol: n ? r.startCol : r.endCol,
			endOffset: n ? r.startOffset : r.endOffset
		};
		this.onParseError(i);
	}
	onItemPush(e, t, n) {
		var r, i;
		(i = (r = this.treeAdapter).onItemPush) == null || i.call(r, e), n && this.openElements.stackTop > 0 && this._setContextModes(e, t);
	}
	onItemPop(e, t) {
		var n, r;
		if (this.options.sourceCodeLocationInfo && this._setEndLocation(e, this.currentToken), (r = (n = this.treeAdapter).onItemPop) == null || r.call(n, e, this.openElements.current), t) {
			let e, t;
			this.openElements.stackTop === 0 && this.fragmentContext ? (e = this.fragmentContext, t = this.fragmentContextID) : {current: e, currentTagId: t} = this.openElements, this._setContextModes(e, t);
		}
	}
	_setContextModes(e, t) {
		let n = e === this.document || e && this.treeAdapter.getNamespaceURI(e) === o.HTML;
		this.currentNotInHTML = !n, this.tokenizer.inForeignNode = !n && e !== void 0 && t !== void 0 && !this._isIntegrationPoint(t, e);
	}
	_switchToTextParsing(e, t) {
		this._insertElement(e, o.HTML), this.tokenizer.state = t, this.originalInsertionMode = this.insertionMode, this.insertionMode = h.TEXT;
	}
	switchToPlaintextParsing() {
		this.insertionMode = h.TEXT, this.originalInsertionMode = h.IN_BODY, this.tokenizer.state = d.PLAINTEXT;
	}
	_getAdjustedCurrentElement() {
		return this.openElements.stackTop === 0 && this.fragmentContext ? this.fragmentContext : this.openElements.current;
	}
	_findFormInFragmentContext() {
		let e = this.fragmentContext;
		for (; e;) {
			if (this.treeAdapter.getTagName(e) === l.FORM) {
				this.formElement = e;
				break;
			}
			e = this.treeAdapter.getParentNode(e);
		}
	}
	_initTokenizerForFragmentParsing() {
		if (!(!this.fragmentContext || this.treeAdapter.getNamespaceURI(this.fragmentContext) !== o.HTML)) switch (this.fragmentContextID) {
			case c.TITLE:
			case c.TEXTAREA:
				this.tokenizer.state = d.RCDATA;
				break;
			case c.STYLE:
			case c.XMP:
			case c.IFRAME:
			case c.NOEMBED:
			case c.NOFRAMES:
			case c.NOSCRIPT:
				this.tokenizer.state = d.RAWTEXT;
				break;
			case c.SCRIPT:
				this.tokenizer.state = d.SCRIPT_DATA;
				break;
			case c.PLAINTEXT:
				this.tokenizer.state = d.PLAINTEXT;
				break;
			default:
		}
	}
	_setDocumentType(e) {
		let t = e.name || "", n = e.publicId || "", r = e.systemId || "";
		if (this.treeAdapter.setDocumentType(this.document, t, n, r), e.location) {
			let t = this.treeAdapter.getChildNodes(this.document).find((e) => this.treeAdapter.isDocumentTypeNode(e));
			t && this.treeAdapter.setNodeSourceCodeLocation(t, e.location);
		}
	}
	_attachElementToTree(e, t) {
		if (this.options.sourceCodeLocationInfo) {
			let n = t && {
				...t,
				startTag: t
			};
			this.treeAdapter.setNodeSourceCodeLocation(e, n);
		}
		if (this._shouldFosterParentOnInsertion()) this._fosterParentElement(e);
		else {
			let t = this.openElements.currentTmplContentOrNode;
			this.treeAdapter.appendChild(t ?? this.document, e);
		}
	}
	_appendElement(e, t) {
		let n = this.treeAdapter.createElement(e.tagName, t, e.attrs);
		this._attachElementToTree(n, e.location);
	}
	_insertElement(e, t) {
		let n = this.treeAdapter.createElement(e.tagName, t, e.attrs);
		this._attachElementToTree(n, e.location), this.openElements.push(n, e.tagID);
	}
	_insertFakeElement(e, t) {
		let n = this.treeAdapter.createElement(e, o.HTML, []);
		this._attachElementToTree(n, null), this.openElements.push(n, t);
	}
	_insertTemplate(e) {
		let t = this.treeAdapter.createElement(e.tagName, o.HTML, e.attrs), n = this.treeAdapter.createDocumentFragment();
		this.treeAdapter.setTemplateContent(t, n), this._attachElementToTree(t, e.location), this.openElements.push(t, e.tagID), this.options.sourceCodeLocationInfo && this.treeAdapter.setNodeSourceCodeLocation(n, null);
	}
	_insertFakeRootElement() {
		let e = this.treeAdapter.createElement(l.HTML, o.HTML, []);
		this.options.sourceCodeLocationInfo && this.treeAdapter.setNodeSourceCodeLocation(e, null), this.treeAdapter.appendChild(this.openElements.current, e), this.openElements.push(e, c.HTML);
	}
	_appendCommentNode(e, t) {
		let n = this.treeAdapter.createCommentNode(e.data);
		this.treeAdapter.appendChild(t, n), this.options.sourceCodeLocationInfo && this.treeAdapter.setNodeSourceCodeLocation(n, e.location);
	}
	_insertCharacters(e) {
		let t, n;
		if (this._shouldFosterParentOnInsertion() ? ({parent: t, beforeElement: n} = this._findFosterParentingLocation(), n ? this.treeAdapter.insertTextBefore(t, e.chars, n) : this.treeAdapter.insertText(t, e.chars)) : (t = this.openElements.currentTmplContentOrNode, this.treeAdapter.insertText(t, e.chars)), !e.location) return;
		let r = this.treeAdapter.getChildNodes(t), i = r[(n ? r.lastIndexOf(n) : r.length) - 1];
		if (this.treeAdapter.getNodeSourceCodeLocation(i)) {
			let { endLine: t, endCol: n, endOffset: r } = e.location;
			this.treeAdapter.updateNodeSourceCodeLocation(i, {
				endLine: t,
				endCol: n,
				endOffset: r
			});
		} else this.options.sourceCodeLocationInfo && this.treeAdapter.setNodeSourceCodeLocation(i, e.location);
	}
	_adoptNodes(e, t) {
		for (let n = this.treeAdapter.getFirstChild(e); n; n = this.treeAdapter.getFirstChild(e)) this.treeAdapter.detachNode(n), this.treeAdapter.appendChild(t, n);
	}
	_setEndLocation(e, t) {
		if (this.treeAdapter.getNodeSourceCodeLocation(e) && t.location) {
			let r = t.location, i = this.treeAdapter.getTagName(e), a = t.type === n.END_TAG && i === t.tagName ? {
				endTag: { ...r },
				endLine: r.endLine,
				endCol: r.endCol,
				endOffset: r.endOffset
			} : {
				endLine: r.startLine,
				endCol: r.startCol,
				endOffset: r.startOffset
			};
			this.treeAdapter.updateNodeSourceCodeLocation(e, a);
		}
	}
	shouldProcessStartTagTokenInForeignContent(e) {
		if (!this.currentNotInHTML) return !1;
		let t, n;
		return this.openElements.stackTop === 0 && this.fragmentContext ? (t = this.fragmentContext, n = this.fragmentContextID) : {current: t, currentTagId: n} = this.openElements, e.tagID === c.SVG && this.treeAdapter.getTagName(t) === l.ANNOTATION_XML && this.treeAdapter.getNamespaceURI(t) === o.MATHML ? !1 : this.tokenizer.inForeignNode || (e.tagID === c.MGLYPH || e.tagID === c.MALIGNMARK) && n !== void 0 && !this._isIntegrationPoint(n, t, o.HTML);
	}
	_processToken(e) {
		switch (e.type) {
			case n.CHARACTER:
				this.onCharacter(e);
				break;
			case n.NULL_CHARACTER:
				this.onNullCharacter(e);
				break;
			case n.COMMENT:
				this.onComment(e);
				break;
			case n.DOCTYPE:
				this.onDoctype(e);
				break;
			case n.START_TAG:
				this._processStartTag(e);
				break;
			case n.END_TAG:
				this.onEndTag(e);
				break;
			case n.EOF:
				this.onEof(e);
				break;
			case n.WHITESPACE_CHARACTER:
				this.onWhitespaceCharacter(e);
				break;
		}
	}
	_isIntegrationPoint(e, t, n) {
		return ue(e, this.treeAdapter.getNamespaceURI(t), this.treeAdapter.getAttrList(t), n);
	}
	_reconstructActiveFormattingElements() {
		let e = this.activeFormattingElements.entries.length;
		if (e) {
			let t = this.activeFormattingElements.entries.findIndex((e) => e.type === re.Marker || this.openElements.contains(e.element)), n = t === -1 ? e - 1 : t - 1;
			for (let e = n; e >= 0; e--) {
				let t = this.activeFormattingElements.entries[e];
				this._insertElement(t.token, this.treeAdapter.getNamespaceURI(t.element)), t.element = this.openElements.current;
			}
		}
	}
	_closeTableCell() {
		this.openElements.generateImpliedEndTags(), this.openElements.popUntilTableCellPopped(), this.activeFormattingElements.clearToLastMarker(), this.insertionMode = h.IN_ROW;
	}
	_closePElement() {
		this.openElements.generateImpliedEndTagsWithExclusion(c.P), this.openElements.popUntilTagNamePopped(c.P);
	}
	_resetInsertionMode() {
		for (let e = this.openElements.stackTop; e >= 0; e--) switch (e === 0 && this.fragmentContext ? this.fragmentContextID : this.openElements.tagIDs[e]) {
			case c.TR:
				this.insertionMode = h.IN_ROW;
				return;
			case c.TBODY:
			case c.THEAD:
			case c.TFOOT:
				this.insertionMode = h.IN_TABLE_BODY;
				return;
			case c.CAPTION:
				this.insertionMode = h.IN_CAPTION;
				return;
			case c.COLGROUP:
				this.insertionMode = h.IN_COLUMN_GROUP;
				return;
			case c.TABLE:
				this.insertionMode = h.IN_TABLE;
				return;
			case c.BODY:
				this.insertionMode = h.IN_BODY;
				return;
			case c.FRAMESET:
				this.insertionMode = h.IN_FRAMESET;
				return;
			case c.SELECT:
				this._resetInsertionModeForSelect(e);
				return;
			case c.TEMPLATE:
				this.insertionMode = this.tmplInsertionModeStack[0];
				return;
			case c.HTML:
				this.insertionMode = this.headElement ? h.AFTER_HEAD : h.BEFORE_HEAD;
				return;
			case c.TD:
			case c.TH:
				if (e > 0) {
					this.insertionMode = h.IN_CELL;
					return;
				}
				break;
			case c.HEAD:
				if (e > 0) {
					this.insertionMode = h.IN_HEAD;
					return;
				}
				break;
		}
		this.insertionMode = h.IN_BODY;
	}
	_resetInsertionModeForSelect(e) {
		if (e > 0) for (let t = e - 1; t > 0; t--) {
			let e = this.openElements.tagIDs[t];
			if (e === c.TEMPLATE) break;
			if (e === c.TABLE) {
				this.insertionMode = h.IN_SELECT_IN_TABLE;
				return;
			}
		}
		this.insertionMode = h.IN_SELECT;
	}
	_isElementCausesFosterParenting(e) {
		return g.has(e);
	}
	_shouldFosterParentOnInsertion() {
		return this.fosterParentingEnabled && this.openElements.currentTagId !== void 0 && this._isElementCausesFosterParenting(this.openElements.currentTagId);
	}
	_findFosterParentingLocation() {
		for (let e = this.openElements.stackTop; e >= 0; e--) {
			let t = this.openElements.items[e];
			switch (this.openElements.tagIDs[e]) {
				case c.TEMPLATE:
					if (this.treeAdapter.getNamespaceURI(t) === o.HTML) return {
						parent: this.treeAdapter.getTemplateContent(t),
						beforeElement: null
					};
					break;
				case c.TABLE: {
					let n = this.treeAdapter.getParentNode(t);
					return n ? {
						parent: n,
						beforeElement: t
					} : {
						parent: this.openElements.items[e - 1],
						beforeElement: null
					};
				}
				default:
			}
		}
		return {
			parent: this.openElements.items[0],
			beforeElement: null
		};
	}
	_fosterParentElement(e) {
		let t = this._findFosterParentingLocation();
		t.beforeElement ? this.treeAdapter.insertBefore(t.parent, e, t.beforeElement) : this.treeAdapter.appendChild(t.parent, e);
	}
	_isSpecialElement(e, t) {
		return ee[this.treeAdapter.getNamespaceURI(e)].has(t);
	}
	onCharacter(e) {
		if (this.skipNextNewLine = !1, this.tokenizer.inForeignNode) {
			Zt(this, e);
			return;
		}
		switch (this.insertionMode) {
			case h.INITIAL:
				x(this, e);
				break;
			case h.BEFORE_HTML:
				S(this, e);
				break;
			case h.BEFORE_HEAD:
				C(this, e);
				break;
			case h.IN_HEAD:
				E(this, e);
				break;
			case h.IN_HEAD_NO_SCRIPT:
				D(this, e);
				break;
			case h.AFTER_HEAD:
				O(this, e);
				break;
			case h.IN_BODY:
			case h.IN_CAPTION:
			case h.IN_CELL:
			case h.IN_TEMPLATE:
				j(this, e);
				break;
			case h.TEXT:
			case h.IN_SELECT:
			case h.IN_SELECT_IN_TABLE:
				this._insertCharacters(e);
				break;
			case h.IN_TABLE:
			case h.IN_TABLE_BODY:
			case h.IN_ROW:
				R(this, e);
				break;
			case h.IN_TABLE_TEXT:
				U(this, e);
				break;
			case h.IN_COLUMN_GROUP:
				q(this, e);
				break;
			case h.AFTER_BODY:
				Q(this, e);
				break;
			case h.AFTER_AFTER_BODY:
				$(this, e);
				break;
			default:
		}
	}
	onNullCharacter(e) {
		if (this.skipNextNewLine = !1, this.tokenizer.inForeignNode) {
			Xt(this, e);
			return;
		}
		switch (this.insertionMode) {
			case h.INITIAL:
				x(this, e);
				break;
			case h.BEFORE_HTML:
				S(this, e);
				break;
			case h.BEFORE_HEAD:
				C(this, e);
				break;
			case h.IN_HEAD:
				E(this, e);
				break;
			case h.IN_HEAD_NO_SCRIPT:
				D(this, e);
				break;
			case h.AFTER_HEAD:
				O(this, e);
				break;
			case h.TEXT:
				this._insertCharacters(e);
				break;
			case h.IN_TABLE:
			case h.IN_TABLE_BODY:
			case h.IN_ROW:
				R(this, e);
				break;
			case h.IN_COLUMN_GROUP:
				q(this, e);
				break;
			case h.AFTER_BODY:
				Q(this, e);
				break;
			case h.AFTER_AFTER_BODY:
				$(this, e);
				break;
			default:
		}
	}
	onComment(e) {
		if (this.skipNextNewLine = !1, this.currentNotInHTML) {
			y(this, e);
			return;
		}
		switch (this.insertionMode) {
			case h.INITIAL:
			case h.BEFORE_HTML:
			case h.BEFORE_HEAD:
			case h.IN_HEAD:
			case h.IN_HEAD_NO_SCRIPT:
			case h.AFTER_HEAD:
			case h.IN_BODY:
			case h.IN_TABLE:
			case h.IN_CAPTION:
			case h.IN_COLUMN_GROUP:
			case h.IN_TABLE_BODY:
			case h.IN_ROW:
			case h.IN_CELL:
			case h.IN_SELECT:
			case h.IN_SELECT_IN_TABLE:
			case h.IN_TEMPLATE:
			case h.IN_FRAMESET:
			case h.AFTER_FRAMESET:
				y(this, e);
				break;
			case h.IN_TABLE_TEXT:
				W(this, e);
				break;
			case h.AFTER_BODY:
				Se(this, e);
				break;
			case h.AFTER_AFTER_BODY:
			case h.AFTER_AFTER_FRAMESET:
				Ce(this, e);
				break;
			default:
		}
	}
	onDoctype(e) {
		switch (this.skipNextNewLine = !1, this.insertionMode) {
			case h.INITIAL:
				we(this, e);
				break;
			case h.BEFORE_HEAD:
			case h.IN_HEAD:
			case h.IN_HEAD_NO_SCRIPT:
			case h.AFTER_HEAD:
				this._err(e, t.misplacedDoctype);
				break;
			case h.IN_TABLE_TEXT:
				W(this, e);
				break;
			default:
		}
	}
	onStartTag(e) {
		this.skipNextNewLine = !1, this.currentToken = e, this._processStartTag(e), e.selfClosing && !e.ackSelfClosing && this._err(e, t.nonVoidHtmlElementStartTagWithTrailingSolidus);
	}
	_processStartTag(e) {
		this.shouldProcessStartTagTokenInForeignContent(e) ? $t(this, e) : this._startTagOutsideForeignContent(e);
	}
	_startTagOutsideForeignContent(e) {
		switch (this.insertionMode) {
			case h.INITIAL:
				x(this, e);
				break;
			case h.BEFORE_HTML:
				Te(this, e);
				break;
			case h.BEFORE_HEAD:
				De(this, e);
				break;
			case h.IN_HEAD:
				w(this, e);
				break;
			case h.IN_HEAD_NO_SCRIPT:
				Ae(this, e);
				break;
			case h.AFTER_HEAD:
				Me(this, e);
				break;
			case h.IN_BODY:
				F(this, e);
				break;
			case h.IN_TABLE:
				z(this, e);
				break;
			case h.IN_TABLE_TEXT:
				W(this, e);
				break;
			case h.IN_CAPTION:
				At(this, e);
				break;
			case h.IN_COLUMN_GROUP:
				K(this, e);
				break;
			case h.IN_TABLE_BODY:
				J(this, e);
				break;
			case h.IN_ROW:
				X(this, e);
				break;
			case h.IN_CELL:
				Nt(this, e);
				break;
			case h.IN_SELECT:
				Ft(this, e);
				break;
			case h.IN_SELECT_IN_TABLE:
				Lt(this, e);
				break;
			case h.IN_TEMPLATE:
				zt(this, e);
				break;
			case h.AFTER_BODY:
				Ht(this, e);
				break;
			case h.IN_FRAMESET:
				Wt(this, e);
				break;
			case h.AFTER_FRAMESET:
				Kt(this, e);
				break;
			case h.AFTER_AFTER_BODY:
				Jt(this, e);
				break;
			case h.AFTER_AFTER_FRAMESET:
				Yt(this, e);
				break;
			default:
		}
	}
	onEndTag(e) {
		this.skipNextNewLine = !1, this.currentToken = e, this.currentNotInHTML ? en(this, e) : this._endTagOutsideForeignContent(e);
	}
	_endTagOutsideForeignContent(e) {
		switch (this.insertionMode) {
			case h.INITIAL:
				x(this, e);
				break;
			case h.BEFORE_HTML:
				Ee(this, e);
				break;
			case h.BEFORE_HEAD:
				Oe(this, e);
				break;
			case h.IN_HEAD:
				ke(this, e);
				break;
			case h.IN_HEAD_NO_SCRIPT:
				je(this, e);
				break;
			case h.AFTER_HEAD:
				Ne(this, e);
				break;
			case h.IN_BODY:
				L(this, e);
				break;
			case h.TEXT:
				bt(this, e);
				break;
			case h.IN_TABLE:
				B(this, e);
				break;
			case h.IN_TABLE_TEXT:
				W(this, e);
				break;
			case h.IN_CAPTION:
				jt(this, e);
				break;
			case h.IN_COLUMN_GROUP:
				Mt(this, e);
				break;
			case h.IN_TABLE_BODY:
				Y(this, e);
				break;
			case h.IN_ROW:
				Z(this, e);
				break;
			case h.IN_CELL:
				Pt(this, e);
				break;
			case h.IN_SELECT:
				It(this, e);
				break;
			case h.IN_SELECT_IN_TABLE:
				Rt(this, e);
				break;
			case h.IN_TEMPLATE:
				Bt(this, e);
				break;
			case h.AFTER_BODY:
				Ut(this, e);
				break;
			case h.IN_FRAMESET:
				Gt(this, e);
				break;
			case h.AFTER_FRAMESET:
				qt(this, e);
				break;
			case h.AFTER_AFTER_BODY:
				$(this, e);
				break;
			default:
		}
	}
	onEof(e) {
		switch (this.insertionMode) {
			case h.INITIAL:
				x(this, e);
				break;
			case h.BEFORE_HTML:
				S(this, e);
				break;
			case h.BEFORE_HEAD:
				C(this, e);
				break;
			case h.IN_HEAD:
				E(this, e);
				break;
			case h.IN_HEAD_NO_SCRIPT:
				D(this, e);
				break;
			case h.AFTER_HEAD:
				O(this, e);
				break;
			case h.IN_BODY:
			case h.IN_TABLE:
			case h.IN_CAPTION:
			case h.IN_COLUMN_GROUP:
			case h.IN_TABLE_BODY:
			case h.IN_ROW:
			case h.IN_CELL:
			case h.IN_SELECT:
			case h.IN_SELECT_IN_TABLE:
				yt(this, e);
				break;
			case h.TEXT:
				xt(this, e);
				break;
			case h.IN_TABLE_TEXT:
				W(this, e);
				break;
			case h.IN_TEMPLATE:
				Vt(this, e);
				break;
			case h.AFTER_BODY:
			case h.IN_FRAMESET:
			case h.AFTER_FRAMESET:
			case h.AFTER_AFTER_BODY:
			case h.AFTER_AFTER_FRAMESET:
				b(this, e);
				break;
			default:
		}
	}
	onWhitespaceCharacter(t) {
		if (this.skipNextNewLine && (this.skipNextNewLine = !1, t.chars.charCodeAt(0) === e.LINE_FEED)) {
			if (t.chars.length === 1) return;
			t.chars = t.chars.substr(1);
		}
		if (this.tokenizer.inForeignNode) {
			this._insertCharacters(t);
			return;
		}
		switch (this.insertionMode) {
			case h.IN_HEAD:
			case h.IN_HEAD_NO_SCRIPT:
			case h.AFTER_HEAD:
			case h.TEXT:
			case h.IN_COLUMN_GROUP:
			case h.IN_SELECT:
			case h.IN_SELECT_IN_TABLE:
			case h.IN_FRAMESET:
			case h.AFTER_FRAMESET:
				this._insertCharacters(t);
				break;
			case h.IN_BODY:
			case h.IN_CAPTION:
			case h.IN_CELL:
			case h.IN_TEMPLATE:
			case h.AFTER_BODY:
			case h.AFTER_AFTER_BODY:
			case h.AFTER_AFTER_FRAMESET:
				A(this, t);
				break;
			case h.IN_TABLE:
			case h.IN_TABLE_BODY:
			case h.IN_ROW:
				R(this, t);
				break;
			case h.IN_TABLE_TEXT:
				H(this, t);
				break;
			default:
		}
	}
};
function ge(e, t) {
	let n = e.activeFormattingElements.getElementEntryInScopeWithTagName(t.tagName);
	return n ? e.openElements.contains(n.element) ? e.openElements.hasInScope(t.tagID) || (n = null) : (e.activeFormattingElements.removeEntry(n), n = null) : I(e, t), n;
}
function _e(e, t) {
	let n = null, r = e.openElements.stackTop;
	for (; r >= 0; r--) {
		let i = e.openElements.items[r];
		if (i === t.element) break;
		e._isSpecialElement(i, e.openElements.tagIDs[r]) && (n = i);
	}
	return n || (e.openElements.shortenToLength(Math.max(r, 0)), e.activeFormattingElements.removeEntry(t)), n;
}
function ve(e, t, n) {
	let r = t, i = e.openElements.getCommonAncestor(t);
	for (let a = 0, o = i; o !== n; a++, o = i) {
		i = e.openElements.getCommonAncestor(o);
		let n = e.activeFormattingElements.getElementEntry(o), s = n && a >= pe;
		!n || s ? (s && e.activeFormattingElements.removeEntry(n), e.openElements.remove(o)) : (o = ye(e, n), r === t && (e.activeFormattingElements.bookmark = n), e.treeAdapter.detachNode(r), e.treeAdapter.appendChild(o, r), r = o);
	}
	return r;
}
function ye(e, t) {
	let n = e.treeAdapter.getNamespaceURI(t.element), r = e.treeAdapter.createElement(t.token.tagName, n, t.token.attrs);
	return e.openElements.replace(t.element, r), t.element = r, r;
}
function be(e, t, n) {
	let r = u(e.treeAdapter.getTagName(t));
	if (e._isElementCausesFosterParenting(r)) e._fosterParentElement(n);
	else {
		let i = e.treeAdapter.getNamespaceURI(t);
		r === c.TEMPLATE && i === o.HTML && (t = e.treeAdapter.getTemplateContent(t)), e.treeAdapter.appendChild(t, n);
	}
}
function xe(e, t, n) {
	let r = e.treeAdapter.getNamespaceURI(n.element), { token: i } = n, a = e.treeAdapter.createElement(i.tagName, r, i.attrs);
	e._adoptNodes(t, a), e.treeAdapter.appendChild(t, a), e.activeFormattingElements.insertElementAfterBookmark(a, i), e.activeFormattingElements.removeEntry(n), e.openElements.remove(n.element), e.openElements.insertAfter(t, a, i.tagID);
}
function v(e, t) {
	for (let n = 0; n < fe; n++) {
		let n = ge(e, t);
		if (!n) break;
		let r = _e(e, n);
		if (!r) break;
		e.activeFormattingElements.bookmark = n;
		let i = ve(e, r, n.element), a = e.openElements.getCommonAncestor(n.element);
		e.treeAdapter.detachNode(i), a && be(e, a, i), xe(e, r, n);
	}
}
function y(e, t) {
	e._appendCommentNode(t, e.openElements.currentTmplContentOrNode);
}
function Se(e, t) {
	e._appendCommentNode(t, e.openElements.items[0]);
}
function Ce(e, t) {
	e._appendCommentNode(t, e.document);
}
function b(e, t) {
	if (e.stopped = !0, t.location) {
		let n = e.fragmentContext ? 0 : 2;
		for (let r = e.openElements.stackTop; r >= n; r--) e._setEndLocation(e.openElements.items[r], t);
		if (!e.fragmentContext && e.openElements.stackTop >= 0) {
			let n = e.openElements.items[0], r = e.treeAdapter.getNodeSourceCodeLocation(n);
			if (r && !r.endTag && (e._setEndLocation(n, t), e.openElements.stackTop >= 1)) {
				let n = e.openElements.items[1], r = e.treeAdapter.getNodeSourceCodeLocation(n);
				r && !r.endTag && e._setEndLocation(n, t);
			}
		}
	}
}
function we(e, n) {
	e._setDocumentType(n);
	let r = n.forceQuirks ? a.QUIRKS : oe(n);
	se(n) || e._err(n, t.nonConformingDoctype), e.treeAdapter.setDocumentMode(e.document, r), e.insertionMode = h.BEFORE_HTML;
}
function x(e, n) {
	e._err(n, t.missingDoctype, !0), e.treeAdapter.setDocumentMode(e.document, a.QUIRKS), e.insertionMode = h.BEFORE_HTML, e._processToken(n);
}
function Te(e, t) {
	t.tagID === c.HTML ? (e._insertElement(t, o.HTML), e.insertionMode = h.BEFORE_HEAD) : S(e, t);
}
function Ee(e, t) {
	let n = t.tagID;
	(n === c.HTML || n === c.HEAD || n === c.BODY || n === c.BR) && S(e, t);
}
function S(e, t) {
	e._insertFakeRootElement(), e.insertionMode = h.BEFORE_HEAD, e._processToken(t);
}
function De(e, t) {
	switch (t.tagID) {
		case c.HTML:
			F(e, t);
			break;
		case c.HEAD:
			e._insertElement(t, o.HTML), e.headElement = e.openElements.current, e.insertionMode = h.IN_HEAD;
			break;
		default: C(e, t);
	}
}
function Oe(e, n) {
	let r = n.tagID;
	r === c.HEAD || r === c.BODY || r === c.HTML || r === c.BR ? C(e, n) : e._err(n, t.endTagWithoutMatchingOpenElement);
}
function C(e, t) {
	e._insertFakeElement(l.HEAD, c.HEAD), e.headElement = e.openElements.current, e.insertionMode = h.IN_HEAD, e._processToken(t);
}
function w(e, n) {
	switch (n.tagID) {
		case c.HTML:
			F(e, n);
			break;
		case c.BASE:
		case c.BASEFONT:
		case c.BGSOUND:
		case c.LINK:
		case c.META:
			e._appendElement(n, o.HTML), n.ackSelfClosing = !0;
			break;
		case c.TITLE:
			e._switchToTextParsing(n, d.RCDATA);
			break;
		case c.NOSCRIPT:
			e.options.scriptingEnabled ? e._switchToTextParsing(n, d.RAWTEXT) : (e._insertElement(n, o.HTML), e.insertionMode = h.IN_HEAD_NO_SCRIPT);
			break;
		case c.NOFRAMES:
		case c.STYLE:
			e._switchToTextParsing(n, d.RAWTEXT);
			break;
		case c.SCRIPT:
			e._switchToTextParsing(n, d.SCRIPT_DATA);
			break;
		case c.TEMPLATE:
			e._insertTemplate(n), e.activeFormattingElements.insertMarker(), e.framesetOk = !1, e.insertionMode = h.IN_TEMPLATE, e.tmplInsertionModeStack.unshift(h.IN_TEMPLATE);
			break;
		case c.HEAD:
			e._err(n, t.misplacedStartTagForHeadElement);
			break;
		default: E(e, n);
	}
}
function ke(e, n) {
	switch (n.tagID) {
		case c.HEAD:
			e.openElements.pop(), e.insertionMode = h.AFTER_HEAD;
			break;
		case c.BODY:
		case c.BR:
		case c.HTML:
			E(e, n);
			break;
		case c.TEMPLATE:
			T(e, n);
			break;
		default: e._err(n, t.endTagWithoutMatchingOpenElement);
	}
}
function T(e, n) {
	e.openElements.tmplCount > 0 ? (e.openElements.generateImpliedEndTagsThoroughly(), e.openElements.currentTagId !== c.TEMPLATE && e._err(n, t.closingOfElementWithOpenChildElements), e.openElements.popUntilTagNamePopped(c.TEMPLATE), e.activeFormattingElements.clearToLastMarker(), e.tmplInsertionModeStack.shift(), e._resetInsertionMode()) : e._err(n, t.endTagWithoutMatchingOpenElement);
}
function E(e, t) {
	e.openElements.pop(), e.insertionMode = h.AFTER_HEAD, e._processToken(t);
}
function Ae(e, n) {
	switch (n.tagID) {
		case c.HTML:
			F(e, n);
			break;
		case c.BASEFONT:
		case c.BGSOUND:
		case c.HEAD:
		case c.LINK:
		case c.META:
		case c.NOFRAMES:
		case c.STYLE:
			w(e, n);
			break;
		case c.NOSCRIPT:
			e._err(n, t.nestedNoscriptInHead);
			break;
		default: D(e, n);
	}
}
function je(e, n) {
	switch (n.tagID) {
		case c.NOSCRIPT:
			e.openElements.pop(), e.insertionMode = h.IN_HEAD;
			break;
		case c.BR:
			D(e, n);
			break;
		default: e._err(n, t.endTagWithoutMatchingOpenElement);
	}
}
function D(e, r) {
	let i = r.type === n.EOF ? t.openElementsLeftAfterEof : t.disallowedContentInNoscriptInHead;
	e._err(r, i), e.openElements.pop(), e.insertionMode = h.IN_HEAD, e._processToken(r);
}
function Me(e, n) {
	switch (n.tagID) {
		case c.HTML:
			F(e, n);
			break;
		case c.BODY:
			e._insertElement(n, o.HTML), e.framesetOk = !1, e.insertionMode = h.IN_BODY;
			break;
		case c.FRAMESET:
			e._insertElement(n, o.HTML), e.insertionMode = h.IN_FRAMESET;
			break;
		case c.BASE:
		case c.BASEFONT:
		case c.BGSOUND:
		case c.LINK:
		case c.META:
		case c.NOFRAMES:
		case c.SCRIPT:
		case c.STYLE:
		case c.TEMPLATE:
		case c.TITLE:
			e._err(n, t.abandonedHeadElementChild), e.openElements.push(e.headElement, c.HEAD), w(e, n), e.openElements.remove(e.headElement);
			break;
		case c.HEAD:
			e._err(n, t.misplacedStartTagForHeadElement);
			break;
		default: O(e, n);
	}
}
function Ne(e, n) {
	switch (n.tagID) {
		case c.BODY:
		case c.HTML:
		case c.BR:
			O(e, n);
			break;
		case c.TEMPLATE:
			T(e, n);
			break;
		default: e._err(n, t.endTagWithoutMatchingOpenElement);
	}
}
function O(e, t) {
	e._insertFakeElement(l.BODY, c.BODY), e.insertionMode = h.IN_BODY, k(e, t);
}
function k(e, t) {
	switch (t.type) {
		case n.CHARACTER:
			j(e, t);
			break;
		case n.WHITESPACE_CHARACTER:
			A(e, t);
			break;
		case n.COMMENT:
			y(e, t);
			break;
		case n.START_TAG:
			F(e, t);
			break;
		case n.END_TAG:
			L(e, t);
			break;
		case n.EOF:
			yt(e, t);
			break;
		default:
	}
}
function A(e, t) {
	e._reconstructActiveFormattingElements(), e._insertCharacters(t);
}
function j(e, t) {
	e._reconstructActiveFormattingElements(), e._insertCharacters(t), e.framesetOk = !1;
}
function Pe(e, t) {
	e.openElements.tmplCount === 0 && e.treeAdapter.adoptAttributes(e.openElements.items[0], t.attrs);
}
function Fe(e, t) {
	let n = e.openElements.tryPeekProperlyNestedBodyElement();
	n && e.openElements.tmplCount === 0 && (e.framesetOk = !1, e.treeAdapter.adoptAttributes(n, t.attrs));
}
function Ie(e, t) {
	let n = e.openElements.tryPeekProperlyNestedBodyElement();
	e.framesetOk && n && (e.treeAdapter.detachNode(n), e.openElements.popAllUpToHtmlElement(), e._insertElement(t, o.HTML), e.insertionMode = h.IN_FRAMESET);
}
function Le(e, t) {
	e.openElements.hasInButtonScope(c.P) && e._closePElement(), e._insertElement(t, o.HTML);
}
function Re(e, t) {
	e.openElements.hasInButtonScope(c.P) && e._closePElement(), e.openElements.currentTagId !== void 0 && s.has(e.openElements.currentTagId) && e.openElements.pop(), e._insertElement(t, o.HTML);
}
function ze(e, t) {
	e.openElements.hasInButtonScope(c.P) && e._closePElement(), e._insertElement(t, o.HTML), e.skipNextNewLine = !0, e.framesetOk = !1;
}
function Be(e, t) {
	let n = e.openElements.tmplCount > 0;
	(!e.formElement || n) && (e.openElements.hasInButtonScope(c.P) && e._closePElement(), e._insertElement(t, o.HTML), n || (e.formElement = e.openElements.current));
}
function Ve(e, t) {
	e.framesetOk = !1;
	let n = t.tagID;
	for (let t = e.openElements.stackTop; t >= 0; t--) {
		let r = e.openElements.tagIDs[t];
		if (n === c.LI && r === c.LI || (n === c.DD || n === c.DT) && (r === c.DD || r === c.DT)) {
			e.openElements.generateImpliedEndTagsWithExclusion(r), e.openElements.popUntilTagNamePopped(r);
			break;
		}
		if (r !== c.ADDRESS && r !== c.DIV && r !== c.P && e._isSpecialElement(e.openElements.items[t], r)) break;
	}
	e.openElements.hasInButtonScope(c.P) && e._closePElement(), e._insertElement(t, o.HTML);
}
function He(e, t) {
	e.openElements.hasInButtonScope(c.P) && e._closePElement(), e._insertElement(t, o.HTML), e.tokenizer.state = d.PLAINTEXT;
}
function Ue(e, t) {
	e.openElements.hasInScope(c.BUTTON) && (e.openElements.generateImpliedEndTags(), e.openElements.popUntilTagNamePopped(c.BUTTON)), e._reconstructActiveFormattingElements(), e._insertElement(t, o.HTML), e.framesetOk = !1;
}
function We(e, t) {
	let n = e.activeFormattingElements.getElementEntryInScopeWithTagName(l.A);
	n && (v(e, t), e.openElements.remove(n.element), e.activeFormattingElements.removeEntry(n)), e._reconstructActiveFormattingElements(), e._insertElement(t, o.HTML), e.activeFormattingElements.pushElement(e.openElements.current, t);
}
function Ge(e, t) {
	e._reconstructActiveFormattingElements(), e._insertElement(t, o.HTML), e.activeFormattingElements.pushElement(e.openElements.current, t);
}
function Ke(e, t) {
	e._reconstructActiveFormattingElements(), e.openElements.hasInScope(c.NOBR) && (v(e, t), e._reconstructActiveFormattingElements()), e._insertElement(t, o.HTML), e.activeFormattingElements.pushElement(e.openElements.current, t);
}
function qe(e, t) {
	e._reconstructActiveFormattingElements(), e._insertElement(t, o.HTML), e.activeFormattingElements.insertMarker(), e.framesetOk = !1;
}
function Je(e, t) {
	e.treeAdapter.getDocumentMode(e.document) !== a.QUIRKS && e.openElements.hasInButtonScope(c.P) && e._closePElement(), e._insertElement(t, o.HTML), e.framesetOk = !1, e.insertionMode = h.IN_TABLE;
}
function M(e, t) {
	e._reconstructActiveFormattingElements(), e._appendElement(t, o.HTML), e.framesetOk = !1, t.ackSelfClosing = !0;
}
function Ye(e) {
	let t = r(e, i.TYPE);
	return t != null && t.toLowerCase() === de;
}
function Xe(e, t) {
	e._reconstructActiveFormattingElements(), e._appendElement(t, o.HTML), Ye(t) || (e.framesetOk = !1), t.ackSelfClosing = !0;
}
function Ze(e, t) {
	e._appendElement(t, o.HTML), t.ackSelfClosing = !0;
}
function Qe(e, t) {
	e.openElements.hasInButtonScope(c.P) && e._closePElement(), e._appendElement(t, o.HTML), e.framesetOk = !1, t.ackSelfClosing = !0;
}
function $e(e, t) {
	t.tagName = l.IMG, t.tagID = c.IMG, M(e, t);
}
function et(e, t) {
	e._insertElement(t, o.HTML), e.skipNextNewLine = !0, e.tokenizer.state = d.RCDATA, e.originalInsertionMode = e.insertionMode, e.framesetOk = !1, e.insertionMode = h.TEXT;
}
function tt(e, t) {
	e.openElements.hasInButtonScope(c.P) && e._closePElement(), e._reconstructActiveFormattingElements(), e.framesetOk = !1, e._switchToTextParsing(t, d.RAWTEXT);
}
function nt(e, t) {
	e.framesetOk = !1, e._switchToTextParsing(t, d.RAWTEXT);
}
function N(e, t) {
	e._switchToTextParsing(t, d.RAWTEXT);
}
function rt(e, t) {
	e._reconstructActiveFormattingElements(), e._insertElement(t, o.HTML), e.framesetOk = !1, e.insertionMode = e.insertionMode === h.IN_TABLE || e.insertionMode === h.IN_CAPTION || e.insertionMode === h.IN_TABLE_BODY || e.insertionMode === h.IN_ROW || e.insertionMode === h.IN_CELL ? h.IN_SELECT_IN_TABLE : h.IN_SELECT;
}
function it(e, t) {
	e.openElements.currentTagId === c.OPTION && e.openElements.pop(), e._reconstructActiveFormattingElements(), e._insertElement(t, o.HTML);
}
function at(e, t) {
	e.openElements.hasInScope(c.RUBY) && e.openElements.generateImpliedEndTags(), e._insertElement(t, o.HTML);
}
function ot(e, t) {
	e.openElements.hasInScope(c.RUBY) && e.openElements.generateImpliedEndTagsWithExclusion(c.RTC), e._insertElement(t, o.HTML);
}
function st(e, t) {
	e._reconstructActiveFormattingElements(), f(t), m(t), t.selfClosing ? e._appendElement(t, o.MATHML) : e._insertElement(t, o.MATHML), t.ackSelfClosing = !0;
}
function ct(e, t) {
	e._reconstructActiveFormattingElements(), p(t), m(t), t.selfClosing ? e._appendElement(t, o.SVG) : e._insertElement(t, o.SVG), t.ackSelfClosing = !0;
}
function P(e, t) {
	e._reconstructActiveFormattingElements(), e._insertElement(t, o.HTML);
}
function F(e, t) {
	switch (t.tagID) {
		case c.I:
		case c.S:
		case c.B:
		case c.U:
		case c.EM:
		case c.TT:
		case c.BIG:
		case c.CODE:
		case c.FONT:
		case c.SMALL:
		case c.STRIKE:
		case c.STRONG:
			Ge(e, t);
			break;
		case c.A:
			We(e, t);
			break;
		case c.H1:
		case c.H2:
		case c.H3:
		case c.H4:
		case c.H5:
		case c.H6:
			Re(e, t);
			break;
		case c.P:
		case c.DL:
		case c.OL:
		case c.UL:
		case c.DIV:
		case c.DIR:
		case c.NAV:
		case c.MAIN:
		case c.MENU:
		case c.ASIDE:
		case c.CENTER:
		case c.FIGURE:
		case c.FOOTER:
		case c.HEADER:
		case c.HGROUP:
		case c.DIALOG:
		case c.DETAILS:
		case c.ADDRESS:
		case c.ARTICLE:
		case c.SEARCH:
		case c.SECTION:
		case c.SUMMARY:
		case c.FIELDSET:
		case c.BLOCKQUOTE:
		case c.FIGCAPTION:
			Le(e, t);
			break;
		case c.LI:
		case c.DD:
		case c.DT:
			Ve(e, t);
			break;
		case c.BR:
		case c.IMG:
		case c.WBR:
		case c.AREA:
		case c.EMBED:
		case c.KEYGEN:
			M(e, t);
			break;
		case c.HR:
			Qe(e, t);
			break;
		case c.RB:
		case c.RTC:
			at(e, t);
			break;
		case c.RT:
		case c.RP:
			ot(e, t);
			break;
		case c.PRE:
		case c.LISTING:
			ze(e, t);
			break;
		case c.XMP:
			tt(e, t);
			break;
		case c.SVG:
			ct(e, t);
			break;
		case c.HTML:
			Pe(e, t);
			break;
		case c.BASE:
		case c.LINK:
		case c.META:
		case c.STYLE:
		case c.TITLE:
		case c.SCRIPT:
		case c.BGSOUND:
		case c.BASEFONT:
		case c.TEMPLATE:
			w(e, t);
			break;
		case c.BODY:
			Fe(e, t);
			break;
		case c.FORM:
			Be(e, t);
			break;
		case c.NOBR:
			Ke(e, t);
			break;
		case c.MATH:
			st(e, t);
			break;
		case c.TABLE:
			Je(e, t);
			break;
		case c.INPUT:
			Xe(e, t);
			break;
		case c.PARAM:
		case c.TRACK:
		case c.SOURCE:
			Ze(e, t);
			break;
		case c.IMAGE:
			$e(e, t);
			break;
		case c.BUTTON:
			Ue(e, t);
			break;
		case c.APPLET:
		case c.OBJECT:
		case c.MARQUEE:
			qe(e, t);
			break;
		case c.IFRAME:
			nt(e, t);
			break;
		case c.SELECT:
			rt(e, t);
			break;
		case c.OPTION:
		case c.OPTGROUP:
			it(e, t);
			break;
		case c.NOEMBED:
		case c.NOFRAMES:
			N(e, t);
			break;
		case c.FRAMESET:
			Ie(e, t);
			break;
		case c.TEXTAREA:
			et(e, t);
			break;
		case c.NOSCRIPT:
			e.options.scriptingEnabled ? N(e, t) : P(e, t);
			break;
		case c.PLAINTEXT:
			He(e, t);
			break;
		case c.COL:
		case c.TH:
		case c.TD:
		case c.TR:
		case c.HEAD:
		case c.FRAME:
		case c.TBODY:
		case c.TFOOT:
		case c.THEAD:
		case c.CAPTION:
		case c.COLGROUP: break;
		default: P(e, t);
	}
}
function lt(e, t) {
	if (e.openElements.hasInScope(c.BODY) && (e.insertionMode = h.AFTER_BODY, e.options.sourceCodeLocationInfo)) {
		let n = e.openElements.tryPeekProperlyNestedBodyElement();
		n && e._setEndLocation(n, t);
	}
}
function ut(e, t) {
	e.openElements.hasInScope(c.BODY) && (e.insertionMode = h.AFTER_BODY, Ut(e, t));
}
function dt(e, t) {
	let n = t.tagID;
	e.openElements.hasInScope(n) && (e.openElements.generateImpliedEndTags(), e.openElements.popUntilTagNamePopped(n));
}
function ft(e) {
	let t = e.openElements.tmplCount > 0, { formElement: n } = e;
	t || (e.formElement = null), (n || t) && e.openElements.hasInScope(c.FORM) && (e.openElements.generateImpliedEndTags(), t ? e.openElements.popUntilTagNamePopped(c.FORM) : n && e.openElements.remove(n));
}
function pt(e) {
	e.openElements.hasInButtonScope(c.P) || e._insertFakeElement(l.P, c.P), e._closePElement();
}
function mt(e) {
	e.openElements.hasInListItemScope(c.LI) && (e.openElements.generateImpliedEndTagsWithExclusion(c.LI), e.openElements.popUntilTagNamePopped(c.LI));
}
function ht(e, t) {
	let n = t.tagID;
	e.openElements.hasInScope(n) && (e.openElements.generateImpliedEndTagsWithExclusion(n), e.openElements.popUntilTagNamePopped(n));
}
function gt(e) {
	e.openElements.hasNumberedHeaderInScope() && (e.openElements.generateImpliedEndTags(), e.openElements.popUntilNumberedHeaderPopped());
}
function _t(e, t) {
	let n = t.tagID;
	e.openElements.hasInScope(n) && (e.openElements.generateImpliedEndTags(), e.openElements.popUntilTagNamePopped(n), e.activeFormattingElements.clearToLastMarker());
}
function vt(e) {
	e._reconstructActiveFormattingElements(), e._insertFakeElement(l.BR, c.BR), e.openElements.pop(), e.framesetOk = !1;
}
function I(e, t) {
	let n = t.tagName, r = t.tagID;
	for (let t = e.openElements.stackTop; t > 0; t--) {
		let i = e.openElements.items[t], a = e.openElements.tagIDs[t];
		if (r === a && (r !== c.UNKNOWN || e.treeAdapter.getTagName(i) === n)) {
			e.openElements.generateImpliedEndTagsWithExclusion(r), e.openElements.stackTop >= t && e.openElements.shortenToLength(t);
			break;
		}
		if (e._isSpecialElement(i, a)) break;
	}
}
function L(e, t) {
	switch (t.tagID) {
		case c.A:
		case c.B:
		case c.I:
		case c.S:
		case c.U:
		case c.EM:
		case c.TT:
		case c.BIG:
		case c.CODE:
		case c.FONT:
		case c.NOBR:
		case c.SMALL:
		case c.STRIKE:
		case c.STRONG:
			v(e, t);
			break;
		case c.P:
			pt(e);
			break;
		case c.DL:
		case c.UL:
		case c.OL:
		case c.DIR:
		case c.DIV:
		case c.NAV:
		case c.PRE:
		case c.MAIN:
		case c.MENU:
		case c.ASIDE:
		case c.BUTTON:
		case c.CENTER:
		case c.FIGURE:
		case c.FOOTER:
		case c.HEADER:
		case c.HGROUP:
		case c.DIALOG:
		case c.ADDRESS:
		case c.ARTICLE:
		case c.DETAILS:
		case c.SEARCH:
		case c.SECTION:
		case c.SUMMARY:
		case c.LISTING:
		case c.FIELDSET:
		case c.BLOCKQUOTE:
		case c.FIGCAPTION:
			dt(e, t);
			break;
		case c.LI:
			mt(e);
			break;
		case c.DD:
		case c.DT:
			ht(e, t);
			break;
		case c.H1:
		case c.H2:
		case c.H3:
		case c.H4:
		case c.H5:
		case c.H6:
			gt(e);
			break;
		case c.BR:
			vt(e);
			break;
		case c.BODY:
			lt(e, t);
			break;
		case c.HTML:
			ut(e, t);
			break;
		case c.FORM:
			ft(e);
			break;
		case c.APPLET:
		case c.OBJECT:
		case c.MARQUEE:
			_t(e, t);
			break;
		case c.TEMPLATE:
			T(e, t);
			break;
		default: I(e, t);
	}
}
function yt(e, t) {
	e.tmplInsertionModeStack.length > 0 ? Vt(e, t) : b(e, t);
}
function bt(e, t) {
	var n;
	t.tagID === c.SCRIPT && ((n = e.scriptHandler) == null || n.call(e, e.openElements.current)), e.openElements.pop(), e.insertionMode = e.originalInsertionMode;
}
function xt(e, n) {
	e._err(n, t.eofInElementThatCanContainOnlyText), e.openElements.pop(), e.insertionMode = e.originalInsertionMode, e.onEof(n);
}
function R(e, t) {
	if (e.openElements.currentTagId !== void 0 && g.has(e.openElements.currentTagId)) switch (e.pendingCharacterTokens.length = 0, e.hasNonWhitespacePendingCharacterToken = !1, e.originalInsertionMode = e.insertionMode, e.insertionMode = h.IN_TABLE_TEXT, t.type) {
		case n.CHARACTER:
			U(e, t);
			break;
		case n.WHITESPACE_CHARACTER:
			H(e, t);
			break;
	}
	else V(e, t);
}
function St(e, t) {
	e.openElements.clearBackToTableContext(), e.activeFormattingElements.insertMarker(), e._insertElement(t, o.HTML), e.insertionMode = h.IN_CAPTION;
}
function Ct(e, t) {
	e.openElements.clearBackToTableContext(), e._insertElement(t, o.HTML), e.insertionMode = h.IN_COLUMN_GROUP;
}
function wt(e, t) {
	e.openElements.clearBackToTableContext(), e._insertFakeElement(l.COLGROUP, c.COLGROUP), e.insertionMode = h.IN_COLUMN_GROUP, K(e, t);
}
function Tt(e, t) {
	e.openElements.clearBackToTableContext(), e._insertElement(t, o.HTML), e.insertionMode = h.IN_TABLE_BODY;
}
function Et(e, t) {
	e.openElements.clearBackToTableContext(), e._insertFakeElement(l.TBODY, c.TBODY), e.insertionMode = h.IN_TABLE_BODY, J(e, t);
}
function Dt(e, t) {
	e.openElements.hasInTableScope(c.TABLE) && (e.openElements.popUntilTagNamePopped(c.TABLE), e._resetInsertionMode(), e._processStartTag(t));
}
function Ot(e, t) {
	Ye(t) ? e._appendElement(t, o.HTML) : V(e, t), t.ackSelfClosing = !0;
}
function kt(e, t) {
	!e.formElement && e.openElements.tmplCount === 0 && (e._insertElement(t, o.HTML), e.formElement = e.openElements.current, e.openElements.pop());
}
function z(e, t) {
	switch (t.tagID) {
		case c.TD:
		case c.TH:
		case c.TR:
			Et(e, t);
			break;
		case c.STYLE:
		case c.SCRIPT:
		case c.TEMPLATE:
			w(e, t);
			break;
		case c.COL:
			wt(e, t);
			break;
		case c.FORM:
			kt(e, t);
			break;
		case c.TABLE:
			Dt(e, t);
			break;
		case c.TBODY:
		case c.TFOOT:
		case c.THEAD:
			Tt(e, t);
			break;
		case c.INPUT:
			Ot(e, t);
			break;
		case c.CAPTION:
			St(e, t);
			break;
		case c.COLGROUP:
			Ct(e, t);
			break;
		default: V(e, t);
	}
}
function B(e, t) {
	switch (t.tagID) {
		case c.TABLE:
			e.openElements.hasInTableScope(c.TABLE) && (e.openElements.popUntilTagNamePopped(c.TABLE), e._resetInsertionMode());
			break;
		case c.TEMPLATE:
			T(e, t);
			break;
		case c.BODY:
		case c.CAPTION:
		case c.COL:
		case c.COLGROUP:
		case c.HTML:
		case c.TBODY:
		case c.TD:
		case c.TFOOT:
		case c.TH:
		case c.THEAD:
		case c.TR: break;
		default: V(e, t);
	}
}
function V(e, t) {
	let n = e.fosterParentingEnabled;
	e.fosterParentingEnabled = !0, k(e, t), e.fosterParentingEnabled = n;
}
function H(e, t) {
	e.pendingCharacterTokens.push(t);
}
function U(e, t) {
	e.pendingCharacterTokens.push(t), e.hasNonWhitespacePendingCharacterToken = !0;
}
function W(e, t) {
	let n = 0;
	if (e.hasNonWhitespacePendingCharacterToken) for (; n < e.pendingCharacterTokens.length; n++) V(e, e.pendingCharacterTokens[n]);
	else for (; n < e.pendingCharacterTokens.length; n++) e._insertCharacters(e.pendingCharacterTokens[n]);
	e.insertionMode = e.originalInsertionMode, e._processToken(t);
}
var G = new Set([
	c.CAPTION,
	c.COL,
	c.COLGROUP,
	c.TBODY,
	c.TD,
	c.TFOOT,
	c.TH,
	c.THEAD,
	c.TR
]);
function At(e, t) {
	let n = t.tagID;
	G.has(n) ? e.openElements.hasInTableScope(c.CAPTION) && (e.openElements.generateImpliedEndTags(), e.openElements.popUntilTagNamePopped(c.CAPTION), e.activeFormattingElements.clearToLastMarker(), e.insertionMode = h.IN_TABLE, z(e, t)) : F(e, t);
}
function jt(e, t) {
	let n = t.tagID;
	switch (n) {
		case c.CAPTION:
		case c.TABLE:
			e.openElements.hasInTableScope(c.CAPTION) && (e.openElements.generateImpliedEndTags(), e.openElements.popUntilTagNamePopped(c.CAPTION), e.activeFormattingElements.clearToLastMarker(), e.insertionMode = h.IN_TABLE, n === c.TABLE && B(e, t));
			break;
		case c.BODY:
		case c.COL:
		case c.COLGROUP:
		case c.HTML:
		case c.TBODY:
		case c.TD:
		case c.TFOOT:
		case c.TH:
		case c.THEAD:
		case c.TR: break;
		default: L(e, t);
	}
}
function K(e, t) {
	switch (t.tagID) {
		case c.HTML:
			F(e, t);
			break;
		case c.COL:
			e._appendElement(t, o.HTML), t.ackSelfClosing = !0;
			break;
		case c.TEMPLATE:
			w(e, t);
			break;
		default: q(e, t);
	}
}
function Mt(e, t) {
	switch (t.tagID) {
		case c.COLGROUP:
			e.openElements.currentTagId === c.COLGROUP && (e.openElements.pop(), e.insertionMode = h.IN_TABLE);
			break;
		case c.TEMPLATE:
			T(e, t);
			break;
		case c.COL: break;
		default: q(e, t);
	}
}
function q(e, t) {
	e.openElements.currentTagId === c.COLGROUP && (e.openElements.pop(), e.insertionMode = h.IN_TABLE, e._processToken(t));
}
function J(e, t) {
	switch (t.tagID) {
		case c.TR:
			e.openElements.clearBackToTableBodyContext(), e._insertElement(t, o.HTML), e.insertionMode = h.IN_ROW;
			break;
		case c.TH:
		case c.TD:
			e.openElements.clearBackToTableBodyContext(), e._insertFakeElement(l.TR, c.TR), e.insertionMode = h.IN_ROW, X(e, t);
			break;
		case c.CAPTION:
		case c.COL:
		case c.COLGROUP:
		case c.TBODY:
		case c.TFOOT:
		case c.THEAD:
			e.openElements.hasTableBodyContextInTableScope() && (e.openElements.clearBackToTableBodyContext(), e.openElements.pop(), e.insertionMode = h.IN_TABLE, z(e, t));
			break;
		default: z(e, t);
	}
}
function Y(e, t) {
	let n = t.tagID;
	switch (t.tagID) {
		case c.TBODY:
		case c.TFOOT:
		case c.THEAD:
			e.openElements.hasInTableScope(n) && (e.openElements.clearBackToTableBodyContext(), e.openElements.pop(), e.insertionMode = h.IN_TABLE);
			break;
		case c.TABLE:
			e.openElements.hasTableBodyContextInTableScope() && (e.openElements.clearBackToTableBodyContext(), e.openElements.pop(), e.insertionMode = h.IN_TABLE, B(e, t));
			break;
		case c.BODY:
		case c.CAPTION:
		case c.COL:
		case c.COLGROUP:
		case c.HTML:
		case c.TD:
		case c.TH:
		case c.TR: break;
		default: B(e, t);
	}
}
function X(e, t) {
	switch (t.tagID) {
		case c.TH:
		case c.TD:
			e.openElements.clearBackToTableRowContext(), e._insertElement(t, o.HTML), e.insertionMode = h.IN_CELL, e.activeFormattingElements.insertMarker();
			break;
		case c.CAPTION:
		case c.COL:
		case c.COLGROUP:
		case c.TBODY:
		case c.TFOOT:
		case c.THEAD:
		case c.TR:
			e.openElements.hasInTableScope(c.TR) && (e.openElements.clearBackToTableRowContext(), e.openElements.pop(), e.insertionMode = h.IN_TABLE_BODY, J(e, t));
			break;
		default: z(e, t);
	}
}
function Z(e, t) {
	switch (t.tagID) {
		case c.TR:
			e.openElements.hasInTableScope(c.TR) && (e.openElements.clearBackToTableRowContext(), e.openElements.pop(), e.insertionMode = h.IN_TABLE_BODY);
			break;
		case c.TABLE:
			e.openElements.hasInTableScope(c.TR) && (e.openElements.clearBackToTableRowContext(), e.openElements.pop(), e.insertionMode = h.IN_TABLE_BODY, Y(e, t));
			break;
		case c.TBODY:
		case c.TFOOT:
		case c.THEAD:
			(e.openElements.hasInTableScope(t.tagID) || e.openElements.hasInTableScope(c.TR)) && (e.openElements.clearBackToTableRowContext(), e.openElements.pop(), e.insertionMode = h.IN_TABLE_BODY, Y(e, t));
			break;
		case c.BODY:
		case c.CAPTION:
		case c.COL:
		case c.COLGROUP:
		case c.HTML:
		case c.TD:
		case c.TH: break;
		default: B(e, t);
	}
}
function Nt(e, t) {
	let n = t.tagID;
	G.has(n) ? (e.openElements.hasInTableScope(c.TD) || e.openElements.hasInTableScope(c.TH)) && (e._closeTableCell(), X(e, t)) : F(e, t);
}
function Pt(e, t) {
	let n = t.tagID;
	switch (n) {
		case c.TD:
		case c.TH:
			e.openElements.hasInTableScope(n) && (e.openElements.generateImpliedEndTags(), e.openElements.popUntilTagNamePopped(n), e.activeFormattingElements.clearToLastMarker(), e.insertionMode = h.IN_ROW);
			break;
		case c.TABLE:
		case c.TBODY:
		case c.TFOOT:
		case c.THEAD:
		case c.TR:
			e.openElements.hasInTableScope(n) && (e._closeTableCell(), Z(e, t));
			break;
		case c.BODY:
		case c.CAPTION:
		case c.COL:
		case c.COLGROUP:
		case c.HTML: break;
		default: L(e, t);
	}
}
function Ft(e, t) {
	switch (t.tagID) {
		case c.HTML:
			F(e, t);
			break;
		case c.OPTION:
			e.openElements.currentTagId === c.OPTION && e.openElements.pop(), e._insertElement(t, o.HTML);
			break;
		case c.OPTGROUP:
			e.openElements.currentTagId === c.OPTION && e.openElements.pop(), e.openElements.currentTagId === c.OPTGROUP && e.openElements.pop(), e._insertElement(t, o.HTML);
			break;
		case c.HR:
			e.openElements.currentTagId === c.OPTION && e.openElements.pop(), e.openElements.currentTagId === c.OPTGROUP && e.openElements.pop(), e._appendElement(t, o.HTML), t.ackSelfClosing = !0;
			break;
		case c.INPUT:
		case c.KEYGEN:
		case c.TEXTAREA:
		case c.SELECT:
			e.openElements.hasInSelectScope(c.SELECT) && (e.openElements.popUntilTagNamePopped(c.SELECT), e._resetInsertionMode(), t.tagID !== c.SELECT && e._processStartTag(t));
			break;
		case c.SCRIPT:
		case c.TEMPLATE:
			w(e, t);
			break;
		default:
	}
}
function It(e, t) {
	switch (t.tagID) {
		case c.OPTGROUP:
			e.openElements.stackTop > 0 && e.openElements.currentTagId === c.OPTION && e.openElements.tagIDs[e.openElements.stackTop - 1] === c.OPTGROUP && e.openElements.pop(), e.openElements.currentTagId === c.OPTGROUP && e.openElements.pop();
			break;
		case c.OPTION:
			e.openElements.currentTagId === c.OPTION && e.openElements.pop();
			break;
		case c.SELECT:
			e.openElements.hasInSelectScope(c.SELECT) && (e.openElements.popUntilTagNamePopped(c.SELECT), e._resetInsertionMode());
			break;
		case c.TEMPLATE:
			T(e, t);
			break;
		default:
	}
}
function Lt(e, t) {
	let n = t.tagID;
	n === c.CAPTION || n === c.TABLE || n === c.TBODY || n === c.TFOOT || n === c.THEAD || n === c.TR || n === c.TD || n === c.TH ? (e.openElements.popUntilTagNamePopped(c.SELECT), e._resetInsertionMode(), e._processStartTag(t)) : Ft(e, t);
}
function Rt(e, t) {
	let n = t.tagID;
	n === c.CAPTION || n === c.TABLE || n === c.TBODY || n === c.TFOOT || n === c.THEAD || n === c.TR || n === c.TD || n === c.TH ? e.openElements.hasInTableScope(n) && (e.openElements.popUntilTagNamePopped(c.SELECT), e._resetInsertionMode(), e.onEndTag(t)) : It(e, t);
}
function zt(e, t) {
	switch (t.tagID) {
		case c.BASE:
		case c.BASEFONT:
		case c.BGSOUND:
		case c.LINK:
		case c.META:
		case c.NOFRAMES:
		case c.SCRIPT:
		case c.STYLE:
		case c.TEMPLATE:
		case c.TITLE:
			w(e, t);
			break;
		case c.CAPTION:
		case c.COLGROUP:
		case c.TBODY:
		case c.TFOOT:
		case c.THEAD:
			e.tmplInsertionModeStack[0] = h.IN_TABLE, e.insertionMode = h.IN_TABLE, z(e, t);
			break;
		case c.COL:
			e.tmplInsertionModeStack[0] = h.IN_COLUMN_GROUP, e.insertionMode = h.IN_COLUMN_GROUP, K(e, t);
			break;
		case c.TR:
			e.tmplInsertionModeStack[0] = h.IN_TABLE_BODY, e.insertionMode = h.IN_TABLE_BODY, J(e, t);
			break;
		case c.TD:
		case c.TH:
			e.tmplInsertionModeStack[0] = h.IN_ROW, e.insertionMode = h.IN_ROW, X(e, t);
			break;
		default: e.tmplInsertionModeStack[0] = h.IN_BODY, e.insertionMode = h.IN_BODY, F(e, t);
	}
}
function Bt(e, t) {
	t.tagID === c.TEMPLATE && T(e, t);
}
function Vt(e, t) {
	e.openElements.tmplCount > 0 ? (e.openElements.popUntilTagNamePopped(c.TEMPLATE), e.activeFormattingElements.clearToLastMarker(), e.tmplInsertionModeStack.shift(), e._resetInsertionMode(), e.onEof(t)) : b(e, t);
}
function Ht(e, t) {
	t.tagID === c.HTML ? F(e, t) : Q(e, t);
}
function Ut(e, t) {
	if (t.tagID === c.HTML) {
		if (e.fragmentContext || (e.insertionMode = h.AFTER_AFTER_BODY), e.options.sourceCodeLocationInfo && e.openElements.tagIDs[0] === c.HTML) {
			e._setEndLocation(e.openElements.items[0], t);
			let n = e.openElements.items[1];
			n && !e.treeAdapter.getNodeSourceCodeLocation(n)?.endTag && e._setEndLocation(n, t);
		}
	} else Q(e, t);
}
function Q(e, t) {
	e.insertionMode = h.IN_BODY, k(e, t);
}
function Wt(e, t) {
	switch (t.tagID) {
		case c.HTML:
			F(e, t);
			break;
		case c.FRAMESET:
			e._insertElement(t, o.HTML);
			break;
		case c.FRAME:
			e._appendElement(t, o.HTML), t.ackSelfClosing = !0;
			break;
		case c.NOFRAMES:
			w(e, t);
			break;
		default:
	}
}
function Gt(e, t) {
	t.tagID === c.FRAMESET && !e.openElements.isRootHtmlElementCurrent() && (e.openElements.pop(), !e.fragmentContext && e.openElements.currentTagId !== c.FRAMESET && (e.insertionMode = h.AFTER_FRAMESET));
}
function Kt(e, t) {
	switch (t.tagID) {
		case c.HTML:
			F(e, t);
			break;
		case c.NOFRAMES:
			w(e, t);
			break;
		default:
	}
}
function qt(e, t) {
	t.tagID === c.HTML && (e.insertionMode = h.AFTER_AFTER_FRAMESET);
}
function Jt(e, t) {
	t.tagID === c.HTML ? F(e, t) : $(e, t);
}
function $(e, t) {
	e.insertionMode = h.IN_BODY, k(e, t);
}
function Yt(e, t) {
	switch (t.tagID) {
		case c.HTML:
			F(e, t);
			break;
		case c.NOFRAMES:
			w(e, t);
			break;
		default:
	}
}
function Xt(e, t) {
	t.chars = "�", e._insertCharacters(t);
}
function Zt(e, t) {
	e._insertCharacters(t), e.framesetOk = !1;
}
function Qt(e) {
	for (; e.treeAdapter.getNamespaceURI(e.openElements.current) !== o.HTML && e.openElements.currentTagId !== void 0 && !e._isIntegrationPoint(e.openElements.currentTagId, e.openElements.current);) e.openElements.pop();
}
function $t(e, t) {
	if (le(t)) Qt(e), e._startTagOutsideForeignContent(t);
	else {
		let n = e._getAdjustedCurrentElement(), r = e.treeAdapter.getNamespaceURI(n);
		r === o.MATHML ? f(t) : r === o.SVG && (ce(t), p(t)), m(t), t.selfClosing ? e._appendElement(t, r) : e._insertElement(t, r), t.ackSelfClosing = !0;
	}
}
function en(e, t) {
	if (t.tagID === c.P || t.tagID === c.BR) {
		Qt(e), e._endTagOutsideForeignContent(t);
		return;
	}
	for (let n = e.openElements.stackTop; n > 0; n--) {
		let r = e.openElements.items[n];
		if (e.treeAdapter.getNamespaceURI(r) === o.HTML) {
			e._endTagOutsideForeignContent(t);
			break;
		}
		let i = e.treeAdapter.getTagName(r);
		if (i.toLowerCase() === t.tagName) {
			t.tagName = i, e.openElements.shortenToLength(n);
			break;
		}
	}
}
//#endregion
export { he as Parser };
