import { K as e, at as t, c as n, o as r } from "../dist-DgSmYkuV.js";
import { a as i, o as a, t as o } from "../base-B7MLNUXu.js";
//#region src/editors/log-viewer.ts
var s = new r(n.define({ token(e) {
	if (e.sol()) {
		if (e.match("[ERROR]") !== null) return "invalid";
		if (e.match("[WARN]") !== null) return "keyword";
		if (e.match("[OK]") !== null) return "string";
		if (e.match("[INFO]") !== null) return "comment";
	}
	return e.match(/\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}:\d{2}/) === null ? e.match(/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/) === null ? e.match(/"(?:[^"\\]|\\.)*"/) === null ? e.match(/\d+(\.\d+)?/) === null ? e.match(/[A-Za-z_][\w]*(?==)/) === null ? (e.next(), null) : "propertyName" : "number" : "string" : "atom" : "number";
} }));
function c(e) {
	switch (e) {
		case "error": return "[ERROR] ";
		case "warning": return "[WARN]  ";
		case "success": return "[OK]    ";
		case "info": return "[INFO]  ";
	}
}
var l = class extends o {
	constructor(e) {
		let n = e.maxLines ?? 1e4, r = e.followMode !== !1, o = [
			...e.severityColors === !1 ? [] : [s],
			i(),
			t.of(a)
		];
		super({
			...e,
			readOnly: !0,
			lineNumbers: e.lineNumbers ?? !1,
			wordWrap: e.wordWrap ?? !0
		}, o), this.maxLines = n, this.followMode = r;
	}
	appendLine(t, n) {
		let r = `${n ? c(n) : ""}${t}`, i = this.view.state.doc, a = i.length > 0 ? `\n${r}` : r, o = [], s = i.lines + 1;
		if (s > this.maxLines) {
			let e = s - this.maxLines, t = i.line(e + 1);
			o.push({
				from: 0,
				to: t.from
			});
		}
		if (o.push({
			from: i.length,
			insert: a
		}), this.view.dispatch({ changes: o }), this.followMode) {
			let t = this.view.state.doc;
			this.view.dispatch({ effects: e.scrollIntoView(t.length) });
		}
	}
	appendLines(t) {
		if (t.length === 0) return;
		let n = t.map((e) => `${e.severity ? c(e.severity) : ""}${e.text}`).join("\n"), r = this.view.state.doc, i = r.length > 0 ? `\n${n}` : n, a = [], o = r.lines + t.length;
		if (o > this.maxLines) {
			let e = o - this.maxLines, t = Math.min(e + 1, r.lines), n = r.line(t);
			a.push({
				from: 0,
				to: n.from
			});
		}
		if (a.push({
			from: r.length,
			insert: i
		}), this.view.dispatch({ changes: a }), this.followMode) {
			let t = this.view.state.doc;
			this.view.dispatch({ effects: e.scrollIntoView(t.length) });
		}
	}
	clear() {
		this.view.dispatch({ changes: {
			from: 0,
			to: this.view.state.doc.length
		} });
	}
	setFollowMode(t) {
		this.followMode = t, t && this.view.dispatch({ effects: e.scrollIntoView(this.view.state.doc.length) });
	}
	getFollowMode() {
		return this.followMode;
	}
	setMaxLines(e) {
		this.maxLines = e;
	}
};
//#endregion
export { l as LogViewer };

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