run npm install to generate a package lock
This commit is contained in:
3
node_modules/dettle/dist/debounce.d.ts
generated
vendored
Normal file
3
node_modules/dettle/dist/debounce.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import type { FN, DebounceOptions, Debounced } from './types.js';
|
||||
declare const debounce: <Args extends unknown[]>(fn: FN<Args, unknown>, wait?: number, options?: DebounceOptions) => Debounced<Args>;
|
||||
export default debounce;
|
||||
91
node_modules/dettle/dist/debounce.js
generated
vendored
Normal file
91
node_modules/dettle/dist/debounce.js
generated
vendored
Normal file
@@ -0,0 +1,91 @@
|
||||
/* IMPORT */
|
||||
/* MAIN */
|
||||
const debounce = (fn, wait = 1, options) => {
|
||||
/* VARIABLES */
|
||||
wait = Math.max(1, wait);
|
||||
const leading = options?.leading ?? false;
|
||||
const trailing = options?.trailing ?? true;
|
||||
const maxWait = Math.max(options?.maxWait ?? Infinity, wait);
|
||||
let args;
|
||||
let timeout;
|
||||
let timestampCall = 0;
|
||||
let timestampInvoke = 0;
|
||||
/* HELPERS */
|
||||
const getInstantData = () => {
|
||||
const timestamp = Date.now();
|
||||
const elapsedCall = timestamp - timestampCall;
|
||||
const elapsedInvoke = timestamp - timestampInvoke;
|
||||
const isInvoke = (elapsedCall >= wait || elapsedInvoke >= maxWait);
|
||||
return [timestamp, isInvoke];
|
||||
};
|
||||
const invoke = (timestamp) => {
|
||||
timestampInvoke = timestamp;
|
||||
if (!args)
|
||||
return; // This should never happen
|
||||
const _args = args;
|
||||
args = undefined;
|
||||
fn.apply(undefined, _args);
|
||||
};
|
||||
const onCancel = () => {
|
||||
resetTimeout(0);
|
||||
};
|
||||
const onFlush = () => {
|
||||
if (!timeout)
|
||||
return;
|
||||
onCancel();
|
||||
invoke(Date.now());
|
||||
};
|
||||
const onLeading = (timestamp) => {
|
||||
timestampInvoke = timestamp;
|
||||
if (leading)
|
||||
return invoke(timestamp);
|
||||
};
|
||||
const onTrailing = (timestamp) => {
|
||||
if (trailing && args)
|
||||
return invoke(timestamp);
|
||||
args = undefined;
|
||||
};
|
||||
const onTimeout = () => {
|
||||
timeout = undefined;
|
||||
const [timestamp, isInvoking] = getInstantData();
|
||||
if (isInvoking)
|
||||
return onTrailing(timestamp);
|
||||
return updateTimeout(timestamp);
|
||||
};
|
||||
const updateTimeout = (timestamp) => {
|
||||
const elapsedCall = timestamp - timestampCall;
|
||||
const elapsedInvoke = timestamp - timestampInvoke;
|
||||
const remainingCall = wait - elapsedCall;
|
||||
const remainingInvoke = maxWait - elapsedInvoke;
|
||||
const ms = Math.min(remainingCall, remainingInvoke);
|
||||
return resetTimeout(ms);
|
||||
};
|
||||
const resetTimeout = (ms) => {
|
||||
if (timeout)
|
||||
clearTimeout(timeout);
|
||||
if (ms <= 0)
|
||||
return;
|
||||
timeout = setTimeout(onTimeout, ms);
|
||||
};
|
||||
/* DEBOUNCED */
|
||||
const debounced = (...argsLatest) => {
|
||||
const [timestamp, isInvoking] = getInstantData();
|
||||
const hadTimeout = !!timeout;
|
||||
args = argsLatest;
|
||||
timestampCall = timestamp;
|
||||
if (isInvoking || !timeout)
|
||||
resetTimeout(wait);
|
||||
if (isInvoking) {
|
||||
if (!hadTimeout)
|
||||
return onLeading(timestamp);
|
||||
return invoke(timestamp);
|
||||
}
|
||||
};
|
||||
/* DEBOUNCED UTILITIES */
|
||||
debounced.cancel = onCancel;
|
||||
debounced.flush = onFlush;
|
||||
/* RETURN */
|
||||
return debounced;
|
||||
};
|
||||
/* EXPORT */
|
||||
export default debounce;
|
||||
5
node_modules/dettle/dist/index.d.ts
generated
vendored
Normal file
5
node_modules/dettle/dist/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import debounce from './debounce.js';
|
||||
import throttle from './throttle.js';
|
||||
import type { DebounceOptions, Debounced, ThrottleOptions, Throttled } from './types.js';
|
||||
export { debounce, throttle };
|
||||
export type { DebounceOptions, Debounced, ThrottleOptions, Throttled };
|
||||
5
node_modules/dettle/dist/index.js
generated
vendored
Normal file
5
node_modules/dettle/dist/index.js
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
/* IMPORT */
|
||||
import debounce from './debounce.js';
|
||||
import throttle from './throttle.js';
|
||||
/* EXPORT */
|
||||
export { debounce, throttle };
|
||||
3
node_modules/dettle/dist/throttle.d.ts
generated
vendored
Normal file
3
node_modules/dettle/dist/throttle.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import type { FN, ThrottleOptions, Throttled } from './types.js';
|
||||
declare const throttle: <Args extends unknown[]>(fn: FN<Args, unknown>, wait?: number, options?: ThrottleOptions) => Throttled<Args>;
|
||||
export default throttle;
|
||||
12
node_modules/dettle/dist/throttle.js
generated
vendored
Normal file
12
node_modules/dettle/dist/throttle.js
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
/* IMPORT */
|
||||
import debounce from './debounce.js';
|
||||
/* MAIN */
|
||||
const throttle = (fn, wait = 1, options) => {
|
||||
return debounce(fn, wait, {
|
||||
leading: options?.leading ?? true,
|
||||
trailing: options?.trailing ?? true,
|
||||
maxWait: wait
|
||||
});
|
||||
};
|
||||
/* EXPORT */
|
||||
export default throttle;
|
||||
20
node_modules/dettle/dist/types.d.ts
generated
vendored
Normal file
20
node_modules/dettle/dist/types.d.ts
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
type Callback = () => void;
|
||||
type FN<Args extends unknown[], Return> = (...args: Args) => Return;
|
||||
type DebounceOptions = {
|
||||
leading?: boolean;
|
||||
trailing?: boolean;
|
||||
maxWait?: number;
|
||||
};
|
||||
type Debounced<Args extends unknown[]> = FN<Args, void> & {
|
||||
cancel: Callback;
|
||||
flush: Callback;
|
||||
};
|
||||
type ThrottleOptions = {
|
||||
leading?: boolean;
|
||||
trailing?: boolean;
|
||||
};
|
||||
type Throttled<Args extends unknown[]> = FN<Args, void> & {
|
||||
cancel: Callback;
|
||||
flush: Callback;
|
||||
};
|
||||
export type { Callback, FN, DebounceOptions, Debounced, ThrottleOptions, Throttled };
|
||||
2
node_modules/dettle/dist/types.js
generated
vendored
Normal file
2
node_modules/dettle/dist/types.js
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/* MAIN */
|
||||
export {};
|
||||
Reference in New Issue
Block a user