nhanh-pure-function 4.2.4 → 4.4.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.
@@ -11,7 +11,7 @@ export declare function _Animate_Schedule(callback: (schedule: number) => void,
11
11
  * @param initialMax - 振荡器初始最大值
12
12
  * @param initialSteps - 从最小值到最大值所需的动画步数
13
13
  * @param callback - 每帧更新时的回调函数,接收当前振荡值
14
- * @param precision - 数值精度(保留小数位数,默认2位)
14
+ * @param precision - 数值精度(保留小数位数,默认4位)
15
15
  * @returns 振荡器控制对象,包含播放/暂停/参数更新等方法
16
16
  */
17
17
  export declare function _Animate_CreateOscillator(initialMin: number, initialMax: number, initialSteps: number, callback: (value: number) => void, precision?: number): {
@@ -14,7 +14,7 @@ export default class LayerGroup extends EventController {
14
14
  defaultClick: EventHandler<"click">;
15
15
  defaultDoubleClick: EventHandler<"doubleClick">;
16
16
  defaultHover: EventHandler<"hover">;
17
- defaultDragg: EventHandler<"dragg">;
17
+ defaultDrag: EventHandler<"drag">;
18
18
  defaultDown: EventHandler<"down">;
19
19
  setMainCanvas(mainCanvas?: _Canvas_Axis): void;
20
20
  setNotifyReload(notifyReload?: () => void): void;
@@ -26,6 +26,8 @@ export default class LayerGroup extends EventController {
26
26
  removeLayer(layers: Layer | Layer[]): void;
27
27
  /** 清空图层 */
28
28
  clearLayer(): void;
29
+ /** 移除图层 */
30
+ removeChild(child: Layer): void;
29
31
  /** 收集图层的 canvas */
30
32
  fetchCanvas(): [number, HTMLCanvasElement, [[number, number], OverlayType][]][];
31
33
  }
@@ -41,6 +41,8 @@ export default class Layer extends EventController {
41
41
  removeGroup(groups: OverlayGroup | OverlayGroup[]): void;
42
42
  /** 清空覆盖物 */
43
43
  clearGroup(): void;
44
+ /** 移除覆盖物组 */
45
+ removeChild(child: OverlayGroup): void;
44
46
  /** 本次绘制的覆盖物 */
45
47
  private currentDrawOverlays;
46
48
  /** 获取画布 */
@@ -75,7 +75,7 @@ export default class Arc extends Overlay<ArcStyleType, [number, number]> {
75
75
  /** 默认点击事件 点击后切换控制点显示状态 */
76
76
  defaultClick: EventHandler<"click">;
77
77
  /** 处理拖动状态变化 */
78
- defaultDragg: EventHandler<"dragg">;
78
+ defaultDrag: EventHandler<"drag">;
79
79
  protected updateValueScope(): void;
80
80
  isPointInPath(x: number, y: number): boolean;
81
81
  isPointInStroke(x: number, y: number): boolean;
@@ -34,7 +34,7 @@ export default class ArcTo extends Overlay<ArcToStyleType, [number, number][]> {
34
34
  /** 默认点击事件 点击后切换控制点显示状态 */
35
35
  defaultClick: EventHandler<"click">;
36
36
  /** 处理拖动状态变化 */
37
- defaultDragg: EventHandler<"dragg">;
37
+ defaultDrag: EventHandler<"drag">;
38
38
  protected updateValueScope(): void;
39
39
  isPointInPath(x: number, y: number): boolean;
40
40
  isPointInStroke(x: number, y: number): boolean;
@@ -37,7 +37,7 @@ declare abstract class BillboardBase extends Overlay<BillboardStyleType, [
37
37
  }
38
38
  export default class Billboard extends BillboardBase {
39
39
  constructor(option: ConstructorOption);
40
- defaultDragg: EventHandler<"dragg">;
40
+ defaultDrag: EventHandler<"drag">;
41
41
  protected updateValueScope(): void;
42
42
  isPointInPath(x: number, y: number): boolean;
43
43
  isPointInStroke(x: number, y: number): boolean;
@@ -28,6 +28,8 @@ export default class OverlayGroup extends EventController {
28
28
  removeOverlay(overlays: OverlayType[] | OverlayType): void;
29
29
  /** 清空覆盖物 */
30
30
  clearOverlay(): void;
31
+ /** 移除覆盖物 */
32
+ removeChild(child: OverlayType): void;
31
33
  /** 获取覆盖物的绘制方法 */
32
34
  getOverlaysDrawingMethod(): [number, [(ctx: CanvasRenderingContext2D) => void, OverlayType]][];
33
35
  }
@@ -7,7 +7,7 @@ export default class Point extends Overlay<PointStyleType, [number, number]> {
7
7
  private angle;
8
8
  constructor(option: ConstructorOption);
9
9
  protected updateValueScope(): void;
10
- defaultDragg: EventHandler<"dragg">;
10
+ defaultDrag: EventHandler<"drag">;
11
11
  /** 填充进度 */
12
12
  private fillProgress?;
13
13
  /** 处理悬停状态变化 */
@@ -61,7 +61,7 @@ export default abstract class GeometricBoundary<T> extends Overlay<T, PointLocat
61
61
  /** 是否可以删除点 */
62
62
  private get canDeleteHandlePoint();
63
63
  /** 处理拖动状态变化 */
64
- defaultDragg: EventHandler<"dragg">;
64
+ defaultDrag: EventHandler<"drag">;
65
65
  /** 更新控制点 */
66
66
  protected updateHandlePoints(): void;
67
67
  /** 更新控制点位置 */
@@ -172,5 +172,7 @@ export default abstract class Overlay<T, V extends [number, number] | [number, n
172
172
  get cursorStyle(): string | undefined;
173
173
  /** 获取绘制函数 */
174
174
  abstract getDraw(): [(ctx: CanvasRenderingContext2D) => void, OverlayType] | void;
175
+ /** 占位,无实际意义 */
176
+ removeChild(): void;
175
177
  }
176
178
  export {};
@@ -14,7 +14,7 @@ export default class Text extends Overlay<TextStyleType, [number, number]> {
14
14
  get text(): string | undefined;
15
15
  set text(text: string | undefined);
16
16
  constructor(option: ConstructorOption);
17
- defaultDragg: EventHandler<"dragg">;
17
+ defaultDrag: EventHandler<"drag">;
18
18
  protected updateValueScope(): void;
19
19
  isPointInPath(x: number, y: number): boolean;
20
20
  isPointInStroke(x: number, y: number): boolean;
@@ -103,6 +103,8 @@ export default class BaseData extends EventController {
103
103
  drawAxis: Axis;
104
104
  /** 图层群组 集合 */
105
105
  layerGroups: Map<string, LayerGroup>;
106
+ /** 占位,由子类实现 */
107
+ removeChild(child: LayerGroup): void;
106
108
  constructor(option: ConstructorOption);
107
109
  setNotifyReload(notifyReload?: () => void): void;
108
110
  /** 获取默认中心点位置 */
@@ -1,3 +1,4 @@
1
+ import { OverlayType } from '../OverlayGroup';
1
2
  import { default as Draw } from './draw';
2
3
  import { EventHandler } from '../public/eventController';
3
4
  type ConstructorOption = ConstructorParameters<typeof Draw>[0];
@@ -14,7 +15,10 @@ export default class Event extends Draw {
14
15
  /** 初始化事件 */
15
16
  private initEvent;
16
17
  /** 上一个被点击的覆盖物 */
17
- private lastClickedOverlay?;
18
+ private _lastClickedOverlay?;
19
+ /** 上一个被点击的覆盖物 */
20
+ get lastClickedOverlay(): OverlayType | undefined;
21
+ private set lastClickedOverlay(value);
18
22
  private lockNotifyClick;
19
23
  /** 鼠标左键点击画布 */
20
24
  private click;
@@ -39,20 +43,26 @@ export default class Event extends Draw {
39
43
  private wheel;
40
44
  defaultWheel: EventHandler<"wheel">;
41
45
  /** 上一个被按下的覆盖物 */
42
- private lastDownOverlay?;
46
+ private _lastDownOverlay?;
47
+ /** 上一个被按下的覆盖物 */
48
+ get lastDownOverlay(): OverlayType | undefined;
49
+ private set lastDownOverlay(value);
43
50
  /** 鼠标按下 */
44
51
  private mousedown;
45
52
  defaultDown: EventHandler<"down">;
46
53
  /** 鼠标松开 */
47
54
  private mouseup;
48
55
  /** 上一个被hover的覆盖物 */
49
- private lastHoverOverlay?;
56
+ private _lastHoverOverlay?;
57
+ /** 上一个被hover的覆盖物 */
58
+ private get lastHoverOverlay();
59
+ private set lastHoverOverlay(value);
50
60
  /** 鼠标移动 */
51
61
  private mousemove;
52
62
  /** 处理拖拽移动 */
53
63
  private handleDragMove;
54
64
  /** 通知可拖拽的 overlays */
55
- private notifyDraggOverlays;
65
+ private notifyDragOverlays;
56
66
  /** 处理画布平移 */
57
67
  private handleCanvasPan;
58
68
  /** 处理 hover 逻辑 */
@@ -62,6 +62,7 @@ export declare class _Canvas_Axis extends QuickMethod {
62
62
  setLayerGroup(layerGroup: LayerGroup): void;
63
63
  /** 移除图层群组 */
64
64
  removeLayerGroup(layerGroup: LayerGroup): void;
65
+ removeChild(layerGroup: LayerGroup): void;
65
66
  /** 添加图层 */
66
67
  addLayer(layers: DeepArray<Layer>): void;
67
68
  /** 移除图层 */
@@ -20,6 +20,10 @@ declare abstract class Base<T extends Base<T>> {
20
20
  notifyReload?: (needForceExecute?: boolean) => void;
21
21
  /** 设置通知重新加载 */
22
22
  abstract setNotifyReload(notifyReload?: () => void): void;
23
+ /** 移除某子项 */
24
+ abstract removeChild(child: Base<any>): void;
25
+ /** 从父级移除自身 */
26
+ remove(): void;
23
27
  }
24
28
  declare abstract class Show<T extends Show<T>> extends Base<T> {
25
29
  private _isVisible;
@@ -17,7 +17,7 @@ type EventMap = {
17
17
  click: State;
18
18
  doubleClick: State;
19
19
  hover: State;
20
- dragg: {
20
+ drag: {
21
21
  offsetX: number;
22
22
  offsetY: number;
23
23
  };
@@ -39,8 +39,8 @@ export default abstract class EventController extends EventControllerBasedata<Ev
39
39
  private trigger;
40
40
  private updateStates;
41
41
  private _eventDate;
42
- private _clearEventDate;
43
- private checkEventDate;
42
+ private _clearEventData;
43
+ private checkEventData;
44
44
  private _isHover;
45
45
  /** 是否触发悬停 */
46
46
  get isHover(): boolean;
@@ -97,7 +97,7 @@ export default abstract class EventController extends EventControllerBasedata<Ev
97
97
  * @param position.offsetY - 相对于元素Y轴的偏移量
98
98
  * @param [event] - 可选的关联鼠标事件对象
99
99
  */
100
- notifyDragg: (position: {
100
+ notifyDrag: (position: {
101
101
  offsetX: number;
102
102
  offsetY: number;
103
103
  }, event?: MouseEvent) => false | void;
@@ -54,3 +54,18 @@ export declare function _Math_GetBoundaryIntersection(startPoint: [number, numbe
54
54
  * 对于其他方法:直接调用原生Math方法
55
55
  */
56
56
  export declare const _Math_Degree: Math;
57
+ /**
58
+ * 根据控制点与参数 t,用 De Casteljau 计算 Bézier 曲线上的点。
59
+ * @param nodes 控制点
60
+ * @param progress 曲线参数,通常取 [0, 1]
61
+ * @returns 曲线上的点
62
+ */
63
+ export declare function _Math_GetBezierCurveNodes(nodes: [number, number][], progress: number): [number, number];
64
+ /**
65
+ * 根据宽高比与参数 progress,计算椭圆上的点(中心在原点)。
66
+ * @param aspectRatio 宽高比(width / height),即 X 半轴与 Y 半轴之比
67
+ * @param progress 曲线参数,通常取 [0, 1],表示沿椭圆一周的位置
68
+ * @param normalizeToUnitSquare 为 true 时将坐标归一化到 [0,1]×[0,1](外接矩形内)
69
+ * @returns 椭圆上的点 [x, y]
70
+ */
71
+ export declare function _Math_GetEllipsePoints(aspectRatio: number, progress: number, normalizeToUnitSquare?: boolean): [number, number];
@@ -0,0 +1,2 @@
1
+ export * from './undoRedoHistory';
2
+ export * from './shortcutKey';
@@ -0,0 +1,88 @@
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
+ /** `bind` 时传入的配置项 */
15
+ interface ShortcutOptions {
16
+ /** 匹配成功后的回调 */
17
+ callback: (event: KeyboardEvent) => void;
18
+ /** 多步序列之间的分隔符,默认 `","` */
19
+ sequenceDelimiter?: string;
20
+ /** 单步组合键内各键的分隔符,默认 `"+"` */
21
+ chordDelimiter?: string;
22
+ /** CSS 选择器,仅在匹配元素内生效;未设置则全局生效 */
23
+ scope?: string;
24
+ /** `scope` 的判定依据:`click` 用最近点击目标,`hover` 用最近悬停目标 */
25
+ scopeType?: "click" | "hover";
26
+ /** 多步序列中,相邻两步之间的最大间隔(毫秒),默认 `5000` */
27
+ timeout?: number;
28
+ /** 为 `true` 时,在 input / textarea / contentEditable 内也响应快捷键 */
29
+ enableInInput?: boolean;
30
+ }
31
+ /**
32
+ * 在 `window` 上监听键盘与鼠标事件,按配置触发快捷键回调。
33
+ */
34
+ export declare class _Utility_ShortcutManager {
35
+ /** 最近一次 `mousedown` 的目标,供 `scopeType: "click"` 使用 */
36
+ private lastClickDom?;
37
+ /** 最近一次 `mouseover` 的目标,供 `scopeType: "hover"` 使用 */
38
+ private lastHoverDom?;
39
+ /** 当前仍按下的键(已 normalize),顺序与物理按下顺序一致 */
40
+ private downKeys;
41
+ /** 注册表:`bind` 时的原始 `key` 字符串 → 运行时绑定 */
42
+ private bindings;
43
+ /** 为 `true` 时在控制台输出 keydown / keyup 日志 */
44
+ private debug;
45
+ constructor(debug?: boolean);
46
+ /**
47
+ * 注册快捷键。
48
+ * @param key 配置字符串,如 `"control+a"` 或 `"g,i"`(两步序列)
49
+ * @param options 回调与其它选项
50
+ */
51
+ bind(key: string | string[], options: ShortcutOptions): void;
52
+ /** 移除指定 `key` 的绑定并清理其超时定时器 */
53
+ unbind(key: string): void;
54
+ /** 移除所有监听、清空状态,实例不可再使用 */
55
+ destroy(): void;
56
+ private handleMouseOver;
57
+ private handleMouseDown;
58
+ /** 窗口失焦时清空按下状态,避免 `keyup` 未触发导致的状态残留 */
59
+ private clearKeys;
60
+ private handleKeyDown;
61
+ private handleKeyUp;
62
+ /**
63
+ * 遍历所有绑定:校验作用域与输入上下文后,用数组匹配当前步骤;
64
+ * 完全匹配则推进序列或触发回调,前缀匹配则等待,否则重置。
65
+ */
66
+ private checkBindings;
67
+ /** 启动多步序列超时;超时未按下一步则重置 `currentIndex` */
68
+ private startSequenceTimer;
69
+ private resetBinding;
70
+ private isValidScope;
71
+ /**
72
+ * 默认在可编辑控件内禁用快捷键,避免与浏览器/输入法默认行为冲突。
73
+ */
74
+ private isValidContext;
75
+ /**
76
+ * 将配置串与 `KeyboardEvent.key` 统一为小写别名,便于与 `event.key` 比较。
77
+ * 例如 `ctrl` → `control`,`cmd` → `meta`。
78
+ */
79
+ private normalizeKey;
80
+ /** 当前按下键与预期组合键在长度与顺序上完全一致 */
81
+ private isExactMatch;
82
+ /**
83
+ * 当前按下键是预期组合键的有序前缀(尚缺后续键)。
84
+ * 使用逐元素比较,避免字符串 `startsWith` 误匹配(如 `"S"` 匹配 `"Shift,a"`)。
85
+ */
86
+ private isPrefixMatch;
87
+ }
88
+ export {};
@@ -0,0 +1,88 @@
1
+ interface _Utility_UndoRedoConfig<T> {
2
+ /** 存储上限;`0` 或负数表示无限制。超出时自动淘汰最早的记录。默认为 50 */
3
+ maxSize?: number;
4
+ /** 自定义克隆/结构共享函数。若不传,则默认直接引用赋值 */
5
+ clone?: (value: T) => T;
6
+ /** 初始状态快照 */
7
+ initialState?: T;
8
+ }
9
+ interface _Utility_UndoRedoRecord<T> {
10
+ /** 历史快照数据 */
11
+ state: T;
12
+ /** 记录产生的时间戳 */
13
+ timestamp: number;
14
+ }
15
+ /** 订阅者回调函数类型 */
16
+ type _Utility_UndoRedoListener<T> = (current: Readonly<T> | undefined) => void;
17
+ /**
18
+ * 通用历史记录状态机
19
+ */
20
+ export declare class _Utility_UndoRedoHistory<T> {
21
+ private stack;
22
+ private _index;
23
+ private _maxSize;
24
+ private cloneFn;
25
+ private listeners;
26
+ constructor(config?: _Utility_UndoRedoConfig<T>);
27
+ /** 获取最大存储上限 */
28
+ get maxSize(): number;
29
+ /** 动态调整最大存储上限,超出时自动裁剪 */
30
+ set maxSize(value: number);
31
+ /** 当前所处的历史记录索引位置 */
32
+ get index(): number;
33
+ /** 历史栈中的总记录数 */
34
+ get length(): number;
35
+ /** 历史栈是否为空 */
36
+ get isEmpty(): boolean;
37
+ /** 当前游标处的只读状态快照;栈为空时返回 `undefined` */
38
+ get current(): Readonly<T> | undefined;
39
+ /** 是否可以执行撤销(Undo) */
40
+ get canUndo(): boolean;
41
+ /** 是否可以执行重做(Redo) */
42
+ get canRedo(): boolean;
43
+ /** 剩余可撤销的步数 */
44
+ get undoCount(): number;
45
+ /** 剩余可重做的步数 */
46
+ get redoCount(): number;
47
+ /**
48
+ * 记录一个新状态。
49
+ * 会自动裁剪掉当前索引之后的“未来(Redo)”分支,并处理容量超限。
50
+ */
51
+ push(state: T): void;
52
+ /**
53
+ * 仅更新当前位置的快照,不产生新的历史节点,不裁剪未来分支。
54
+ * 常用于高频连续变更的中间状态同步
55
+ */
56
+ replace(state: T): void;
57
+ /**
58
+ * 撤销一步
59
+ * @returns 是否撤销成功
60
+ */
61
+ undo(): boolean;
62
+ /**
63
+ * 重进一步
64
+ * @returns 是否重进成功
65
+ */
66
+ redo(): boolean;
67
+ /**
68
+ * 跳转到指定的历史索引位置
69
+ */
70
+ jump(index: number): boolean;
71
+ /**
72
+ * 清空所有历史记录并重置状态
73
+ */
74
+ clear(): void;
75
+ /**
76
+ * 支持多重事件监听。返回一个取消订阅的函数,便于在组件销毁时规避内存泄漏。
77
+ */
78
+ subscribe(listener: _Utility_UndoRedoListener<T>): () => void;
79
+ /**
80
+ * 返回整个历史栈的外部只读镜像,专门用于调试、分析或序列化暂存,防止内部数据被篡改。
81
+ */
82
+ snapshot(): readonly Readonly<_Utility_UndoRedoRecord<T>>[];
83
+ /** 内部超出容量时的核心裁剪逻辑 */
84
+ private trimOverflow;
85
+ /** 统一通知所有订阅者 */
86
+ private notify;
87
+ }
88
+ export {};
@@ -1,3 +1,4 @@
1
+ export * from './Runtime';
1
2
  /**
2
3
  * 寻找空闲时机执行传入方法
3
4
  * @param callback 需执行的方法
@@ -71,7 +71,7 @@ export declare function _Valid_CheckConnectionWithXHR(url: string): Promise<unkn
71
71
  */
72
72
  export declare class _Valid_FileTypeChecker {
73
73
  private static cachedEntries;
74
- constructor();
74
+ private constructor();
75
75
  /**
76
76
  * 检查给定URL的文件类型
77
77
  * @param {string} url - 文件的URL