function e(e,{waitMs:t,timing:n=`trailing`,maxWaitMs:r}){if(r!==void 0&&t!==void 0&&r<t)throw Error(`debounce: maxWaitMs (${r.toString()}) cannot be less than waitMs (${t.toString()})`);let i,a,o,s,c=()=>{if(a!==void 0){let e=a;a=void 0,clearTimeout(e)}if(o===void 0)throw Error(`REMEDA[debounce]: latestCallArgs was unexpectedly undefined.`);let t=o;o=void 0,s=e(...t)},l=()=>{if(i===void 0)return;let e=i;i=void 0,clearTimeout(e),o!==void 0&&c()},u=e=>{o=e,r!==void 0&&a===void 0&&(a=setTimeout(c,r))};return{call:(...a)=>{if(i===void 0)n===`trailing`?u(a):s=e(...a);else{n!==`leading`&&u(a);let e=i;i=void 0,clearTimeout(e)}return i=setTimeout(l,t??r??0),s},cancel:()=>{if(i!==void 0){let e=i;i=void 0,clearTimeout(e)}if(a!==void 0){let e=a;a=void 0,clearTimeout(e)}o=void 0},flush:()=>(l(),s),get isPending(){return i!==void 0},get cachedValue(){return s}}}export{e as debounce};
//# sourceMappingURL=debounce.js.map