// ../../node_modules/es-toolkit/dist/function/debounce.mjs
function debounce(func, debounceMs, { signal, edges } = {}) {
  let pendingThis, pendingArgs = null, leading = edges != null && edges.includes("leading"), trailing = edges == null || edges.includes("trailing"), invoke = () => {
    pendingArgs !== null && (func.apply(pendingThis, pendingArgs), pendingThis = void 0, pendingArgs = null);
  }, onTimerEnd = () => {
    trailing && invoke(), cancel();
  }, timeoutId = null, schedule = () => {
    timeoutId != null && clearTimeout(timeoutId), timeoutId = setTimeout(() => {
      timeoutId = null, onTimerEnd();
    }, debounceMs);
  }, cancelTimer = () => {
    timeoutId !== null && (clearTimeout(timeoutId), timeoutId = null);
  }, cancel = () => {
    cancelTimer(), pendingThis = void 0, pendingArgs = null;
  }, flush = () => {
    cancelTimer(), invoke();
  }, debounced = function(...args) {
    if (signal?.aborted)
      return;
    pendingThis = this, pendingArgs = args;
    let isFirstCall = timeoutId == null;
    schedule(), leading && isFirstCall && invoke();
  };
  return debounced.schedule = schedule, debounced.cancel = cancel, debounced.flush = flush, signal?.addEventListener("abort", cancel, { once: !0 }), debounced;
}

// ../../node_modules/es-toolkit/dist/function/partial.mjs
function partial(func, ...partialArgs) {
  return partialImpl(func, placeholderSymbol, ...partialArgs);
}
function partialImpl(func, placeholder, ...partialArgs) {
  let partialed = function(...providedArgs) {
    let providedArgsIndex = 0, substitutedArgs = partialArgs.slice().map((arg) => arg === placeholder ? providedArgs[providedArgsIndex++] : arg), remainingArgs = providedArgs.slice(providedArgsIndex);
    return func.apply(this, substitutedArgs.concat(remainingArgs));
  };
  return func.prototype && (partialed.prototype = Object.create(func.prototype)), partialed;
}
var placeholderSymbol = Symbol("partial.placeholder");
partial.placeholder = placeholderSymbol;

// ../../node_modules/es-toolkit/dist/function/partialRight.mjs
function partialRight(func, ...partialArgs) {
  return partialRightImpl(func, placeholderSymbol2, ...partialArgs);
}
function partialRightImpl(func, placeholder, ...partialArgs) {
  let partialedRight = function(...providedArgs) {
    let placeholderLength = partialArgs.filter((arg) => arg === placeholder).length, rangeLength = Math.max(providedArgs.length - placeholderLength, 0), remainingArgs = providedArgs.slice(0, rangeLength), providedArgsIndex = rangeLength, substitutedArgs = partialArgs.slice().map((arg) => arg === placeholder ? providedArgs[providedArgsIndex++] : arg);
    return func.apply(this, remainingArgs.concat(substitutedArgs));
  };
  return func.prototype && (partialedRight.prototype = Object.create(func.prototype)), partialedRight;
}
var placeholderSymbol2 = Symbol("partialRight.placeholder");
partialRight.placeholder = placeholderSymbol2;

// ../../node_modules/es-toolkit/dist/function/asyncNoop.mjs
async function asyncNoop() {
}

// ../../node_modules/es-toolkit/dist/function/identity.mjs
function identity(x) {
  return x;
}

// ../../node_modules/es-toolkit/dist/function/memoize.mjs
function memoize(fn, options = {}) {
  let { cache = /* @__PURE__ */ new Map(), getCacheKey } = options, memoizedFn = function(arg) {
    let key = getCacheKey ? getCacheKey(arg) : arg;
    if (cache.has(key))
      return cache.get(key);
    let result = fn.call(this, arg);
    return cache.set(key, result), result;
  };
  return memoizedFn.cache = cache, memoizedFn;
}

// ../../node_modules/es-toolkit/dist/function/once.mjs
function once(func) {
  let called = !1, cache;
  return function(...args) {
    return called || (called = !0, cache = func(...args)), cache;
  };
}

// ../../node_modules/es-toolkit/dist/error/AbortError.mjs
var AbortError = class extends Error {
  constructor(message = "The operation was aborted") {
    super(message), this.name = "AbortError";
  }
};

// ../../node_modules/es-toolkit/dist/promise/delay.mjs
function delay(ms, { signal } = {}) {
  return new Promise((resolve, reject) => {
    let abortError = () => {
      reject(new AbortError());
    }, abortHandler = () => {
      clearTimeout(timeoutId), abortError();
    };
    if (signal?.aborted)
      return abortError();
    let timeoutId = setTimeout(() => {
      signal?.removeEventListener("abort", abortHandler), resolve();
    }, ms);
    signal?.addEventListener("abort", abortHandler, { once: !0 });
  });
}

// ../../node_modules/es-toolkit/dist/function/retry.mjs
var DEFAULT_DELAY = 0, DEFAULT_RETRIES = Number.POSITIVE_INFINITY;
async function retry(func, _options) {
  let delay$1, retries, signal;
  typeof _options == "number" ? (delay$1 = DEFAULT_DELAY, retries = _options, signal = void 0) : (delay$1 = _options?.delay ?? DEFAULT_DELAY, retries = _options?.retries ?? DEFAULT_RETRIES, signal = _options?.signal);
  let error;
  for (let attempts = 0; attempts < retries; attempts++) {
    if (signal?.aborted)
      throw error ?? new Error("The retry operation was aborted due to an abort signal.");
    try {
      return await func();
    } catch (err) {
      error = err;
      let currentDelay = typeof delay$1 == "function" ? delay$1(attempts) : delay$1;
      await delay(currentDelay);
    }
  }
  throw error;
}

// ../../node_modules/es-toolkit/dist/function/ary.mjs
function ary(func, n) {
  return function(...args) {
    return func.apply(this, args.slice(0, n));
  };
}

// ../../node_modules/es-toolkit/dist/function/unary.mjs
function unary(func) {
  return ary(func, 1);
}

// ../../node_modules/es-toolkit/dist/function/negate.mjs
function negate(func) {
  return ((...args) => !func(...args));
}

// ../../node_modules/es-toolkit/dist/function/flow.mjs
function flow(...funcs) {
  return function(...args) {
    let result = funcs.length ? funcs[0].apply(this, args) : args[0];
    for (let i = 1; i < funcs.length; i++)
      result = funcs[i].call(this, result);
    return result;
  };
}

// ../../node_modules/es-toolkit/dist/function/flowRight.mjs
function flowRight(...funcs) {
  return flow(...funcs.reverse());
}

// ../../node_modules/es-toolkit/dist/function/rest.mjs
function rest(func, startIndex = func.length - 1) {
  return function(...args) {
    let rest2 = args.slice(startIndex), params = args.slice(0, startIndex);
    for (; params.length < startIndex; )
      params.push(void 0);
    return func.apply(this, [...params, rest2]);
  };
}

// ../../node_modules/es-toolkit/dist/function/after.mjs
function after(n, func) {
  if (!Number.isInteger(n) || n < 0)
    throw new Error("n must be a non-negative integer.");
  let counter = 0;
  return (...args) => {
    if (++counter >= n)
      return func(...args);
  };
}

export {
  partialImpl,
  partialRightImpl,
  AbortError,
  asyncNoop,
  identity,
  memoize,
  once,
  delay,
  retry,
  ary,
  unary,
  negate,
  debounce,
  flow,
  flowRight,
  rest,
  after
};
