import process$1 from "node:process";

//#region ../../node_modules/.pnpm/mimic-function@5.0.1/node_modules/mimic-function/index.js
const copyProperty = (to, from, property, ignoreNonConfigurable) => {
	if (property === "length" || property === "prototype") return;
	if (property === "arguments" || property === "caller") return;
	const toDescriptor = Object.getOwnPropertyDescriptor(to, property);
	const fromDescriptor = Object.getOwnPropertyDescriptor(from, property);
	if (!canCopyProperty(toDescriptor, fromDescriptor) && ignoreNonConfigurable) return;
	Object.defineProperty(to, property, fromDescriptor);
};
const canCopyProperty = function(toDescriptor, fromDescriptor) {
	return toDescriptor === void 0 || toDescriptor.configurable || toDescriptor.writable === fromDescriptor.writable && toDescriptor.enumerable === fromDescriptor.enumerable && toDescriptor.configurable === fromDescriptor.configurable && (toDescriptor.writable || toDescriptor.value === fromDescriptor.value);
};
const changePrototype = (to, from) => {
	const fromPrototype = Object.getPrototypeOf(from);
	if (fromPrototype === Object.getPrototypeOf(to)) return;
	Object.setPrototypeOf(to, fromPrototype);
};
const wrappedToString = (withName, fromBody) => `/* Wrapped ${withName}*/\n${fromBody}`;
const toStringDescriptor = Object.getOwnPropertyDescriptor(Function.prototype, "toString");
const toStringName = Object.getOwnPropertyDescriptor(Function.prototype.toString, "name");
const changeToString = (to, from, name) => {
	const withName = name === "" ? "" : `with ${name.trim()}() `;
	const newToString = wrappedToString.bind(null, withName, from.toString());
	Object.defineProperty(newToString, "name", toStringName);
	const { writable, enumerable, configurable } = toStringDescriptor;
	Object.defineProperty(to, "toString", {
		value: newToString,
		writable,
		enumerable,
		configurable
	});
};
function mimicFunction(to, from, { ignoreNonConfigurable = false } = {}) {
	const { name } = to;
	for (const property of Reflect.ownKeys(from)) copyProperty(to, from, property, ignoreNonConfigurable);
	changePrototype(to, from);
	changeToString(to, from, name);
	return to;
}

//#endregion
//#region ../../node_modules/.pnpm/onetime@7.0.0/node_modules/onetime/index.js
const calledFunctions = /* @__PURE__ */ new WeakMap();
const onetime = (function_, options = {}) => {
	if (typeof function_ !== "function") throw new TypeError("Expected a function");
	let returnValue;
	let callCount = 0;
	const functionName = function_.displayName || function_.name || "<anonymous>";
	const onetime$1 = function(...arguments_) {
		calledFunctions.set(onetime$1, ++callCount);
		if (callCount === 1) {
			returnValue = function_.apply(this, arguments_);
			function_ = void 0;
		} else if (options.throw === true) throw new Error(`Function \`${functionName}\` can only be called once`);
		return returnValue;
	};
	mimicFunction(onetime$1, function_);
	calledFunctions.set(onetime$1, callCount);
	return onetime$1;
};
onetime.callCount = (function_) => {
	if (!calledFunctions.has(function_)) throw new Error(`The given function \`${function_.name}\` is not wrapped by the \`onetime\` package`);
	return calledFunctions.get(function_);
};
var onetime_default = onetime;

//#endregion
//#region ../../node_modules/.pnpm/signal-exit@4.1.0/node_modules/signal-exit/dist/mjs/signals.js
/**
* This is not the set of all possible signals.
*
* It IS, however, the set of all signals that trigger
* an exit on either Linux or BSD systems.  Linux is a
* superset of the signal names supported on BSD, and
* the unknown signals just fail to register, so we can
* catch that easily enough.
*
* Windows signals are a different set, since there are
* signals that terminate Windows processes, but don't
* terminate (or don't even exist) on Posix systems.
*
* Don't bother with SIGKILL.  It's uncatchable, which
* means that we can't fire any callbacks anyway.
*
* If a user does happen to register a handler on a non-
* fatal signal like SIGWINCH or something, and then
* exit, it'll end up firing `process.emit('exit')`, so
* the handler will be fired anyway.
*
* SIGBUS, SIGFPE, SIGSEGV and SIGILL, when not raised
* artificially, inherently leave the process in a
* state from which it is not safe to try and enter JS
* listeners.
*/
const signals = [];
signals.push("SIGHUP", "SIGINT", "SIGTERM");
if (process.platform !== "win32") signals.push("SIGALRM", "SIGABRT", "SIGVTALRM", "SIGXCPU", "SIGXFSZ", "SIGUSR2", "SIGTRAP", "SIGSYS", "SIGQUIT", "SIGIOT");
if (process.platform === "linux") signals.push("SIGIO", "SIGPOLL", "SIGPWR", "SIGSTKFLT");

//#endregion
//#region \0@oxc-project+runtime@0.98.0/helpers/checkPrivateRedeclaration.js
function _checkPrivateRedeclaration(e, t) {
	if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object");
}

//#endregion
//#region \0@oxc-project+runtime@0.98.0/helpers/classPrivateMethodInitSpec.js
function _classPrivateMethodInitSpec(e, a) {
	_checkPrivateRedeclaration(e, a), a.add(e);
}

//#endregion
//#region \0@oxc-project+runtime@0.98.0/helpers/classPrivateFieldInitSpec.js
function _classPrivateFieldInitSpec(e, t, a) {
	_checkPrivateRedeclaration(e, t), t.set(e, a);
}

//#endregion
//#region \0@oxc-project+runtime@0.98.0/helpers/assertClassBrand.js
function _assertClassBrand(e, t, n) {
	if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n;
	throw new TypeError("Private element is not present on this object");
}

//#endregion
//#region \0@oxc-project+runtime@0.98.0/helpers/classPrivateFieldSet2.js
function _classPrivateFieldSet2(s, a, r) {
	return s.set(_assertClassBrand(s, a), r), r;
}

//#endregion
//#region \0@oxc-project+runtime@0.98.0/helpers/classPrivateFieldGet2.js
function _classPrivateFieldGet2(s, a) {
	return s.get(_assertClassBrand(s, a));
}

//#endregion
//#region ../../node_modules/.pnpm/signal-exit@4.1.0/node_modules/signal-exit/dist/mjs/index.js
const processOk = (process$3) => !!process$3 && typeof process$3 === "object" && typeof process$3.removeListener === "function" && typeof process$3.emit === "function" && typeof process$3.reallyExit === "function" && typeof process$3.listeners === "function" && typeof process$3.kill === "function" && typeof process$3.pid === "number" && typeof process$3.on === "function";
const kExitEmitter = Symbol.for("signal-exit emitter");
const global = globalThis;
const ObjectDefineProperty = Object.defineProperty.bind(Object);
var Emitter = class {
	constructor() {
		this.emitted = {
			afterExit: false,
			exit: false
		};
		this.listeners = {
			afterExit: [],
			exit: []
		};
		this.count = 0;
		this.id = Math.random();
		if (global[kExitEmitter]) return global[kExitEmitter];
		ObjectDefineProperty(global, kExitEmitter, {
			value: this,
			writable: false,
			enumerable: false,
			configurable: false
		});
	}
	on(ev, fn) {
		this.listeners[ev].push(fn);
	}
	removeListener(ev, fn) {
		const list = this.listeners[ev];
		const i = list.indexOf(fn);
		/* c8 ignore start */
		if (i === -1) return;
		/* c8 ignore stop */
		if (i === 0 && list.length === 1) list.length = 0;
		else list.splice(i, 1);
	}
	emit(ev, code, signal) {
		if (this.emitted[ev]) return false;
		this.emitted[ev] = true;
		let ret = false;
		for (const fn of this.listeners[ev]) ret = fn(code, signal) === true || ret;
		if (ev === "exit") ret = this.emit("afterExit", code, signal) || ret;
		return ret;
	}
};
var SignalExitBase = class {};
const signalExitWrap = (handler) => {
	return {
		onExit(cb, opts) {
			return handler.onExit(cb, opts);
		},
		load() {
			return handler.load();
		},
		unload() {
			return handler.unload();
		}
	};
};
var SignalExitFallback = class extends SignalExitBase {
	onExit() {
		return () => {};
	}
	load() {}
	unload() {}
};
var _hupSig = /* @__PURE__ */ new WeakMap();
var _emitter = /* @__PURE__ */ new WeakMap();
var _process = /* @__PURE__ */ new WeakMap();
var _originalProcessEmit = /* @__PURE__ */ new WeakMap();
var _originalProcessReallyExit = /* @__PURE__ */ new WeakMap();
var _sigListeners = /* @__PURE__ */ new WeakMap();
var _loaded = /* @__PURE__ */ new WeakMap();
var _SignalExit_brand = /* @__PURE__ */ new WeakSet();
var SignalExit = class extends SignalExitBase {
	constructor(_process2) {
		super();
		_classPrivateMethodInitSpec(this, _SignalExit_brand);
		_classPrivateFieldInitSpec(this, _hupSig, process$2.platform === "win32" ? "SIGINT" : "SIGHUP");
		_classPrivateFieldInitSpec(this, _emitter, new Emitter());
		_classPrivateFieldInitSpec(this, _process, void 0);
		_classPrivateFieldInitSpec(this, _originalProcessEmit, void 0);
		_classPrivateFieldInitSpec(this, _originalProcessReallyExit, void 0);
		_classPrivateFieldInitSpec(this, _sigListeners, {});
		_classPrivateFieldInitSpec(this, _loaded, false);
		_classPrivateFieldSet2(_process, this, _process2);
		_classPrivateFieldSet2(_sigListeners, this, {});
		for (const sig of signals) _classPrivateFieldGet2(_sigListeners, this)[sig] = () => {
			const listeners = _classPrivateFieldGet2(_process, this).listeners(sig);
			let { count } = _classPrivateFieldGet2(_emitter, this);
			/* c8 ignore start */
			const p = _process2;
			if (typeof p.__signal_exit_emitter__ === "object" && typeof p.__signal_exit_emitter__.count === "number") count += p.__signal_exit_emitter__.count;
			/* c8 ignore stop */
			if (listeners.length === count) {
				this.unload();
				const ret = _classPrivateFieldGet2(_emitter, this).emit("exit", null, sig);
				/* c8 ignore start */
				const s = sig === "SIGHUP" ? _classPrivateFieldGet2(_hupSig, this) : sig;
				if (!ret) _process2.kill(_process2.pid, s);
			}
		};
		_classPrivateFieldSet2(_originalProcessReallyExit, this, _process2.reallyExit);
		_classPrivateFieldSet2(_originalProcessEmit, this, _process2.emit);
	}
	onExit(cb, opts) {
		/* c8 ignore start */
		if (!processOk(_classPrivateFieldGet2(_process, this))) return () => {};
		/* c8 ignore stop */
		if (_classPrivateFieldGet2(_loaded, this) === false) this.load();
		const ev = opts?.alwaysLast ? "afterExit" : "exit";
		_classPrivateFieldGet2(_emitter, this).on(ev, cb);
		return () => {
			_classPrivateFieldGet2(_emitter, this).removeListener(ev, cb);
			if (_classPrivateFieldGet2(_emitter, this).listeners["exit"].length === 0 && _classPrivateFieldGet2(_emitter, this).listeners["afterExit"].length === 0) this.unload();
		};
	}
	load() {
		if (_classPrivateFieldGet2(_loaded, this)) return;
		_classPrivateFieldSet2(_loaded, this, true);
		_classPrivateFieldGet2(_emitter, this).count += 1;
		for (const sig of signals) try {
			const fn = _classPrivateFieldGet2(_sigListeners, this)[sig];
			if (fn) _classPrivateFieldGet2(_process, this).on(sig, fn);
		} catch (_) {}
		_classPrivateFieldGet2(_process, this).emit = (ev, ...a) => {
			return _assertClassBrand(_SignalExit_brand, this, _processEmit).call(this, ev, ...a);
		};
		_classPrivateFieldGet2(_process, this).reallyExit = (code) => {
			return _assertClassBrand(_SignalExit_brand, this, _processReallyExit).call(this, code);
		};
	}
	unload() {
		if (!_classPrivateFieldGet2(_loaded, this)) return;
		_classPrivateFieldSet2(_loaded, this, false);
		signals.forEach((sig) => {
			const listener = _classPrivateFieldGet2(_sigListeners, this)[sig];
			/* c8 ignore start */
			if (!listener) throw new Error("Listener not defined for signal: " + sig);
			/* c8 ignore stop */
			try {
				_classPrivateFieldGet2(_process, this).removeListener(sig, listener);
			} catch (_) {}
			/* c8 ignore stop */
		});
		_classPrivateFieldGet2(_process, this).emit = _classPrivateFieldGet2(_originalProcessEmit, this);
		_classPrivateFieldGet2(_process, this).reallyExit = _classPrivateFieldGet2(_originalProcessReallyExit, this);
		_classPrivateFieldGet2(_emitter, this).count -= 1;
	}
};
function _processReallyExit(code) {
	/* c8 ignore start */
	if (!processOk(_classPrivateFieldGet2(_process, this))) return 0;
	_classPrivateFieldGet2(_process, this).exitCode = code || 0;
	/* c8 ignore stop */
	_classPrivateFieldGet2(_emitter, this).emit("exit", _classPrivateFieldGet2(_process, this).exitCode, null);
	return _classPrivateFieldGet2(_originalProcessReallyExit, this).call(_classPrivateFieldGet2(_process, this), _classPrivateFieldGet2(_process, this).exitCode);
}
function _processEmit(ev, ...args) {
	const og = _classPrivateFieldGet2(_originalProcessEmit, this);
	if (ev === "exit" && processOk(_classPrivateFieldGet2(_process, this))) {
		if (typeof args[0] === "number") _classPrivateFieldGet2(_process, this).exitCode = args[0];
		/* c8 ignore start */
		const ret = og.call(_classPrivateFieldGet2(_process, this), ev, ...args);
		/* c8 ignore start */
		_classPrivateFieldGet2(_emitter, this).emit("exit", _classPrivateFieldGet2(_process, this).exitCode, null);
		/* c8 ignore stop */
		return ret;
	} else return og.call(_classPrivateFieldGet2(_process, this), ev, ...args);
}
const process$2 = globalThis.process;
const { onExit, load, unload } = signalExitWrap(processOk(process$2) ? new SignalExit(process$2) : new SignalExitFallback());

//#endregion
//#region ../../node_modules/.pnpm/restore-cursor@5.1.0/node_modules/restore-cursor/index.js
const terminal = process$1.stderr.isTTY ? process$1.stderr : process$1.stdout.isTTY ? process$1.stdout : void 0;
const restoreCursor = terminal ? onetime_default(() => {
	onExit(() => {
		terminal.write("\x1B[?25h");
	}, { alwaysLast: true });
}) : () => {};
var restore_cursor_default = restoreCursor;

//#endregion
//#region ../../node_modules/.pnpm/cli-cursor@5.0.0/node_modules/cli-cursor/index.js
let isHidden = false;
const cliCursor = {};
cliCursor.show = (writableStream = process$1.stderr) => {
	if (!writableStream.isTTY) return;
	isHidden = false;
	writableStream.write("\x1B[?25h");
};
cliCursor.hide = (writableStream = process$1.stderr) => {
	if (!writableStream.isTTY) return;
	restore_cursor_default();
	isHidden = true;
	writableStream.write("\x1B[?25l");
};
cliCursor.toggle = (force, writableStream) => {
	if (force !== void 0) isHidden = force;
	if (isHidden) cliCursor.show(writableStream);
	else cliCursor.hide(writableStream);
};
var cli_cursor_default = cliCursor;

//#endregion
export { _classPrivateFieldInitSpec as a, _assertClassBrand as i, _classPrivateFieldGet2 as n, _classPrivateMethodInitSpec as o, _classPrivateFieldSet2 as r, cli_cursor_default as t };
//# sourceMappingURL=cli-cursor-DNwIWJW3.mjs.map