export const debounce = (func, delay) => {
    let timeoutId = null;
    const debounced = function (...args) {
        // Clear the previous timeout if it exists
        if (timeoutId)
            clearTimeout(timeoutId);
        // Set a new timeout
        timeoutId = setTimeout(() => {
            func.apply(this, args);
        }, delay);
    };
    // Method to cancel the debounced function
    debounced.cancel = () => {
        if (timeoutId)
            clearTimeout(timeoutId);
        timeoutId = null;
    };
    return debounced;
};
//# sourceMappingURL=debounce.js.map