const require_rolldown_runtime = require("./rolldown-runtime-Dp2H1eGw.cjs");
const require_lib = require("./lib-vD29ZLUp.cjs");
const VOID = -1;
const PRIMITIVE = 0;
const ARRAY = 1;
const OBJECT = 2;
const DATE = 3;
const REGEXP = 4;
const MAP = 5;
const SET = 6;
const ERROR = 7;
const BIGINT = 8;
var env = typeof self === "object" ? self : globalThis;
var deserializer = ($, _) => {
	const as = (out, index) => {
		$.set(index, out);
		return out;
	};
	const unpair = (index) => {
		if ($.has(index)) return $.get(index);
		const [type, value] = _[index];
		switch (type) {
			case 0:
			case -1: return as(value, index);
			case 1: {
				const arr = as([], index);
				for (const index$1 of value) arr.push(unpair(index$1));
				return arr;
			}
			case 2: {
				const object = as({}, index);
				for (const [key, index$1] of value) object[unpair(key)] = unpair(index$1);
				return object;
			}
			case 3: return as(new Date(value), index);
			case 4: {
				const { source, flags } = value;
				return as(new RegExp(source, flags), index);
			}
			case 5: {
				const map = as(/* @__PURE__ */ new Map(), index);
				for (const [key, index$1] of value) map.set(unpair(key), unpair(index$1));
				return map;
			}
			case 6: {
				const set = as(/* @__PURE__ */ new Set(), index);
				for (const index$1 of value) set.add(unpair(index$1));
				return set;
			}
			case 7: {
				const { name, message } = value;
				return as(new env[name](message), index);
			}
			case 8: return as(BigInt(value), index);
			case "BigInt": return as(Object(BigInt(value)), index);
			case "ArrayBuffer": return as(new Uint8Array(value).buffer, value);
			case "DataView": {
				const { buffer } = new Uint8Array(value);
				return as(new DataView(buffer), value);
			}
		}
		return as(new env[type](value), index);
	};
	return unpair;
};
const deserialize = (serialized) => deserializer(/* @__PURE__ */ new Map(), serialized)(0);
var EMPTY = "";
var { toString: toString$1 } = {};
var { keys } = Object;
var typeOf = (value) => {
	const type = typeof value;
	if (type !== "object" || !value) return [0, type];
	const asString = toString$1.call(value).slice(8, -1);
	switch (asString) {
		case "Array": return [1, EMPTY];
		case "Object": return [2, EMPTY];
		case "Date": return [3, EMPTY];
		case "RegExp": return [4, EMPTY];
		case "Map": return [5, EMPTY];
		case "Set": return [6, EMPTY];
		case "DataView": return [1, asString];
	}
	if (asString.includes("Array")) return [1, asString];
	if (asString.includes("Error")) return [7, asString];
	return [2, asString];
};
var shouldSkip = ([TYPE, type]) => TYPE === 0 && (type === "function" || type === "symbol");
var serializer = (strict, json, $, _) => {
	const as = (out, value) => {
		const index = _.push(out) - 1;
		$.set(value, index);
		return index;
	};
	const pair = (value) => {
		if ($.has(value)) return $.get(value);
		let [TYPE, type] = typeOf(value);
		switch (TYPE) {
			case 0: {
				let entry = value;
				switch (type) {
					case "bigint":
						TYPE = 8;
						entry = value.toString();
						break;
					case "function":
					case "symbol":
						if (strict) throw new TypeError("unable to serialize " + type);
						entry = null;
						break;
					case "undefined": return as([-1], value);
				}
				return as([TYPE, entry], value);
			}
			case 1: {
				if (type) {
					let spread = value;
					if (type === "DataView") spread = new Uint8Array(value.buffer);
					else if (type === "ArrayBuffer") spread = new Uint8Array(value);
					return as([type, [...spread]], value);
				}
				const arr = [];
				const index = as([TYPE, arr], value);
				for (const entry of value) arr.push(pair(entry));
				return index;
			}
			case 2: {
				if (type) switch (type) {
					case "BigInt": return as([type, value.toString()], value);
					case "Boolean":
					case "Number":
					case "String": return as([type, value.valueOf()], value);
				}
				if (json && "toJSON" in value) return pair(value.toJSON());
				const entries = [];
				const index = as([TYPE, entries], value);
				for (const key of keys(value)) if (strict || !shouldSkip(typeOf(value[key]))) entries.push([pair(key), pair(value[key])]);
				return index;
			}
			case 3: return as([TYPE, value.toISOString()], value);
			case 4: {
				const { source, flags } = value;
				return as([TYPE, {
					source,
					flags
				}], value);
			}
			case 5: {
				const entries = [];
				const index = as([TYPE, entries], value);
				for (const [key, entry] of value) if (strict || !(shouldSkip(typeOf(key)) || shouldSkip(typeOf(entry)))) entries.push([pair(key), pair(entry)]);
				return index;
			}
			case 6: {
				const entries = [];
				const index = as([TYPE, entries], value);
				for (const entry of value) if (strict || !shouldSkip(typeOf(entry))) entries.push(pair(entry));
				return index;
			}
		}
		const { message } = value;
		return as([TYPE, {
			name: type,
			message
		}], value);
	};
	return pair;
};
const serialize = (value, { json, lossy } = {}) => {
	const _ = [];
	return serializer(!(json || lossy), !!json, /* @__PURE__ */ new Map(), _)(value), _;
};
var esm_default = typeof structuredClone === "function" ? (any, options) => options && ("json" in options || "lossy" in options) ? deserialize(serialize(any, options)) : structuredClone(any) : (any, options) => deserialize(serialize(any, options));
const isElement = (function(element$1, test, index, parent, context) {
	const check = convertElement(test);
	if (index !== null && index !== void 0 && (typeof index !== "number" || index < 0 || index === Number.POSITIVE_INFINITY)) throw new Error("Expected positive finite `index`");
	if (parent !== null && parent !== void 0 && (!parent.type || !parent.children)) throw new Error("Expected valid `parent`");
	if ((index === null || index === void 0) !== (parent === null || parent === void 0)) throw new Error("Expected both `index` and `parent`");
	return looksLikeAnElement(element$1) ? check.call(context, element$1, index, parent) : false;
});
const convertElement = (function(test) {
	if (test === null || test === void 0) return element;
	if (typeof test === "string") return tagNameFactory(test);
	if (typeof test === "object") return anyFactory(test);
	if (typeof test === "function") return castFactory(test);
	throw new Error("Expected function, string, or array as `test`");
});
function anyFactory(tests) {
	const checks = [];
	let index = -1;
	while (++index < tests.length) checks[index] = convertElement(tests[index]);
	return castFactory(any);
	function any(...parameters) {
		let index$1 = -1;
		while (++index$1 < checks.length) if (checks[index$1].apply(this, parameters)) return true;
		return false;
	}
}
function tagNameFactory(check) {
	return castFactory(tagName);
	function tagName(element$1) {
		return element$1.tagName === check;
	}
}
function castFactory(testFunction) {
	return check;
	function check(value, index, parent) {
		return Boolean(looksLikeAnElement(value) && testFunction.call(this, value, typeof index === "number" ? index : void 0, parent || void 0));
	}
}
function element(element$1) {
	return Boolean(element$1 && typeof element$1 === "object" && "type" in element$1 && element$1.type === "element" && "tagName" in element$1 && typeof element$1.tagName === "string");
}
function looksLikeAnElement(value) {
	return value !== null && typeof value === "object" && "type" in value && "tagName" in value;
}
const embedded = convertElement(function(element$1) {
	return element$1.tagName === "audio" || element$1.tagName === "canvas" || element$1.tagName === "embed" || element$1.tagName === "iframe" || element$1.tagName === "img" || element$1.tagName === "math" || element$1.tagName === "object" || element$1.tagName === "picture" || element$1.tagName === "svg" || element$1.tagName === "video";
});
var re = /[ \t\n\f\r]/g;
function whitespace(thing) {
	return typeof thing === "object" ? thing.type === "text" ? empty(thing.value) : false : empty(thing);
}
function empty(value) {
	return value.replace(re, "") === "";
}
const blocks = [
	"address",
	"article",
	"aside",
	"blockquote",
	"body",
	"br",
	"caption",
	"center",
	"col",
	"colgroup",
	"dd",
	"dialog",
	"dir",
	"div",
	"dl",
	"dt",
	"figcaption",
	"figure",
	"footer",
	"form",
	"h1",
	"h2",
	"h3",
	"h4",
	"h5",
	"h6",
	"head",
	"header",
	"hgroup",
	"hr",
	"html",
	"legend",
	"li",
	"li",
	"listing",
	"main",
	"menu",
	"nav",
	"ol",
	"optgroup",
	"option",
	"p",
	"plaintext",
	"pre",
	"section",
	"summary",
	"table",
	"tbody",
	"td",
	"td",
	"tfoot",
	"th",
	"th",
	"thead",
	"tr",
	"ul",
	"wbr",
	"xmp"
];
const content = [
	"button",
	"input",
	"select",
	"textarea"
];
const skippable = [
	"area",
	"base",
	"basefont",
	"dialog",
	"datalist",
	"head",
	"link",
	"meta",
	"noembed",
	"noframes",
	"param",
	"rp",
	"script",
	"source",
	"style",
	"template",
	"track",
	"title"
];
var emptyOptions$1 = {};
var ignorableNode = require_lib.convert(["comment", "doctype"]);
function minifyWhitespace(tree, options) {
	minify(tree, {
		collapse: collapseFactory((options || emptyOptions$1).newlines ? replaceNewlines : replaceWhitespace),
		whitespace: "normal"
	});
}
function minify(node, state) {
	if ("children" in node) {
		const settings = { ...state };
		if (node.type === "root" || blocklike(node)) {
			settings.before = true;
			settings.after = true;
		}
		settings.whitespace = inferWhiteSpace(node, state);
		return all$2(node, settings);
	}
	if (node.type === "text") {
		if (state.whitespace === "normal") return minifyText(node, state);
		if (state.whitespace === "nowrap") node.value = state.collapse(node.value);
	}
	return {
		ignore: ignorableNode(node),
		stripAtStart: false,
		remove: false
	};
}
function minifyText(node, state) {
	const value = state.collapse(node.value);
	const result = {
		ignore: false,
		stripAtStart: false,
		remove: false
	};
	let start = 0;
	let end = value.length;
	if (state.before && removable(value.charAt(0))) start++;
	if (start !== end && removable(value.charAt(end - 1))) if (state.after) end--;
	else result.stripAtStart = true;
	if (start === end) result.remove = true;
	else node.value = value.slice(start, end);
	return result;
}
function all$2(parent, state) {
	let before = state.before;
	const after = state.after;
	const children = parent.children;
	let length = children.length;
	let index = -1;
	while (++index < length) {
		const result = minify(children[index], {
			...state,
			after: collapsableAfter(children, index, after),
			before
		});
		if (result.remove) {
			children.splice(index, 1);
			index--;
			length--;
		} else if (!result.ignore) before = result.stripAtStart;
		if (content$1(children[index])) before = false;
	}
	return {
		ignore: false,
		stripAtStart: Boolean(before || after),
		remove: false
	};
}
function collapsableAfter(nodes, index, after) {
	while (++index < nodes.length) {
		const node = nodes[index];
		let result = inferBoundary(node);
		if (result === void 0 && "children" in node && !skippable$1(node)) result = collapsableAfter(node.children, -1);
		if (typeof result === "boolean") return result;
	}
	return after;
}
function inferBoundary(node) {
	if (node.type === "element") {
		if (content$1(node)) return false;
		if (blocklike(node)) return true;
	} else if (node.type === "text") {
		if (!whitespace(node)) return false;
	} else if (!ignorableNode(node)) return false;
}
function content$1(node) {
	return embedded(node) || isElement(node, content);
}
function blocklike(node) {
	return isElement(node, blocks);
}
function skippable$1(node) {
	return Boolean(node.type === "element" && node.properties.hidden) || ignorableNode(node) || isElement(node, skippable);
}
function removable(character) {
	return character === " " || character === "\n";
}
function replaceNewlines(value) {
	const match = /\r?\n|\r/.exec(value);
	return match ? match[0] : " ";
}
function replaceWhitespace() {
	return " ";
}
function collapseFactory(replace) {
	return collapse;
	function collapse(value) {
		return String(value).replace(/[\t\n\v\f\r ]+/g, replace);
	}
}
function inferWhiteSpace(node, state) {
	if ("tagName" in node && node.properties) switch (node.tagName) {
		case "listing":
		case "plaintext":
		case "script":
		case "style":
		case "xmp": return "pre";
		case "nobr": return "nowrap";
		case "pre": return node.properties.wrap ? "pre-wrap" : "pre";
		case "td":
		case "th": return node.properties.noWrap ? "nowrap" : state.whitespace;
		case "textarea": return "pre-wrap";
		default:
	}
	return state.whitespace;
}
function rehypeMinifyWhitespace(options) {
	return function(tree) {
		minifyWhitespace(tree, options);
	};
}
const pointEnd = point("end");
const pointStart = point("start");
function point(type) {
	return point$1;
	function point$1(node) {
		const point$2 = node && node.position && node.position[type] || {};
		if (typeof point$2.line === "number" && point$2.line > 0 && typeof point$2.column === "number" && point$2.column > 0) return {
			line: point$2.line,
			column: point$2.column,
			offset: typeof point$2.offset === "number" && point$2.offset > -1 ? point$2.offset : void 0
		};
	}
}
function position(node) {
	const start = pointStart(node);
	const end = pointEnd(node);
	if (start && end) return {
		start,
		end
	};
}
function a(state, node) {
	const properties = node.properties || {};
	const children = state.all(node);
	const result = {
		type: "link",
		url: state.resolve(String(properties.href || "") || null),
		title: properties.title ? String(properties.title) : null,
		children
	};
	state.patch(node, result);
	return result;
}
function base(state, node) {
	if (!state.baseFound) {
		state.frozenBaseUrl = String(node.properties && node.properties.href || "") || void 0;
		state.baseFound = true;
	}
}
function blockquote(state, node) {
	const result = {
		type: "blockquote",
		children: state.toFlow(state.all(node))
	};
	state.patch(node, result);
	return result;
}
function br(state, node) {
	const result = { type: "break" };
	state.patch(node, result);
	return result;
}
const findAfter = (function(parent, index, test) {
	const is = require_lib.convert(test);
	if (!parent || !parent.type || !parent.children) throw new Error("Expected parent node");
	if (typeof index === "number") {
		if (index < 0 || index === Number.POSITIVE_INFINITY) throw new Error("Expected positive finite number as index");
	} else {
		index = parent.children.indexOf(index);
		if (index < 0) throw new Error("Expected child node or index");
	}
	while (++index < parent.children.length) if (is(parent.children[index], index, parent)) return parent.children[index];
});
var searchLineFeeds = /\n/g;
var searchTabOrSpaces = /[\t ]+/g;
var br$1 = convertElement("br");
var cell = convertElement(isCell);
var p$1 = convertElement("p");
var row = convertElement("tr");
var notRendered = convertElement([
	"datalist",
	"head",
	"noembed",
	"noframes",
	"noscript",
	"rp",
	"script",
	"style",
	"template",
	"title",
	hidden,
	closedDialog
]);
var blockOrCaption = convertElement([
	"address",
	"article",
	"aside",
	"blockquote",
	"body",
	"caption",
	"center",
	"dd",
	"dialog",
	"dir",
	"dl",
	"dt",
	"div",
	"figure",
	"figcaption",
	"footer",
	"form,",
	"h1",
	"h2",
	"h3",
	"h4",
	"h5",
	"h6",
	"header",
	"hgroup",
	"hr",
	"html",
	"legend",
	"li",
	"listing",
	"main",
	"menu",
	"nav",
	"ol",
	"p",
	"plaintext",
	"pre",
	"section",
	"ul",
	"xmp"
]);
function toText(tree, options) {
	const options_ = options || {};
	const children = "children" in tree ? tree.children : [];
	const block = blockOrCaption(tree);
	const whitespace$1 = inferWhitespace(tree, {
		whitespace: options_.whitespace || "normal",
		breakBefore: false,
		breakAfter: false
	});
	const results = [];
	if (tree.type === "text" || tree.type === "comment") results.push(...collectText(tree, {
		whitespace: whitespace$1,
		breakBefore: true,
		breakAfter: true
	}));
	let index = -1;
	while (++index < children.length) results.push(...renderedTextCollection(children[index], tree, {
		whitespace: whitespace$1,
		breakBefore: index ? void 0 : block,
		breakAfter: index < children.length - 1 ? br$1(children[index + 1]) : block
	}));
	const result = [];
	let count;
	index = -1;
	while (++index < results.length) {
		const value = results[index];
		if (typeof value === "number") {
			if (count !== void 0 && value > count) count = value;
		} else if (value) {
			if (count !== void 0 && count > -1) result.push("\n".repeat(count) || " ");
			count = -1;
			result.push(value);
		}
	}
	return result.join("");
}
function renderedTextCollection(node, parent, info) {
	if (node.type === "element") return collectElement(node, parent, info);
	if (node.type === "text") return info.whitespace === "normal" ? collectText(node, info) : collectPreText(node);
	return [];
}
function collectElement(node, parent, info) {
	const whitespace$1 = inferWhitespace(node, info);
	const children = node.children || [];
	let index = -1;
	let items = [];
	if (notRendered(node)) return items;
	let prefix$1;
	let suffix;
	if (br$1(node)) suffix = "\n";
	else if (row(node) && findAfter(parent, node, row)) suffix = "\n";
	else if (p$1(node)) {
		prefix$1 = 2;
		suffix = 2;
	} else if (blockOrCaption(node)) {
		prefix$1 = 1;
		suffix = 1;
	}
	while (++index < children.length) items = items.concat(renderedTextCollection(children[index], node, {
		whitespace: whitespace$1,
		breakBefore: index ? void 0 : prefix$1,
		breakAfter: index < children.length - 1 ? br$1(children[index + 1]) : suffix
	}));
	if (cell(node) && findAfter(parent, node, cell)) items.push("	");
	if (prefix$1) items.unshift(prefix$1);
	if (suffix) items.push(suffix);
	return items;
}
function collectText(node, info) {
	const value = String(node.value);
	const lines = [];
	const result = [];
	let start = 0;
	while (start <= value.length) {
		searchLineFeeds.lastIndex = start;
		const match = searchLineFeeds.exec(value);
		const end = match && "index" in match ? match.index : value.length;
		lines.push(trimAndCollapseSpacesAndTabs(value.slice(start, end).replace(/[\u061C\u200E\u200F\u202A-\u202E\u2066-\u2069]/g, ""), start === 0 ? info.breakBefore : true, end === value.length ? info.breakAfter : true));
		start = end + 1;
	}
	let index = -1;
	let join;
	while (++index < lines.length) if (lines[index].charCodeAt(lines[index].length - 1) === 8203 || index < lines.length - 1 && lines[index + 1].charCodeAt(0) === 8203) {
		result.push(lines[index]);
		join = void 0;
	} else if (lines[index]) {
		if (typeof join === "number") result.push(join);
		result.push(lines[index]);
		join = 0;
	} else if (index === 0 || index === lines.length - 1) result.push(0);
	return result;
}
function collectPreText(node) {
	return [String(node.value)];
}
function trimAndCollapseSpacesAndTabs(value, breakBefore, breakAfter) {
	const result = [];
	let start = 0;
	let end;
	while (start < value.length) {
		searchTabOrSpaces.lastIndex = start;
		const match = searchTabOrSpaces.exec(value);
		end = match ? match.index : value.length;
		if (!start && !end && match && !breakBefore) result.push("");
		if (start !== end) result.push(value.slice(start, end));
		start = match ? end + match[0].length : end;
	}
	if (start !== end && !breakAfter) result.push("");
	return result.join(" ");
}
function inferWhitespace(node, info) {
	if (node.type === "element") {
		const properties = node.properties || {};
		switch (node.tagName) {
			case "listing":
			case "plaintext":
			case "xmp": return "pre";
			case "nobr": return "nowrap";
			case "pre": return properties.wrap ? "pre-wrap" : "pre";
			case "td":
			case "th": return properties.noWrap ? "nowrap" : info.whitespace;
			case "textarea": return "pre-wrap";
			default:
		}
	}
	return info.whitespace;
}
function hidden(node) {
	return Boolean((node.properties || {}).hidden);
}
function isCell(node) {
	return node.tagName === "td" || node.tagName === "th";
}
function closedDialog(node) {
	return node.tagName === "dialog" && !(node.properties || {}).open;
}
function trimTrailingLines(value) {
	const input$1 = String(value);
	let end = input$1.length;
	while (end > 0) {
		const code$1 = input$1.codePointAt(end - 1);
		if (code$1 !== void 0 && (code$1 === 10 || code$1 === 13)) end--;
		else break;
	}
	return input$1.slice(0, end);
}
var prefix = "language-";
function code(state, node) {
	const children = node.children;
	let index = -1;
	let classList;
	let lang;
	if (node.tagName === "pre") while (++index < children.length) {
		const child = children[index];
		if (child.type === "element" && child.tagName === "code" && child.properties && child.properties.className && Array.isArray(child.properties.className)) {
			classList = child.properties.className;
			break;
		}
	}
	if (classList) {
		index = -1;
		while (++index < classList.length) if (String(classList[index]).slice(0, 9) === prefix) {
			lang = String(classList[index]).slice(9);
			break;
		}
	}
	const result = {
		type: "code",
		lang: lang || null,
		meta: null,
		value: trimTrailingLines(toText(node))
	};
	state.patch(node, result);
	return result;
}
function comment(state, node) {
	const result = {
		type: "html",
		value: "<!--" + node.value + "-->"
	};
	state.patch(node, result);
	return result;
}
function del(state, node) {
	const result = {
		type: "delete",
		children: state.all(node)
	};
	state.patch(node, result);
	return result;
}
function listItemsSpread(children) {
	let index = -1;
	if (children.length > 1) {
		while (++index < children.length) if (children[index].spread) return true;
	}
	return false;
}
function dl(state, node) {
	const clean = [];
	const groups = [];
	let index = -1;
	while (++index < node.children.length) {
		const child = node.children[index];
		if (child.type === "element" && child.tagName === "div") clean.push(...child.children);
		else clean.push(child);
	}
	let group = {
		definitions: [],
		titles: []
	};
	index = -1;
	while (++index < clean.length) {
		const child = clean[index];
		if (child.type === "element" && child.tagName === "dt") {
			const previous = clean[index - 1];
			if (previous && previous.type === "element" && previous.tagName === "dd") {
				groups.push(group);
				group = {
					definitions: [],
					titles: []
				};
			}
			group.titles.push(child);
		} else group.definitions.push(child);
	}
	groups.push(group);
	index = -1;
	const content$2 = [];
	while (++index < groups.length) {
		const result = [...handle(state, groups[index].titles), ...handle(state, groups[index].definitions)];
		if (result.length > 0) content$2.push({
			type: "listItem",
			spread: result.length > 1,
			checked: null,
			children: result
		});
	}
	if (content$2.length > 0) {
		const result = {
			type: "list",
			ordered: false,
			start: null,
			spread: listItemsSpread(content$2),
			children: content$2
		};
		state.patch(node, result);
		return result;
	}
}
function handle(state, children) {
	const nodes = state.all({
		type: "root",
		children
	});
	const listItems = state.toSpecificContent(nodes, create$2);
	if (listItems.length === 0) return [];
	if (listItems.length === 1) return listItems[0].children;
	return [{
		type: "list",
		ordered: false,
		start: null,
		spread: listItemsSpread(listItems),
		children: listItems
	}];
}
function create$2() {
	return {
		type: "listItem",
		spread: false,
		checked: null,
		children: []
	};
}
function em(state, node) {
	const result = {
		type: "emphasis",
		children: state.all(node)
	};
	state.patch(node, result);
	return result;
}
function dropSurroundingBreaks(nodes) {
	let start = 0;
	let end = nodes.length;
	while (start < end && nodes[start].type === "break") start++;
	while (end > start && nodes[end - 1].type === "break") end--;
	return start === 0 && end === nodes.length ? nodes : nodes.slice(start, end);
}
function heading(state, node) {
	const result = {
		type: "heading",
		depth: Number(node.tagName.charAt(1)) || 1,
		children: dropSurroundingBreaks(state.all(node))
	};
	state.patch(node, result);
	return result;
}
function hr(state, node) {
	const result = { type: "thematicBreak" };
	state.patch(node, result);
	return result;
}
function iframe(state, node) {
	const properties = node.properties || {};
	const source = String(properties.src || "");
	const title = String(properties.title || "");
	if (source && title) {
		const result = {
			type: "link",
			title: null,
			url: state.resolve(source),
			children: [{
				type: "text",
				value: title
			}]
		};
		state.patch(node, result);
		return result;
	}
}
function img(state, node) {
	const properties = node.properties || {};
	const result = {
		type: "image",
		url: state.resolve(String(properties.src || "") || null),
		title: properties.title ? String(properties.title) : null,
		alt: properties.alt ? String(properties.alt) : ""
	};
	state.patch(node, result);
	return result;
}
function inlineCode(state, node) {
	const result = {
		type: "inlineCode",
		value: toText(node)
	};
	state.patch(node, result);
	return result;
}
function findSelectedOptions(node, explicitProperties) {
	const selectedOptions = [];
	const values = [];
	const properties = explicitProperties || node.properties || {};
	const options = findOptions(node);
	const size = Math.min(Number.parseInt(String(properties.size), 10), 0) || (properties.multiple ? 4 : 1);
	let index = -1;
	while (++index < options.length) {
		const option = options[index];
		if (option && option.properties && option.properties.selected) selectedOptions.push(option);
	}
	const list$2 = selectedOptions.length > 0 ? selectedOptions : options;
	const max = Math.min(list$2.length, size);
	index = -1;
	while (++index < max) {
		const option = list$2[index];
		const properties$1 = option.properties || {};
		const content$2 = toText(option);
		const label = content$2 || String(properties$1.label || "");
		const value = String(properties$1.value || "") || content$2;
		values.push([value, label === value ? void 0 : label]);
	}
	return values;
}
function findOptions(node) {
	const results = [];
	let index = -1;
	while (++index < node.children.length) {
		const child = node.children[index];
		if ("children" in child && Array.isArray(child.children)) results.push(...findOptions(child));
		if (child.type === "element" && child.tagName === "option" && (!child.properties || !child.properties.disabled)) results.push(child);
	}
	return results;
}
var defaultChecked = "[x]";
var defaultUnchecked = "[ ]";
function input(state, node) {
	const properties = node.properties || {};
	const value = String(properties.value || properties.placeholder || "");
	if (properties.disabled || properties.type === "hidden" || properties.type === "file") return;
	if (properties.type === "checkbox" || properties.type === "radio") {
		const result$1 = {
			type: "text",
			value: properties.checked ? state.options.checked || defaultChecked : state.options.unchecked || defaultUnchecked
		};
		state.patch(node, result$1);
		return result$1;
	}
	if (properties.type === "image") {
		const alt = properties.alt || value;
		if (alt) {
			const result$1 = {
				type: "image",
				url: state.resolve(String(properties.src || "") || null),
				title: String(properties.title || "") || null,
				alt: String(alt)
			};
			state.patch(node, result$1);
			return result$1;
		}
		return;
	}
	let values = [];
	if (value) values = [[value, void 0]];
	else if (properties.type !== "button" && properties.type !== "file" && properties.type !== "password" && properties.type !== "reset" && properties.type !== "submit" && properties.list) {
		const list$2 = String(properties.list);
		const datalist = state.elementById.get(list$2);
		if (datalist && datalist.tagName === "datalist") values = findSelectedOptions(datalist, properties);
	}
	if (values.length === 0) return;
	if (properties.type === "password") values[0] = ["•".repeat(values[0][0].length), void 0];
	if (properties.type === "email" || properties.type === "url") {
		const results = [];
		let index$1 = -1;
		while (++index$1 < values.length) {
			const value$1 = state.resolve(values[index$1][0]);
			const result$1 = {
				type: "link",
				title: null,
				url: properties.type === "email" ? "mailto:" + value$1 : value$1,
				children: [{
					type: "text",
					value: values[index$1][1] || value$1
				}]
			};
			results.push(result$1);
			if (index$1 !== values.length - 1) results.push({
				type: "text",
				value: ", "
			});
		}
		return results;
	}
	const texts = [];
	let index = -1;
	while (++index < values.length) texts.push(values[index][1] ? values[index][1] + " (" + values[index][0] + ")" : values[index][0]);
	const result = {
		type: "text",
		value: texts.join(", ")
	};
	state.patch(node, result);
	return result;
}
var own$1 = {}.hasOwnProperty;
function hasProperty(node, name) {
	const value = node.type === "element" && own$1.call(node.properties, name) && node.properties[name];
	return value !== null && value !== void 0 && value !== false;
}
var list$1 = new Set([
	"pingback",
	"prefetch",
	"stylesheet"
]);
function isBodyOkLink(node) {
	if (node.type !== "element" || node.tagName !== "link") return false;
	if (node.properties.itemProp) return true;
	const value = node.properties.rel;
	let index = -1;
	if (!Array.isArray(value) || value.length === 0) return false;
	while (++index < value.length) if (!list$1.has(String(value[index]))) return false;
	return true;
}
var basic = convertElement([
	"a",
	"abbr",
	"area",
	"b",
	"bdi",
	"bdo",
	"br",
	"button",
	"cite",
	"code",
	"data",
	"datalist",
	"del",
	"dfn",
	"em",
	"i",
	"input",
	"ins",
	"kbd",
	"keygen",
	"label",
	"map",
	"mark",
	"meter",
	"noscript",
	"output",
	"progress",
	"q",
	"ruby",
	"s",
	"samp",
	"script",
	"select",
	"small",
	"span",
	"strong",
	"sub",
	"sup",
	"template",
	"textarea",
	"time",
	"u",
	"var",
	"wbr"
]);
var meta = convertElement("meta");
function phrasing(value) {
	return Boolean(value.type === "text" || basic(value) || embedded(value) || isBodyOkLink(value) || meta(value) && hasProperty(value, "itemProp"));
}
function li(state, node) {
	const { rest, checkbox } = extractLeadingCheckbox(node);
	const checked = checkbox ? Boolean(checkbox.properties.checked) : null;
	const result = {
		type: "listItem",
		spread: spreadout(rest),
		checked,
		children: state.toFlow(state.all(rest))
	};
	state.patch(node, result);
	return result;
}
function spreadout(node) {
	let index = -1;
	let seenFlow = false;
	while (++index < node.children.length) {
		const child = node.children[index];
		if (child.type === "element") {
			if (phrasing(child)) continue;
			if (child.tagName === "p" || seenFlow || spreadout(child)) return true;
			seenFlow = true;
		}
	}
	return false;
}
function extractLeadingCheckbox(node) {
	const head = node.children[0];
	if (head && head.type === "element" && head.tagName === "input" && head.properties && (head.properties.type === "checkbox" || head.properties.type === "radio")) return {
		checkbox: head,
		rest: {
			...node,
			children: node.children.slice(1)
		}
	};
	if (head && head.type === "element" && head.tagName === "p") {
		const { checkbox, rest: restHead } = extractLeadingCheckbox(head);
		if (checkbox) return {
			checkbox,
			rest: {
				...node,
				children: [restHead, ...node.children.slice(1)]
			}
		};
	}
	return {
		checkbox: void 0,
		rest: node
	};
}
function list(state, node) {
	const ordered = node.tagName === "ol";
	const children = state.toSpecificContent(state.all(node), create$1);
	let start = null;
	if (ordered) start = node.properties && node.properties.start ? Number.parseInt(String(node.properties.start), 10) : 1;
	const result = {
		type: "list",
		ordered,
		start,
		spread: listItemsSpread(children),
		children
	};
	state.patch(node, result);
	return result;
}
function create$1() {
	return {
		type: "listItem",
		spread: false,
		checked: null,
		children: []
	};
}
function wrapNeeded(nodes) {
	let index = -1;
	while (++index < nodes.length) {
		const node = nodes[index];
		if (!phrasing$2(node) || "children" in node && wrapNeeded(node.children)) return true;
	}
	return false;
}
function wrap(nodes) {
	return runs(nodes, onphrasing, function(d) {
		return d;
	});
	function onphrasing(nodes$1) {
		return nodes$1.every(function(d) {
			return d.type === "text" ? whitespace(d.value) : false;
		}) ? [] : [{
			type: "paragraph",
			children: dropSurroundingBreaks(nodes$1)
		}];
	}
}
function split(node) {
	return runs(node.children, onphrasing, onnonphrasing);
	function onphrasing(nodes) {
		const newParent = cloneWithoutChildren(node);
		newParent.children = nodes;
		return [newParent];
	}
	function onnonphrasing(child) {
		if ("children" in child && "children" in node) {
			const newParent = cloneWithoutChildren(node);
			const newChild = cloneWithoutChildren(child);
			newParent.children = child.children;
			newChild.children.push(newParent);
			return newChild;
		}
		return { ...child };
	}
}
function runs(nodes, onphrasing, onnonphrasing) {
	const flattened = flatten(nodes);
	const result = [];
	let queue = [];
	let index = -1;
	while (++index < flattened.length) {
		const node = flattened[index];
		if (phrasing$2(node)) queue.push(node);
		else {
			if (queue.length > 0) {
				result.push(...onphrasing(queue));
				queue = [];
			}
			result.push(onnonphrasing(node));
		}
	}
	if (queue.length > 0) {
		result.push(...onphrasing(queue));
		queue = [];
	}
	return result;
}
function flatten(nodes) {
	const flattened = [];
	let index = -1;
	while (++index < nodes.length) {
		const node = nodes[index];
		if ((node.type === "delete" || node.type === "link") && wrapNeeded(node.children)) flattened.push(...split(node));
		else flattened.push(node);
	}
	return flattened;
}
function phrasing$2(node) {
	const tagName = node.data && node.data.hName;
	return tagName ? phrasing({
		type: "element",
		tagName,
		properties: {},
		children: []
	}) : require_lib.phrasing(node);
}
function cloneWithoutChildren(node) {
	return esm_default({
		...node,
		children: []
	});
}
function media(state, node) {
	const properties = node.properties || {};
	const poster = node.tagName === "video" ? String(properties.poster || "") : "";
	let source = String(properties.src || "");
	let index = -1;
	let linkInFallbackContent = false;
	let nodes = state.all(node);
	require_lib.visit({
		type: "root",
		children: nodes
	}, function(node$1) {
		if (node$1.type === "link") {
			linkInFallbackContent = true;
			return false;
		}
	});
	if (linkInFallbackContent || wrapNeeded(nodes)) return nodes;
	while (!source && ++index < node.children.length) {
		const child = node.children[index];
		if (child.type === "element" && child.tagName === "source" && child.properties) source = String(child.properties.src || "");
	}
	if (poster) {
		const image = {
			type: "image",
			title: null,
			url: state.resolve(poster),
			alt: require_lib.toString(nodes)
		};
		state.patch(node, image);
		nodes = [image];
	}
	const children = nodes;
	const result = {
		type: "link",
		title: properties.title ? String(properties.title) : null,
		url: state.resolve(source),
		children
	};
	state.patch(node, result);
	return result;
}
function p(state, node) {
	const children = dropSurroundingBreaks(state.all(node));
	if (children.length > 0) {
		const result = {
			type: "paragraph",
			children
		};
		state.patch(node, result);
		return result;
	}
}
var defaultQuotes = ["\""];
function q(state, node) {
	const quotes = state.options.quotes || defaultQuotes;
	state.qNesting++;
	const contents = state.all(node);
	state.qNesting--;
	const quote = quotes[state.qNesting % quotes.length];
	const head = contents[0];
	const tail = contents[contents.length - 1];
	const open = quote.charAt(0);
	const close = quote.length > 1 ? quote.charAt(1) : quote;
	if (head && head.type === "text") head.value = open + head.value;
	else contents.unshift({
		type: "text",
		value: open
	});
	if (tail && tail.type === "text") tail.value += close;
	else contents.push({
		type: "text",
		value: close
	});
	return contents;
}
function root(state, node) {
	let children = state.all(node);
	if (state.options.document || wrapNeeded(children)) children = wrap(children);
	const result = {
		type: "root",
		children
	};
	state.patch(node, result);
	return result;
}
function select(state, node) {
	const values = findSelectedOptions(node);
	let index = -1;
	const results = [];
	while (++index < values.length) {
		const value = values[index];
		results.push(value[1] ? value[1] + " (" + value[0] + ")" : value[0]);
	}
	if (results.length > 0) {
		const result = {
			type: "text",
			value: results.join(", ")
		};
		state.patch(node, result);
		return result;
	}
}
function strong(state, node) {
	const result = {
		type: "strong",
		children: state.all(node)
	};
	state.patch(node, result);
	return result;
}
function tableCell(state, node) {
	const result = {
		type: "tableCell",
		children: state.all(node)
	};
	state.patch(node, result);
	if (node.properties) {
		const rowSpan = node.properties.rowSpan;
		const colSpan = node.properties.colSpan;
		if (rowSpan || colSpan) {
			const data = result.data || (result.data = {});
			if (rowSpan) data.hastUtilToMdastTemporaryRowSpan = rowSpan;
			if (colSpan) data.hastUtilToMdastTemporaryColSpan = colSpan;
		}
	}
	return result;
}
function tableRow(state, node) {
	const result = {
		type: "tableRow",
		children: state.toSpecificContent(state.all(node), create)
	};
	state.patch(node, result);
	return result;
}
function create() {
	return {
		type: "tableCell",
		children: []
	};
}
function table(state, node) {
	if (state.inTable) {
		const result$1 = {
			type: "text",
			value: toText(node)
		};
		state.patch(node, result$1);
		return result$1;
	}
	state.inTable = true;
	const { align, headless } = inspect(node);
	const rows = state.toSpecificContent(state.all(node), createRow);
	if (headless) rows.unshift(createRow());
	let rowIndex = -1;
	while (++rowIndex < rows.length) {
		const row$1 = rows[rowIndex];
		row$1.children = state.toSpecificContent(row$1.children, createCell);
	}
	let columns = 1;
	rowIndex = -1;
	while (++rowIndex < rows.length) {
		const cells = rows[rowIndex].children;
		let cellIndex = -1;
		while (++cellIndex < cells.length) {
			const cell$1 = cells[cellIndex];
			if (cell$1.data) {
				const data = cell$1.data;
				const colSpan = Number.parseInt(String(data.hastUtilToMdastTemporaryColSpan), 10) || 1;
				const rowSpan = Number.parseInt(String(data.hastUtilToMdastTemporaryRowSpan), 10) || 1;
				if (colSpan > 1 || rowSpan > 1) {
					let otherRowIndex = rowIndex - 1;
					while (++otherRowIndex < rowIndex + rowSpan) {
						let colIndex = cellIndex - 1;
						while (++colIndex < cellIndex + colSpan) {
							if (!rows[otherRowIndex]) break;
							const newCells = [];
							if (otherRowIndex !== rowIndex || colIndex !== cellIndex) newCells.push({
								type: "tableCell",
								children: []
							});
							rows[otherRowIndex].children.splice(colIndex, 0, ...newCells);
						}
					}
				}
				if ("hastUtilToMdastTemporaryColSpan" in cell$1.data) delete cell$1.data.hastUtilToMdastTemporaryColSpan;
				if ("hastUtilToMdastTemporaryRowSpan" in cell$1.data) delete cell$1.data.hastUtilToMdastTemporaryRowSpan;
				if (Object.keys(cell$1.data).length === 0) delete cell$1.data;
			}
		}
		if (cells.length > columns) columns = cells.length;
	}
	rowIndex = -1;
	while (++rowIndex < rows.length) {
		const cells = rows[rowIndex].children;
		let cellIndex = cells.length - 1;
		while (++cellIndex < columns) cells.push({
			type: "tableCell",
			children: []
		});
	}
	let alignIndex = align.length - 1;
	while (++alignIndex < columns) align.push(null);
	state.inTable = false;
	const result = {
		type: "table",
		align,
		children: rows
	};
	state.patch(node, result);
	return result;
}
function inspect(node) {
	const info = {
		align: [null],
		headless: true
	};
	let rowIndex = 0;
	let cellIndex = 0;
	require_lib.visit(node, function(child) {
		if (child.type === "element") {
			if (child.tagName === "table" && node !== child) return require_lib.SKIP;
			if ((child.tagName === "th" || child.tagName === "td") && child.properties) {
				if (!info.align[cellIndex]) {
					const value = String(child.properties.align || "") || null;
					if (value === "center" || value === "left" || value === "right" || value === null) info.align[cellIndex] = value;
				}
				if (info.headless && rowIndex < 2 && child.tagName === "th") info.headless = false;
				cellIndex++;
			} else if (child.tagName === "thead") info.headless = false;
			else if (child.tagName === "tr") {
				rowIndex++;
				cellIndex = 0;
			}
		}
	});
	return info;
}
function createCell() {
	return {
		type: "tableCell",
		children: []
	};
}
function createRow() {
	return {
		type: "tableRow",
		children: []
	};
}
function text(state, node) {
	const result = {
		type: "text",
		value: node.value
	};
	state.patch(node, result);
	return result;
}
function textarea(state, node) {
	const result = {
		type: "text",
		value: toText(node)
	};
	state.patch(node, result);
	return result;
}
function wbr(state, node) {
	const result = {
		type: "text",
		value: "​"
	};
	state.patch(node, result);
	return result;
}
const nodeHandlers = {
	comment,
	doctype: ignore,
	root,
	text
};
const handlers = {
	applet: ignore,
	area: ignore,
	basefont: ignore,
	bgsound: ignore,
	caption: ignore,
	col: ignore,
	colgroup: ignore,
	command: ignore,
	content: ignore,
	datalist: ignore,
	dialog: ignore,
	element: ignore,
	embed: ignore,
	frame: ignore,
	frameset: ignore,
	isindex: ignore,
	keygen: ignore,
	link: ignore,
	math: ignore,
	menu: ignore,
	menuitem: ignore,
	meta: ignore,
	nextid: ignore,
	noembed: ignore,
	noframes: ignore,
	optgroup: ignore,
	option: ignore,
	param: ignore,
	script: ignore,
	shadow: ignore,
	source: ignore,
	spacer: ignore,
	style: ignore,
	svg: ignore,
	template: ignore,
	title: ignore,
	track: ignore,
	abbr: all$1,
	acronym: all$1,
	bdi: all$1,
	bdo: all$1,
	big: all$1,
	blink: all$1,
	button: all$1,
	canvas: all$1,
	cite: all$1,
	data: all$1,
	details: all$1,
	dfn: all$1,
	font: all$1,
	ins: all$1,
	label: all$1,
	map: all$1,
	marquee: all$1,
	meter: all$1,
	nobr: all$1,
	noscript: all$1,
	object: all$1,
	output: all$1,
	progress: all$1,
	rb: all$1,
	rbc: all$1,
	rp: all$1,
	rt: all$1,
	rtc: all$1,
	ruby: all$1,
	slot: all$1,
	small: all$1,
	span: all$1,
	sup: all$1,
	sub: all$1,
	tbody: all$1,
	tfoot: all$1,
	thead: all$1,
	time: all$1,
	address: flow,
	article: flow,
	aside: flow,
	body: flow,
	center: flow,
	div: flow,
	fieldset: flow,
	figcaption: flow,
	figure: flow,
	form: flow,
	footer: flow,
	header: flow,
	hgroup: flow,
	html: flow,
	legend: flow,
	main: flow,
	multicol: flow,
	nav: flow,
	picture: flow,
	section: flow,
	a,
	audio: media,
	b: strong,
	base,
	blockquote,
	br,
	code: inlineCode,
	dir: list,
	dl,
	dt: li,
	dd: li,
	del,
	em,
	h1: heading,
	h2: heading,
	h3: heading,
	h4: heading,
	h5: heading,
	h6: heading,
	hr,
	i: em,
	iframe,
	img,
	image: img,
	input,
	kbd: inlineCode,
	li,
	listing: code,
	mark: em,
	ol: list,
	p,
	plaintext: code,
	pre: code,
	q,
	s: del,
	samp: inlineCode,
	select,
	strike: del,
	strong,
	summary: p,
	table,
	td: tableCell,
	textarea,
	th: tableCell,
	tr: tableRow,
	tt: inlineCode,
	u: em,
	ul: list,
	var: inlineCode,
	video: media,
	wbr,
	xmp: code
};
function all$1(state, node) {
	return state.all(node);
}
function flow(state, node) {
	return state.toFlow(state.all(node));
}
function ignore() {}
var own = {}.hasOwnProperty;
function createState(options) {
	return {
		all,
		baseFound: false,
		elementById: /* @__PURE__ */ new Map(),
		frozenBaseUrl: void 0,
		handlers: {
			...handlers,
			...options.handlers
		},
		inTable: false,
		nodeHandlers: {
			...nodeHandlers,
			...options.nodeHandlers
		},
		one,
		options,
		patch,
		qNesting: 0,
		resolve,
		toFlow,
		toSpecificContent
	};
}
function all(parent) {
	const children = parent.children || [];
	const results = [];
	let index = -1;
	while (++index < children.length) {
		const child = children[index];
		const result = this.one(child, parent);
		if (Array.isArray(result)) results.push(...result);
		else if (result) results.push(result);
	}
	return results;
}
function one(node, parent) {
	if (node.type === "element") {
		if (node.properties && node.properties.dataMdast === "ignore") return;
		if (own.call(this.handlers, node.tagName)) return this.handlers[node.tagName](this, node, parent) || void 0;
	} else if (own.call(this.nodeHandlers, node.type)) return this.nodeHandlers[node.type](this, node, parent) || void 0;
	if ("value" in node && typeof node.value === "string") {
		const result = {
			type: "text",
			value: node.value
		};
		this.patch(node, result);
		return result;
	}
	if ("children" in node) return this.all(node);
}
function patch(origin, node) {
	if (origin.position) node.position = position(origin);
}
function resolve(url) {
	const base$1 = this.frozenBaseUrl;
	if (url === null || url === void 0) return "";
	if (base$1) return String(new URL(url, base$1));
	return url;
}
function toFlow(nodes) {
	return wrap(nodes);
}
function toSpecificContent(nodes, build) {
	const reference = build();
	const results = [];
	let queue = [];
	let index = -1;
	while (++index < nodes.length) {
		const node = nodes[index];
		if (expectedParent(node)) {
			if (queue.length > 0) {
				node.children.unshift(...queue);
				queue = [];
			}
			results.push(node);
		} else {
			const child = node;
			queue.push(child);
		}
	}
	if (queue.length > 0) {
		let node = results[results.length - 1];
		if (!node) {
			node = build();
			results.push(node);
		}
		node.children.push(...queue);
		queue = [];
	}
	return results;
	function expectedParent(node) {
		return node.type === reference.type;
	}
}
var emptyOptions = {};
function toMdast(tree, options) {
	const cleanTree = esm_default(tree);
	const settings = options || emptyOptions;
	const transformWhitespace = rehypeMinifyWhitespace({ newlines: settings.newlines === true });
	const state = createState(settings);
	let mdast;
	transformWhitespace(cleanTree);
	require_lib.visit(cleanTree, function(node) {
		if (node && node.type === "element" && node.properties) {
			const id = String(node.properties.id || "") || void 0;
			if (id && !state.elementById.has(id)) state.elementById.set(id, node);
		}
	});
	const result = state.one(cleanTree, void 0);
	if (!result) mdast = {
		type: "root",
		children: []
	};
	else if (Array.isArray(result)) mdast = {
		type: "root",
		children: result
	};
	else mdast = result;
	require_lib.visit(mdast, function(node, index, parent) {
		if (node.type === "text" && index !== void 0 && parent) {
			const previous = parent.children[index - 1];
			if (previous && previous.type === node.type) {
				previous.value += node.value;
				parent.children.splice(index, 1);
				if (previous.position && node.position) previous.position.end = node.position.end;
				return index - 1;
			}
			node.value = node.value.replace(/[\t ]*(\r?\n|\r)[\t ]*/, "$1");
			if (parent && (parent.type === "heading" || parent.type === "paragraph" || parent.type === "root")) {
				if (!index) node.value = node.value.replace(/^[\t ]+/, "");
				if (index === parent.children.length - 1) node.value = node.value.replace(/[\t ]+$/, "");
			}
			if (!node.value) {
				parent.children.splice(index, 1);
				return index;
			}
		}
	});
	return mdast;
}
var defaults = { document: true };
function rehypeRemark(destination, options) {
	if (destination && "run" in destination) return async function(tree, file) {
		const mdastTree = toMdast(tree, {
			...defaults,
			...options
		});
		await destination.run(mdastTree, file);
	};
	return function(tree) {
		return toMdast(tree, {
			...defaults,
			...destination
		});
	};
}
exports.default = rehypeRemark;
