import { markdownLineEnding as e } from "../../micromark-util-character/index.js";
//#region ../../node_modules/micromark-extension-math/lib/math-text.js
function t(t) {
	let i = (t || {}).singleDollarTextMath;
	return i ??= !0, {
		tokenize: a,
		resolve: n,
		previous: r,
		name: "mathText"
	};
	function a(t, n, r) {
		let a = 0, o, s;
		return c;
		function c(e) {
			return t.enter("mathText"), t.enter("mathTextSequence"), l(e);
		}
		function l(e) {
			return e === 36 ? (t.consume(e), a++, l) : a < 2 && !i ? r(e) : (t.exit("mathTextSequence"), u(e));
		}
		function u(n) {
			return n === null ? r(n) : n === 36 ? (s = t.enter("mathTextSequence"), o = 0, f(n)) : n === 32 ? (t.enter("space"), t.consume(n), t.exit("space"), u) : e(n) ? (t.enter("lineEnding"), t.consume(n), t.exit("lineEnding"), u) : (t.enter("mathTextData"), d(n));
		}
		function d(n) {
			return n === null || n === 32 || n === 36 || e(n) ? (t.exit("mathTextData"), u(n)) : (t.consume(n), d);
		}
		function f(e) {
			return e === 36 ? (t.consume(e), o++, f) : o === a ? (t.exit("mathTextSequence"), t.exit("mathText"), n(e)) : (s.type = "mathTextData", d(e));
		}
	}
}
function n(e) {
	let t = e.length - 4, n = 3, r, i;
	if ((e[n][1].type === "lineEnding" || e[n][1].type === "space") && (e[t][1].type === "lineEnding" || e[t][1].type === "space")) {
		for (r = n; ++r < t;) if (e[r][1].type === "mathTextData") {
			e[t][1].type = "mathTextPadding", e[n][1].type = "mathTextPadding", n += 2, t -= 2;
			break;
		}
	}
	for (r = n - 1, t++; ++r <= t;) i === void 0 ? r !== t && e[r][1].type !== "lineEnding" && (i = r) : (r === t || e[r][1].type === "lineEnding") && (e[i][1].type = "mathTextData", r !== i + 2 && (e[i][1].end = e[r - 1][1].end, e.splice(i + 2, r - i - 2), t -= r - i - 2, r = i + 2), i = void 0);
	return e;
}
function r(e) {
	return e !== 36 || this.events[this.events.length - 1][1].type === "characterEscape";
}
//#endregion
export { t as mathText };
