import { getAttributesFromExtensions as e, getExtensionField as t, getSchemaByResolvedExtensions as n, mergeAttributes as r, resolveExtensions as i, splitExtensions as a } from "@tiptap/core";
import { Node as o } from "@tiptap/pm/model";
//#region ../../node_modules/.pnpm/@tiptap+static-renderer@3.19.0_@tiptap+core@3.19.0_@tiptap+pm@3.19.0__@tiptap+pm@3.19.0_react_4n7lapq7bmfej5hsrzhdkukr6e/node_modules/@tiptap/static-renderer/dist/pm/markdown/index.js
function s(e, t, n) {
	let i = e.attrs;
	return i ? t.filter((t) => t.type === (typeof e.type == "string" ? e.type : e.type.name) ? n ? t.attribute.rendered : !0 : !1).map((e) => e.attribute.renderHTML && e.attribute.renderHTML(i) || { [e.name]: e.name in i ? i[e.name] : e.attribute.default }).reduce((e, t) => r(e, t), {}) : {};
}
function c(e, t) {
	return s(e, t, !0);
}
function l(e, n, r, i) {
	let a = t(n, "renderHTML", {
		name: n.name,
		options: n.options,
		storage: n.storage,
		parent: n.parent
	});
	return a ? [n.name, ({ node: t, children: i }) => {
		try {
			return e(a({
				node: t,
				HTMLAttributes: c(t, r)
			}))(i);
		} catch (e) {
			throw Error(`[tiptap error]: Node ${n.name} cannot be rendered, it's "renderToHTML" method threw an error: ${e.message}`, { cause: e });
		}
	}] : i?.unhandledNode ? [n.name, i.unhandledNode] : [n.name, () => {
		throw Error(`[tiptap error]: Node ${n.name} cannot be rendered, it is missing a "renderToHTML" method, please implement it or override the corresponding "nodeMapping" method to have a custom rendering`);
	}];
}
function u(e, n, r, i) {
	let a = t(n, "renderHTML", {
		name: n.name,
		options: n.options,
		storage: n.storage,
		parent: n.parent
	});
	return a ? [n.name, ({ mark: t, children: i }) => {
		try {
			return e(a({
				mark: t,
				HTMLAttributes: c(t, r)
			}))(i);
		} catch (e) {
			throw Error(`[tiptap error]: Mark ${n.name} cannot be rendered, it's "renderToHTML" method threw an error: ${e.message}`, { cause: e });
		}
	}] : i?.unhandledMark ? [n.name, i.unhandledMark] : [n.name, () => {
		throw Error(`Node ${n.name} cannot be rendered, it is missing a "renderToHTML" method`);
	}];
}
function d({ renderer: t, domOutputSpecToElement: r, mapDefinedTypes: s, content: c, extensions: d, options: f }) {
	d = i(d);
	let p = e(d), { nodeExtensions: m, markExtensions: h } = a(d);
	return c instanceof o || (c = o.fromJSON(n(d), c)), t({
		...f,
		nodeMapping: {
			...Object.fromEntries(m.filter((e) => e.name in s ? !1 : f?.nodeMapping ? !(e.name in f.nodeMapping) : !0).map((e) => l(r, e, p, f))),
			...s,
			...f?.nodeMapping
		},
		markMapping: {
			...Object.fromEntries(h.filter((e) => f?.markMapping ? !(e.name in f.markMapping) : !0).map((e) => u(r, e, p, f))),
			...f?.markMapping
		}
	})({ content: c });
}
function f(e, { nodeMapping: t, markMapping: n, unhandledNode: r, unhandledMark: i }) {
	return function a({ content: o, parent: s }) {
		let c = typeof o.type == "string" ? o.type : o.type.name, l = t[c] ?? r;
		if (!l) throw Error(`missing handler for node type ${c}`);
		let u = e({
			component: l,
			props: {
				node: o,
				parent: s,
				renderElement: a,
				get children() {
					let e = [];
					return o.content && o.content.forEach((t) => {
						e.push(a({
							content: t,
							parent: o
						}));
					}), e;
				}
			}
		});
		return o.marks ? o.marks.reduce((t, r) => {
			let a = typeof r.type == "string" ? r.type : r.type.name, c = n[a] ?? i;
			if (!c) throw Error(`missing handler for mark type ${a}`);
			return e({
				component: c,
				props: {
					mark: r,
					parent: s,
					node: o,
					children: t
				}
			});
		}, u) : u;
	};
}
function p(e) {
	return f((e) => e.component(e.props), e);
}
function m(e) {
	let t = Object.entries(e || {}).map(([e, t]) => `${e.split(" ").at(-1)}=${JSON.stringify(t)}`).join(" ");
	return t ? ` ${t}` : "";
}
function h(e) {
	return [].concat(e || "").filter(Boolean).join("");
}
var g = /* @__PURE__ */ new Set([
	"iframe",
	"script",
	"style",
	"title",
	"textarea",
	"div",
	"span",
	"a",
	"button"
]);
function _(e) {
	if (typeof e == "string") return () => e;
	if (typeof e == "object" && "length" in e) {
		let [t, n, r, ...i] = e, a = t, o = a.split(" ");
		if (o.length > 1 && (a = `${o[1]} xmlns="${o[0]}"`), n === void 0) return () => `<${a}/>`;
		if (n === 0) return (e) => `<${a}>${h(e)}</${a}>`;
		if (typeof n == "object") return Array.isArray(n) ? r === void 0 || r === 0 ? (e) => `<${a}>${_(n)(e)}</${a}>` : (e) => `<${a}>${_(n)(e)}${[r].concat(i).map((t) => _(t)(e))}</${a}>` : r === void 0 ? g.has(a) ? () => `<${a}${m(n)}></${a}>` : () => `<${a}${m(n)}/>` : r === 0 ? (e) => `<${a}${m(n)}>${h(e)}</${a}>` : (e) => `<${a}${m(n)}>${[r].concat(i).map((t) => _(t)(e)).join("")}</${a}>`;
	}
	throw Error("[tiptap error]: Unsupported DomOutputSpec type, check the `renderHTML` method output or implement a node mapping", { cause: e });
}
function v({ content: e, extensions: t, options: n }) {
	return d({
		renderer: p,
		domOutputSpecToElement: _,
		mapDefinedTypes: {
			doc: ({ children: e }) => h(e),
			text: ({ node: e }) => e.text ?? ""
		},
		content: e,
		extensions: t,
		options: n
	});
}
function y({ content: e, extensions: t, options: n }) {
	return v({
		content: e,
		extensions: t,
		options: {
			...n,
			nodeMapping: {
				bulletList({ children: e }) {
					return `
${h(e)}`;
				},
				orderedList({ children: e }) {
					return `
${h(e)}`;
				},
				listItem({ node: e, children: t, parent: n }) {
					if (n?.type.name === "bulletList") return `- ${h(t).trim()}
`;
					if (n?.type.name === "orderedList") {
						let r = n.attrs.start || 1;
						return n.forEach((t, n, i) => {
							e === t && (r = i + 1);
						}), `${r}. ${h(t).trim()}
`;
					}
					return h(t);
				},
				paragraph({ children: e }) {
					return `
${h(e)}
`;
				},
				heading({ node: e, children: t }) {
					let n = e.attrs.level;
					return `${Array(n).fill("#").join("")} ${t}
`;
				},
				codeBlock({ node: e, children: t }) {
					return `
\`\`\`${e.attrs.language}
${h(t)}
\`\`\`
`;
				},
				blockquote({ children: e }) {
					return `
${h(e).trim().split("\n").map((e) => `> ${e}`).join("\n")}`;
				},
				image({ node: e }) {
					return `![${e.attrs.alt}](${e.attrs.src})`;
				},
				hardBreak() {
					return "\n";
				},
				horizontalRule() {
					return "\n---\n";
				},
				table({ children: e, node: t }) {
					if (!Array.isArray(e)) return `
${h(e)}
`;
					let n = t.children[0].childCount;
					return `
${h(e[0])}| ${Array(n).fill("---").join(" | ")} |
${h(e.slice(1))}
`;
				},
				tableRow({ children: e }) {
					return Array.isArray(e) ? `| ${e.join(" | ")} |
` : `${h(e)}
`;
				},
				tableHeader({ children: e }) {
					return h(e).trim();
				},
				tableCell({ children: e }) {
					return h(e).trim();
				},
				...n?.nodeMapping
			},
			markMapping: {
				bold({ children: e }) {
					return `**${h(e)}**`;
				},
				italic({ children: e, node: t }) {
					let n = !1;
					return t?.marks.some((e) => e.type.name === "bold") && (n = !0), n ? `*${h(e)}*` : `_${h(e)}_`;
				},
				code({ children: e }) {
					return `\`${h(e)}\``;
				},
				strike({ children: e }) {
					return `~~${h(e)}~~`;
				},
				underline({ children: e }) {
					return `<u>${h(e)}</u>`;
				},
				subscript({ children: e }) {
					return `<sub>${h(e)}</sub>`;
				},
				superscript({ children: e }) {
					return `<sup>${h(e)}</sup>`;
				},
				link({ mark: e, children: t }) {
					return `[${h(t)}](${e.attrs.href})`;
				},
				highlight({ children: e }) {
					return `==${h(e)}==`;
				},
				...n?.markMapping
			}
		}
	});
}
//#endregion
//#region components/rich_text_editor/markdownRenderer.js
var b = (e) => Array.isArray(e) ? e.join("") : e || "", x = (e, t, n) => {
	let r = e.trim();
	return r ? `${e.slice(0, e.length - e.trimStart().length)}${t}${r}${n}${e.slice(e.trimEnd().length)}` : e;
};
function S(e, t) {
	return y({
		extensions: t,
		content: e,
		options: {
			nodeMapping: {
				blockquote({ children: e }) {
					return b(e).trim().split("\n").map((e) => e ? `> ${e}` : ">").join("\n") + "\n";
				},
				codeBlock({ node: e, children: t }) {
					return `\`\`\`${e.attrs?.language || ""}\n${b(t)}\n\`\`\`\n`;
				},
				mention({ node: e }) {
					return `<!-- @mention: {"id": "${e.attrs?.id || ""}", "contactKey": "${e.attrs?.contactKey || ""}", "name": "${e.attrs?.name || ""}"} -->`;
				},
				channel({ node: e }) {
					return `<!-- @channel: {"id": "${e.attrs?.id || ""}", "channelKey": "${e.attrs?.channelKey || ""}", "name": "${e.attrs?.name || ""}", "locked": "${String(e.attrs?.locked ?? "")}"} -->`;
				},
				"slash-commands"({ node: e }) {
					return `/${e.attrs?.command || ""}`;
				},
				emoji({ node: e }) {
					return e.attrs?.code || "";
				},
				variable({ node: e }) {
					return `{{${e.attrs?.id || ""}=${e.attrs?.altText || ""}}}`;
				}
			},
			markMapping: {
				bold({ children: e }) {
					return x(b(e), "**", "**");
				},
				italic({ children: e }) {
					return x(b(e), "*", "*");
				},
				strike({ children: e }) {
					return x(b(e), "~~", "~~");
				},
				code({ children: e }) {
					return x(b(e), "`", "`");
				},
				link({ mark: e, children: t }) {
					let n = b(t), r = e.attrs?.href || "", i = n.trim();
					return `${n.slice(0, n.length - n.trimStart().length)}[${i}](${r})${n.slice(n.trimEnd().length)}`;
				},
				underline({ children: e }) {
					return b(e);
				}
			}
		}
	}).replace(/\n{3,}/g, "\n\n").replace(/^\n+|\n+$/g, "");
}
//#endregion
export { S as t };

//# sourceMappingURL=markdownRenderer-D_P94RyM.js.map