@ls-stack/utils 3.57.0 → 3.58.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/asyncQueue.js +2 -2
- package/dist/cache.js +3 -3
- package/dist/{chunk-5MNYPLZI.js → chunk-6FBIEPWU.js} +1 -1
- package/dist/{chunk-NW5H5EW7.js → chunk-CCUPDGSZ.js} +44 -12
- package/dist/chunk-DBOWTYR4.js +49 -0
- package/dist/{chunk-AULH7VMS.js → chunk-DX2524CZ.js} +1 -1
- package/dist/createThrottleController.js +2 -2
- package/dist/debounce.cjs +44 -12
- package/dist/debounce.d.cts +9 -0
- package/dist/debounce.d.ts +9 -0
- package/dist/debounce.js +1 -1
- package/dist/interpolate.js +1 -1
- package/dist/matchPath.js +3 -3
- package/dist/mathUtils.cjs +28 -2
- package/dist/mathUtils.d.cts +48 -1
- package/dist/mathUtils.d.ts +48 -1
- package/dist/mathUtils.js +11 -3
- package/dist/testUtils.js +1 -1
- package/dist/throttle.cjs +43 -11
- package/dist/throttle.js +1 -1
- package/dist/time.js +2 -2
- package/package.json +1 -1
- package/dist/chunk-HTCYUMDR.js +0 -27
package/dist/asyncQueue.js
CHANGED
package/dist/cache.js
CHANGED
|
@@ -4,9 +4,9 @@ import {
|
|
|
4
4
|
cachedGetter,
|
|
5
5
|
createCache,
|
|
6
6
|
fastCache
|
|
7
|
-
} from "./chunk-
|
|
8
|
-
import "./chunk-
|
|
9
|
-
import "./chunk-
|
|
7
|
+
} from "./chunk-DX2524CZ.js";
|
|
8
|
+
import "./chunk-6FBIEPWU.js";
|
|
9
|
+
import "./chunk-DBOWTYR4.js";
|
|
10
10
|
import "./chunk-II4R3VVX.js";
|
|
11
11
|
import "./chunk-C2SVCIWE.js";
|
|
12
12
|
import "./chunk-JF2MDHOJ.js";
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
// src/debounce.ts
|
|
2
2
|
function debounce(func, wait, options) {
|
|
3
|
+
let currentCallback = func;
|
|
4
|
+
let waitMs = wait;
|
|
5
|
+
let currentOptions = options;
|
|
3
6
|
let lastArgs;
|
|
4
7
|
let lastThis;
|
|
5
8
|
let maxWait;
|
|
@@ -10,35 +13,37 @@ function debounce(func, wait, options) {
|
|
|
10
13
|
let leading = false;
|
|
11
14
|
let maxing = false;
|
|
12
15
|
let trailing = true;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
function applyOptions() {
|
|
17
|
+
const opts = currentOptions;
|
|
18
|
+
leading = !!opts?.leading;
|
|
19
|
+
trailing = opts && "trailing" in opts ? !!opts.trailing : true;
|
|
20
|
+
maxing = !!(opts && "maxWait" in opts);
|
|
21
|
+
maxWait = maxing ? Math.max(opts?.maxWait ?? 0, waitMs) : void 0;
|
|
18
22
|
}
|
|
23
|
+
applyOptions();
|
|
19
24
|
function invokeFunc(time) {
|
|
20
25
|
const args = lastArgs;
|
|
21
26
|
const thisArg = lastThis;
|
|
22
27
|
lastArgs = lastThis = void 0;
|
|
23
28
|
lastInvokeTime = time;
|
|
24
|
-
result =
|
|
29
|
+
result = currentCallback.apply(thisArg, args);
|
|
25
30
|
return result;
|
|
26
31
|
}
|
|
27
32
|
function leadingEdge(time) {
|
|
28
33
|
lastInvokeTime = time;
|
|
29
|
-
timerId = setTimeout(timerExpired,
|
|
34
|
+
timerId = setTimeout(timerExpired, waitMs);
|
|
30
35
|
return leading ? invokeFunc(time) : result;
|
|
31
36
|
}
|
|
32
37
|
function remainingWait(time) {
|
|
33
38
|
const timeSinceLastCall = time - (lastCallTime ?? 0);
|
|
34
39
|
const timeSinceLastInvoke = time - lastInvokeTime;
|
|
35
|
-
const timeWaiting =
|
|
40
|
+
const timeWaiting = waitMs - timeSinceLastCall;
|
|
36
41
|
return maxing ? Math.min(timeWaiting, (maxWait ?? 0) - timeSinceLastInvoke) : timeWaiting;
|
|
37
42
|
}
|
|
38
43
|
function shouldInvoke(time) {
|
|
39
44
|
const timeSinceLastCall = time - (lastCallTime ?? 0);
|
|
40
45
|
const timeSinceLastInvoke = time - lastInvokeTime;
|
|
41
|
-
return lastCallTime === void 0 || timeSinceLastCall >=
|
|
46
|
+
return lastCallTime === void 0 || timeSinceLastCall >= waitMs || timeSinceLastCall < 0 || maxing && timeSinceLastInvoke >= (maxWait ?? 0);
|
|
42
47
|
}
|
|
43
48
|
function timerExpired() {
|
|
44
49
|
const time = Date.now();
|
|
@@ -65,6 +70,30 @@ function debounce(func, wait, options) {
|
|
|
65
70
|
function flush() {
|
|
66
71
|
return timerId === void 0 ? result : trailingEdge(Date.now());
|
|
67
72
|
}
|
|
73
|
+
function pending() {
|
|
74
|
+
return timerId !== void 0;
|
|
75
|
+
}
|
|
76
|
+
function updateCb(callback) {
|
|
77
|
+
currentCallback = callback;
|
|
78
|
+
}
|
|
79
|
+
function updateParams(newWait, newOptions) {
|
|
80
|
+
waitMs = newWait;
|
|
81
|
+
if (newOptions !== void 0) {
|
|
82
|
+
currentOptions = newOptions;
|
|
83
|
+
}
|
|
84
|
+
applyOptions();
|
|
85
|
+
if (timerId !== void 0) {
|
|
86
|
+
const time = Date.now();
|
|
87
|
+
const shouldRun = shouldInvoke(time);
|
|
88
|
+
clearTimeout(timerId);
|
|
89
|
+
if (shouldRun) {
|
|
90
|
+
timerId = setTimeout(timerExpired, 0);
|
|
91
|
+
} else {
|
|
92
|
+
const delay = remainingWait(time);
|
|
93
|
+
timerId = setTimeout(timerExpired, delay > 0 ? delay : 0);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
68
97
|
function debounced() {
|
|
69
98
|
const time = Date.now();
|
|
70
99
|
const isInvoking = shouldInvoke(time);
|
|
@@ -77,21 +106,24 @@ function debounce(func, wait, options) {
|
|
|
77
106
|
}
|
|
78
107
|
if (maxing) {
|
|
79
108
|
clearTimeout(timerId);
|
|
80
|
-
timerId = setTimeout(timerExpired,
|
|
109
|
+
timerId = setTimeout(timerExpired, waitMs);
|
|
81
110
|
return invokeFunc(lastCallTime);
|
|
82
111
|
}
|
|
83
112
|
}
|
|
84
113
|
if (timerId === void 0) {
|
|
85
|
-
timerId = setTimeout(timerExpired,
|
|
114
|
+
timerId = setTimeout(timerExpired, waitMs);
|
|
86
115
|
}
|
|
87
116
|
return result;
|
|
88
117
|
}
|
|
89
118
|
debounced.cancel = cancel;
|
|
90
119
|
debounced.flush = flush;
|
|
120
|
+
debounced.pending = pending;
|
|
121
|
+
debounced.updateCb = updateCb;
|
|
122
|
+
debounced.updateParams = updateParams;
|
|
91
123
|
return debounced;
|
|
92
124
|
}
|
|
93
125
|
function isDebouncedFn(fn) {
|
|
94
|
-
return typeof fn === "function" && "cancel" in fn && "flush" in fn;
|
|
126
|
+
return typeof fn === "function" && "cancel" in fn && typeof fn.cancel === "function" && "flush" in fn && typeof fn.flush === "function" && "pending" in fn && typeof fn.pending === "function" && "updateCb" in fn && typeof fn.updateCb === "function" && "updateParams" in fn && typeof fn.updateParams === "function";
|
|
95
127
|
}
|
|
96
128
|
|
|
97
129
|
export {
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// src/mathUtils.ts
|
|
2
|
+
function clampMax(value, max) {
|
|
3
|
+
return value > max ? max : value;
|
|
4
|
+
}
|
|
5
|
+
function clampMin(value, min) {
|
|
6
|
+
return value < min ? min : value;
|
|
7
|
+
}
|
|
8
|
+
function clampRange(num, v1, v2) {
|
|
9
|
+
if (v2 > v1) {
|
|
10
|
+
return clamp(num, v1, v2);
|
|
11
|
+
}
|
|
12
|
+
return clamp(num, v2, v1);
|
|
13
|
+
}
|
|
14
|
+
function clamp(num, min, max) {
|
|
15
|
+
return num > max ? max : num < min ? min : num;
|
|
16
|
+
}
|
|
17
|
+
function fixFloatingPointNumber(value) {
|
|
18
|
+
return Number(value.toPrecision(15));
|
|
19
|
+
}
|
|
20
|
+
function roundToStep(value, step, offset = 0) {
|
|
21
|
+
const inv = 1 / step;
|
|
22
|
+
const snapped = Math.round((value - offset) * inv) / inv + offset;
|
|
23
|
+
return Number(snapped.toFixed(12));
|
|
24
|
+
}
|
|
25
|
+
function floorToStep(value, step, offset = 0) {
|
|
26
|
+
const inv = 1 / step;
|
|
27
|
+
const snapped = Math.floor((value - offset) * inv) / inv + offset;
|
|
28
|
+
return Number(snapped.toFixed(12));
|
|
29
|
+
}
|
|
30
|
+
function ceilToStep(value, step, offset = 0) {
|
|
31
|
+
const inv = 1 / step;
|
|
32
|
+
const snapped = Math.ceil((value - offset) * inv) / inv + offset;
|
|
33
|
+
return Number(snapped.toFixed(12));
|
|
34
|
+
}
|
|
35
|
+
function round(num, precision) {
|
|
36
|
+
return Math.round(num * 10 ** precision) / 10 ** precision;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export {
|
|
40
|
+
clampMax,
|
|
41
|
+
clampMin,
|
|
42
|
+
clampRange,
|
|
43
|
+
clamp,
|
|
44
|
+
fixFloatingPointNumber,
|
|
45
|
+
roundToStep,
|
|
46
|
+
floorToStep,
|
|
47
|
+
ceilToStep,
|
|
48
|
+
round
|
|
49
|
+
};
|
|
@@ -3,8 +3,8 @@ import {
|
|
|
3
3
|
} from "./chunk-7CQPOM5I.js";
|
|
4
4
|
import {
|
|
5
5
|
durationObjToMs
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
import "./chunk-
|
|
6
|
+
} from "./chunk-6FBIEPWU.js";
|
|
7
|
+
import "./chunk-DBOWTYR4.js";
|
|
8
8
|
import "./chunk-II4R3VVX.js";
|
|
9
9
|
import "./chunk-C2SVCIWE.js";
|
|
10
10
|
import "./chunk-JF2MDHOJ.js";
|
package/dist/debounce.cjs
CHANGED
|
@@ -25,6 +25,9 @@ __export(debounce_exports, {
|
|
|
25
25
|
});
|
|
26
26
|
module.exports = __toCommonJS(debounce_exports);
|
|
27
27
|
function debounce(func, wait, options) {
|
|
28
|
+
let currentCallback = func;
|
|
29
|
+
let waitMs = wait;
|
|
30
|
+
let currentOptions = options;
|
|
28
31
|
let lastArgs;
|
|
29
32
|
let lastThis;
|
|
30
33
|
let maxWait;
|
|
@@ -35,35 +38,37 @@ function debounce(func, wait, options) {
|
|
|
35
38
|
let leading = false;
|
|
36
39
|
let maxing = false;
|
|
37
40
|
let trailing = true;
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
function applyOptions() {
|
|
42
|
+
const opts = currentOptions;
|
|
43
|
+
leading = !!opts?.leading;
|
|
44
|
+
trailing = opts && "trailing" in opts ? !!opts.trailing : true;
|
|
45
|
+
maxing = !!(opts && "maxWait" in opts);
|
|
46
|
+
maxWait = maxing ? Math.max(opts?.maxWait ?? 0, waitMs) : void 0;
|
|
43
47
|
}
|
|
48
|
+
applyOptions();
|
|
44
49
|
function invokeFunc(time) {
|
|
45
50
|
const args = lastArgs;
|
|
46
51
|
const thisArg = lastThis;
|
|
47
52
|
lastArgs = lastThis = void 0;
|
|
48
53
|
lastInvokeTime = time;
|
|
49
|
-
result =
|
|
54
|
+
result = currentCallback.apply(thisArg, args);
|
|
50
55
|
return result;
|
|
51
56
|
}
|
|
52
57
|
function leadingEdge(time) {
|
|
53
58
|
lastInvokeTime = time;
|
|
54
|
-
timerId = setTimeout(timerExpired,
|
|
59
|
+
timerId = setTimeout(timerExpired, waitMs);
|
|
55
60
|
return leading ? invokeFunc(time) : result;
|
|
56
61
|
}
|
|
57
62
|
function remainingWait(time) {
|
|
58
63
|
const timeSinceLastCall = time - (lastCallTime ?? 0);
|
|
59
64
|
const timeSinceLastInvoke = time - lastInvokeTime;
|
|
60
|
-
const timeWaiting =
|
|
65
|
+
const timeWaiting = waitMs - timeSinceLastCall;
|
|
61
66
|
return maxing ? Math.min(timeWaiting, (maxWait ?? 0) - timeSinceLastInvoke) : timeWaiting;
|
|
62
67
|
}
|
|
63
68
|
function shouldInvoke(time) {
|
|
64
69
|
const timeSinceLastCall = time - (lastCallTime ?? 0);
|
|
65
70
|
const timeSinceLastInvoke = time - lastInvokeTime;
|
|
66
|
-
return lastCallTime === void 0 || timeSinceLastCall >=
|
|
71
|
+
return lastCallTime === void 0 || timeSinceLastCall >= waitMs || timeSinceLastCall < 0 || maxing && timeSinceLastInvoke >= (maxWait ?? 0);
|
|
67
72
|
}
|
|
68
73
|
function timerExpired() {
|
|
69
74
|
const time = Date.now();
|
|
@@ -90,6 +95,30 @@ function debounce(func, wait, options) {
|
|
|
90
95
|
function flush() {
|
|
91
96
|
return timerId === void 0 ? result : trailingEdge(Date.now());
|
|
92
97
|
}
|
|
98
|
+
function pending() {
|
|
99
|
+
return timerId !== void 0;
|
|
100
|
+
}
|
|
101
|
+
function updateCb(callback) {
|
|
102
|
+
currentCallback = callback;
|
|
103
|
+
}
|
|
104
|
+
function updateParams(newWait, newOptions) {
|
|
105
|
+
waitMs = newWait;
|
|
106
|
+
if (newOptions !== void 0) {
|
|
107
|
+
currentOptions = newOptions;
|
|
108
|
+
}
|
|
109
|
+
applyOptions();
|
|
110
|
+
if (timerId !== void 0) {
|
|
111
|
+
const time = Date.now();
|
|
112
|
+
const shouldRun = shouldInvoke(time);
|
|
113
|
+
clearTimeout(timerId);
|
|
114
|
+
if (shouldRun) {
|
|
115
|
+
timerId = setTimeout(timerExpired, 0);
|
|
116
|
+
} else {
|
|
117
|
+
const delay = remainingWait(time);
|
|
118
|
+
timerId = setTimeout(timerExpired, delay > 0 ? delay : 0);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
93
122
|
function debounced() {
|
|
94
123
|
const time = Date.now();
|
|
95
124
|
const isInvoking = shouldInvoke(time);
|
|
@@ -102,21 +131,24 @@ function debounce(func, wait, options) {
|
|
|
102
131
|
}
|
|
103
132
|
if (maxing) {
|
|
104
133
|
clearTimeout(timerId);
|
|
105
|
-
timerId = setTimeout(timerExpired,
|
|
134
|
+
timerId = setTimeout(timerExpired, waitMs);
|
|
106
135
|
return invokeFunc(lastCallTime);
|
|
107
136
|
}
|
|
108
137
|
}
|
|
109
138
|
if (timerId === void 0) {
|
|
110
|
-
timerId = setTimeout(timerExpired,
|
|
139
|
+
timerId = setTimeout(timerExpired, waitMs);
|
|
111
140
|
}
|
|
112
141
|
return result;
|
|
113
142
|
}
|
|
114
143
|
debounced.cancel = cancel;
|
|
115
144
|
debounced.flush = flush;
|
|
145
|
+
debounced.pending = pending;
|
|
146
|
+
debounced.updateCb = updateCb;
|
|
147
|
+
debounced.updateParams = updateParams;
|
|
116
148
|
return debounced;
|
|
117
149
|
}
|
|
118
150
|
function isDebouncedFn(fn) {
|
|
119
|
-
return typeof fn === "function" && "cancel" in fn && "flush" in fn;
|
|
151
|
+
return typeof fn === "function" && "cancel" in fn && typeof fn.cancel === "function" && "flush" in fn && typeof fn.flush === "function" && "pending" in fn && typeof fn.pending === "function" && "updateCb" in fn && typeof fn.updateCb === "function" && "updateParams" in fn && typeof fn.updateParams === "function";
|
|
120
152
|
}
|
|
121
153
|
// Annotate the CommonJS export names for ESM import in node:
|
|
122
154
|
0 && (module.exports = {
|
package/dist/debounce.d.cts
CHANGED
|
@@ -27,11 +27,20 @@ interface DebouncedFunc<T extends (...args: any[]) => void> {
|
|
|
27
27
|
* debounced function was never invoked.
|
|
28
28
|
*/
|
|
29
29
|
flush: () => ReturnType<T> | undefined;
|
|
30
|
+
/** Return true if the debounced function still has a scheduled run. */
|
|
31
|
+
pending: () => boolean;
|
|
32
|
+
/** Update the debounced function with a new callback. */
|
|
33
|
+
updateCb: (callback: T) => void;
|
|
34
|
+
/** Update the debounce wait and options while keeping scheduled runs. */
|
|
35
|
+
updateParams: (wait: number, options?: DebounceOptions) => void;
|
|
30
36
|
}
|
|
31
37
|
declare function debounce<T extends (...args: any[]) => void>(func: T, wait: number, options?: DebounceOptions): DebouncedFunc<T>;
|
|
32
38
|
declare function isDebouncedFn<T extends (...args: any[]) => void>(fn: T): fn is T & {
|
|
33
39
|
cancel: () => void;
|
|
34
40
|
flush: () => ReturnType<T> | undefined;
|
|
41
|
+
pending: () => boolean;
|
|
42
|
+
updateCb: (callback: T) => void;
|
|
43
|
+
updateParams: (wait: number, options?: DebounceOptions) => void;
|
|
35
44
|
};
|
|
36
45
|
|
|
37
46
|
export { type DebounceOptions, type DebouncedFunc, debounce, isDebouncedFn };
|
package/dist/debounce.d.ts
CHANGED
|
@@ -27,11 +27,20 @@ interface DebouncedFunc<T extends (...args: any[]) => void> {
|
|
|
27
27
|
* debounced function was never invoked.
|
|
28
28
|
*/
|
|
29
29
|
flush: () => ReturnType<T> | undefined;
|
|
30
|
+
/** Return true if the debounced function still has a scheduled run. */
|
|
31
|
+
pending: () => boolean;
|
|
32
|
+
/** Update the debounced function with a new callback. */
|
|
33
|
+
updateCb: (callback: T) => void;
|
|
34
|
+
/** Update the debounce wait and options while keeping scheduled runs. */
|
|
35
|
+
updateParams: (wait: number, options?: DebounceOptions) => void;
|
|
30
36
|
}
|
|
31
37
|
declare function debounce<T extends (...args: any[]) => void>(func: T, wait: number, options?: DebounceOptions): DebouncedFunc<T>;
|
|
32
38
|
declare function isDebouncedFn<T extends (...args: any[]) => void>(fn: T): fn is T & {
|
|
33
39
|
cancel: () => void;
|
|
34
40
|
flush: () => ReturnType<T> | undefined;
|
|
41
|
+
pending: () => boolean;
|
|
42
|
+
updateCb: (callback: T) => void;
|
|
43
|
+
updateParams: (wait: number, options?: DebounceOptions) => void;
|
|
35
44
|
};
|
|
36
45
|
|
|
37
46
|
export { type DebounceOptions, type DebouncedFunc, debounce, isDebouncedFn };
|
package/dist/debounce.js
CHANGED
package/dist/interpolate.js
CHANGED
package/dist/matchPath.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
fastCache
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import "./chunk-
|
|
5
|
-
import "./chunk-
|
|
3
|
+
} from "./chunk-DX2524CZ.js";
|
|
4
|
+
import "./chunk-6FBIEPWU.js";
|
|
5
|
+
import "./chunk-DBOWTYR4.js";
|
|
6
6
|
import "./chunk-II4R3VVX.js";
|
|
7
7
|
import "./chunk-C2SVCIWE.js";
|
|
8
8
|
import "./chunk-JF2MDHOJ.js";
|
package/dist/mathUtils.cjs
CHANGED
|
@@ -20,11 +20,15 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/mathUtils.ts
|
|
21
21
|
var mathUtils_exports = {};
|
|
22
22
|
__export(mathUtils_exports, {
|
|
23
|
+
ceilToStep: () => ceilToStep,
|
|
23
24
|
clamp: () => clamp,
|
|
24
25
|
clampMax: () => clampMax,
|
|
25
26
|
clampMin: () => clampMin,
|
|
26
27
|
clampRange: () => clampRange,
|
|
27
|
-
fixFloatingPointNumber: () => fixFloatingPointNumber
|
|
28
|
+
fixFloatingPointNumber: () => fixFloatingPointNumber,
|
|
29
|
+
floorToStep: () => floorToStep,
|
|
30
|
+
round: () => round,
|
|
31
|
+
roundToStep: () => roundToStep
|
|
28
32
|
});
|
|
29
33
|
module.exports = __toCommonJS(mathUtils_exports);
|
|
30
34
|
function clampMax(value, max) {
|
|
@@ -45,11 +49,33 @@ function clamp(num, min, max) {
|
|
|
45
49
|
function fixFloatingPointNumber(value) {
|
|
46
50
|
return Number(value.toPrecision(15));
|
|
47
51
|
}
|
|
52
|
+
function roundToStep(value, step, offset = 0) {
|
|
53
|
+
const inv = 1 / step;
|
|
54
|
+
const snapped = Math.round((value - offset) * inv) / inv + offset;
|
|
55
|
+
return Number(snapped.toFixed(12));
|
|
56
|
+
}
|
|
57
|
+
function floorToStep(value, step, offset = 0) {
|
|
58
|
+
const inv = 1 / step;
|
|
59
|
+
const snapped = Math.floor((value - offset) * inv) / inv + offset;
|
|
60
|
+
return Number(snapped.toFixed(12));
|
|
61
|
+
}
|
|
62
|
+
function ceilToStep(value, step, offset = 0) {
|
|
63
|
+
const inv = 1 / step;
|
|
64
|
+
const snapped = Math.ceil((value - offset) * inv) / inv + offset;
|
|
65
|
+
return Number(snapped.toFixed(12));
|
|
66
|
+
}
|
|
67
|
+
function round(num, precision) {
|
|
68
|
+
return Math.round(num * 10 ** precision) / 10 ** precision;
|
|
69
|
+
}
|
|
48
70
|
// Annotate the CommonJS export names for ESM import in node:
|
|
49
71
|
0 && (module.exports = {
|
|
72
|
+
ceilToStep,
|
|
50
73
|
clamp,
|
|
51
74
|
clampMax,
|
|
52
75
|
clampMin,
|
|
53
76
|
clampRange,
|
|
54
|
-
fixFloatingPointNumber
|
|
77
|
+
fixFloatingPointNumber,
|
|
78
|
+
floorToStep,
|
|
79
|
+
round,
|
|
80
|
+
roundToStep
|
|
55
81
|
});
|
package/dist/mathUtils.d.cts
CHANGED
|
@@ -3,5 +3,52 @@ declare function clampMin(value: number, min: number): number;
|
|
|
3
3
|
declare function clampRange(num: number, v1: number, v2: number): number;
|
|
4
4
|
declare function clamp(num: number, min: number, max: number): number;
|
|
5
5
|
declare function fixFloatingPointNumber(value: number): number;
|
|
6
|
+
/**
|
|
7
|
+
* Rounds a number to the nearest multiple of the specified step value.
|
|
8
|
+
*
|
|
9
|
+
* @param value - The number to round
|
|
10
|
+
* @param step - The step size to round to
|
|
11
|
+
* @param offset - Optional offset to shift the rounding grid
|
|
12
|
+
* @returns The rounded value
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* roundToStep(23, 5) // 25 (nearest multiple of 5)
|
|
16
|
+
*/
|
|
17
|
+
declare function roundToStep(value: number, step: number, offset?: number): number;
|
|
18
|
+
/**
|
|
19
|
+
* Floors a number down to the nearest multiple of the specified step value.
|
|
20
|
+
*
|
|
21
|
+
* @param value - The number to floor
|
|
22
|
+
* @param step - The step size to floor to
|
|
23
|
+
* @param offset - Optional offset to shift the flooring grid
|
|
24
|
+
* @returns The floored value
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* floorToStep(23, 5) // 20 (largest multiple of 5 ≤ 23)
|
|
28
|
+
*/
|
|
29
|
+
declare function floorToStep(value: number, step: number, offset?: number): number;
|
|
30
|
+
/**
|
|
31
|
+
* Ceils a number up to the nearest multiple of the specified step value.
|
|
32
|
+
*
|
|
33
|
+
* @param value - The number to ceil
|
|
34
|
+
* @param step - The step size to ceil to
|
|
35
|
+
* @param offset - Optional offset to shift the ceiling grid
|
|
36
|
+
* @returns The ceiled value
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ceilToStep(23, 5) // 25 (smallest multiple of 5 ≥ 23)
|
|
40
|
+
*/
|
|
41
|
+
declare function ceilToStep(value: number, step: number, offset?: number): number;
|
|
42
|
+
/**
|
|
43
|
+
* Rounds a number to the specified number of decimal places.
|
|
44
|
+
*
|
|
45
|
+
* @param num - The number to round
|
|
46
|
+
* @param precision - Number of decimal places
|
|
47
|
+
* @returns The rounded number
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* round(3.14159, 2) // 3.14
|
|
51
|
+
*/
|
|
52
|
+
declare function round(num: number, precision: number): number;
|
|
6
53
|
|
|
7
|
-
export { clamp, clampMax, clampMin, clampRange, fixFloatingPointNumber };
|
|
54
|
+
export { ceilToStep, clamp, clampMax, clampMin, clampRange, fixFloatingPointNumber, floorToStep, round, roundToStep };
|
package/dist/mathUtils.d.ts
CHANGED
|
@@ -3,5 +3,52 @@ declare function clampMin(value: number, min: number): number;
|
|
|
3
3
|
declare function clampRange(num: number, v1: number, v2: number): number;
|
|
4
4
|
declare function clamp(num: number, min: number, max: number): number;
|
|
5
5
|
declare function fixFloatingPointNumber(value: number): number;
|
|
6
|
+
/**
|
|
7
|
+
* Rounds a number to the nearest multiple of the specified step value.
|
|
8
|
+
*
|
|
9
|
+
* @param value - The number to round
|
|
10
|
+
* @param step - The step size to round to
|
|
11
|
+
* @param offset - Optional offset to shift the rounding grid
|
|
12
|
+
* @returns The rounded value
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* roundToStep(23, 5) // 25 (nearest multiple of 5)
|
|
16
|
+
*/
|
|
17
|
+
declare function roundToStep(value: number, step: number, offset?: number): number;
|
|
18
|
+
/**
|
|
19
|
+
* Floors a number down to the nearest multiple of the specified step value.
|
|
20
|
+
*
|
|
21
|
+
* @param value - The number to floor
|
|
22
|
+
* @param step - The step size to floor to
|
|
23
|
+
* @param offset - Optional offset to shift the flooring grid
|
|
24
|
+
* @returns The floored value
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* floorToStep(23, 5) // 20 (largest multiple of 5 ≤ 23)
|
|
28
|
+
*/
|
|
29
|
+
declare function floorToStep(value: number, step: number, offset?: number): number;
|
|
30
|
+
/**
|
|
31
|
+
* Ceils a number up to the nearest multiple of the specified step value.
|
|
32
|
+
*
|
|
33
|
+
* @param value - The number to ceil
|
|
34
|
+
* @param step - The step size to ceil to
|
|
35
|
+
* @param offset - Optional offset to shift the ceiling grid
|
|
36
|
+
* @returns The ceiled value
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ceilToStep(23, 5) // 25 (smallest multiple of 5 ≥ 23)
|
|
40
|
+
*/
|
|
41
|
+
declare function ceilToStep(value: number, step: number, offset?: number): number;
|
|
42
|
+
/**
|
|
43
|
+
* Rounds a number to the specified number of decimal places.
|
|
44
|
+
*
|
|
45
|
+
* @param num - The number to round
|
|
46
|
+
* @param precision - Number of decimal places
|
|
47
|
+
* @returns The rounded number
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* round(3.14159, 2) // 3.14
|
|
51
|
+
*/
|
|
52
|
+
declare function round(num: number, precision: number): number;
|
|
6
53
|
|
|
7
|
-
export { clamp, clampMax, clampMin, clampRange, fixFloatingPointNumber };
|
|
54
|
+
export { ceilToStep, clamp, clampMax, clampMin, clampRange, fixFloatingPointNumber, floorToStep, round, roundToStep };
|
package/dist/mathUtils.js
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
import {
|
|
2
|
+
ceilToStep,
|
|
2
3
|
clamp,
|
|
3
4
|
clampMax,
|
|
4
5
|
clampMin,
|
|
5
6
|
clampRange,
|
|
6
|
-
fixFloatingPointNumber
|
|
7
|
-
|
|
7
|
+
fixFloatingPointNumber,
|
|
8
|
+
floorToStep,
|
|
9
|
+
round,
|
|
10
|
+
roundToStep
|
|
11
|
+
} from "./chunk-DBOWTYR4.js";
|
|
8
12
|
export {
|
|
13
|
+
ceilToStep,
|
|
9
14
|
clamp,
|
|
10
15
|
clampMax,
|
|
11
16
|
clampMin,
|
|
12
17
|
clampRange,
|
|
13
|
-
fixFloatingPointNumber
|
|
18
|
+
fixFloatingPointNumber,
|
|
19
|
+
floorToStep,
|
|
20
|
+
round,
|
|
21
|
+
roundToStep
|
|
14
22
|
};
|
package/dist/testUtils.js
CHANGED
package/dist/throttle.cjs
CHANGED
|
@@ -27,6 +27,9 @@ module.exports = __toCommonJS(throttle_exports);
|
|
|
27
27
|
|
|
28
28
|
// src/debounce.ts
|
|
29
29
|
function debounce(func, wait, options) {
|
|
30
|
+
let currentCallback = func;
|
|
31
|
+
let waitMs = wait;
|
|
32
|
+
let currentOptions = options;
|
|
30
33
|
let lastArgs;
|
|
31
34
|
let lastThis;
|
|
32
35
|
let maxWait;
|
|
@@ -37,35 +40,37 @@ function debounce(func, wait, options) {
|
|
|
37
40
|
let leading = false;
|
|
38
41
|
let maxing = false;
|
|
39
42
|
let trailing = true;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
function applyOptions() {
|
|
44
|
+
const opts = currentOptions;
|
|
45
|
+
leading = !!opts?.leading;
|
|
46
|
+
trailing = opts && "trailing" in opts ? !!opts.trailing : true;
|
|
47
|
+
maxing = !!(opts && "maxWait" in opts);
|
|
48
|
+
maxWait = maxing ? Math.max(opts?.maxWait ?? 0, waitMs) : void 0;
|
|
45
49
|
}
|
|
50
|
+
applyOptions();
|
|
46
51
|
function invokeFunc(time) {
|
|
47
52
|
const args = lastArgs;
|
|
48
53
|
const thisArg = lastThis;
|
|
49
54
|
lastArgs = lastThis = void 0;
|
|
50
55
|
lastInvokeTime = time;
|
|
51
|
-
result =
|
|
56
|
+
result = currentCallback.apply(thisArg, args);
|
|
52
57
|
return result;
|
|
53
58
|
}
|
|
54
59
|
function leadingEdge(time) {
|
|
55
60
|
lastInvokeTime = time;
|
|
56
|
-
timerId = setTimeout(timerExpired,
|
|
61
|
+
timerId = setTimeout(timerExpired, waitMs);
|
|
57
62
|
return leading ? invokeFunc(time) : result;
|
|
58
63
|
}
|
|
59
64
|
function remainingWait(time) {
|
|
60
65
|
const timeSinceLastCall = time - (lastCallTime ?? 0);
|
|
61
66
|
const timeSinceLastInvoke = time - lastInvokeTime;
|
|
62
|
-
const timeWaiting =
|
|
67
|
+
const timeWaiting = waitMs - timeSinceLastCall;
|
|
63
68
|
return maxing ? Math.min(timeWaiting, (maxWait ?? 0) - timeSinceLastInvoke) : timeWaiting;
|
|
64
69
|
}
|
|
65
70
|
function shouldInvoke(time) {
|
|
66
71
|
const timeSinceLastCall = time - (lastCallTime ?? 0);
|
|
67
72
|
const timeSinceLastInvoke = time - lastInvokeTime;
|
|
68
|
-
return lastCallTime === void 0 || timeSinceLastCall >=
|
|
73
|
+
return lastCallTime === void 0 || timeSinceLastCall >= waitMs || timeSinceLastCall < 0 || maxing && timeSinceLastInvoke >= (maxWait ?? 0);
|
|
69
74
|
}
|
|
70
75
|
function timerExpired() {
|
|
71
76
|
const time = Date.now();
|
|
@@ -92,6 +97,30 @@ function debounce(func, wait, options) {
|
|
|
92
97
|
function flush() {
|
|
93
98
|
return timerId === void 0 ? result : trailingEdge(Date.now());
|
|
94
99
|
}
|
|
100
|
+
function pending() {
|
|
101
|
+
return timerId !== void 0;
|
|
102
|
+
}
|
|
103
|
+
function updateCb(callback) {
|
|
104
|
+
currentCallback = callback;
|
|
105
|
+
}
|
|
106
|
+
function updateParams(newWait, newOptions) {
|
|
107
|
+
waitMs = newWait;
|
|
108
|
+
if (newOptions !== void 0) {
|
|
109
|
+
currentOptions = newOptions;
|
|
110
|
+
}
|
|
111
|
+
applyOptions();
|
|
112
|
+
if (timerId !== void 0) {
|
|
113
|
+
const time = Date.now();
|
|
114
|
+
const shouldRun = shouldInvoke(time);
|
|
115
|
+
clearTimeout(timerId);
|
|
116
|
+
if (shouldRun) {
|
|
117
|
+
timerId = setTimeout(timerExpired, 0);
|
|
118
|
+
} else {
|
|
119
|
+
const delay = remainingWait(time);
|
|
120
|
+
timerId = setTimeout(timerExpired, delay > 0 ? delay : 0);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
95
124
|
function debounced() {
|
|
96
125
|
const time = Date.now();
|
|
97
126
|
const isInvoking = shouldInvoke(time);
|
|
@@ -104,17 +133,20 @@ function debounce(func, wait, options) {
|
|
|
104
133
|
}
|
|
105
134
|
if (maxing) {
|
|
106
135
|
clearTimeout(timerId);
|
|
107
|
-
timerId = setTimeout(timerExpired,
|
|
136
|
+
timerId = setTimeout(timerExpired, waitMs);
|
|
108
137
|
return invokeFunc(lastCallTime);
|
|
109
138
|
}
|
|
110
139
|
}
|
|
111
140
|
if (timerId === void 0) {
|
|
112
|
-
timerId = setTimeout(timerExpired,
|
|
141
|
+
timerId = setTimeout(timerExpired, waitMs);
|
|
113
142
|
}
|
|
114
143
|
return result;
|
|
115
144
|
}
|
|
116
145
|
debounced.cancel = cancel;
|
|
117
146
|
debounced.flush = flush;
|
|
147
|
+
debounced.pending = pending;
|
|
148
|
+
debounced.updateCb = updateCb;
|
|
149
|
+
debounced.updateParams = updateParams;
|
|
118
150
|
return debounced;
|
|
119
151
|
}
|
|
120
152
|
|
package/dist/throttle.js
CHANGED
package/dist/time.js
CHANGED
|
@@ -15,8 +15,8 @@ import {
|
|
|
15
15
|
getUnixSeconds,
|
|
16
16
|
msToTimeString,
|
|
17
17
|
parseTimeStringToMs
|
|
18
|
-
} from "./chunk-
|
|
19
|
-
import "./chunk-
|
|
18
|
+
} from "./chunk-6FBIEPWU.js";
|
|
19
|
+
import "./chunk-DBOWTYR4.js";
|
|
20
20
|
import "./chunk-II4R3VVX.js";
|
|
21
21
|
export {
|
|
22
22
|
DAY_AS_MS,
|
package/package.json
CHANGED
package/dist/chunk-HTCYUMDR.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
// src/mathUtils.ts
|
|
2
|
-
function clampMax(value, max) {
|
|
3
|
-
return value > max ? max : value;
|
|
4
|
-
}
|
|
5
|
-
function clampMin(value, min) {
|
|
6
|
-
return value < min ? min : value;
|
|
7
|
-
}
|
|
8
|
-
function clampRange(num, v1, v2) {
|
|
9
|
-
if (v2 > v1) {
|
|
10
|
-
return clamp(num, v1, v2);
|
|
11
|
-
}
|
|
12
|
-
return clamp(num, v2, v1);
|
|
13
|
-
}
|
|
14
|
-
function clamp(num, min, max) {
|
|
15
|
-
return num > max ? max : num < min ? min : num;
|
|
16
|
-
}
|
|
17
|
-
function fixFloatingPointNumber(value) {
|
|
18
|
-
return Number(value.toPrecision(15));
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export {
|
|
22
|
-
clampMax,
|
|
23
|
-
clampMin,
|
|
24
|
-
clampRange,
|
|
25
|
-
clamp,
|
|
26
|
-
fixFloatingPointNumber
|
|
27
|
-
};
|