/**
 * @since 6.0.0
 */ export function throttle(fn, wait) {
    let args;
    let result;
    let timeout;
    let lastCalledTime = 0;
    const throttled = (...nextArgs)=>{
        args = nextArgs;
        const now = Date.now();
        const remaining = wait - (now - lastCalledTime);
        if (remaining <= 0 || remaining > wait) {
            lastCalledTime = now;
            result = fn(...args);
        } else if (!timeout) {
            timeout = setTimeout(()=>{
                lastCalledTime = Date.now();
                timeout = undefined;
                result = fn(...args);
            }, remaining);
        }
        return result;
    };
    throttled.cancel = ()=>{
        clearTimeout(timeout);
    };
    return throttled;
}

//# sourceMappingURL=throttle.js.map