nhanh-pure-function 4.4.0 → 4.5.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/Animate/index.d.ts +2 -2
- package/dist/Element/Runtime/drop.d.ts +45 -0
- package/dist/Element/Runtime/index.d.ts +2 -1
- package/dist/Math/index.d.ts +9 -3
- package/dist/Utility/Runtime/shortcutKey.d.ts +25 -15
- package/dist/index.cjs.js +3 -3
- package/dist/index.es.js +835 -653
- package/package.json +1 -1
package/dist/Animate/index.d.ts
CHANGED
|
@@ -10,11 +10,11 @@ export declare function _Animate_Schedule(callback: (schedule: number) => void,
|
|
|
10
10
|
* @param initialMin - 振荡器初始最小值
|
|
11
11
|
* @param initialMax - 振荡器初始最大值
|
|
12
12
|
* @param initialSteps - 从最小值到最大值所需的动画步数
|
|
13
|
-
* @param callback -
|
|
13
|
+
* @param callback - 每帧回调 `(value, direction)`:`value` 为经 `precision` 处理后的当前值;`direction` 为本帧步进方向(`1` 朝向 `max`,`-1` 朝向 `min`),触边翻转后传入
|
|
14
14
|
* @param precision - 数值精度(保留小数位数,默认4位)
|
|
15
15
|
* @returns 振荡器控制对象,包含播放/暂停/参数更新等方法
|
|
16
16
|
*/
|
|
17
|
-
export declare function _Animate_CreateOscillator(initialMin: number, initialMax: number, initialSteps: number, callback: (value: number) => void, precision?: number): {
|
|
17
|
+
export declare function _Animate_CreateOscillator(initialMin: number, initialMax: number, initialSteps: number, callback: (value: number, direction: 1 | -1) => void, precision?: number): {
|
|
18
18
|
/** 启动/继续动画 */
|
|
19
19
|
play(target?: number): void;
|
|
20
20
|
/** 暂停动画 */
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/** 自定义拖拽校验与提取器 */
|
|
2
|
+
export interface CustomDropValidator {
|
|
3
|
+
/**
|
|
4
|
+
* 悬停拦截:拖拽进入/悬停时触发。
|
|
5
|
+
* 此时出于安全策略无法读取文件内容,仅能通过暴露的 types 判断是否允许拖入。
|
|
6
|
+
*/
|
|
7
|
+
matchTypes: (types: readonly string[]) => boolean;
|
|
8
|
+
/**
|
|
9
|
+
* 精确提取:拖拽放下(drop)时触发。
|
|
10
|
+
* 遍历 dataTransfer.items 的每一项,返回 true 代表将该项提取并交由回调处理。
|
|
11
|
+
*/
|
|
12
|
+
matchItem: (item: DataTransferItem) => boolean;
|
|
13
|
+
}
|
|
14
|
+
/** 拖放区接受的拖拽数据类型 */
|
|
15
|
+
export type DropTargetType = "text" | "file" | "image" | "video" | "audio" | "application" | `.${string}` | `${string}/${string}` | (string & {}) | CustomDropValidator;
|
|
16
|
+
/** 单一拖放规则配置 */
|
|
17
|
+
export interface DropZoneRule {
|
|
18
|
+
/** 允许传入单一类型或多种类型组合的数组 */
|
|
19
|
+
targetType?: DropTargetType | DropTargetType[];
|
|
20
|
+
/** 拖放回调 */
|
|
21
|
+
dropCallback: (data: any[]) => void;
|
|
22
|
+
/** 当前规则匹配成功时的激活回调 */
|
|
23
|
+
activeCallback?: (active: boolean) => void;
|
|
24
|
+
}
|
|
25
|
+
/** 注册拖放区时的配置 */
|
|
26
|
+
export type DropZoneOption = {
|
|
27
|
+
/** 拖放区元素 */
|
|
28
|
+
dom: HTMLElement | string;
|
|
29
|
+
/** 拖放区全局激活回调(只要有任意规则匹配就会触发) */
|
|
30
|
+
activeCallback?: (active: boolean) => void;
|
|
31
|
+
} & (DropZoneRule | {
|
|
32
|
+
/** 多规则配置(允许对不同类型独立处理) */
|
|
33
|
+
rules: DropZoneRule[];
|
|
34
|
+
});
|
|
35
|
+
export declare class _Element_DropZoneManager {
|
|
36
|
+
private entries;
|
|
37
|
+
private extractRules;
|
|
38
|
+
add(config: DropZoneOption): void;
|
|
39
|
+
delete(dom: HTMLElement | string): void;
|
|
40
|
+
destroy(): void;
|
|
41
|
+
private onDragEnter;
|
|
42
|
+
private onDragLeave;
|
|
43
|
+
private onDragOver;
|
|
44
|
+
private onDrop;
|
|
45
|
+
}
|
package/dist/Math/index.d.ts
CHANGED
|
@@ -55,12 +55,18 @@ export declare function _Math_GetBoundaryIntersection(startPoint: [number, numbe
|
|
|
55
55
|
*/
|
|
56
56
|
export declare const _Math_Degree: Math;
|
|
57
57
|
/**
|
|
58
|
-
* 根据控制点与参数 t,用 De Casteljau 计算 Bézier
|
|
58
|
+
* 根据控制点与参数 t,用 De Casteljau 计算 Bézier 曲线上的点和方向弧度。
|
|
59
|
+
*
|
|
60
|
+
* 【为什么可以这样获取方向】
|
|
61
|
+
* 根据 De Casteljau 算法的特性,当循环降维到倒数第二层(只剩最后 2 个点)时,
|
|
62
|
+
* 这两点连线的方向 [p1 - p0] 刚好就是曲线在该点处的切线向量。
|
|
63
|
+
* 此时使用 Math.atan2 即可直接换算出切线方向的弧度,无需单独执行求导公式。
|
|
64
|
+
*
|
|
59
65
|
* @param nodes 控制点
|
|
60
66
|
* @param progress 曲线参数,通常取 [0, 1]
|
|
61
|
-
* @returns
|
|
67
|
+
* @returns 曲线上的点和方向 [x, y, radian]
|
|
62
68
|
*/
|
|
63
|
-
export declare function _Math_GetBezierCurveNodes(nodes: [number, number][], progress: number): [number, number];
|
|
69
|
+
export declare function _Math_GetBezierCurveNodes(nodes: [number, number][], progress: number): [number, number, number];
|
|
64
70
|
/**
|
|
65
71
|
* 根据宽高比与参数 progress,计算椭圆上的点(中心在原点)。
|
|
66
72
|
* @param aspectRatio 宽高比(width / height),即 X 半轴与 Y 半轴之比
|
|
@@ -1,16 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 全局快捷键管理:支持组合键、多步序列、作用域与输入框上下文过滤。
|
|
3
|
-
*
|
|
4
|
-
* @example
|
|
5
|
-
* ```ts
|
|
6
|
-
* const shortcuts = new _Utility_ShortcutManager();
|
|
7
|
-
* shortcuts.bind("control+s,control+shift+s", {
|
|
8
|
-
* callback: (e) => { e.preventDefault(); save(); },
|
|
9
|
-
* sequenceDelimiter: ",",
|
|
10
|
-
* chordDelimiter: "+",
|
|
11
|
-
* });
|
|
12
|
-
* ```
|
|
13
|
-
*/
|
|
14
1
|
/** `bind` 时传入的配置项 */
|
|
15
2
|
interface ShortcutOptions {
|
|
16
3
|
/** 匹配成功后的回调 */
|
|
@@ -27,11 +14,30 @@ interface ShortcutOptions {
|
|
|
27
14
|
timeout?: number;
|
|
28
15
|
/** 为 `true` 时,在 input / textarea / contentEditable 内也响应快捷键 */
|
|
29
16
|
enableInInput?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* 是否允许长按按键时重复触发回调,默认 `false`。
|
|
19
|
+
* 适用于如 `+`、`-`、方向键等需要连续操作的场景。
|
|
20
|
+
*/
|
|
21
|
+
allowRepeat?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* 允许重复触发时的最小时间间隔(毫秒)。
|
|
24
|
+
* 由于操作系统的原生长按触发频率不可控且通常极高,利用该属性对重复事件进行节流。
|
|
25
|
+
*/
|
|
26
|
+
repeatInterval?: number;
|
|
30
27
|
}
|
|
31
28
|
/**
|
|
32
|
-
*
|
|
29
|
+
* 全局快捷键管理器
|
|
30
|
+
*
|
|
31
|
+
* ⚠️ **注意**:本组件会在全局 `window` 上绑定多个事件监听器。
|
|
32
|
+
* 为了防止内存泄漏及非预期的快捷键触发,**在组件卸载或页面关闭时,必须显式调用 `.destroy()` 方法**。
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* const manager = new _Utility_ShortcutManager();
|
|
36
|
+
* // 离开页面时
|
|
37
|
+
* manager.destroy();
|
|
33
38
|
*/
|
|
34
39
|
export declare class _Utility_ShortcutManager {
|
|
40
|
+
private static activeInstances;
|
|
35
41
|
/** 最近一次 `mousedown` 的目标,供 `scopeType: "click"` 使用 */
|
|
36
42
|
private lastClickDom?;
|
|
37
43
|
/** 最近一次 `mouseover` 的目标,供 `scopeType: "hover"` 使用 */
|
|
@@ -51,7 +57,11 @@ export declare class _Utility_ShortcutManager {
|
|
|
51
57
|
bind(key: string | string[], options: ShortcutOptions): void;
|
|
52
58
|
/** 移除指定 `key` 的绑定并清理其超时定时器 */
|
|
53
59
|
unbind(key: string): void;
|
|
54
|
-
/**
|
|
60
|
+
/**
|
|
61
|
+
* 彻底销毁当前实例,清空所有快捷键绑定,并移除全局 window 事件监听器。
|
|
62
|
+
*
|
|
63
|
+
* ⚠️ **调用时机**:在单页应用(如 Vue/React 组件卸载)或不需要快捷键时**务必调用**。
|
|
64
|
+
*/
|
|
55
65
|
destroy(): void;
|
|
56
66
|
private handleMouseOver;
|
|
57
67
|
private handleMouseDown;
|