import { stringify as e } from "../../../comma-separated-tokens/index.js";
import { find as t } from "../../../property-information/lib/find.js";
import { svg as n } from "../../../property-information/index.js";
import { stringify as r } from "../../../space-separated-tokens/index.js";
import { stringifyEntities as i } from "../../../stringify-entities/lib/index.js";
import { ccount as a } from "../../../ccount/index.js";
import { closing as o } from "../omission/closing.js";
import { opening as s } from "../omission/opening.js";
//#region ../../node_modules/hast-util-to-html/lib/handle/element.js
var c = {
	name: [["	\n\f\r &/=>".split(""), "	\n\f\r \"&'/=>`".split("")], ["\0	\n\f\r \"&'/<=>".split(""), "\0	\n\f\r \"&'/<=>`".split("")]],
	unquoted: [["	\n\f\r &>".split(""), "\0	\n\f\r \"&'<=>`".split("")], ["\0	\n\f\r \"&'<=>`".split(""), "\0	\n\f\r \"&'<=>`".split("")]],
	single: [["&'".split(""), "\"&'`".split("")], ["\0&'".split(""), "\0\"&'`".split("")]],
	double: [["\"&".split(""), "\"&'`".split("")], ["\0\"&".split(""), "\0\"&'`".split("")]]
};
function l(e, t, r, i) {
	let a = i.schema, c = a.space === "svg" ? !1 : i.settings.omitOptionalTags, l = a.space === "svg" ? i.settings.closeEmptyElements : i.settings.voids.includes(e.tagName.toLowerCase()), d = [], f;
	a.space === "html" && e.tagName === "svg" && (i.schema = n);
	let p = u(i, e.properties), m = i.all(a.space === "html" && e.tagName === "template" ? e.content : e);
	return i.schema = a, m && (l = !1), (p || !c || !s(e, t, r)) && (d.push("<", e.tagName, p ? " " + p : ""), l && (a.space === "svg" || i.settings.closeSelfClosing) && (f = p.charAt(p.length - 1), (!i.settings.tightSelfClosing || f === "/" || f && f !== "\"" && f !== "'") && d.push(" "), d.push("/")), d.push(">")), d.push(m), !l && (!c || !o(e, t, r)) && d.push("</" + e.tagName + ">"), d.join("");
}
function u(e, t) {
	let n = [], r = -1, i;
	if (t) {
		for (i in t) if (t[i] !== null && t[i] !== void 0) {
			let r = d(e, i, t[i]);
			r && n.push(r);
		}
	}
	for (; ++r < n.length;) {
		let t = e.settings.tightAttributes ? n[r].charAt(n[r].length - 1) : void 0;
		r !== n.length - 1 && t !== "\"" && t !== "'" && (n[r] += " ");
	}
	return n.join("");
}
function d(n, o, s) {
	let l = t(n.schema, o), u = n.settings.allowParseErrors && n.schema.space === "html" ? 0 : 1, d = +!n.settings.allowDangerousCharacters, f = n.quote, p;
	if (l.overloadedBoolean && (s === l.attribute || s === "") ? s = !0 : (l.boolean || l.overloadedBoolean) && (typeof s != "string" || s === l.attribute || s === "") && (s = !!s), s == null || s === !1 || typeof s == "number" && Number.isNaN(s)) return "";
	let m = i(l.attribute, Object.assign({}, n.settings.characterReferences, { subset: c.name[u][d] }));
	return s === !0 || (s = Array.isArray(s) ? (l.commaSeparated ? e : r)(s, { padLeft: !n.settings.tightCommaSeparatedLists }) : String(s), n.settings.collapseEmptyAttributes && !s) ? m : (n.settings.preferUnquoted && (p = i(s, Object.assign({}, n.settings.characterReferences, {
		attribute: !0,
		subset: c.unquoted[u][d]
	}))), p !== s && (n.settings.quoteSmart && a(s, f) > a(s, n.alternative) && (f = n.alternative), p = f + i(s, Object.assign({}, n.settings.characterReferences, {
		subset: (f === "'" ? c.single : c.double)[u][d],
		attribute: !0
	})) + f), m + (p && "=" + p));
}
//#endregion
export { l as element };

//# sourceMappingURL=element.js.map