hypnagaga/docs/assets/throttle-dfed7c30.js
Prasanta Kumar Dutta c523f6e003 build
2023-09-08 17:38:39 +05:30

2 lines
1.3 KiB
JavaScript

import{i as y}from"./isObject-32699ff3.js";import{t as W,n as x}from"./now-bd49f550.js";var S="Expected a function",_=Math.max,p=Math.min;function F(d,t,n){var r,a,g,l,i,f,c=0,E=!1,m=!1,v=!0;if(typeof d!="function")throw new TypeError(S);t=W(t)||0,y(n)&&(E=!!n.leading,m="maxWait"in n,g=m?_(W(n.maxWait)||0,t):g,v="trailing"in n?!!n.trailing:v);function T(e){var u=r,o=a;return r=a=void 0,c=e,l=d.apply(o,u),l}function C(e){return c=e,i=setTimeout(s,t),E?T(e):l}function b(e){var u=e-f,o=e-c,R=t-u;return m?p(R,g-o):R}function k(e){var u=e-f,o=e-c;return f===void 0||u>=t||u<0||m&&o>=g}function s(){var e=x();if(k(e))return I(e);i=setTimeout(s,b(e))}function I(e){return i=void 0,v&&r?T(e):(r=a=void 0,l)}function L(){i!==void 0&&clearTimeout(i),c=0,r=f=a=i=void 0}function M(){return i===void 0?l:I(x())}function h(){var e=x(),u=k(e);if(r=arguments,a=this,f=e,u){if(i===void 0)return C(f);if(m)return clearTimeout(i),i=setTimeout(s,t),T(f)}return i===void 0&&(i=setTimeout(s,t)),l}return h.cancel=L,h.flush=M,h}var N="Expected a function";function U(d,t,n){var r=!0,a=!0;if(typeof d!="function")throw new TypeError(N);return y(n)&&(r="leading"in n?!!n.leading:r,a="trailing"in n?!!n.trailing:a),F(d,t,{leading:r,maxWait:t,trailing:a})}export{U as t};
//# sourceMappingURL=throttle-dfed7c30.js.map