import { t as e } from "./dist-BWeVpZNn.mjs";
import { t } from "./github-dark-VJmj9Uie.mjs";
import { createBlock as n, createCommentVNode as r, createElementBlock as i, createElementVNode as a, createTextVNode as o, defineComponent as s, isRef as c, nextTick as l, openBlock as u, ref as d, toDisplayString as f, unref as p, withCtx as m } from "vue";
import { Drawer as h } from "ant-design-vue/es";
import './drawerViewJson.css';//#region ../../node_modules/.pnpm/steady-xml@0.1.0/node_modules/steady-xml/dist/index.mjs
var g = Object.defineProperty, _ = Object.getOwnPropertySymbols, v = Object.prototype.hasOwnProperty, y = Object.prototype.propertyIsEnumerable, b = (e, t, n) => t in e ? g(e, t, {
	enumerable: !0,
	configurable: !0,
	writable: !0,
	value: n
}) : e[t] = n, x = (e, t) => {
	for (var n in t ||= {}) v.call(t, n) && b(e, n, t[n]);
	if (_) for (var n of _(t)) y.call(t, n) && b(e, n, t[n]);
	return e;
}, S = (e, t) => {
	var n = {};
	for (var r in e) v.call(e, r) && t.indexOf(r) < 0 && (n[r] = e[r]);
	if (e != null && _) for (var r of _(e)) t.indexOf(r) < 0 && y.call(e, r) && (n[r] = e[r]);
	return n;
}, C = (e, t, n) => (b(e, typeof t == "symbol" ? t : t + "", n), n);
function w(e) {
	return e == null;
}
function T(e) {
	return typeof e == "string";
}
function E(e) {
	return typeof e == "boolean";
}
var D;
(function(e) {
	e.Root = "Root", e.Declaration = "Declaration", e.Comment = "Comment", e.DocumentType = "DocumentType", e.Element = "Element", e.Text = "Text", e.Instruction = "Instruction", e.CDATA = "CDATA";
})(D ||= {});
var O = class {
	constructor(e, t = null, n = null) {
		C(this, "name"), C(this, "type"), C(this, "parent"), C(this, "children"), C(this, "attributes"), C(this, "value"), C(this, "selfClosing"), C(this, "prefix"), this.name = "", this.type = e, this.parent = t, this.value = n, this.children = null, this.attributes = {}, this.selfClosing = !1, this.prefix = "";
	}
	setName(e) {
		return this.name = e, this;
	}
	setType(e) {
		return this.type = e, this;
	}
	setParent(e) {
		return this.parent = e, this;
	}
	setChildren(e) {
		return this.children = e && Array.from(e), this;
	}
	setAttributes(e) {
		return this.attributes = x({}, e), this;
	}
	setValue(e) {
		return this.value = e, this;
	}
	setSelfClosing(e) {
		return this.selfClosing = e, this;
	}
	setPrefix(e) {
		return this.prefix = e, this;
	}
	addAttribute(e, t) {
		return this.attributes[e] = t, this;
	}
	removeAttribute(e) {
		return delete this.attributes[e], this;
	}
	addChild(e) {
		return e === this ? this : (this.children ||= [], this.children.push(e), e.parent !== this && (e.parent = this), this);
	}
	removeChild(e) {
		if (this.children && this.children.length) {
			let t = this.children.findIndex((t) => t === e);
			~t && (this.children.splice(t, 1), e.parent = null);
		}
		return this;
	}
	toJsObject() {
		return {
			name: this.name || void 0,
			prefix: this.prefix || void 0,
			type: this.type,
			attributes: Object.keys(this.attributes).length ? this.attributes : void 0,
			value: w(this.value) ? void 0 : this.value,
			selfClosing: this.selfClosing || void 0,
			children: (this.type === D.Element || this.type === D.Root) && this.children && this.children.length ? this.children.map((e) => e.toJSON()) : void 0
		};
	}
	toXmlString(e = "  ", t = "\n", n = 0) {
		let r = e.repeat(n), i = "";
		switch (this.type) {
			case D.Root:
				i += this.children && this.children.length ? this.children.map((r) => r.toXmlString(e, t, n)).join(t) : "";
				break;
			case D.Element: {
				if (!this.name) return "";
				let a = this.prefix ? `${this.prefix}:${this.name}` : this.name;
				i += `${r}<${a}`;
				let o = k(this.attributes || {});
				o && (i += ` ${o}`), this.children && this.children.length ? i += `>${t}${this.children.map((r) => r.toXmlString(e, t, n + 1)).join(t)}${t}${r}</${a}>` : i += this.selfClosing ? " />" : `></${a}>`;
				break;
			}
			case D.CDATA:
				i += `${r}<![CDATA[${w(this.value) ? "" : this.value}]]>`;
				break;
			case D.Text:
				i += w(this.value) ? "" : `${r}${this.value}`;
				break;
			case D.DocumentType:
				i += w(this.value) ? "" : `${r}<!DOCTYPE ${this.value}>`;
				break;
			case D.Comment:
				i += `${r}<!-- ${w(this.value) ? "" : this.value + " "}-->`;
				break;
			case D.Declaration:
				if (i += `${r}<?xml `, !this.attributes || w(this.attributes.version)) i += "version=\"1.0\" ";
				else {
					let e = parseFloat(this.attributes.version);
					i += `version="${Number.isNaN(e) ? "1.0" : e.toFixed(1)}" `;
				}
				if (this.attributes) {
					let e = this.attributes, { version: t } = e, n = S(e, ["version"]);
					n && (i += k(n));
				}
				i += "?>";
				break;
			case D.Instruction:
				i += w(this.value) ? "" : `${r}<?${this.value}?>`;
				break;
		}
		return i;
	}
	toJSON() {
		return this.toJsObject();
	}
	toString() {
		return this.toXmlString("", "");
	}
};
function k(e) {
	return Object.keys(e).map((t) => {
		let n = e[t];
		return w(n) ? null : E(n) ? n ? t : null : `${t}="${n}"`;
	}).filter(Boolean).join(" ");
}
var A = (e) => e, j = {
	ignoreAttributes: !1,
	parseNodeValue: !0,
	trimValues: !0,
	prefixInName: !1,
	valueProcessor: A,
	attributeProcessor: A
}, M = Object.keys(j);
function N(e = {}) {
	let t = x({}, e);
	return M.forEach((e) => {
		w(t[e]) && (t[e] = j[e]);
	}), t;
}
var P = "Tag is not closed.";
function F(e, t = {}) {
	let n = e.replace(/\r\n?/g, "\n"), r = N(t), i = n.length, a = new O(D.Root), o = a, s = "";
	for (let e = 0; e < i; e++) {
		let t = n[e];
		if (t !== "<") s += t;
		else if (n[e + 1] === "/") {
			let t = I(n, ">", e, `Element End ${P}`), i = n.substring(e + 2, t), a = "";
			if (!r.prefixInName) {
				let e = i.indexOf(":");
				~e && (a = i.substring(0, e), i = i.substring(e + 1));
			}
			if (o.prefix !== a || o.name !== i) throw Error("End Tag is incorrect.");
			if (s) {
				let e = B(L("", D.Text, s, r));
				e && o.addChild(new O(D.Text, o, e));
			}
			o = o.parent, s = "", e = t;
		} else if (n[e + 1] === "?") {
			let t = I(n, "?>", e, `Processing Instruction ${P}`), i = n.substring(e + 2, t - 1);
			if (o) if (i.startsWith("xml ") && i.includes("version=") && o.type === D.Root) {
				let e = new O(D.Declaration, o);
				e.attributes = H(i.substr(4), D.Declaration, r), o.addChild(e);
			} else o.addChild(new O(D.Instruction, o, L("", D.Instruction, i, r)));
			e = t;
		} else if (n.substr(e + 1, 3) === "!--") {
			let t = I(n, "-->", e, `Comment ${P}`), i = n.substring(e + 4, t - 2);
			o && o.addChild(new O(D.Comment, o, L("", D.Comment, i, r))), e = t;
		} else if (n.substr(e + 1, 8) === "!DOCTYPE") {
			let t = I(n, ">", e, `Document Type ${P}`), i = n.substring(e + 9, t);
			i.includes("[") && (t = I(n, "]>", e, `Document Type ${P}`), i = n.substring(e + 9, t)), o && o.addChild(new O(D.DocumentType, o, L("", D.DocumentType, i, r))), e = t;
		} else if (n.substr(e + 1, 8) === "![CDATA[") {
			let t = I(n, "]]>", e, `CDATA Section ${P}`), i = n.substring(e + 9, t - 2);
			if (o && s) {
				let e = B(L("", D.Text, s, r));
				e && o.addChild(new O(D.Text, o, e));
			}
			o.addChild(new O(D.CDATA, o, L("", D.CDATA, i, r))), s = "", e = t;
		} else {
			let t = "", a = "", c = e + 1;
			for (; c <= i;) {
				let e = n[c];
				if (t) e === t && (t = "");
				else if (e === "\"" || e === "'") t = e;
				else if (e === "	") e = " ";
				else if (e === ">") break;
				a += e, c++;
			}
			if (c > i) throw Error(`Element ${P}`);
			a = a.trim();
			let l = a.indexOf(" "), u = a, d = "";
			if (~l ? (u = a.substr(0, l), a = a.substr(l + 1)) : a = "", !r.prefixInName) {
				let e = u.indexOf(":");
				~e && (d = u.substring(0, e), u = u.substring(e + 1));
			}
			if (o && s) {
				let e = B(L("", D.Text, s, r));
				e && o.addChild(new O(D.Text, o, e));
			}
			if (a.length && a.lastIndexOf("/") === a.length - 1) {
				u[u.length - 1] === "/" ? (u = u.substr(0, u.length - 1), a = "") : a = a.substr(0, a.length - 1);
				let e = new O(D.Element, o);
				e.name = u, e.selfClosing = !0, e.prefix = d, a && !r.ignoreAttributes && (e.attributes = H(a, D.Element, r)), o.addChild(e);
			} else {
				let e = new O(D.Element, o);
				a && !r.ignoreAttributes && (e.attributes = H(a, D.Element, r)), e.name = u, e.prefix = d, o.addChild(e), o = e;
			}
			s = "", e = c;
		}
	}
	return a;
}
function I(e, t, n, r) {
	let i = e.indexOf(t, n);
	if (!~i) throw Error(r);
	return i + t.length - 1;
}
function L(e, t, n, r) {
	return n ? (r.trimValues && (n = n.trim()), R(r.valueProcessor(n, t, e), r.parseNodeValue)) : null;
}
function R(e, t) {
	return t && T(e) ? (e = e.trim(), e === "true" ? !0 : e === "false" ? !1 : z(e)) : w(e) ? null : e;
}
function z(e) {
	let t = parseFloat(e);
	return Number.isNaN(t) ? e : t;
}
function B(e) {
	return w(e) ? "" : T(e) ? e : String(e);
}
var V = /[^\s=]+\s*(=\s*['"][\s\S]*?['"])?/g;
function H(e, t, n) {
	e = e.replace(/\r?\n/g, " ");
	let r = e.match(V) || [], i = {};
	for (let e = 0; e < r.length; e++) {
		let [a, o] = r[e].split("=");
		a = a.trim(), T(o) ? (o = o.substring(1, o.length - 1), n.trimValues && (o = o.trim()), i[a] = R(n.attributeProcessor(o, a, t), n.parseNodeValue)) : i[a] = !0;
	}
	return i;
}
//#endregion
//#region src/pages/flow-create/flow-model/createComponents/flow/components/drawerViewJson.vue?vue&type=script&setup=true&lang.ts
var U = {
	"size-full": "",
	class: "mt-[-20px]"
}, W = {
	key: 0,
	class: "error-message"
}, G = { class: "w-full my-0px! p-0px!" }, K = /* @__PURE__ */ s({
	name: "DrawerViewJson",
	__name: "drawerViewJson",
	setup(s, { expose: g }) {
		let [_, v] = e(!1), y = d(""), b = d(null), x = d("");
		async function S(e) {
			v(!0);
			try {
				let n = new O(D.Root, F(e)).parent?.toJSON();
				if (y.value = JSON.stringify(n, null, 2), await l(), b.value) {
					b.value.textContent = y.value;
					try {
						t.highlightElement(b.value);
					} catch {}
				}
			} catch (e) {
				x.value = e?.message ?? String(e), y.value = x.value;
			}
		}
		function C() {
			v(!1);
		}
		return g({ open: S }), (e, t) => {
			let s = h;
			return u(), n(s, {
				open: p(_),
				"onUpdate:open": t[0] ||= (e) => c(_) ? _.value = e : null,
				title: "json预览",
				placement: "right",
				width: 1e3,
				"destroy-on-close": "",
				footer: !1,
				onClose: C
			}, {
				default: m(() => [a("div", U, [x.value ? (u(), i("div", W, f(x.value), 1)) : r("", !0), a("pre", G, [
					t[1] ||= o("        ", -1),
					a("code", {
						ref_key: "codeRef",
						ref: b,
						class: "language-json"
					}, null, 512),
					t[2] ||= o("\n      ", -1)
				])])]),
				_: 1
			}, 8, ["open"]);
		};
	}
});
//#endregion
export { K as t };
