import { Dt as e, H as t, M as n, Mt as r, O as i, Ot as a, P as o, Q as s, S as c, V as l, _ as u, d, g as f, h as p, it as m, l as h, m as g, n as _, p as v, s as y, u as b, w as x } from "./vue.runtime.esm-bundler-DpvJL-nX.js";
import { C as S, D as C, n as w, w as T } from "./dist-e0ylhlSV.js";
import { t as E } from "./useI18n-Jp3X6Q0t.js";
import { t as D } from "./useMergeTag-CEE4CG-D.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-CmrXHeJS.js";
import { n as L, t as R } from "./dist-QoJxR1uP.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(o) {
		let c = o, { syntax: d } = D(), { t: _ } = E(), x = v(() => C(c.node.attrs.value, d)), w = v(() => S(c.node.attrs.value, d)), T = s(!1), O = s(""), k = s(null), A = !1;
		function j() {
			O.value = c.node.attrs.value, A = !1, T.value = !0, i(() => {
				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 !== c.node.attrs.value && c.updateAttributes({
				value: e,
				keyword: C(e, d) ? S(e, d) : ""
			}), T.value = !1;
		}
		function N(e) {
			e.key === "Enter" ? (e.preventDefault(), M()) : e.key === "Escape" && (T.value = !1);
		}
		return (i, s) => (n(), p(m(R), {
			as: "span",
			class: e(x.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: a(x.value ? "background-color: transparent; border: 1.5px solid color-mix(in srgb, var(--tpl-primary) 50%, transparent); color: var(--tpl-primary);" : ""),
			contenteditable: "false"
		}, {
			default: l(() => [T.value ? t((n(), u("input", {
				key: 0,
				ref_key: "inputRef",
				ref: k,
				"onUpdate:modelValue": s[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)), [[y, O.value]]) : x.value ? (n(), u("span", {
				key: 1,
				role: "button",
				tabindex: "0",
				"aria-label": m(_).mergeTag.editValue,
				class: "tpl-tooltip tpl:cursor-pointer",
				"data-tooltip": o.node.attrs.value,
				onClick: b(j, ["stop"]),
				onKeydown: [h(b(j, ["stop"]), ["enter"]), h(b(j, ["prevent", "stop"]), ["space"])]
			}, r(w.value), 41, z)) : (n(), u("span", {
				key: 2,
				role: "button",
				tabindex: "0",
				"aria-label": m(_).mergeTag.editValue,
				onClick: b(j, ["stop"]),
				onKeydown: [h(b(j, ["stop"]), ["enter"]), h(b(j, ["prevent", "stop"]), ["space"])]
			}, r(o.node.attrs.value), 41, B)), x.value ? (n(), u("button", {
				key: 3,
				type: "button",
				"aria-label": m(_).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: s[1] ||= b((...e) => o.deleteNode && o.deleteNode(...e), ["stop", "prevent"])
			}, [...s[2] ||= [g("svg", {
				width: "10",
				height: "10",
				viewBox: "0 0 24 24",
				fill: "none",
				stroke: "currentColor",
				"stroke-width": "3",
				"aria-hidden": "true"
			}, [g("line", {
				x1: "18",
				y1: "6",
				x2: "6",
				y2: "18"
			}), g("line", {
				x1: "6",
				y1: "6",
				x2: "18",
				y2: "18"
			})], -1)]], 8, V)) : f("", !0)]),
			_: 1
		}, 8, ["class", "style"]));
	}
});
//#endregion
//#region src/extensions/isNodeSelected.ts
function U(e, t) {
	let { selection: n } = e.state, { $from: r, $to: i } = n, a = !1;
	return e.state.doc.nodesBetween(r.pos, i.pos, (e) => {
		if (e.type.name === t) return a = !0, !1;
	}), !!(a || r.pos > 0 && r.nodeBefore?.type.name === t || r.nodeAfter?.type.name === t);
}
//#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(e) {
		let a = e, { getMergeTagLabel: o } = D(), { t: c } = E(), d = v(() => o(a.node.attrs.value)), f = s(!1), _ = s(""), x = s(null);
		function S() {
			_.value = a.node.attrs.value, f.value = !0, i(() => {
				x.value?.focus(), x.value?.select();
			});
		}
		function C() {
			let e = _.value.trim();
			e && e !== a.node.attrs.value && a.updateAttributes({
				value: e,
				label: o(e)
			}), f.value = !1;
		}
		function w(e) {
			e.key === "Enter" ? (e.preventDefault(), C()) : e.key === "Escape" && (f.value = !1);
		}
		return (i, a) => (n(), p(m(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: l(() => [f.value ? t((n(), u("input", {
				key: 0,
				ref_key: "inputRef",
				ref: x,
				"onUpdate:modelValue": a[0] ||= (e) => _.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)), [[y, _.value]]) : (n(), u("span", {
				key: 1,
				role: "button",
				tabindex: "0",
				"aria-label": m(c).mergeTag.editValue,
				class: "tpl-tooltip tpl:cursor-pointer",
				"data-tooltip": e.node.attrs.value,
				onClick: b(S, ["stop"]),
				onKeydown: [h(b(S, ["stop"]), ["enter"]), h(b(S, ["prevent", "stop"]), ["space"])]
			}, r(d.value), 41, K)), g("button", {
				type: "button",
				"aria-label": m(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: a[1] ||= b((...t) => e.deleteNode && e.deleteNode(...t), ["stop", "prevent"])
			}, [...a[2] ||= [g("svg", {
				width: "10",
				height: "10",
				viewBox: "0 0 24 24",
				fill: "none",
				stroke: "currentColor",
				"stroke-width": "3",
				"aria-hidden": "true"
			}, [g("line", {
				x1: "18",
				y1: "6",
				x2: "6",
				y2: "18"
			}), g("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 i = t;
		function a(e) {
			return i.listId ? `${i.listId}-opt-${e}` : void 0;
		}
		return (i, s) => (n(), u("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 ? (n(), u("div", ue, r(t.emptyText), 1)) : f("", !0), (n(!0), u(d, null, o(t.items, (o, s) => (n(), u("button", {
			key: o.value,
			id: a(s),
			type: "button",
			role: "option",
			"aria-selected": s === t.selectedIndex,
			"data-selected": s === t.selectedIndex ? "true" : "false",
			"data-merge-tag-value": o.value,
			class: e(["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", s === 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: b((e) => i.$emit("select", o), ["prevent", "stop"]),
			onMousemove: (e) => s !== t.selectedIndex && i.$emit("hover", s)
		}, [g("span", X, r(o.label), 1), g("span", fe, r(o.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"
		};
	},
	addProseMirrorPlugins() {
		let e = this.options.mergeTags, t = this.options.emptyText, n = {
			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, n = null, r = null, i = s([]), a = s(0), o = null, c = `tpl-merge-tag-suggestion-${++me}`, l = null, u = [];
				function d() {
					h(l?.() ?? null);
				}
				function f(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 p(e) {
					u = [window, ...f(e)];
					for (let e of u) e.addEventListener("scroll", d, {
						passive: !0,
						capture: !0
					});
					window.addEventListener("resize", d, { passive: !0 });
				}
				function m() {
					for (let e of u) e.removeEventListener("scroll", d, { capture: !0 });
					window.removeEventListener("resize", d), u = [];
				}
				function h(e) {
					if (!n || !e || e.bottom < 0 || e.top > window.innerHeight) return;
					n.style.position = "fixed", n.style.left = `${e.left}px`, n.style.zIndex = "9999", n.style.top = `${e.bottom}px`;
					let t = n.offsetHeight;
					if (t !== 0 && window.innerHeight - e.bottom < t) {
						let r = Math.max(0, e.top - t);
						n.style.top = `${r}px`;
					}
				}
				function g(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 v(e) {
					r && (e ? (r.setAttribute("role", "combobox"), r.setAttribute("aria-haspopup", "listbox"), r.setAttribute("aria-expanded", "true"), r.setAttribute("aria-controls", c)) : (r.removeAttribute("aria-expanded"), r.removeAttribute("aria-controls"), r.removeAttribute("aria-activedescendant"), r.removeAttribute("aria-haspopup"), r.removeAttribute("role")));
				}
				function y() {
					if (r) {
						if (i.value.length === 0) {
							r.removeAttribute("aria-activedescendant");
							return;
						}
						r.setAttribute("aria-activedescendant", `${c}-opt-${a.value}`);
					}
				}
				function b(e) {
					o?.(e);
				}
				return {
					onStart: (s) => {
						i.value = s.items, a.value = 0, o = (e) => s.command(e), n = document.createElement("div"), n.setAttribute("data-testid", "merge-tag-suggestion-popup");
						let u = s.editor.view?.dom;
						r = u ?? null, g(n, u ?? null), document.body.appendChild(n), e = _({ render() {
							return x(pe, {
								items: i.value,
								selectedIndex: a.value,
								emptyText: t,
								listId: c,
								onSelect: (e) => b(e),
								onHover: (e) => {
									a.value = e, y();
								}
							});
						} }), e.mount(n), v(!0), y(), l = s.clientRect ?? null, h(l?.() ?? null), p(u ?? null);
					},
					onUpdate: (e) => {
						i.value = e.items, a.value >= e.items.length && (a.value = 0), o = (t) => e.command(t), y(), l = e.clientRect ?? null, h(l?.() ?? null);
					},
					onKeyDown: (e) => {
						if (e.event.key === "Escape") return !0;
						let t = $(e.event, i.value, a, b);
						return t && y(), t;
					},
					onExit: () => {
						m(), v(!1), e?.unmount(), n?.remove(), e = null, n = null, r = null, o = null, l = null;
					}
				};
			}
		};
		return [ce({
			editor: this.editor,
			...n
		})];
	}
});
//#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 };
