export function debounce(func, waitMilliseconds) {
    let timeoutId = null;
    const debouncedFunction = function (...args) {
        if (timeoutId !== null) {
            globalThis.clearTimeout(timeoutId);
        }
        timeoutId = globalThis.setTimeout(() => {
            timeoutId = null;
            func.apply(this, args);
        }, waitMilliseconds);
    };
    debouncedFunction.cancel = () => {
        if (timeoutId !== null) {
            globalThis.clearTimeout(timeoutId);
            timeoutId = null;
        }
    };
    return debouncedFunction;
}
//# sourceMappingURL=debounce.js.map