import { find as e } from "../../property-information/lib/find.js";
import { html as t, svg as n } from "../../property-information/index.js";
import { h as r, s as i } from "../../hastscript/lib/index.js";
import { webNamespaces as a } from "../../web-namespaces/index.js";
import "../../devlop/lib/default.js";
import { location as o } from "../../vfile-location/lib/index.js";
//#region ../../node_modules/hast-util-from-parse5/lib/index.js
var s = {}.hasOwnProperty, c = Object.prototype;
function l(e, r) {
	let i = r || {};
	return u({
		file: i.file || void 0,
		location: !1,
		schema: i.space === "svg" ? n : t,
		verbose: i.verbose || !1
	}, e);
}
function u(e, t) {
	let n;
	switch (t.nodeName) {
		case "#comment": {
			let r = t;
			return n = {
				type: "comment",
				value: r.data
			}, p(e, r, n), n;
		}
		case "#document":
		case "#document-fragment": {
			let r = t, i = "mode" in r ? r.mode === "quirks" || r.mode === "limited-quirks" : !1;
			if (n = {
				type: "root",
				children: d(e, t.childNodes),
				data: { quirksMode: i }
			}, e.file && e.location) {
				let t = String(e.file), r = o(t), i = r.toPoint(0), a = r.toPoint(t.length);
				n.position = {
					start: i,
					end: a
				};
			}
			return n;
		}
		case "#documentType": {
			let r = t;
			return n = { type: "doctype" }, p(e, r, n), n;
		}
		case "#text": {
			let r = t;
			return n = {
				type: "text",
				value: r.value
			}, p(e, r, n), n;
		}
		default: return n = f(e, t), n;
	}
}
function d(e, t) {
	let n = -1, r = [];
	for (; ++n < t.length;) {
		let i = u(e, t[n]);
		r.push(i);
	}
	return r;
}
function f(e, o) {
	let l = e.schema;
	e.schema = o.namespaceURI === a.svg ? n : t;
	let f = -1, m = {};
	for (; ++f < o.attrs.length;) {
		let e = o.attrs[f], t = (e.prefix ? e.prefix + ":" : "") + e.name;
		s.call(c, t) || (m[t] = e.value);
	}
	let g = (e.schema.space === "svg" ? i : r)(o.tagName, m, d(e, o.childNodes));
	if (p(e, o, g), g.tagName === "template") {
		let t = o, n = t.sourceCodeLocation, r = n && n.startTag && h(n.startTag), i = n && n.endTag && h(n.endTag), a = u(e, t.content);
		r && i && e.file && (a.position = {
			start: r.end,
			end: i.start
		}), g.content = a;
	}
	return e.schema = l, g;
}
function p(e, t, n) {
	if ("sourceCodeLocation" in t && t.sourceCodeLocation && e.file) {
		let r = m(e, n, t.sourceCodeLocation);
		r && (e.location = !0, n.position = r);
	}
}
function m(t, n, r) {
	let i = h(r);
	if (n.type === "element") {
		let a = n.children[n.children.length - 1];
		if (i && !r.endTag && a && a.position && a.position.end && (i.end = Object.assign({}, a.position.end)), t.verbose) {
			let i = {}, a;
			if (r.attrs) for (a in r.attrs) s.call(r.attrs, a) && (i[e(t.schema, a).property] = h(r.attrs[a]));
			r.startTag;
			let o = h(r.startTag), c = r.endTag ? h(r.endTag) : void 0, l = { opening: o };
			c && (l.closing = c), l.properties = i, n.data = { position: l };
		}
	}
	return i;
}
function h(e) {
	let t = g({
		line: e.startLine,
		column: e.startCol,
		offset: e.startOffset
	}), n = g({
		line: e.endLine,
		column: e.endCol,
		offset: e.endOffset
	});
	return t || n ? {
		start: t,
		end: n
	} : void 0;
}
function g(e) {
	return e.line && e.column ? e : void 0;
}
//#endregion
export { l as fromParse5 };
