minutool 1.0.26 → 1.0.29
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 +21 -0
- package/dist/index.d.ts +189 -3
- package/dist/minutool.js +523 -443
- package/dist/minutool.js.map +1 -1
- package/dist/minutool.umd.cjs +5 -5
- package/dist/minutool.umd.cjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -109,6 +109,27 @@ const cloned = deepClone(obj)
|
|
|
109
109
|
- `arraySortByKey<T>(obj: T): T` - Sort object by keys
|
|
110
110
|
- `arrayChunk<T>(list: T[], size: number): T[][]` - Split array into chunks
|
|
111
111
|
|
|
112
|
+
### Animate Utilities
|
|
113
|
+
|
|
114
|
+
**Types:**
|
|
115
|
+
- `EasingFn` - Easing function type `(t: number) => number`
|
|
116
|
+
|
|
117
|
+
**Functions:**
|
|
118
|
+
- `linear(t: number): number` - Linear easing (no easing)
|
|
119
|
+
- `easeInQuad(t) / easeOutQuad(t) / easeInOutQuad(t)` - Quadratic easing
|
|
120
|
+
- `easeInCubic(t) / easeOutCubic(t) / easeInOutCubic(t)` - Cubic easing
|
|
121
|
+
- `easeInQuart(t) / easeOutQuart(t) / easeInOutQuart(t)` - Quartic easing
|
|
122
|
+
- `easeInQuint(t) / easeOutQuint(t) / easeInOutQuint(t)` - Quintic easing
|
|
123
|
+
- `easeInSine(t) / easeOutSine(t) / easeInOutSine(t)` - Sine easing
|
|
124
|
+
- `easeInExpo(t) / easeOutExpo(t) / easeInOutExpo(t)` - Exponential easing
|
|
125
|
+
- `easeInCirc(t) / easeOutCirc(t) / easeInOutCirc(t)` - Circular easing
|
|
126
|
+
- `easeInBack(t, s?) / easeOutBack(t, s?) / easeInOutBack(t, s?)` - Back easing (with overshoot)
|
|
127
|
+
- `easeInElastic(t) / easeOutElastic(t) / easeInOutElastic(t)` - Elastic easing
|
|
128
|
+
- `easeInBounce(t) / easeOutBounce(t) / easeInOutBounce(t)` - Bounce easing
|
|
129
|
+
- `clamp01(t: number): number` - Clamp value into [0, 1]
|
|
130
|
+
- `lerp(from: number, to: number, t: number): number` - Linear interpolation
|
|
131
|
+
- `easeValue(from: number, to: number, t: number, easing?: EasingFn): number` - Interpolate with easing applied
|
|
132
|
+
|
|
112
133
|
### Math Utilities
|
|
113
134
|
|
|
114
135
|
**Constants:**
|
package/dist/index.d.ts
CHANGED
|
@@ -151,7 +151,7 @@ export declare const bindClick: (element: EventTarget | string, payload: (event:
|
|
|
151
151
|
* @param payload - 事件回调函数
|
|
152
152
|
* @returns 解绑函数
|
|
153
153
|
*/
|
|
154
|
-
export declare const bindDomEvent: <E extends Event = Event>(element: EventTarget | string, eventName: string, payload: (event: E) => void) => () => void;
|
|
154
|
+
export declare const bindDomEvent: <E extends Event = Event>(element: EventTarget | string, eventName: string, payload: (event: E) => void, options?: boolean | AddEventListenerOptions) => () => void;
|
|
155
155
|
|
|
156
156
|
/**
|
|
157
157
|
* 绑定双击事件,并返回一个解绑函数
|
|
@@ -165,7 +165,7 @@ export declare const bindDoubleClick: (element: EventTarget | string, payload: (
|
|
|
165
165
|
* 为 input/textarea 绑定支持 IME 的防抖函数
|
|
166
166
|
* @param element - DOM 元素
|
|
167
167
|
* @param callback - 回调,参数为 { value, event }
|
|
168
|
-
* @param delay - 防抖延迟(ms),默认
|
|
168
|
+
* @param delay - 防抖延迟(ms),默认 50
|
|
169
169
|
* @returns { destroy, cancel, flush }
|
|
170
170
|
*/
|
|
171
171
|
export declare const bindInputDebounce: (element: HTMLInputElement | HTMLTextAreaElement, callback: (value: string, event: InputEvent) => void, delay?: number) => (() => void);
|
|
@@ -257,6 +257,12 @@ export declare const calcRemainingMSecs: (progress: number, total: number, start
|
|
|
257
257
|
*/
|
|
258
258
|
export declare function camelCase(str: string): string;
|
|
259
259
|
|
|
260
|
+
/**
|
|
261
|
+
* 取消 el 上正在进行的滚动动画(若有),并还原 CSS 滚动行为
|
|
262
|
+
* @param el 要取消滚动动画的元素
|
|
263
|
+
*/
|
|
264
|
+
export declare function cancelScrollAnimation(el: HTMLElement): void;
|
|
265
|
+
|
|
260
266
|
/**
|
|
261
267
|
* 首字母大写
|
|
262
268
|
* @param str - 输入字符串
|
|
@@ -266,6 +272,16 @@ export declare function camelCase(str: string): string;
|
|
|
266
272
|
*/
|
|
267
273
|
export declare function capitalize(str: string): string;
|
|
268
274
|
|
|
275
|
+
/**
|
|
276
|
+
* 将任意数值限制到 [0, 1] 区间,常用于保证动画进度合法
|
|
277
|
+
* @param t - 进度值
|
|
278
|
+
* @returns 限制后的进度
|
|
279
|
+
* @example
|
|
280
|
+
* clamp01(-0.5) // 0
|
|
281
|
+
* clamp01(1.5) // 1
|
|
282
|
+
*/
|
|
283
|
+
export declare const clamp01: (t: number) => number;
|
|
284
|
+
|
|
269
285
|
/**
|
|
270
286
|
* 清理对象中的 null 值
|
|
271
287
|
* @param {any} obj - 要清理的对象
|
|
@@ -437,6 +453,135 @@ export { dispatchEvent_2 as dispatchEvent }
|
|
|
437
453
|
*/
|
|
438
454
|
export declare const downloadFile: (uri: string, fileName: string) => void;
|
|
439
455
|
|
|
456
|
+
/**
|
|
457
|
+
* 回退缓入:先向后蓄力再前进
|
|
458
|
+
* @param t - 时间进度,范围 [0, 1]
|
|
459
|
+
* @param s - 过冲系数,默认为 1.70158
|
|
460
|
+
* @returns 缓动后的值
|
|
461
|
+
*/
|
|
462
|
+
export declare const easeInBack: (t: number, s?: number) => number;
|
|
463
|
+
|
|
464
|
+
/** 弹跳缓入 */
|
|
465
|
+
export declare const easeInBounce: (t: number) => number;
|
|
466
|
+
|
|
467
|
+
/** 圆形缓入 */
|
|
468
|
+
export declare const easeInCirc: (t: number) => number;
|
|
469
|
+
|
|
470
|
+
/** 三次方缓入:由慢到快 */
|
|
471
|
+
export declare const easeInCubic: (t: number) => number;
|
|
472
|
+
|
|
473
|
+
/** 弹性缓入 */
|
|
474
|
+
export declare const easeInElastic: (t: number) => number;
|
|
475
|
+
|
|
476
|
+
/** 指数缓入 */
|
|
477
|
+
export declare const easeInExpo: (t: number) => number;
|
|
478
|
+
|
|
479
|
+
/**
|
|
480
|
+
* 回退缓入缓出
|
|
481
|
+
* @param t - 时间进度,范围 [0, 1]
|
|
482
|
+
* @param s - 过冲系数,默认为 1.70158
|
|
483
|
+
* @returns 缓动后的值
|
|
484
|
+
*/
|
|
485
|
+
export declare const easeInOutBack: (t: number, s?: number) => number;
|
|
486
|
+
|
|
487
|
+
/** 弹跳缓入缓出 */
|
|
488
|
+
export declare const easeInOutBounce: (t: number) => number;
|
|
489
|
+
|
|
490
|
+
/** 圆形缓入缓出 */
|
|
491
|
+
export declare const easeInOutCirc: (t: number) => number;
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
* 三次方缓入缓出
|
|
495
|
+
* @param t - 时间进度,范围 [0, 1]
|
|
496
|
+
* @returns 缓动后的值,范围 [0, 1]
|
|
497
|
+
* @example
|
|
498
|
+
* easeInOutCubic(0.25) // 0.0625
|
|
499
|
+
*/
|
|
500
|
+
export declare const easeInOutCubic: (t: number) => number;
|
|
501
|
+
|
|
502
|
+
/** 弹性缓入缓出 */
|
|
503
|
+
export declare const easeInOutElastic: (t: number) => number;
|
|
504
|
+
|
|
505
|
+
/** 指数缓入缓出 */
|
|
506
|
+
export declare const easeInOutExpo: (t: number) => number;
|
|
507
|
+
|
|
508
|
+
/** 二次方缓入缓出 */
|
|
509
|
+
export declare const easeInOutQuad: (t: number) => number;
|
|
510
|
+
|
|
511
|
+
/** 四次方缓入缓出 */
|
|
512
|
+
export declare const easeInOutQuart: (t: number) => number;
|
|
513
|
+
|
|
514
|
+
/** 五次方缓入缓出 */
|
|
515
|
+
export declare const easeInOutQuint: (t: number) => number;
|
|
516
|
+
|
|
517
|
+
/** 正弦缓入缓出 */
|
|
518
|
+
export declare const easeInOutSine: (t: number) => number;
|
|
519
|
+
|
|
520
|
+
/** 二次方缓入:由慢到快 */
|
|
521
|
+
export declare const easeInQuad: (t: number) => number;
|
|
522
|
+
|
|
523
|
+
/** 四次方缓入 */
|
|
524
|
+
export declare const easeInQuart: (t: number) => number;
|
|
525
|
+
|
|
526
|
+
/** 五次方缓入 */
|
|
527
|
+
export declare const easeInQuint: (t: number) => number;
|
|
528
|
+
|
|
529
|
+
/** 正弦缓入 */
|
|
530
|
+
export declare const easeInSine: (t: number) => number;
|
|
531
|
+
|
|
532
|
+
/**
|
|
533
|
+
* 回退缓出:超过终点再回弹到终点
|
|
534
|
+
* @param t - 时间进度,范围 [0, 1]
|
|
535
|
+
* @param s - 过冲系数,默认为 1.70158
|
|
536
|
+
* @returns 缓动后的值
|
|
537
|
+
*/
|
|
538
|
+
export declare const easeOutBack: (t: number, s?: number) => number;
|
|
539
|
+
|
|
540
|
+
/** 弹跳缓出:落地点弹跳衰减 */
|
|
541
|
+
export declare const easeOutBounce: (t: number) => number;
|
|
542
|
+
|
|
543
|
+
/** 圆形缓出 */
|
|
544
|
+
export declare const easeOutCirc: (t: number) => number;
|
|
545
|
+
|
|
546
|
+
/** 三次方缓出:由快到慢 */
|
|
547
|
+
export declare const easeOutCubic: (t: number) => number;
|
|
548
|
+
|
|
549
|
+
/** 弹性缓出:终点前反复振荡 */
|
|
550
|
+
export declare const easeOutElastic: (t: number) => number;
|
|
551
|
+
|
|
552
|
+
/** 指数缓出 */
|
|
553
|
+
export declare const easeOutExpo: (t: number) => number;
|
|
554
|
+
|
|
555
|
+
/** 二次方缓出:由快到慢 */
|
|
556
|
+
export declare const easeOutQuad: (t: number) => number;
|
|
557
|
+
|
|
558
|
+
/** 四次方缓出 */
|
|
559
|
+
export declare const easeOutQuart: (t: number) => number;
|
|
560
|
+
|
|
561
|
+
/** 五次方缓出 */
|
|
562
|
+
export declare const easeOutQuint: (t: number) => number;
|
|
563
|
+
|
|
564
|
+
/** 正弦缓出 */
|
|
565
|
+
export declare const easeOutSine: (t: number) => number;
|
|
566
|
+
|
|
567
|
+
/**
|
|
568
|
+
* 按缓动函数计算 from 到 to 之间某一进度的插值
|
|
569
|
+
* @param from - 起始值
|
|
570
|
+
* @param to - 结束值
|
|
571
|
+
* @param t - 原始时间进度,范围 [0, 1]
|
|
572
|
+
* @param easing - 缓动函数,默认为 linear
|
|
573
|
+
* @returns 缓动后的插值结果
|
|
574
|
+
* @example
|
|
575
|
+
* easeValue(0, 100, 0.5, easeOutCubic) // 87.5
|
|
576
|
+
*/
|
|
577
|
+
export declare const easeValue: (from: number, to: number, t: number, easing?: EasingFn) => number;
|
|
578
|
+
|
|
579
|
+
/**
|
|
580
|
+
* 缓动函数类型:接收时间进度 t(范围 [0, 1]),返回缓动后的进度
|
|
581
|
+
* 注意:部分缓动(如 back / elastic)中间过程可能超出 [0, 1],但起点与终点仍是 0 和 1
|
|
582
|
+
*/
|
|
583
|
+
export declare type EasingFn = (t: number) => number;
|
|
584
|
+
|
|
440
585
|
/**
|
|
441
586
|
* 启用元素(允许交互,移除disabled)
|
|
442
587
|
* @param {String|Node} el
|
|
@@ -875,6 +1020,17 @@ export declare const keepRectInContainer: (objDim: Dimension, ctnDim?: Dimension
|
|
|
875
1020
|
top: number;
|
|
876
1021
|
};
|
|
877
1022
|
|
|
1023
|
+
/**
|
|
1024
|
+
* 线性插值:根据进度 t 在 from 与 to 之间取值
|
|
1025
|
+
* @param from - 起始值
|
|
1026
|
+
* @param to - 结束值
|
|
1027
|
+
* @param t - 进度,范围 [0, 1]
|
|
1028
|
+
* @returns 插值结果
|
|
1029
|
+
* @example
|
|
1030
|
+
* lerp(0, 100, 0.5) // 50
|
|
1031
|
+
*/
|
|
1032
|
+
export declare const lerp: (from: number, to: number, t: number) => number;
|
|
1033
|
+
|
|
878
1034
|
/**
|
|
879
1035
|
* 限制数值在指定范围内
|
|
880
1036
|
* @param {number} num - 要限制的数值
|
|
@@ -886,6 +1042,15 @@ export declare const keepRectInContainer: (objDim: Dimension, ctnDim?: Dimension
|
|
|
886
1042
|
*/
|
|
887
1043
|
export declare const limit: (num: number, min: number, max: number) => number;
|
|
888
1044
|
|
|
1045
|
+
/**
|
|
1046
|
+
* 线性缓动:匀速运动,无加减速
|
|
1047
|
+
* @param t - 时间进度,范围 [0, 1]
|
|
1048
|
+
* @returns 缓动后的值,恒等于 t
|
|
1049
|
+
* @example
|
|
1050
|
+
* linear(0.5) // 0.5
|
|
1051
|
+
*/
|
|
1052
|
+
export declare const linear: (t: number) => number;
|
|
1053
|
+
|
|
889
1054
|
/**
|
|
890
1055
|
* 挂载 CSS 文件
|
|
891
1056
|
* @param {string} file - CSS 文件路径
|
|
@@ -1447,7 +1612,7 @@ export declare const onEvents: (events: (string | symbol)[], handler: EventListe
|
|
|
1447
1612
|
* @param onHoverOut - 鼠标离开回调函数
|
|
1448
1613
|
* @returns 返回解绑函数
|
|
1449
1614
|
*/
|
|
1450
|
-
export declare const onHover: (el: HTMLElement | string, onHoverIn: () => void, onHoverOut: () => void) => () => void;
|
|
1615
|
+
export declare const onHover: (el: HTMLElement | string, onHoverIn: () => void, onHoverOut: () => void) => (() => void);
|
|
1451
1616
|
|
|
1452
1617
|
/**
|
|
1453
1618
|
* 非自关闭标签
|
|
@@ -1655,6 +1820,27 @@ export declare const sanitizeFileName: (name: string) => string;
|
|
|
1655
1820
|
|
|
1656
1821
|
export declare const SCREEN_DPI: number;
|
|
1657
1822
|
|
|
1823
|
+
export declare type ScrollAxis = "scrollLeft" | "scrollTop";
|
|
1824
|
+
|
|
1825
|
+
/**
|
|
1826
|
+
* 用 rAF + 缓动把 el 平滑滚动到 target(自动夹取在合法滚动范围内)
|
|
1827
|
+
* @param el 要滚动的元素
|
|
1828
|
+
* @param target 目标滚动位置
|
|
1829
|
+
* @param options 动画选项
|
|
1830
|
+
*/
|
|
1831
|
+
export declare function scrollToAnimated(el: HTMLElement, target: number, options?: ScrollToAnimatedOptions): void;
|
|
1832
|
+
|
|
1833
|
+
export declare interface ScrollToAnimatedOptions {
|
|
1834
|
+
/** 动画时长(ms),默认 380 */
|
|
1835
|
+
duration?: number;
|
|
1836
|
+
/** 滚动的属性,默认横向 'scrollLeft' */
|
|
1837
|
+
axis?: ScrollAxis;
|
|
1838
|
+
/** 缓动函数,默认 easeInOutCubic */
|
|
1839
|
+
easingFn?: (t: number) => number;
|
|
1840
|
+
/** 动画自然结束(或被取消/被新动画取代)时回调 */
|
|
1841
|
+
onEnd?: () => void;
|
|
1842
|
+
}
|
|
1843
|
+
|
|
1658
1844
|
/**
|
|
1659
1845
|
* 自关闭标签
|
|
1660
1846
|
*/
|