import { markdownLineEnding as e } from "../../micromark-util-character/index.js";
import { factorySpace as t } from "../../micromark-factory-space/index.js";
//#region ../../node_modules/micromark-extension-math/lib/math-flow.js
var n = {
	tokenize: i,
	concrete: !0,
	name: "mathFlow"
}, r = {
	tokenize: a,
	partial: !0
};
function i(n, i, a) {
	let o = this, s = o.events[o.events.length - 1], c = s && s[1].type === "linePrefix" ? s[2].sliceSerialize(s[1], !0).length : 0, l = 0;
	return u;
	function u(e) {
		return n.enter("mathFlow"), n.enter("mathFlowFence"), n.enter("mathFlowFenceSequence"), d(e);
	}
	function d(e) {
		return e === 36 ? (n.consume(e), l++, d) : l < 2 ? a(e) : (n.exit("mathFlowFenceSequence"), t(n, f, "whitespace")(e));
	}
	function f(t) {
		return t === null || e(t) ? m(t) : (n.enter("mathFlowFenceMeta"), n.enter("chunkString", { contentType: "string" }), p(t));
	}
	function p(t) {
		return t === null || e(t) ? (n.exit("chunkString"), n.exit("mathFlowFenceMeta"), m(t)) : t === 36 ? a(t) : (n.consume(t), p);
	}
	function m(e) {
		return n.exit("mathFlowFence"), o.interrupt ? i(e) : n.attempt(r, h, y)(e);
	}
	function h(e) {
		return n.attempt({
			tokenize: b,
			partial: !0
		}, y, g)(e);
	}
	function g(e) {
		return (c ? t(n, _, "linePrefix", c + 1) : _)(e);
	}
	function _(t) {
		return t === null ? y(t) : e(t) ? n.attempt(r, h, y)(t) : (n.enter("mathFlowValue"), v(t));
	}
	function v(t) {
		return t === null || e(t) ? (n.exit("mathFlowValue"), _(t)) : (n.consume(t), v);
	}
	function y(e) {
		return n.exit("mathFlow"), i(e);
	}
	function b(n, r, i) {
		let a = 0;
		return t(n, s, "linePrefix", o.parser.constructs.disable.null.includes("codeIndented") ? void 0 : 4);
		function s(e) {
			return n.enter("mathFlowFence"), n.enter("mathFlowFenceSequence"), c(e);
		}
		function c(e) {
			return e === 36 ? (a++, n.consume(e), c) : a < l ? i(e) : (n.exit("mathFlowFenceSequence"), t(n, u, "whitespace")(e));
		}
		function u(t) {
			return t === null || e(t) ? (n.exit("mathFlowFence"), r(t)) : i(t);
		}
	}
}
function a(e, t, n) {
	let r = this;
	return i;
	function i(n) {
		return n === null ? t(n) : (e.enter("lineEnding"), e.consume(n), e.exit("lineEnding"), a);
	}
	function a(e) {
		return r.parser.lazy[r.now().line] ? n(e) : t(e);
	}
}
//#endregion
export { n as mathFlow };
