/**
 * Debounce function: delays the execution of the callback until after
 * the specified delay has elapsed since the last invocation.
 */
export const debounce = (callback, delay) => {
    let timer = null;
    return (...args) => {
        if (timer) {
            clearTimeout(timer);
        }
        timer = setTimeout(() => callback(...args), delay);
    };
};
/**
 * Throttle function: ensures the callback is executed at most once
 * during the specified delay period.
 */
export const throttle = (callback, delay) => {
    let isThrottling = false;
    let lastArgs = null;
    return (...args) => {
        if (isThrottling) {
            lastArgs = args;
            return;
        }
        callback(...args);
        isThrottling = true;
        setTimeout(() => {
            isThrottling = false;
            if (lastArgs) {
                callback(...lastArgs);
                lastArgs = null;
            }
        }, delay);
    };
};
//# sourceMappingURL=timing.js.map