import { markdownLineEnding as e } from "../../micromark-util-character/index.js";
//#region ../../node_modules/micromark-core-commonmark/lib/code-text.js
var t = {
	name: "codeText",
	previous: r,
	resolve: n,
	tokenize: i
};
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 === "codeTextData") {
			e[n][1].type = "codeTextPadding", e[t][1].type = "codeTextPadding", 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 = "codeTextData", 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 !== 96 || this.events[this.events.length - 1][1].type === "characterEscape";
}
function i(t, n, r) {
	let i = 0, a, o;
	return s;
	function s(e) {
		return t.enter("codeText"), t.enter("codeTextSequence"), c(e);
	}
	function c(e) {
		return e === 96 ? (t.consume(e), i++, c) : (t.exit("codeTextSequence"), l(e));
	}
	function l(n) {
		return n === null ? r(n) : n === 32 ? (t.enter("space"), t.consume(n), t.exit("space"), l) : n === 96 ? (o = t.enter("codeTextSequence"), a = 0, d(n)) : e(n) ? (t.enter("lineEnding"), t.consume(n), t.exit("lineEnding"), l) : (t.enter("codeTextData"), u(n));
	}
	function u(n) {
		return n === null || n === 32 || n === 96 || e(n) ? (t.exit("codeTextData"), l(n)) : (t.consume(n), u);
	}
	function d(e) {
		return e === 96 ? (t.consume(e), a++, d) : a === i ? (t.exit("codeTextSequence"), t.exit("codeText"), n(e)) : (o.type = "codeTextData", u(e));
	}
}
//#endregion
export { t as codeText };
