import { A as e, B as t, E as n, M as r, S as i, X as a, a as o, at as s, b as c, c as l, d as u, f as d, h as f, l as p, m, n as h, ot as g, p as _, rt as v, s as y, st as b, z as x } from "./vue.runtime.esm-bundler-Bxqkjqhc.js";
import { C as S, D as C, n as w, w as T } from "./dist-DJmnUmW9.js";
import { t as E } from "./useI18n-CWX9ZTCW.js";
import { t as D } from "./useMergeTag-B3F9VR04.js";
import { F as O, Gt as k, _n as A, bn as j, i as M, o as N, p as P, u as F, vn as ee, xn as I } from "./dist-CQQS9SRN.js";
import { n as L, t as R } from "./dist-U5guDm2w.js";
//#region src/extensions/FontSize.ts
var te = M.create({
	name: "fontSize",
	addOptions() {
		return { types: ["textStyle"] };
	},
	addGlobalAttributes() {
		return [{
			types: this.options.types,
			attributes: { fontSize: {
				default: null,
				parseHTML: (e) => e.style.fontSize?.replace(/['"]+/g, "") || null,
				renderHTML: (e) => e.fontSize ? { style: `font-size: ${e.fontSize}` } : {}
			} }
		}];
	},
	addCommands() {
		return {
			setFontSize: (e) => ({ chain: t }) => t().setMark("textStyle", { fontSize: e }).run(),
			unsetFontSize: () => ({ chain: e }) => e().setMark("textStyle", { fontSize: null }).removeEmptyTextStyle().run()
		};
	}
}), ne = M.create({
	name: "letterSpacing",
	addOptions() {
		return { types: ["textStyle"] };
	},
	addGlobalAttributes() {
		return [{
			types: this.options.types,
			attributes: { letterSpacing: {
				default: null,
				parseHTML: (e) => e.style.letterSpacing?.replace(/['"]+/g, "") || null,
				renderHTML: (e) => e.letterSpacing ? { style: `letter-spacing: ${e.letterSpacing}` } : {}
			} }
		}];
	},
	addCommands() {
		return {
			setLetterSpacing: (e) => ({ chain: t }) => t().setMark("textStyle", { letterSpacing: e }).run(),
			unsetLetterSpacing: () => ({ chain: e }) => e().setMark("textStyle", { letterSpacing: null }).removeEmptyTextStyle().run()
		};
	}
}), re = M.create({
	name: "lineHeight",
	addOptions() {
		return {
			types: ["paragraph"],
			defaultLineHeight: "1.5"
		};
	},
	addGlobalAttributes() {
		return [{
			types: this.options.types,
			attributes: { lineHeight: {
				default: null,
				parseHTML: (e) => e.style.lineHeight || null,
				renderHTML: (e) => e.lineHeight ? { style: `line-height: ${e.lineHeight}` } : {}
			} }
		}];
	},
	addCommands() {
		return {
			setLineHeight: (e) => ({ commands: t }) => this.options.types.every((n) => t.updateAttributes(n, { lineHeight: e })),
			unsetLineHeight: () => ({ commands: e }) => this.options.types.every((t) => e.resetAttributes(t, "lineHeight"))
		};
	}
}), z = [
	"aria-label",
	"data-tooltip",
	"onKeydown"
], B = ["aria-label", "onKeydown"], V = ["aria-label"], H = /* @__PURE__ */ c({
	__name: "LogicMergeTagNodeView",
	props: {
		node: {},
		editor: {},
		getPos: { type: Function },
		deleteNode: { type: Function },
		updateAttributes: { type: Function }
	},
	setup(r) {
		let i = r, { syntax: c } = D(), { t: p } = E(), h = u(() => C(i.node.attrs.value, c)), w = u(() => S(i.node.attrs.value, c)), T = a(!1), O = a(""), k = a(null), A = !1;
		function j() {
			O.value = i.node.attrs.value, A = !1, T.value = !0, n(() => {
				k.value?.focus(), k.value?.select();
			});
		}
		function M() {
			if (A) return;
			A = !0;
			let e = O.value.trim();
			if (!e) {
				T.value = !1;
				return;
			}
			e !== i.node.attrs.value && i.updateAttributes({
				value: e,
				keyword: C(e, c) ? S(e, c) : ""
			}), T.value = !1;
		}
		function N(e) {
			e.key === "Enter" ? (e.preventDefault(), M()) : e.key === "Escape" && (T.value = !1);
		}
		return (n, i) => (e(), _(v(R), {
			as: "span",
			class: s(h.value ? "tpl-logic-merge-tag-node tpl:group tpl:mx-0.5 tpl:inline-flex tpl:items-center tpl:gap-1 tpl:rounded tpl:px-1.5 tpl:py-0.5 tpl:text-[0.8em] tpl:font-bold tpl:tracking-wide tpl:uppercase tpl:select-none" : ""),
			style: g(h.value ? "background-color: transparent; border: 1.5px solid color-mix(in srgb, var(--tpl-primary) 50%, transparent); color: var(--tpl-primary);" : ""),
			contenteditable: "false"
		}, {
			default: x(() => [T.value ? t((e(), f("input", {
				key: 0,
				ref_key: "inputRef",
				ref: k,
				"onUpdate:modelValue": i[0] ||= (e) => O.value = e,
				type: "text",
				class: "tpl:w-40 tpl:rounded tpl:border-none tpl:bg-transparent tpl:px-0.5 tpl:py-0 tpl:text-[1em] tpl:font-medium tpl:normal-case tpl:outline-none tpl:text-[var(--tpl-primary)]",
				onBlur: M,
				onKeydown: N
			}, null, 544)), [[o, O.value]]) : h.value ? (e(), f("span", {
				key: 1,
				role: "button",
				tabindex: "0",
				"aria-label": v(p).mergeTag.editValue,
				class: "tpl-tooltip tpl:cursor-pointer",
				"data-tooltip": r.node.attrs.value,
				onClick: l(j, ["stop"]),
				onKeydown: [y(l(j, ["stop"]), ["enter"]), y(l(j, ["prevent", "stop"]), ["space"])]
			}, b(w.value), 41, z)) : (e(), f("span", {
				key: 2,
				role: "button",
				tabindex: "0",
				"aria-label": v(p).mergeTag.editValue,
				onClick: l(j, ["stop"]),
				onKeydown: [y(l(j, ["stop"]), ["enter"]), y(l(j, ["prevent", "stop"]), ["space"])]
			}, b(r.node.attrs.value), 41, B)), h.value ? (e(), f("button", {
				key: 3,
				type: "button",
				"aria-label": v(p).mergeTag.deleteMergeTag,
				class: "tpl-merge-tag-delete tpl:flex tpl:size-5 tpl:cursor-pointer tpl:items-center tpl:justify-center tpl:rounded-full tpl:border-none tpl:bg-transparent tpl:p-0 tpl:opacity-60 tpl:transition-all hover:tpl:opacity-100 tpl:text-[var(--tpl-primary)]",
				contenteditable: "false",
				onClick: i[1] ||= l((...e) => r.deleteNode && r.deleteNode(...e), ["stop", "prevent"])
			}, [...i[2] ||= [d("svg", {
				width: "10",
				height: "10",
				viewBox: "0 0 24 24",
				fill: "none",
				stroke: "currentColor",
				"stroke-width": "3",
				"aria-hidden": "true"
			}, [d("line", {
				x1: "18",
				y1: "6",
				x2: "6",
				y2: "18"
			}), d("line", {
				x1: "6",
				y1: "6",
				x2: "18",
				y2: "18"
			})], -1)]], 8, V)) : m("", !0)]),
			_: 1
		}, 8, ["class", "style"]));
	}
});
//#endregion
//#region src/extensions/isNodeSelected.ts
function U(e, t) {
	let { $from: n, $to: r } = e.state.selection;
	return n.pos === r.pos ? n.pos > 0 && n.nodeBefore?.type.name === t || n.nodeAfter?.type.name === t : !1;
}
//#endregion
//#region src/extensions/renderVueNodeView.ts
function W(e) {
	return L(e);
}
//#endregion
//#region src/extensions/LogicMergeTagNode.ts
var G = F.create({
	name: "logicMergeTagNode",
	group: "inline",
	inline: !0,
	atom: !0,
	addOptions() {
		return { syntax: w.liquid };
	},
	addAttributes() {
		return {
			value: {
				default: "",
				parseHTML: (e) => e.getAttribute("data-logic-merge-tag") || ""
			},
			keyword: {
				default: "",
				parseHTML: (e) => e.getAttribute("data-keyword") || e.textContent || ""
			}
		};
	},
	parseHTML() {
		return [{ tag: "span[data-logic-merge-tag]" }];
	},
	renderHTML({ node: e, HTMLAttributes: t }) {
		if (!C(e.attrs.value, this.options.syntax)) return [
			"span",
			{},
			e.attrs.value
		];
		let n = S(e.attrs.value, this.options.syntax);
		return [
			"span",
			k(t, {
				"data-logic-merge-tag": e.attrs.value,
				"data-keyword": n
			}),
			n
		];
	},
	addNodeView() {
		return W(H);
	},
	addKeyboardShortcuts() {
		return {
			Backspace: () => U(this.editor, this.name),
			Delete: () => U(this.editor, this.name)
		};
	},
	addInputRules() {
		return [new N({
			find: RegExp(this.options.syntax.logic.source + "$", ""),
			handler: ({ state: e, range: t, match: n }) => {
				let r = n[0];
				if (!C(r, this.options.syntax)) return;
				let i = S(r, this.options.syntax), a = this.type.create({
					value: r,
					keyword: i
				});
				e.tr.replaceWith(t.from, t.to, a);
			}
		})];
	},
	addPasteRules() {
		return [new P({
			find: new RegExp(this.options.syntax.logic.source, "g"),
			handler: ({ state: e, range: t, match: n }) => {
				let r = n[0];
				if (!C(r, this.options.syntax)) return;
				let i = S(r, this.options.syntax), a = this.type.create({
					value: r,
					keyword: i
				});
				e.tr.replaceWith(t.from, t.to, a);
			}
		})];
	}
}), K = [
	"aria-label",
	"data-tooltip",
	"onKeydown"
], q = ["aria-label"], J = /* @__PURE__ */ c({
	__name: "MergeTagNodeView",
	props: {
		node: {},
		deleteNode: { type: Function },
		updateAttributes: { type: Function }
	},
	setup(r) {
		let i = r, { getMergeTagLabel: s } = D(), { t: c } = E(), p = u(() => s(i.node.attrs.value)), m = a(!1), h = a(""), g = a(null);
		function S() {
			h.value = i.node.attrs.value, m.value = !0, n(() => {
				g.value?.focus(), g.value?.select();
			});
		}
		function C() {
			let e = h.value.trim();
			e && e !== i.node.attrs.value && i.updateAttributes({
				value: e,
				label: s(e)
			}), m.value = !1;
		}
		function w(e) {
			e.key === "Enter" ? (e.preventDefault(), C()) : e.key === "Escape" && (m.value = !1);
		}
		return (n, i) => (e(), _(v(R), {
			as: "span",
			class: "tpl-merge-tag-node tpl:group tpl:mx-0.5 tpl:inline-flex tpl:items-center tpl:gap-1 tpl:rounded tpl:px-1.5 tpl:py-0.5 tpl:text-[0.9em] tpl:font-medium tpl:select-none tpl:text-[var(--tpl-primary)]",
			style: { "background-color": "color-mix(in srgb, var(--tpl-primary) 20%, transparent)" },
			contenteditable: "false"
		}, {
			default: x(() => [m.value ? t((e(), f("input", {
				key: 0,
				ref_key: "inputRef",
				ref: g,
				"onUpdate:modelValue": i[0] ||= (e) => h.value = e,
				type: "text",
				class: "tpl:w-32 tpl:rounded tpl:border-none tpl:bg-transparent tpl:px-0.5 tpl:py-0 tpl:text-[1em] tpl:font-medium tpl:outline-none tpl:text-[var(--tpl-primary)]",
				onBlur: C,
				onKeydown: w
			}, null, 544)), [[o, h.value]]) : (e(), f("span", {
				key: 1,
				role: "button",
				tabindex: "0",
				"aria-label": v(c).mergeTag.editValue,
				class: "tpl-tooltip tpl:cursor-pointer",
				"data-tooltip": r.node.attrs.value,
				onClick: l(S, ["stop"]),
				onKeydown: [y(l(S, ["stop"]), ["enter"]), y(l(S, ["prevent", "stop"]), ["space"])]
			}, b(p.value), 41, K)), d("button", {
				type: "button",
				"aria-label": v(c).mergeTag.deleteMergeTag,
				class: "tpl-merge-tag-delete tpl:flex tpl:size-5 tpl:cursor-pointer tpl:items-center tpl:justify-center tpl:rounded-full tpl:border-none tpl:bg-transparent tpl:p-0 tpl:opacity-60 tpl:transition-all hover:tpl:opacity-100 tpl:text-[var(--tpl-primary)]",
				contenteditable: "false",
				onClick: i[1] ||= l((...e) => r.deleteNode && r.deleteNode(...e), ["stop", "prevent"])
			}, [...i[2] ||= [d("svg", {
				width: "10",
				height: "10",
				viewBox: "0 0 24 24",
				fill: "none",
				stroke: "currentColor",
				"stroke-width": "3",
				"aria-hidden": "true"
			}, [d("line", {
				x1: "18",
				y1: "6",
				x2: "6",
				y2: "18"
			}), d("line", {
				x1: "6",
				y1: "6",
				x2: "18",
				y2: "18"
			})], -1)]], 8, q)]),
			_: 1
		}));
	}
}), Y = F.create({
	name: "mergeTagNode",
	group: "inline",
	inline: !0,
	atom: !0,
	addOptions() {
		return {
			mergeTags: [],
			syntax: w.liquid
		};
	},
	addAttributes() {
		return {
			label: {
				default: "",
				parseHTML: (e) => e.getAttribute("data-label") || e.textContent || ""
			},
			value: {
				default: "",
				parseHTML: (e) => e.getAttribute("data-merge-tag") || ""
			}
		};
	},
	parseHTML() {
		return [{ tag: "span[data-merge-tag]" }];
	},
	renderHTML({ node: e, HTMLAttributes: t }) {
		let n = T(e.attrs.value, this.options.mergeTags);
		return [
			"span",
			k(t, {
				"data-merge-tag": e.attrs.value,
				"data-label": n
			}),
			n
		];
	},
	addNodeView() {
		return W(J);
	},
	addCommands() {
		return { insertMergeTag: (e) => ({ commands: t }) => t.insertContent({
			type: this.name,
			attrs: e
		}) };
	},
	addKeyboardShortcuts() {
		return {
			Backspace: () => U(this.editor, this.name),
			Delete: () => U(this.editor, this.name)
		};
	},
	addInputRules() {
		return [new N({
			find: RegExp(this.options.syntax.value.source + "$", ""),
			handler: ({ state: e, range: t, match: n }) => {
				let r = n[0], i = T(r, this.options.mergeTags), a = this.type.create({
					label: i,
					value: r
				});
				e.tr.replaceWith(t.from, t.to, a);
			}
		})];
	},
	addPasteRules() {
		return [new P({
			find: new RegExp(this.options.syntax.value.source, "g"),
			handler: ({ state: e, range: t, match: n }) => {
				let r = n[0], i = T(r, this.options.mergeTags), a = this.type.create({
					label: i,
					value: r
				});
				e.tr.replaceWith(t.from, t.to, a);
			}
		})];
	}
});
//#endregion
//#region ../../node_modules/.pnpm/@tiptap+suggestion@3.22.5_@tiptap+core@3.22.5_@tiptap+pm@3.22.5__@tiptap+pm@3.22.5/node_modules/@tiptap/suggestion/dist/index.js
function ie(e) {
	let { char: t, allowSpaces: n, allowToIncludeChar: r, allowedPrefixes: i, startOfLine: a, $position: o } = e, s = n && !r, c = O(t), l = RegExp(`\\s${c}$`), u = a ? "^" : "", d = r ? "" : c, f = RegExp(s ? `${u}${c}.*?(?=\\s${d}|$)` : `${u}(?:^)?${c}[^\\s${d}]*`, "gm"), p = o.nodeBefore?.isText && o.nodeBefore.text;
	if (!p) return null;
	let m = o.pos - p.length, h = Array.from(p.matchAll(f)).pop();
	if (!h || h.input === void 0 || h.index === void 0) return null;
	let g = h.input.slice(Math.max(0, h.index - 1), h.index), _ = RegExp(`^[${i?.join("")}\0]?$`).test(g);
	if (i !== null && !_) return null;
	let v = m + h.index, y = v + h[0].length;
	return s && l.test(p.slice(y - 1, y + 1)) && (h[0] += " ", y += 1), v < o.pos && y >= o.pos ? {
		range: {
			from: v,
			to: y
		},
		query: h[0].slice(t.length),
		text: h[0]
	} : null;
}
function ae(e) {
	return e.docChanged ? e.steps.some((e) => {
		let t = e.slice;
		if (!t?.content) return !1;
		let n = t.content.textBetween(0, t.content.size, "\n");
		return /\s/.test(n);
	}) : !1;
}
var oe = new I("suggestion");
function se({ pluginKey: e = oe, editor: t, char: n = "@", allowSpaces: r = !1, allowToIncludeChar: i = !1, allowedPrefixes: a = [" "], startOfLine: o = !1, decorationTag: s = "span", decorationClass: c = "suggestion", decorationContent: l = "", decorationEmptyClass: u = "is-empty", command: d = () => null, items: f = () => [], render: p = () => ({}), allow: m = () => !0, findSuggestionMatch: h = ie, shouldShow: g, shouldResetDismissed: _ }) {
	let v, y = p?.(), b = r && !i, x = () => {
		let e = t.state.selection.$anchor.pos, { top: n, right: r, bottom: i, left: a } = t.view.coordsAtPos(e);
		try {
			return new DOMRect(a, n, r - a, i - n);
		} catch {
			return null;
		}
	}, S = (n, r) => r ? () => {
		let r = e.getState(t.state)?.decorationId;
		return n.dom.querySelector(`[data-decoration-id="${r}"]`)?.getBoundingClientRect() || null;
	} : x, C = ({ match: e, dismissedRange: n, state: r, transaction: i }) => _?.({
		editor: t,
		state: r,
		range: n,
		match: e,
		transaction: i,
		allowSpaces: b
	}) ? !1 : b ? e.range.from === n.from : e.range.from === n.from && !ae(i);
	function w(n, r) {
		var i;
		try {
			let r = e.getState(n.state), a = r?.decorationId ? n.dom.querySelector(`[data-decoration-id="${r.decorationId}"]`) : null, o = {
				editor: t,
				range: r?.range || {
					from: 0,
					to: 0
				},
				query: r?.query || null,
				text: r?.text || null,
				items: [],
				command: (e) => d({
					editor: t,
					range: r?.range || {
						from: 0,
						to: 0
					},
					props: e
				}),
				decorationNode: a,
				clientRect: S(n, a)
			};
			(i = y?.onExit) == null || i.call(y, o);
		} catch {}
		let a = n.state.tr.setMeta(r, { exit: !0 });
		n.dispatch(a);
	}
	let T = new j({
		key: e,
		view() {
			return {
				update: async (e, n) => {
					var r, i, a, o, s;
					let c = this.key?.getState(n), l = this.key?.getState(e.state), u = c.active && l.active && c.range.from !== l.range.from, p = !c.active && l.active, m = c.active && !l.active, h = !p && !m && c.query !== l.query, g = p || u && h, _ = h || u, b = m || u && h;
					if (!g && !_ && !b) return;
					let x = b && !g ? c : l, C = e.dom.querySelector(`[data-decoration-id="${x.decorationId}"]`);
					v = {
						editor: t,
						range: x.range,
						query: x.query,
						text: x.text,
						items: [],
						command: (e) => d({
							editor: t,
							range: x.range,
							props: e
						}),
						decorationNode: C,
						clientRect: S(e, C)
					}, g && ((r = y?.onBeforeStart) == null || r.call(y, v)), _ && ((i = y?.onBeforeUpdate) == null || i.call(y, v)), (_ || g) && (v.items = await f({
						editor: t,
						query: x.query
					})), b && ((a = y?.onExit) == null || a.call(y, v)), _ && ((o = y?.onUpdate) == null || o.call(y, v)), g && ((s = y?.onStart) == null || s.call(y, v));
				},
				destroy: () => {
					var e;
					v && ((e = y?.onExit) == null || e.call(y, v));
				}
			};
		},
		state: {
			init() {
				return {
					active: !1,
					range: {
						from: 0,
						to: 0
					},
					query: null,
					text: null,
					composing: !1,
					dismissedRange: null
				};
			},
			apply(s, c, l, u) {
				let { isEditable: d } = t, { composing: f } = t.view, { selection: p } = s, { empty: _, from: v } = p, y = { ...c }, b = s.getMeta(e);
				if (b && b.exit) return y.active = !1, y.decorationId = null, y.range = {
					from: 0,
					to: 0
				}, y.query = null, y.text = null, y.dismissedRange = c.active ? { ...c.range } : c.dismissedRange, y;
				if (y.composing = f, s.docChanged && y.dismissedRange !== null && (y.dismissedRange = {
					from: s.mapping.map(y.dismissedRange.from),
					to: s.mapping.map(y.dismissedRange.to)
				}), d && (_ || t.view.composing)) {
					(v < c.range.from || v > c.range.to) && !f && !c.composing && (y.active = !1);
					let e = h({
						char: n,
						allowSpaces: r,
						allowToIncludeChar: i,
						allowedPrefixes: a,
						startOfLine: o,
						$position: p.$from
					}), l = `id_${Math.floor(Math.random() * 4294967295)}`;
					e && m({
						editor: t,
						state: u,
						range: e.range,
						isActive: c.active
					}) && (!g || g({
						editor: t,
						range: e.range,
						query: e.query,
						text: e.text,
						transaction: s
					})) ? (y.dismissedRange !== null && !C({
						match: e,
						dismissedRange: y.dismissedRange,
						state: u,
						transaction: s
					}) && (y.dismissedRange = null), y.dismissedRange === null ? (y.active = !0, y.decorationId = c.decorationId ? c.decorationId : l, y.range = e.range, y.query = e.query, y.text = e.text) : y.active = !1) : (e || (y.dismissedRange = null), y.active = !1);
				} else y.active = !1;
				return y.active || (y.decorationId = null, y.range = {
					from: 0,
					to: 0
				}, y.query = null, y.text = null), y;
			}
		},
		props: {
			handleKeyDown(t, n) {
				var r;
				let { active: i, range: a } = T.getState(t.state);
				if (!i) return !1;
				if (n.key === "Escape" || n.key === "Esc") {
					let i = T.getState(t.state);
					return (r = y?.onKeyDown) == null || r.call(y, {
						view: t,
						event: n,
						range: i.range
					}), w(t, e), !0;
				}
				return (y?.onKeyDown)?.call(y, {
					view: t,
					event: n,
					range: a
				}) || !1;
			},
			decorations(e) {
				let { active: t, range: n, decorationId: r, query: i } = T.getState(e);
				if (!t) return null;
				let a = !i?.length, o = [c];
				return a && o.push(u), ee.create(e.doc, [A.inline(n.from, n.to, {
					nodeName: s,
					class: o.join(" "),
					"data-decoration-id": r,
					"data-decoration-content": l
				})]);
			}
		}
	});
	return T;
}
var ce = se, le = ["id"], ue = {
	key: 0,
	class: "tpl:px-3 tpl:py-2 tpl:text-xs tpl:text-[var(--tpl-text-dim)]",
	"data-testid": "merge-tag-suggestion-empty"
}, de = [
	"id",
	"aria-selected",
	"data-selected",
	"data-merge-tag-value",
	"onMousedown",
	"onMousemove"
], X = { class: "tpl:font-medium" }, fe = { class: "tpl:text-[var(--tpl-text-dim)] tpl:font-mono" }, pe = /* @__PURE__ */ c({
	__name: "MergeTagSuggestionList",
	props: {
		items: {},
		selectedIndex: {},
		emptyText: {},
		listId: {}
	},
	emits: ["select", "hover"],
	setup(t) {
		let n = t;
		function i(e) {
			return n.listId ? `${n.listId}-opt-${e}` : void 0;
		}
		return (n, a) => (e(), f("div", {
			id: t.listId,
			class: "tpl:min-w-[200px] tpl:max-w-[320px] tpl:max-h-[50vh] tpl:overflow-y-auto tpl:rounded-[var(--tpl-radius)] tpl:border tpl:border-[var(--tpl-border)] tpl:bg-[var(--tpl-bg-elevated)] tpl:py-1 tpl:shadow-lg",
			role: "listbox",
			"data-testid": "merge-tag-suggestion-list"
		}, [t.items.length === 0 ? (e(), f("div", ue, b(t.emptyText), 1)) : m("", !0), (e(!0), f(p, null, r(t.items, (r, a) => (e(), f("button", {
			key: r.value,
			id: i(a),
			type: "button",
			role: "option",
			"aria-selected": a === t.selectedIndex,
			"data-selected": a === t.selectedIndex ? "true" : "false",
			"data-merge-tag-value": r.value,
			class: s(["tpl:flex tpl:w-full tpl:flex-col tpl:items-start tpl:gap-0.5 tpl:px-3 tpl:py-1.5 tpl:text-left tpl:text-xs tpl:transition-colors", a === t.selectedIndex ? "tpl:bg-[var(--tpl-primary-light)] tpl:text-[var(--tpl-primary)]" : "tpl:text-[var(--tpl-text)] hover:tpl:bg-[var(--tpl-bg-hover)]"]),
			onMousedown: l((e) => n.$emit("select", r), ["prevent", "stop"]),
			onMousemove: (e) => a !== t.selectedIndex && n.$emit("hover", a)
		}, [d("span", X, b(r.label), 1), d("span", fe, b(r.value), 1)], 42, de))), 128))], 8, le));
	}
}), Z = 10, me = 0;
function Q(e, t) {
	let n = t.trim().toLowerCase();
	return n === "" ? e.slice(0, Z) : e.filter((e) => {
		let t = e.label.toLowerCase(), r = e.value.toLowerCase();
		return t.includes(n) || r.includes(n);
	}).slice(0, Z);
}
function $(e, t, n, r) {
	return t.length === 0 ? e.key === "Enter" || e.key === "Tab" : e.key === "ArrowDown" ? (n.value = (n.value + 1) % t.length, !0) : e.key === "ArrowUp" ? (n.value = (n.value - 1 + t.length) % t.length, !0) : e.key === "Enter" || e.key === "Tab" ? (r(t[n.value]), !0) : !1;
}
var he = M.create({
	name: "mergeTagSuggestion",
	addOptions() {
		return {
			mergeTags: [],
			char: "{{",
			emptyText: "No matching merge tags",
			popoverRoot: null
		};
	},
	addProseMirrorPlugins() {
		let e = this.options.mergeTags, t = this.options.emptyText, n = this.options.popoverRoot, r = {
			char: this.options.char,
			allowSpaces: !1,
			startOfLine: !1,
			allowedPrefixes: null,
			items: ({ query: t }) => Q(e, t),
			command: ({ editor: e, range: t, props: n }) => {
				e.chain().focus().insertContentAt(t, {
					type: "mergeTagNode",
					attrs: {
						label: n.label,
						value: n.value
					}
				}).run();
			},
			render: () => {
				let e = null, r = null, o = null, s = a([]), c = a(0), l = null, u = `tpl-merge-tag-suggestion-${++me}`, d = null, f = [], p = null;
				function m() {
					b(d?.() ?? null);
				}
				function g() {
					m(), p !== null && cancelAnimationFrame(p), p = requestAnimationFrame(() => {
						p = null, m();
					});
				}
				function _(e) {
					let t = [], n = e?.parentElement ?? null;
					for (; n && n !== document.body && n !== document.documentElement;) {
						let e = window.getComputedStyle(n), r = e.overflow + e.overflowX + e.overflowY;
						/(auto|scroll|overlay)/.test(r) && t.push(n), n = n.parentElement;
					}
					return t;
				}
				function v(e) {
					f = [window, ..._(e)];
					for (let e of f) e.addEventListener("scroll", m, {
						passive: !0,
						capture: !0
					});
					window.addEventListener("resize", m, { passive: !0 });
				}
				function y() {
					for (let e of f) e.removeEventListener("scroll", m, { capture: !0 });
					window.removeEventListener("resize", m), f = [];
				}
				function b(e) {
					if (!r || !e || e.bottom < 0 || e.top > window.innerHeight) return;
					r.style.position = "fixed", r.style.left = `${e.left}px`, r.style.zIndex = "9999", r.style.top = `${e.bottom}px`;
					let t = r.offsetHeight;
					if (t !== 0 && window.innerHeight - e.bottom < t) {
						let n = Math.max(0, e.top - t);
						r.style.top = `${n}px`;
					}
				}
				function x(e, t) {
					let n = t?.closest("[data-tpl-theme]");
					if (!n) return;
					let r = n.getAttribute("data-tpl-theme");
					r && e.setAttribute("data-tpl-theme", r);
					let i = window.getComputedStyle(n);
					for (let t = 0; t < i.length; t++) {
						let n = i[t];
						n.startsWith("--tpl-") && e.style.setProperty(n, i.getPropertyValue(n));
					}
					e.style.fontFamily = i.fontFamily, e.style.fontSize = i.fontSize, e.style.lineHeight = i.lineHeight;
				}
				function S(e) {
					o && (e ? (o.setAttribute("role", "combobox"), o.setAttribute("aria-haspopup", "listbox"), o.setAttribute("aria-expanded", "true"), o.setAttribute("aria-controls", u)) : (o.removeAttribute("aria-expanded"), o.removeAttribute("aria-controls"), o.removeAttribute("aria-activedescendant"), o.removeAttribute("aria-haspopup"), o.removeAttribute("role")));
				}
				function C() {
					if (o) {
						if (s.value.length === 0) {
							o.removeAttribute("aria-activedescendant");
							return;
						}
						o.setAttribute("aria-activedescendant", `${u}-opt-${c.value}`);
					}
				}
				function w(e) {
					l?.(e);
				}
				return {
					onStart: (a) => {
						s.value = a.items, c.value = 0, l = (e) => a.command(e), r = document.createElement("div"), r.setAttribute("data-testid", "merge-tag-suggestion-popup");
						let f = a.editor.view?.dom;
						o = f ?? null, x(r, f ?? null), (n?.value ?? document.body).appendChild(r), e = h({ render() {
							return i(pe, {
								items: s.value,
								selectedIndex: c.value,
								emptyText: t,
								listId: u,
								onSelect: (e) => w(e),
								onHover: (e) => {
									c.value = e, C();
								}
							});
						} }), e.mount(r), S(!0), C(), d = a.clientRect ?? null, g(), v(f ?? null);
					},
					onUpdate: (e) => {
						s.value = e.items, c.value >= e.items.length && (c.value = 0), l = (t) => e.command(t), C(), d = e.clientRect ?? null, g();
					},
					onKeyDown: (e) => {
						if (e.event.key === "Escape") return !0;
						let t = $(e.event, s.value, c, w);
						return t && C(), t;
					},
					onExit: () => {
						p !== null && (cancelAnimationFrame(p), p = null), y(), S(!1), e?.unmount(), r?.remove(), e = null, r = null, o = null, l = null, d = null;
					}
				};
			}
		};
		return [ce({
			editor: this.editor,
			...r
		})];
	}
});
//#endregion
export { te as FontSize, ne as LetterSpacing, re as LineHeight, G as LogicMergeTagNode, Y as MergeTagNode, he as MergeTagSuggestion, Q as filterMergeTags, $ as handleSuggestionKeyDown };
