@ceale/util 1.7.1 → 1.9.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/README.md +39 -1
- package/dist/cjs/index.js +150 -1
- package/dist/esm/index.js +150 -1
- package/dist/types/bezier.d.ts +96 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/task.d.ts +20 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,3 +1,41 @@
|
|
|
1
1
|
# @ceale/util
|
|
2
2
|
|
|
3
|
-
小工具集
|
|
3
|
+
小工具集
|
|
4
|
+
|
|
5
|
+
提供了
|
|
6
|
+
- String.prototype
|
|
7
|
+
- removePrefix()
|
|
8
|
+
- removeSuffix()
|
|
9
|
+
- removeAllPrefixes()
|
|
10
|
+
- removeAllSuffixes()
|
|
11
|
+
- toCamelCase()
|
|
12
|
+
- toKebabCase()
|
|
13
|
+
- Function.prototype
|
|
14
|
+
- isDirectSubclass()
|
|
15
|
+
- isSubclass()
|
|
16
|
+
- isDirectInstance()
|
|
17
|
+
- isInstance()
|
|
18
|
+
- namespace: `uri`
|
|
19
|
+
- join()
|
|
20
|
+
- namespace: `css`
|
|
21
|
+
- rule()
|
|
22
|
+
- selector()
|
|
23
|
+
- at()
|
|
24
|
+
- join()
|
|
25
|
+
- `time.ts`
|
|
26
|
+
- wait() `# Alias: sleepAsync()`
|
|
27
|
+
- sleep() `# Alias: waitSync()`
|
|
28
|
+
- `task.ts`
|
|
29
|
+
- debounce()
|
|
30
|
+
- throttle()
|
|
31
|
+
- `bezier.ts`
|
|
32
|
+
- namespace `quadraticCurve`
|
|
33
|
+
- solveX()
|
|
34
|
+
- solveY()
|
|
35
|
+
- solveTForX()
|
|
36
|
+
- namespace `cubicCurve`
|
|
37
|
+
- solveX()
|
|
38
|
+
- solveY()
|
|
39
|
+
- solveTForX()
|
|
40
|
+
- class `QuadraticBezier`
|
|
41
|
+
- class `CubicBezier`
|
package/dist/cjs/index.js
CHANGED
|
@@ -32,9 +32,15 @@ __export(exports_src, {
|
|
|
32
32
|
waitSync: () => waitSync,
|
|
33
33
|
wait: () => wait,
|
|
34
34
|
uri: () => uri,
|
|
35
|
+
throttle: () => throttle,
|
|
35
36
|
sleepAsync: () => sleepAsync,
|
|
36
37
|
sleep: () => sleep,
|
|
37
|
-
|
|
38
|
+
quadraticCurve: () => quadraticCurve,
|
|
39
|
+
debounce: () => debounce,
|
|
40
|
+
cubicCurve: () => cubicCurve,
|
|
41
|
+
css: () => css,
|
|
42
|
+
QuadraticBezier: () => QuadraticBezier,
|
|
43
|
+
CubicBezier: () => CubicBezier
|
|
38
44
|
});
|
|
39
45
|
module.exports = __toCommonJS(exports_src);
|
|
40
46
|
|
|
@@ -216,3 +222,146 @@ var sleep = (time) => {
|
|
|
216
222
|
return;
|
|
217
223
|
};
|
|
218
224
|
var waitSync = sleep;
|
|
225
|
+
// src/task.ts
|
|
226
|
+
var debounce = (func, delay) => {
|
|
227
|
+
let timer = null;
|
|
228
|
+
return function(...args) {
|
|
229
|
+
if (timer) {
|
|
230
|
+
clearTimeout(timer);
|
|
231
|
+
}
|
|
232
|
+
timer = setTimeout(() => {
|
|
233
|
+
func.apply(this, args);
|
|
234
|
+
}, delay);
|
|
235
|
+
};
|
|
236
|
+
};
|
|
237
|
+
var throttle = (func, delay) => {
|
|
238
|
+
let timer = false;
|
|
239
|
+
let lastArgs = null;
|
|
240
|
+
return function(...args) {
|
|
241
|
+
if (timer) {
|
|
242
|
+
lastArgs = args;
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
func.apply(this, args);
|
|
246
|
+
timer = true;
|
|
247
|
+
setTimeout(() => {
|
|
248
|
+
if (lastArgs) {
|
|
249
|
+
func.apply(this, lastArgs);
|
|
250
|
+
lastArgs = null;
|
|
251
|
+
}
|
|
252
|
+
timer = false;
|
|
253
|
+
}, delay);
|
|
254
|
+
};
|
|
255
|
+
};
|
|
256
|
+
// src/bezier.ts
|
|
257
|
+
class BezierError extends Error {
|
|
258
|
+
constructor(message) {
|
|
259
|
+
super(message);
|
|
260
|
+
this.name = "BezierError";
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
var quadraticCurve;
|
|
264
|
+
((quadraticCurve) => {
|
|
265
|
+
quadraticCurve.solveX = (p1, t) => {
|
|
266
|
+
const [p1x, p1y] = p1;
|
|
267
|
+
const oneMinusT = 1 - t;
|
|
268
|
+
return 2 * oneMinusT * t * p1x + t * t;
|
|
269
|
+
};
|
|
270
|
+
quadraticCurve.solveY = (p1, t) => {
|
|
271
|
+
const [p1x, p1y] = p1;
|
|
272
|
+
const oneMinusT = 1 - t;
|
|
273
|
+
return 2 * oneMinusT * t * p1y + t * t;
|
|
274
|
+
};
|
|
275
|
+
quadraticCurve.solveTForX = (p1, x, iterations = 8) => {
|
|
276
|
+
let tMin = 0;
|
|
277
|
+
let tMax = 1;
|
|
278
|
+
let tGuess;
|
|
279
|
+
for (let i = 0;i < iterations; i++) {
|
|
280
|
+
tGuess = (tMin + tMax) / 2;
|
|
281
|
+
const xGuess = quadraticCurve.solveX(p1, tGuess);
|
|
282
|
+
if (xGuess < x) {
|
|
283
|
+
tMin = tGuess;
|
|
284
|
+
} else {
|
|
285
|
+
tMax = tGuess;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
return (tMin + tMax) / 2;
|
|
289
|
+
};
|
|
290
|
+
})(quadraticCurve ||= {});
|
|
291
|
+
var cubicCurve;
|
|
292
|
+
((cubicCurve) => {
|
|
293
|
+
cubicCurve.solveX = ([p1, p2], t) => {
|
|
294
|
+
const [p1x, p1y] = p1;
|
|
295
|
+
const [p2x, p2y] = p2;
|
|
296
|
+
const oneMinusT = 1 - t;
|
|
297
|
+
const t2 = t * t;
|
|
298
|
+
return 3 * oneMinusT * oneMinusT * t * p1x + 3 * oneMinusT * t2 * p2x + t2 * t;
|
|
299
|
+
};
|
|
300
|
+
cubicCurve.solveY = ([p1, p2], t) => {
|
|
301
|
+
const [p1x, p1y] = p1;
|
|
302
|
+
const [p2x, p2y] = p2;
|
|
303
|
+
const oneMinusT = 1 - t;
|
|
304
|
+
const t2 = t * t;
|
|
305
|
+
return 3 * oneMinusT * oneMinusT * t * p1y + 3 * oneMinusT * t2 * p2y + t2 * t;
|
|
306
|
+
};
|
|
307
|
+
cubicCurve.solveTForX = ([p1, p2], x, iterations = 12) => {
|
|
308
|
+
let tMin = 0;
|
|
309
|
+
let tMax = 1;
|
|
310
|
+
let tGuess;
|
|
311
|
+
for (let i = 0;i < iterations; i++) {
|
|
312
|
+
tGuess = (tMin + tMax) / 2;
|
|
313
|
+
const xGuess = cubicCurve.solveX([p1, p2], tGuess);
|
|
314
|
+
if (xGuess < x) {
|
|
315
|
+
tMin = tGuess;
|
|
316
|
+
} else {
|
|
317
|
+
tMax = tGuess;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
return (tMin + tMax) / 2;
|
|
321
|
+
};
|
|
322
|
+
})(cubicCurve ||= {});
|
|
323
|
+
|
|
324
|
+
class QuadraticBezier {
|
|
325
|
+
p1;
|
|
326
|
+
constructor(p1) {
|
|
327
|
+
this.p1 = p1;
|
|
328
|
+
if (this.p1[0] < 0 || this.p1[0] > 1) {
|
|
329
|
+
throw new BezierError("控制点P1的x坐标必须在[0, 1]之间");
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
solveX(t) {
|
|
333
|
+
return quadraticCurve.solveX(this.p1, t);
|
|
334
|
+
}
|
|
335
|
+
solveY(t) {
|
|
336
|
+
return quadraticCurve.solveY(this.p1, t);
|
|
337
|
+
}
|
|
338
|
+
solveYForX(x) {
|
|
339
|
+
const t = quadraticCurve.solveTForX(this.p1, x);
|
|
340
|
+
return this.solveY(t);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
class CubicBezier {
|
|
345
|
+
p1;
|
|
346
|
+
p2;
|
|
347
|
+
constructor(p1, p2) {
|
|
348
|
+
this.p1 = p1;
|
|
349
|
+
this.p2 = p2;
|
|
350
|
+
if (this.p1[0] < 0 || this.p1[0] > 1) {
|
|
351
|
+
throw new BezierError("控制点P1的x坐标必须在[0, 1]之间");
|
|
352
|
+
}
|
|
353
|
+
if (this.p2[0] < 0 || this.p2[0] > 1) {
|
|
354
|
+
throw new BezierError("控制点P2的x坐标必须在[0, 1]之间");
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
solveX(t) {
|
|
358
|
+
return cubicCurve.solveX([this.p1, this.p2], t);
|
|
359
|
+
}
|
|
360
|
+
solveY(t) {
|
|
361
|
+
return cubicCurve.solveY([this.p1, this.p2], t);
|
|
362
|
+
}
|
|
363
|
+
solveYForX(x) {
|
|
364
|
+
const t = cubicCurve.solveTForX([this.p1, this.p2], x);
|
|
365
|
+
return this.solveY(t);
|
|
366
|
+
}
|
|
367
|
+
}
|
package/dist/esm/index.js
CHANGED
|
@@ -176,11 +176,160 @@ var sleep = (time) => {
|
|
|
176
176
|
return;
|
|
177
177
|
};
|
|
178
178
|
var waitSync = sleep;
|
|
179
|
+
// src/task.ts
|
|
180
|
+
var debounce = (func, delay) => {
|
|
181
|
+
let timer = null;
|
|
182
|
+
return function(...args) {
|
|
183
|
+
if (timer) {
|
|
184
|
+
clearTimeout(timer);
|
|
185
|
+
}
|
|
186
|
+
timer = setTimeout(() => {
|
|
187
|
+
func.apply(this, args);
|
|
188
|
+
}, delay);
|
|
189
|
+
};
|
|
190
|
+
};
|
|
191
|
+
var throttle = (func, delay) => {
|
|
192
|
+
let timer = false;
|
|
193
|
+
let lastArgs = null;
|
|
194
|
+
return function(...args) {
|
|
195
|
+
if (timer) {
|
|
196
|
+
lastArgs = args;
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
func.apply(this, args);
|
|
200
|
+
timer = true;
|
|
201
|
+
setTimeout(() => {
|
|
202
|
+
if (lastArgs) {
|
|
203
|
+
func.apply(this, lastArgs);
|
|
204
|
+
lastArgs = null;
|
|
205
|
+
}
|
|
206
|
+
timer = false;
|
|
207
|
+
}, delay);
|
|
208
|
+
};
|
|
209
|
+
};
|
|
210
|
+
// src/bezier.ts
|
|
211
|
+
class BezierError extends Error {
|
|
212
|
+
constructor(message) {
|
|
213
|
+
super(message);
|
|
214
|
+
this.name = "BezierError";
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
var quadraticCurve;
|
|
218
|
+
((quadraticCurve) => {
|
|
219
|
+
quadraticCurve.solveX = (p1, t) => {
|
|
220
|
+
const [p1x, p1y] = p1;
|
|
221
|
+
const oneMinusT = 1 - t;
|
|
222
|
+
return 2 * oneMinusT * t * p1x + t * t;
|
|
223
|
+
};
|
|
224
|
+
quadraticCurve.solveY = (p1, t) => {
|
|
225
|
+
const [p1x, p1y] = p1;
|
|
226
|
+
const oneMinusT = 1 - t;
|
|
227
|
+
return 2 * oneMinusT * t * p1y + t * t;
|
|
228
|
+
};
|
|
229
|
+
quadraticCurve.solveTForX = (p1, x, iterations = 8) => {
|
|
230
|
+
let tMin = 0;
|
|
231
|
+
let tMax = 1;
|
|
232
|
+
let tGuess;
|
|
233
|
+
for (let i = 0;i < iterations; i++) {
|
|
234
|
+
tGuess = (tMin + tMax) / 2;
|
|
235
|
+
const xGuess = quadraticCurve.solveX(p1, tGuess);
|
|
236
|
+
if (xGuess < x) {
|
|
237
|
+
tMin = tGuess;
|
|
238
|
+
} else {
|
|
239
|
+
tMax = tGuess;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
return (tMin + tMax) / 2;
|
|
243
|
+
};
|
|
244
|
+
})(quadraticCurve ||= {});
|
|
245
|
+
var cubicCurve;
|
|
246
|
+
((cubicCurve) => {
|
|
247
|
+
cubicCurve.solveX = ([p1, p2], t) => {
|
|
248
|
+
const [p1x, p1y] = p1;
|
|
249
|
+
const [p2x, p2y] = p2;
|
|
250
|
+
const oneMinusT = 1 - t;
|
|
251
|
+
const t2 = t * t;
|
|
252
|
+
return 3 * oneMinusT * oneMinusT * t * p1x + 3 * oneMinusT * t2 * p2x + t2 * t;
|
|
253
|
+
};
|
|
254
|
+
cubicCurve.solveY = ([p1, p2], t) => {
|
|
255
|
+
const [p1x, p1y] = p1;
|
|
256
|
+
const [p2x, p2y] = p2;
|
|
257
|
+
const oneMinusT = 1 - t;
|
|
258
|
+
const t2 = t * t;
|
|
259
|
+
return 3 * oneMinusT * oneMinusT * t * p1y + 3 * oneMinusT * t2 * p2y + t2 * t;
|
|
260
|
+
};
|
|
261
|
+
cubicCurve.solveTForX = ([p1, p2], x, iterations = 12) => {
|
|
262
|
+
let tMin = 0;
|
|
263
|
+
let tMax = 1;
|
|
264
|
+
let tGuess;
|
|
265
|
+
for (let i = 0;i < iterations; i++) {
|
|
266
|
+
tGuess = (tMin + tMax) / 2;
|
|
267
|
+
const xGuess = cubicCurve.solveX([p1, p2], tGuess);
|
|
268
|
+
if (xGuess < x) {
|
|
269
|
+
tMin = tGuess;
|
|
270
|
+
} else {
|
|
271
|
+
tMax = tGuess;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
return (tMin + tMax) / 2;
|
|
275
|
+
};
|
|
276
|
+
})(cubicCurve ||= {});
|
|
277
|
+
|
|
278
|
+
class QuadraticBezier {
|
|
279
|
+
p1;
|
|
280
|
+
constructor(p1) {
|
|
281
|
+
this.p1 = p1;
|
|
282
|
+
if (this.p1[0] < 0 || this.p1[0] > 1) {
|
|
283
|
+
throw new BezierError("控制点P1的x坐标必须在[0, 1]之间");
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
solveX(t) {
|
|
287
|
+
return quadraticCurve.solveX(this.p1, t);
|
|
288
|
+
}
|
|
289
|
+
solveY(t) {
|
|
290
|
+
return quadraticCurve.solveY(this.p1, t);
|
|
291
|
+
}
|
|
292
|
+
solveYForX(x) {
|
|
293
|
+
const t = quadraticCurve.solveTForX(this.p1, x);
|
|
294
|
+
return this.solveY(t);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
class CubicBezier {
|
|
299
|
+
p1;
|
|
300
|
+
p2;
|
|
301
|
+
constructor(p1, p2) {
|
|
302
|
+
this.p1 = p1;
|
|
303
|
+
this.p2 = p2;
|
|
304
|
+
if (this.p1[0] < 0 || this.p1[0] > 1) {
|
|
305
|
+
throw new BezierError("控制点P1的x坐标必须在[0, 1]之间");
|
|
306
|
+
}
|
|
307
|
+
if (this.p2[0] < 0 || this.p2[0] > 1) {
|
|
308
|
+
throw new BezierError("控制点P2的x坐标必须在[0, 1]之间");
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
solveX(t) {
|
|
312
|
+
return cubicCurve.solveX([this.p1, this.p2], t);
|
|
313
|
+
}
|
|
314
|
+
solveY(t) {
|
|
315
|
+
return cubicCurve.solveY([this.p1, this.p2], t);
|
|
316
|
+
}
|
|
317
|
+
solveYForX(x) {
|
|
318
|
+
const t = cubicCurve.solveTForX([this.p1, this.p2], x);
|
|
319
|
+
return this.solveY(t);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
179
322
|
export {
|
|
180
323
|
waitSync,
|
|
181
324
|
wait,
|
|
182
325
|
uri,
|
|
326
|
+
throttle,
|
|
183
327
|
sleepAsync,
|
|
184
328
|
sleep,
|
|
185
|
-
|
|
329
|
+
quadraticCurve,
|
|
330
|
+
debounce,
|
|
331
|
+
cubicCurve,
|
|
332
|
+
css,
|
|
333
|
+
QuadraticBezier,
|
|
334
|
+
CubicBezier
|
|
186
335
|
};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
type Point = [number, number];
|
|
2
|
+
export declare namespace quadraticCurve {
|
|
3
|
+
/**
|
|
4
|
+
* [二次] 给定控制点 P1 和 t (时间),计算 x 坐标
|
|
5
|
+
* @param p1 控制点1 的坐标
|
|
6
|
+
* @param t 时间比例 [0, 1]
|
|
7
|
+
* @returns x 坐标
|
|
8
|
+
*/
|
|
9
|
+
const solveX: (p1: Point, t: number) => number;
|
|
10
|
+
/**
|
|
11
|
+
* [二次] 给定控制点 P1 和 t (时间),计算 y 坐标
|
|
12
|
+
* @param p1 控制点1 坐标
|
|
13
|
+
* @param t 时间比例 [0, 1]
|
|
14
|
+
* @returns y 坐标
|
|
15
|
+
*/
|
|
16
|
+
const solveY: (p1: Point, t: number) => number;
|
|
17
|
+
/**
|
|
18
|
+
* [二次] 给定控制点 P1 和 x (坐标),反向求解 t (时间)
|
|
19
|
+
* 使用二分查找法
|
|
20
|
+
* @param p1 控制点1 坐标
|
|
21
|
+
* @param x 目标 x 坐标 [0, 1]
|
|
22
|
+
* @returns 对应的时间 t
|
|
23
|
+
*/
|
|
24
|
+
const solveTForX: (p1: Point, x: number, iterations?: number) => number;
|
|
25
|
+
}
|
|
26
|
+
export declare namespace cubicCurve {
|
|
27
|
+
/**
|
|
28
|
+
* [三次] 给定控制点 P1, P2 和 t (时间),计算 x 坐标
|
|
29
|
+
* @param \[p1, p2] 控制点1 控制点2 的坐标
|
|
30
|
+
* @param t 时间比例 [0, 1]
|
|
31
|
+
* @returns x 坐标
|
|
32
|
+
*/
|
|
33
|
+
const solveX: ([p1, p2]: [Point, Point], t: number) => number;
|
|
34
|
+
/**
|
|
35
|
+
* [三次] 给定控制点 P1, P2 和 t (时间),计算 y 坐标
|
|
36
|
+
* @param \[p1, p2] 控制点1 控制点2 的坐标
|
|
37
|
+
* @param t 时间比例 [0, 1]
|
|
38
|
+
* @returns y 坐标
|
|
39
|
+
*/
|
|
40
|
+
const solveY: ([p1, p2]: [Point, Point], t: number) => number;
|
|
41
|
+
/**
|
|
42
|
+
* [三次] 给定控制点 P1, P2 和 x (坐标),反向求解 t (时间)
|
|
43
|
+
* 使用二分查找法
|
|
44
|
+
* @param \[p1, p2] 控制点1 控制点2 的坐标
|
|
45
|
+
* @param x 目标 x 坐标 [0, 1]
|
|
46
|
+
* @returns 对应的时间 t
|
|
47
|
+
*/
|
|
48
|
+
const solveTForX: ([p1, p2]: [Point, Point], x: number, iterations?: number) => number;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* 代表一个二次贝塞尔缓动曲线
|
|
52
|
+
*/
|
|
53
|
+
export declare class QuadraticBezier {
|
|
54
|
+
private readonly p1;
|
|
55
|
+
/**
|
|
56
|
+
* @param p1 控制点 P1
|
|
57
|
+
*/
|
|
58
|
+
constructor(p1: Point);
|
|
59
|
+
/**
|
|
60
|
+
* 根据时间 t [0, 1],计算 x 坐标
|
|
61
|
+
*/
|
|
62
|
+
solveX(t: number): number;
|
|
63
|
+
/**
|
|
64
|
+
* 根据时间 t [0, 1],计算 y 坐标
|
|
65
|
+
*/
|
|
66
|
+
solveY(t: number): number;
|
|
67
|
+
/**
|
|
68
|
+
* 根据 x 坐标 [0, 1],计算 y 坐标
|
|
69
|
+
*/
|
|
70
|
+
solveYForX(x: number): number;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* 代表一个三次贝塞尔缓动曲线
|
|
74
|
+
*/
|
|
75
|
+
export declare class CubicBezier {
|
|
76
|
+
private readonly p1;
|
|
77
|
+
private readonly p2;
|
|
78
|
+
/**
|
|
79
|
+
* @param p1 控制点 P1
|
|
80
|
+
* @param p2 控制点 P2
|
|
81
|
+
*/
|
|
82
|
+
constructor(p1: Point, p2: Point);
|
|
83
|
+
/**
|
|
84
|
+
* 根据时间 t [0, 1],计算 x 坐标
|
|
85
|
+
*/
|
|
86
|
+
solveX(t: number): number;
|
|
87
|
+
/**
|
|
88
|
+
* 根据时间 t [0, 1],计算 y 坐标
|
|
89
|
+
*/
|
|
90
|
+
solveY(t: number): number;
|
|
91
|
+
/**
|
|
92
|
+
* 根据 x 坐标 [0, 1],计算 y 坐标
|
|
93
|
+
*/
|
|
94
|
+
solveYForX(x: number): number;
|
|
95
|
+
}
|
|
96
|
+
export {};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 将传入的函数变为防抖版本
|
|
3
|
+
*
|
|
4
|
+
* 在间隔低于`delay`连续触发函数时,只会执行最后一次调用,并在最后一次调用后延时`delay`执行
|
|
5
|
+
* @param func 原始函数
|
|
6
|
+
* @param delay 防抖时长,毫秒
|
|
7
|
+
* @returns 带防抖的函数
|
|
8
|
+
*/
|
|
9
|
+
export declare const debounce: <F extends (...args: any[]) => void>(func: F, delay: number) => ((...args: Parameters<F>) => void);
|
|
10
|
+
/**
|
|
11
|
+
* 将传入的函数变为节流版本
|
|
12
|
+
*
|
|
13
|
+
* 函数将在首次调用后执行,首次调用后的`delay`内,如重复调用,
|
|
14
|
+
*
|
|
15
|
+
* 则函数将以最后一次调用的参数,在首次调用后延迟`delay`后执行
|
|
16
|
+
* @param func 原始函数
|
|
17
|
+
* @param delay 节流时长,毫秒
|
|
18
|
+
* @returns 带节流的函数
|
|
19
|
+
*/
|
|
20
|
+
export declare const throttle: <F extends (...args: any[]) => void>(func: F, delay: number) => ((...args: Parameters<F>) => void);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ceale/util",
|
|
3
3
|
"author": "Ceale",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.9.0",
|
|
5
5
|
"module": "index.ts",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "dist/esm/index.js",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"typescript": "^5"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"
|
|
35
|
-
"
|
|
34
|
+
"csstype": "^3.1.3",
|
|
35
|
+
"vue": "^3.5.21"
|
|
36
36
|
}
|
|
37
37
|
}
|