'use strict';function W(v,a=0,t={}){t=Object.assign({},t);let u,o,d,r,n,s,c=0,R=!!t.leading,h=t.trailing!==false;t.maxWait!==void 0&&(d=t.maxWait);let g=()=>Date.now();function p(e){let i=e-(s||0);return s===void 0||i>=a?true:d!==void 0?e-c>=d:false}function b(e){let i=u,f=o;return u=void 0,o=void 0,c=e,r=v.apply(f,i),r}function l(e,i){return setTimeout(e,i)}function x(){n!==void 0&&(clearTimeout(n),n=void 0);}function T(){let e=g();if(p(e))return I(e);let i=e-(s||0),f=e-c,y=a-i;if(d!==void 0){let P=d-f;y=Math.min(y,P);}n=l(T,y);}function k(e){return c=e,n=l(T,a),R?b(e):r}function I(e){return n=void 0,h&&u?b(e):(u=void 0,o=void 0,r)}function m(...e){let i=g(),f=p(i);if(u=e,o=this,s=i,f){if(n===void 0)return k(i);if(d!==void 0)return x(),n=l(T,a),b(i)}return n===void 0&&(n=l(T,a)),r}return m.cancel=function(){n!==void 0&&x(),c=0,u=void 0,s=void 0,o=void 0,n=void 0;},m.flush=function(){return n!==void 0?I(g()):r},m.isPending=function(){return n!==void 0},m}exports.debounce=W;