import { asciiAlphanumeric as e, asciiDigit as t, asciiHexDigit as n } from "../../micromark-util-character/index.js";
import { decodeNamedCharacterReference as r } from "../../decode-named-character-reference/index.dom.js";
//#region ../../node_modules/micromark-core-commonmark/lib/character-reference.js
var i = {
	name: "characterReference",
	tokenize: a
};
function a(i, a, o) {
	let s = this, c = 0, l, u;
	return d;
	function d(e) {
		return i.enter("characterReference"), i.enter("characterReferenceMarker"), i.consume(e), i.exit("characterReferenceMarker"), f;
	}
	function f(t) {
		return t === 35 ? (i.enter("characterReferenceMarkerNumeric"), i.consume(t), i.exit("characterReferenceMarkerNumeric"), p) : (i.enter("characterReferenceValue"), l = 31, u = e, m(t));
	}
	function p(e) {
		return e === 88 || e === 120 ? (i.enter("characterReferenceMarkerHexadecimal"), i.consume(e), i.exit("characterReferenceMarkerHexadecimal"), i.enter("characterReferenceValue"), l = 6, u = n, m) : (i.enter("characterReferenceValue"), l = 7, u = t, m(e));
	}
	function m(t) {
		if (t === 59 && c) {
			let n = i.exit("characterReferenceValue");
			return u === e && !r(s.sliceSerialize(n)) ? o(t) : (i.enter("characterReferenceMarker"), i.consume(t), i.exit("characterReferenceMarker"), i.exit("characterReference"), a);
		}
		return u(t) && c++ < l ? (i.consume(t), m) : o(t);
	}
}
//#endregion
export { i as characterReference };
