import path, { relative, resolve } from "node:path";
//#region src/gateway/workspace-editor-path.ts
/** Resolve a workspace-relative POSIX path safely (no `..`, stays under root). */
function resolveWorkspaceSafePath(workspaceRoot, rel) {
	const trimmed = rel.trim().replace(/\\/g, "/").replace(/^\/+/, "");
	if (trimmed.includes("..")) return null;
	const abs = resolve(workspaceRoot, trimmed);
	const relToRoot = relative(resolve(workspaceRoot), abs);
	if (relToRoot.startsWith("..") || relToRoot.split(/[/\\]/).includes("..")) return null;
	return abs;
}
function toWorkspaceRelativePosix(workspaceRoot, absPath) {
	return relative(resolve(workspaceRoot), absPath).replace(/\\/g, "/") || "";
}
function isPathUnderWorkspace(workspaceRoot, absPath) {
	const relToRoot = relative(resolve(workspaceRoot), resolve(absPath));
	return relToRoot === "" || !relToRoot.startsWith("..") && !path.isAbsolute(relToRoot);
}
//#endregion
export { isPathUnderWorkspace, resolveWorkspaceSafePath, toWorkspaceRelativePosix };

//# sourceMappingURL=workspace-editor-path.js.map