import { at as e, g as t, v as n } from "../dist-DgSmYkuV.js";
import { t as r } from "../base-B7MLNUXu.js";
import { n as i, t as a } from "../dist-CYSk5SkB.js";
import { t as o } from "../json-D8YcUjFo.js";
//#region src/editors/json-viewer.ts
function s(e) {
	let t = e.state.doc.toString();
	if (!t.trim()) return [];
	try {
		return JSON.parse(t), [];
	} catch (t) {
		let n = t instanceof SyntaxError ? t.message : "Invalid JSON", r = /position (\d+)/.exec(n), i = r?.[1] ? parseInt(r[1], 10) : 0, a = Math.min(i, e.state.doc.length);
		return [{
			from: a,
			to: Math.min(a + 1, e.state.doc.length),
			severity: "error",
			message: n
		}];
	}
}
var c = class extends r {
	constructor(r) {
		let c = r.editable === !0, l = r.formatOnLoad !== !1, u = [
			o(),
			t(),
			e.of(n),
			i(s, { delay: 500 }),
			a()
		], d = r.value ?? "";
		if (l && d.trim()) try {
			let e = JSON.parse(d);
			d = JSON.stringify(e, null, 2);
		} catch {}
		super({
			...r,
			value: d,
			readOnly: !c
		}, u), this.editable = c;
	}
	format() {
		let e = this.getValue();
		if (e.trim()) try {
			let t = JSON.parse(e);
			this.setValue(JSON.stringify(t, null, 2));
		} catch {}
	}
	minify() {
		let e = this.getValue();
		if (e.trim()) try {
			let t = JSON.parse(e);
			this.setValue(JSON.stringify(t));
		} catch {}
	}
	validate() {
		try {
			return JSON.parse(this.getValue()), !0;
		} catch {
			return !1;
		}
	}
	getParsed() {
		try {
			return JSON.parse(this.getValue());
		} catch {
			return null;
		}
	}
	setJson(e) {
		this.setValue(JSON.stringify(e, null, 2));
	}
	setEditable(e) {
		this.editable = e, this.setReadOnly(!e);
	}
};
//#endregion
export { c as JsonViewer };

//# sourceMappingURL=json-viewer.js.map