import { markdownLineEnding as e, markdownLineEndingOrSpace as t, markdownSpace as n } from "../../micromark-util-character/index.js";
import { splice as r } from "../../micromark-util-chunked/index.js";
import { factorySpace as i } from "../../micromark-factory-space/index.js";
//#region ../../node_modules/micromark-core-commonmark/lib/heading-atx.js
var a = {
	name: "headingAtx",
	resolve: o,
	tokenize: s
};
function o(e, t) {
	let n = e.length - 2, i = 3, a, o;
	return e[i][1].type === "whitespace" && (i += 2), n - 2 > i && e[n][1].type === "whitespace" && (n -= 2), e[n][1].type === "atxHeadingSequence" && (i === n - 1 || n - 4 > i && e[n - 2][1].type === "whitespace") && (n -= i + 1 === n ? 2 : 4), n > i && (a = {
		type: "atxHeadingText",
		start: e[i][1].start,
		end: e[n][1].end
	}, o = {
		type: "chunkText",
		start: e[i][1].start,
		end: e[n][1].end,
		contentType: "text"
	}, r(e, i, n - i + 1, [
		[
			"enter",
			a,
			t
		],
		[
			"enter",
			o,
			t
		],
		[
			"exit",
			o,
			t
		],
		[
			"exit",
			a,
			t
		]
	])), e;
}
function s(r, a, o) {
	let s = 0;
	return c;
	function c(e) {
		return r.enter("atxHeading"), l(e);
	}
	function l(e) {
		return r.enter("atxHeadingSequence"), u(e);
	}
	function u(e) {
		return e === 35 && s++ < 6 ? (r.consume(e), u) : e === null || t(e) ? (r.exit("atxHeadingSequence"), d(e)) : o(e);
	}
	function d(t) {
		return t === 35 ? (r.enter("atxHeadingSequence"), f(t)) : t === null || e(t) ? (r.exit("atxHeading"), a(t)) : n(t) ? i(r, d, "whitespace")(t) : (r.enter("atxHeadingText"), p(t));
	}
	function f(e) {
		return e === 35 ? (r.consume(e), f) : (r.exit("atxHeadingSequence"), d(e));
	}
	function p(e) {
		return e === null || e === 35 || t(e) ? (r.exit("atxHeadingText"), d(e)) : (r.consume(e), p);
	}
}
//#endregion
export { a as headingAtx };
