//#region ../../node_modules/vscode-languageserver-textdocument/lib/esm/main.js
var e = class e {
	constructor(e, t, n, r) {
		this._uri = e, this._languageId = t, this._version = n, this._content = r, this._lineOffsets = void 0;
	}
	get uri() {
		return this._uri;
	}
	get languageId() {
		return this._languageId;
	}
	get version() {
		return this._version;
	}
	getText(e) {
		if (e) {
			let t = this.offsetAt(e.start), n = this.offsetAt(e.end);
			return this._content.substring(t, n);
		}
		return this._content;
	}
	update(t, n) {
		for (let n of t) if (e.isIncremental(n)) {
			let e = a(n.range), t = this.offsetAt(e.start), i = this.offsetAt(e.end);
			this._content = this._content.substring(0, t) + n.text + this._content.substring(i, this._content.length);
			let o = Math.max(e.start.line, 0), s = Math.max(e.end.line, 0), c = this._lineOffsets, l = r(n.text, !1, t);
			if (s - o === l.length) for (let e = 0, t = l.length; e < t; e++) c[e + o + 1] = l[e];
			else l.length < 1e4 ? c.splice(o + 1, s - o, ...l) : this._lineOffsets = c = c.slice(0, o + 1).concat(l, c.slice(s + 1));
			let u = n.text.length - (i - t);
			if (u !== 0) for (let e = o + 1 + l.length, t = c.length; e < t; e++) c[e] = c[e] + u;
		} else if (e.isFull(n)) this._content = n.text, this._lineOffsets = void 0;
		else throw Error("Unknown change event received");
		this._version = n;
	}
	getLineOffsets() {
		return this._lineOffsets === void 0 && (this._lineOffsets = r(this._content, !0)), this._lineOffsets;
	}
	positionAt(e) {
		e = Math.max(Math.min(e, this._content.length), 0);
		let t = this.getLineOffsets(), n = 0, r = t.length;
		if (r === 0) return {
			line: 0,
			character: e
		};
		for (; n < r;) {
			let i = Math.floor((n + r) / 2);
			t[i] > e ? r = i : n = i + 1;
		}
		let i = n - 1;
		return e = this.ensureBeforeEOL(e, t[i]), {
			line: i,
			character: e - t[i]
		};
	}
	offsetAt(e) {
		let t = this.getLineOffsets();
		if (e.line >= t.length) return this._content.length;
		if (e.line < 0) return 0;
		let n = t[e.line];
		if (e.character <= 0) return n;
		let r = e.line + 1 < t.length ? t[e.line + 1] : this._content.length, i = Math.min(n + e.character, r);
		return this.ensureBeforeEOL(i, n);
	}
	ensureBeforeEOL(e, t) {
		for (; e > t && i(this._content.charCodeAt(e - 1));) e--;
		return e;
	}
	get lineCount() {
		return this.getLineOffsets().length;
	}
	static isIncremental(e) {
		let t = e;
		return t != null && typeof t.text == "string" && t.range !== void 0 && (t.rangeLength === void 0 || typeof t.rangeLength == "number");
	}
	static isFull(e) {
		let t = e;
		return t != null && typeof t.text == "string" && t.range === void 0 && t.rangeLength === void 0;
	}
}, t;
(function(t) {
	function r(t, n, r, i) {
		return new e(t, n, r, i);
	}
	t.create = r;
	function i(t, n, r) {
		if (t instanceof e) return t.update(n, r), t;
		throw Error("TextDocument.update: document must be created by TextDocument.create");
	}
	t.update = i;
	function a(e, t) {
		let r = e.getText(), i = n(t.map(o), (e, t) => {
			let n = e.range.start.line - t.range.start.line;
			return n === 0 ? e.range.start.character - t.range.start.character : n;
		}), a = 0, s = [];
		for (let t of i) {
			let n = e.offsetAt(t.range.start);
			if (n < a) throw Error("Overlapping edit");
			n > a && s.push(r.substring(a, n)), t.newText.length && s.push(t.newText), a = e.offsetAt(t.range.end);
		}
		return s.push(r.substr(a)), s.join("");
	}
	t.applyEdits = a;
})(t ||= {});
function n(e, t) {
	if (e.length <= 1) return e;
	let r = e.length / 2 | 0, i = e.slice(0, r), a = e.slice(r);
	n(i, t), n(a, t);
	let o = 0, s = 0, c = 0;
	for (; o < i.length && s < a.length;) t(i[o], a[s]) <= 0 ? e[c++] = i[o++] : e[c++] = a[s++];
	for (; o < i.length;) e[c++] = i[o++];
	for (; s < a.length;) e[c++] = a[s++];
	return e;
}
function r(e, t, n = 0) {
	let r = t ? [n] : [];
	for (let t = 0; t < e.length; t++) {
		let a = e.charCodeAt(t);
		i(a) && (a === 13 && t + 1 < e.length && e.charCodeAt(t + 1) === 10 && t++, r.push(n + t + 1));
	}
	return r;
}
function i(e) {
	return e === 13 || e === 10;
}
function a(e) {
	let t = e.start, n = e.end;
	return t.line > n.line || t.line === n.line && t.character > n.character ? {
		start: n,
		end: t
	} : e;
}
function o(e) {
	let t = a(e.range);
	return t === e.range ? e : {
		newText: e.newText,
		range: t
	};
}
//#endregion
export { t as TextDocument };
