//#region ../../node_modules/.pnpm/@stryke+path@0.26.3/node_modules/@stryke/path/dist/regex.mjs
const DRIVE_LETTER_START_REGEX = /^[A-Z]:\//i;
const DRIVE_LETTER_REGEX = /^[A-Z]:$/i;
const UNC_REGEX = /^[/\\]{2}/;
const ABSOLUTE_PATH_REGEX = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^~[/\\]|^[A-Z]:[/\\]/i;

//#endregion
//#region ../../node_modules/.pnpm/@stryke+path@0.26.3/node_modules/@stryke/path/dist/slash.mjs
/**
* Replace backslash to slash
*
* @param path - The string to replace
* @returns The string with replaced backslashes
*/
function slash(path) {
	if (path.startsWith("\\\\?\\")) return path;
	return path.replace(/\\/g, "/");
}

//#endregion
//#region ../../node_modules/.pnpm/@stryke+path@0.26.3/node_modules/@stryke/path/dist/is-type.mjs
/**
* Check if the path is an absolute path.
*
* @param path - The path to check
* @returns An indicator specifying if the path is an absolute path
*/
function isAbsolutePath(path) {
	return ABSOLUTE_PATH_REGEX.test(slash(path));
}
/**
* Check if the path is an absolute path.
*
* @remarks
* This is an alias for {@link isAbsolutePath}.
*
* @param path - The path to check
* @returns An indicator specifying if the path is an absolute path
*/
function isAbsolute(path) {
	return isAbsolutePath(path);
}

//#endregion
//#region ../../node_modules/.pnpm/@stryke+path@0.26.3/node_modules/@stryke/path/dist/join-paths.mjs
function normalizeWindowsPath(input = "") {
	if (!input) return input;
	return input.replace(/\\/g, "/").replace(DRIVE_LETTER_START_REGEX, (r) => r.toUpperCase());
}
function correctPaths(path) {
	if (!path || path.length === 0) return ".";
	path = normalizeWindowsPath(path);
	const isUNCPath = path.match(UNC_REGEX);
	const isPathAbsolute = isAbsolute(path);
	const trailingSeparator = path[path.length - 1] === "/";
	path = normalizeString(path, !isPathAbsolute);
	if (path.length === 0) {
		if (isPathAbsolute) return "/";
		return trailingSeparator ? "./" : ".";
	}
	if (trailingSeparator) path += "/";
	if (DRIVE_LETTER_REGEX.test(path)) path += "/";
	if (isUNCPath) {
		if (!isPathAbsolute) return `//./${path}`;
		return `//${path}`;
	}
	return isPathAbsolute && !isAbsolute(path) ? `/${path}` : path;
}
/**
* Joins all given path segments together using the platform-specific separator as a delimiter.
* The resulting path is normalized to remove any redundant or unnecessary segments.
*
* @param segments - The path segments to join.
* @returns The joined and normalized path string.
*/
function joinPaths(...segments) {
	let path = "";
	for (const seg of segments) {
		if (!seg) continue;
		if (path.length > 0) {
			const pathTrailing = path[path.length - 1] === "/";
			const segLeading = seg[0] === "/";
			if (pathTrailing && segLeading) path += seg.slice(1);
			else path += pathTrailing || segLeading ? seg : `/${seg}`;
		} else path += seg;
	}
	return correctPaths(path);
}
/**
* Resolves a string path, resolving '.' and '.' segments and allowing paths above the root.
*
* @param path - The path to normalize.
* @param allowAboveRoot - Whether to allow the resulting path to be above the root directory.
* @returns the normalized path string.
*/
function normalizeString(path, allowAboveRoot) {
	let res = "";
	let lastSegmentLength = 0;
	let lastSlash = -1;
	let dots = 0;
	let char = null;
	for (let index = 0; index <= path.length; ++index) {
		if (index < path.length) char = path[index];
		else if (char === "/") break;
		else char = "/";
		if (char === "/") {
			if (lastSlash === index - 1 || dots === 1) {} else if (dots === 2) {
				if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
					if (res.length > 2) {
						const lastSlashIndex = res.lastIndexOf("/");
						if (lastSlashIndex === -1) {
							res = "";
							lastSegmentLength = 0;
						} else {
							res = res.slice(0, lastSlashIndex);
							lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
						}
						lastSlash = index;
						dots = 0;
						continue;
					} else if (res.length > 0) {
						res = "";
						lastSegmentLength = 0;
						lastSlash = index;
						dots = 0;
						continue;
					}
				}
				if (allowAboveRoot) {
					res += res.length > 0 ? "/.." : "..";
					lastSegmentLength = 2;
				}
			} else {
				if (res.length > 0) res += `/${path.slice(lastSlash + 1, index)}`;
				else res = path.slice(lastSlash + 1, index);
				lastSegmentLength = index - lastSlash - 1;
			}
			lastSlash = index;
			dots = 0;
		} else if (char === "." && dots !== -1) ++dots;
		else dots = -1;
	}
	return res;
}

//#endregion
export { slash as n, joinPaths as t };
//# sourceMappingURL=join-paths-BMg51Ddi.mjs.map