import { t as __commonJSMin } from "../rolldown-runtime.mjs";

//#region node_modules/suspend-react/index.cjs.js
var require_index_cjs = /* @__PURE__ */ __commonJSMin(((exports) => {
	Object.defineProperty(exports, "__esModule", { value: true });
	const isPromise = (promise) => typeof promise === "object" && typeof promise.then === "function";
	const globalCache = [];
	function shallowEqualArrays(arrA, arrB, equal = (a, b) => a === b) {
		if (arrA === arrB) return true;
		if (!arrA || !arrB) return false;
		const len = arrA.length;
		if (arrB.length !== len) return false;
		for (let i = 0; i < len; i++) if (!equal(arrA[i], arrB[i])) return false;
		return true;
	}
	function query(fn, keys = null, preload = false, config = {}) {
		if (keys === null) keys = [fn];
		for (const entry$1 of globalCache) if (shallowEqualArrays(keys, entry$1.keys, entry$1.equal)) {
			if (preload) return void 0;
			if (Object.prototype.hasOwnProperty.call(entry$1, "error")) throw entry$1.error;
			if (Object.prototype.hasOwnProperty.call(entry$1, "response")) {
				if (config.lifespan && config.lifespan > 0) {
					if (entry$1.timeout) clearTimeout(entry$1.timeout);
					entry$1.timeout = setTimeout(entry$1.remove, config.lifespan);
				}
				return entry$1.response;
			}
			if (!preload) throw entry$1.promise;
		}
		const entry = {
			keys,
			equal: config.equal,
			remove: () => {
				const index = globalCache.indexOf(entry);
				if (index !== -1) globalCache.splice(index, 1);
			},
			promise: (isPromise(fn) ? fn : fn(...keys)).then((response) => {
				entry.response = response;
				if (config.lifespan && config.lifespan > 0) entry.timeout = setTimeout(entry.remove, config.lifespan);
			}).catch((error) => entry.error = error)
		};
		globalCache.push(entry);
		if (!preload) throw entry.promise;
	}
	const suspend = (fn, keys, config) => query(fn, keys, false, config);
	const preload = (fn, keys, config) => void query(fn, keys, true, config);
	const clear = (keys) => {
		if (keys === void 0 || keys.length === 0) globalCache.splice(0, globalCache.length);
		else {
			const entry = globalCache.find((entry$1) => shallowEqualArrays(keys, entry$1.keys, entry$1.equal));
			if (entry) entry.remove();
		}
	};
	exports.clear = clear;
	exports.preload = preload;
	exports.suspend = suspend;
}));

//#endregion
export { require_index_cjs as t };