import { find as e } from "../../property-information/lib/find.js";
import { html as t, svg as n } from "../../property-information/index.js";
import { stringify as r } from "../../comma-separated-tokens/index.js";
import { stringify as i } from "../../space-separated-tokens/index.js";
import { webNamespaces as a } from "../../web-namespaces/index.js";
import "../../devlop/lib/default.js";
import { zwitch as o } from "../../zwitch/index.js";
//#region ../../node_modules/hast-util-to-parse5/lib/index.js
var s = {}, c = {}.hasOwnProperty, l = o("type", { handlers: {
	root: d,
	element: g,
	text: m,
	comment: h,
	doctype: p
} });
function u(e, r) {
	let i = (r || s).space;
	return l(e, i === "svg" ? n : t);
}
function d(e, t) {
	let n = {
		nodeName: "#document",
		mode: (e.data || {}).quirksMode ? "quirks" : "no-quirks",
		childNodes: []
	};
	return n.childNodes = v(e.children, n, t), y(e, n), n;
}
function f(e, t) {
	let n = {
		nodeName: "#document-fragment",
		childNodes: []
	};
	return n.childNodes = v(e.children, n, t), y(e, n), n;
}
function p(e) {
	let t = {
		nodeName: "#documentType",
		name: "html",
		publicId: "",
		systemId: "",
		parentNode: null
	};
	return y(e, t), t;
}
function m(e) {
	let t = {
		nodeName: "#text",
		value: e.value,
		parentNode: null
	};
	return y(e, t), t;
}
function h(e) {
	let t = {
		nodeName: "#comment",
		data: e.value,
		parentNode: null
	};
	return y(e, t), t;
}
function g(e, t) {
	let r = t, i = r;
	e.type === "element" && e.tagName.toLowerCase() === "svg" && r.space === "html" && (i = n);
	let o = [], s;
	if (e.properties) {
		for (s in e.properties) if (s !== "children" && c.call(e.properties, s)) {
			let t = _(i, s, e.properties[s]);
			t && o.push(t);
		}
	}
	let l = i.space, u = {
		nodeName: e.tagName,
		tagName: e.tagName,
		attrs: o,
		namespaceURI: a[l],
		childNodes: [],
		parentNode: null
	};
	return u.childNodes = v(e.children, u, i), y(e, u), e.tagName === "template" && e.content && (u.content = f(e.content, i)), u;
}
function _(t, n, o) {
	let s = e(t, n);
	if (o === !1 || o == null || typeof o == "number" && Number.isNaN(o) || !o && s.boolean) return;
	Array.isArray(o) && (o = s.commaSeparated ? r(o) : i(o));
	let c = {
		name: s.attribute,
		value: o === !0 ? "" : String(o)
	};
	if (s.space && s.space !== "html" && s.space !== "svg") {
		let e = c.name.indexOf(":");
		e < 0 ? c.prefix = "" : (c.name = c.name.slice(e + 1), c.prefix = s.attribute.slice(0, e)), c.namespace = a[s.space];
	}
	return c;
}
function v(e, t, n) {
	let r = -1, i = [];
	if (e) for (; ++r < e.length;) {
		let a = l(e[r], n);
		a.parentNode = t, i.push(a);
	}
	return i;
}
function y(e, t) {
	let n = e.position;
	n && n.start && n.end && (n.start.offset, n.end.offset, t.sourceCodeLocation = {
		startLine: n.start.line,
		startCol: n.start.column,
		startOffset: n.start.offset,
		endLine: n.end.line,
		endCol: n.end.column,
		endOffset: n.end.offset
	});
}
//#endregion
export { u as toParse5 };
