import { isCompositeCstNode as e, isLeafCstNode as t, isRootCstNode as n } from "../syntax-tree.js";
import { TreeStreamImpl as r } from "./stream.js";
//#region ../../node_modules/langium/lib/utils/cst-utils.js
function i(t) {
	return new r(t, (t) => e(t) ? t.content : [], { includeRoot: !0 });
}
function a(e, t) {
	for (; e.container;) if (e = e.container, e === t) return !0;
	return !1;
}
function o(e) {
	return {
		start: {
			character: e.startColumn - 1,
			line: e.startLine - 1
		},
		end: {
			character: e.endColumn,
			line: e.endLine - 1
		}
	};
}
function s(e) {
	if (!e) return;
	let { offset: t, end: n, range: r } = e;
	return {
		range: r,
		offset: t,
		end: n,
		length: n - t
	};
}
var c;
(function(e) {
	e[e.Before = 0] = "Before", e[e.After = 1] = "After", e[e.OverlapFront = 2] = "OverlapFront", e[e.OverlapBack = 3] = "OverlapBack", e[e.Inside = 4] = "Inside", e[e.Outside = 5] = "Outside";
})(c ||= {});
function l(e, t) {
	if (e.end.line < t.start.line || e.end.line === t.start.line && e.end.character <= t.start.character) return c.Before;
	if (e.start.line > t.end.line || e.start.line === t.end.line && e.start.character >= t.end.character) return c.After;
	let n = e.start.line > t.start.line || e.start.line === t.start.line && e.start.character >= t.start.character, r = e.end.line < t.end.line || e.end.line === t.end.line && e.end.character <= t.end.character;
	return n && r ? c.Inside : n ? c.OverlapBack : r ? c.OverlapFront : c.Outside;
}
function u(e, t) {
	return l(e, t) > c.After;
}
var d = /^[\w\p{L}]$/u;
function f(e, t) {
	if (e) {
		let r = m(e, !0);
		if (r && p(r, t)) return r;
		if (n(e)) {
			let n = e.content.findIndex((e) => !e.hidden);
			for (let r = n - 1; r >= 0; r--) {
				let n = e.content[r];
				if (p(n, t)) return n;
			}
		}
	}
}
function p(e, n) {
	return t(e) && n.includes(e.tokenType.name);
}
function m(e, t = !0) {
	for (; e.container;) {
		let n = e.container, r = n.content.indexOf(e);
		for (; r > 0;) {
			r--;
			let e = n.content[r];
			if (t || !e.hidden) return e;
		}
		e = n;
	}
}
//#endregion
export { d as DefaultNameRegexp, f as findCommentNode, u as inRange, a as isChildNode, i as streamCst, s as toDocumentSegment, o as tokenToRange };
