import { asciiControl, markdownLineEnding, markdownLineEndingOrSpace } from "../micromark-util-character/index.js";
function factoryDestination(r, i, a, o, s, c, l, u, d) {
	let f = d || Infinity, p = 0;
	return m;
	function m(n) {
		return n === 60 ? (r.enter(o), r.enter(s), r.enter(c), r.consume(n), r.exit(c), h) : n === null || n === 32 || n === 41 || asciiControl(n) ? a(n) : (r.enter(o), r.enter(l), r.enter(u), r.enter("chunkString", { contentType: "string" }), v(n));
	}
	function h(e) {
		return e === 62 ? (r.enter(c), r.consume(e), r.exit(c), r.exit(s), r.exit(o), i) : (r.enter(u), r.enter("chunkString", { contentType: "string" }), g(e));
	}
	function g(e) {
		return e === 62 ? (r.exit("chunkString"), r.exit(u), h(e)) : e === null || e === 60 || markdownLineEnding(e) ? a(e) : (r.consume(e), e === 92 ? _ : g);
	}
	function _(e) {
		return e === 60 || e === 62 || e === 92 ? (r.consume(e), g) : g(e);
	}
	function v(n) {
		return !p && (n === null || n === 41 || markdownLineEndingOrSpace(n)) ? (r.exit("chunkString"), r.exit(u), r.exit(l), r.exit(o), i(n)) : p < f && n === 40 ? (r.consume(n), p++, v) : n === 41 ? (r.consume(n), p--, v) : n === null || n === 32 || n === 40 || asciiControl(n) ? a(n) : (r.consume(n), n === 92 ? y : v);
	}
	function y(e) {
		return e === 40 || e === 41 || e === 92 ? (r.consume(e), v) : v(e);
	}
}
export { factoryDestination };
