minutool 1.0.27 → 1.0.30

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 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
@@ -191,7 +191,7 @@ export declare const bindKeyUp: (element: EventTarget | string, payload: (event:
191
191
  * @param element - 要移动的元素
192
192
  * @param handle - 拖动句柄,默认为元素本身
193
193
  */
194
- export declare function bindNodeMove(element: HTMLElement | string, handle?: HTMLElement | string | null): () => void;
194
+ export declare const bindNodeMove: (element: HTMLElement | string, handle?: HTMLElement | string | null) => () => void;
195
195
 
196
196
  /**
197
197
  * 转换 Blob 数据到 Base64 Data URL
@@ -255,7 +255,13 @@ export declare const calcRemainingMSecs: (progress: number, total: number, start
255
255
  * camelCase('hello-world') // 'helloWorld'
256
256
  * camelCase('hello_world') // 'helloWorld'
257
257
  */
258
- export declare function camelCase(str: string): string;
258
+ export declare const camelCase: (str: string) => string;
259
+
260
+ /**
261
+ * 取消 el 上正在进行的滚动动画(若有),并还原 CSS 滚动行为
262
+ * @param el 要取消滚动动画的元素
263
+ */
264
+ export declare const cancelScrollAnimation: (el: HTMLElement) => void;
259
265
 
260
266
  /**
261
267
  * 首字母大写
@@ -264,7 +270,17 @@ export declare function camelCase(str: string): string;
264
270
  * @example
265
271
  * capitalize('hello') // 'Hello'
266
272
  */
267
- export declare function capitalize(str: string): string;
273
+ export declare const capitalize: (str: string) => string;
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;
268
284
 
269
285
  /**
270
286
  * 清理对象中的 null 值
@@ -359,7 +375,7 @@ export declare const decodeHTMLEntities: (str: string) => string;
359
375
  * @example
360
376
  * deepClone({ a: 1, b: { c: 2 } })
361
377
  */
362
- export declare function deepClone<T>(obj: T): T;
378
+ export declare const deepClone: <T>(obj: T) => T;
363
379
 
364
380
  /**
365
381
  * 删除 Cookie
@@ -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
@@ -748,7 +893,7 @@ export declare const isChinese: (str: string) => boolean;
748
893
  * isEmptyObject({}) // true
749
894
  * isEmptyObject({ a: 1 }) // false
750
895
  */
751
- export declare function isEmptyObject(obj: object): boolean;
896
+ export declare const isEmptyObject: (obj: object) => boolean;
752
897
 
753
898
  /**
754
899
  * 检测是否为 Firefox 浏览器
@@ -854,7 +999,7 @@ export declare const isUrl: (str: string) => boolean;
854
999
  * kebabCase('helloWorld') // 'hello-world'
855
1000
  * kebabCase('HelloWorld') // 'hello-world'
856
1001
  */
857
- export declare function kebabCase(str: string): string;
1002
+ export declare const kebabCase: (str: string) => string;
858
1003
 
859
1004
  /**
860
1005
  * 保持对象尽量在容器内部,优先保证上边、左边显示
@@ -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 文件路径
@@ -1340,7 +1505,7 @@ export declare const objectFromEntries: <T extends Record<string | number | symb
1340
1505
  * get({ a: { b: { c: 1 } } }, 'a.b.c') // 1
1341
1506
  * get({ a: { b: 1 } }, 'a.b.c', 0) // 0
1342
1507
  */
1343
- export declare function objectGet<T = any>(obj: object, path: string, defaultValue?: T): T;
1508
+ export declare const objectGet: <T = any>(obj: object, path: string, defaultValue?: T) => T;
1344
1509
 
1345
1510
  /**
1346
1511
  * 根据映射关系替换对象的键
@@ -1360,7 +1525,7 @@ export declare const objectKeyReplace: (obj: Record<string, any>, mapping: Recor
1360
1525
  * @example
1361
1526
  * merge({ a: 1 }, { b: 2 }, { c: 3 }) // { a: 1, b: 2, c: 3 }
1362
1527
  */
1363
- export declare function objectMerge<T extends object>(target: T, ...sources: Partial<T>[]): T;
1528
+ export declare const objectMerge: <T extends object>(target: T, ...sources: Partial<T>[]) => T;
1364
1529
 
1365
1530
  /**
1366
1531
  * 设置对象指定路径的值
@@ -1370,7 +1535,7 @@ export declare function objectMerge<T extends object>(target: T, ...sources: Par
1370
1535
  * @example
1371
1536
  * set({}, 'a.b.c', 1) // { a: { b: { c: 1 } } }
1372
1537
  */
1373
- export declare function objectSet(obj: any, path: string, value: any): void;
1538
+ export declare const objectSet: (obj: any, path: string, value: any) => void;
1374
1539
 
1375
1540
  /**
1376
1541
  * 交换对象中的键值对
@@ -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 const 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
  */
@@ -1870,7 +2056,7 @@ export declare const TRIM_RIGHT = 2;
1870
2056
  * @example
1871
2057
  * truncate('hello world', 5) // 'hello...'
1872
2058
  */
1873
- export declare function truncate(str: string, length: number, suffix?: string): string;
2059
+ export declare const truncate: (str: string, length: number, suffix?: string) => string;
1874
2060
 
1875
2061
  /**
1876
2062
  * 反转义 HTML(将 HTML 实体转换为字符)