nhanh-pure-function 3.0.7 → 4.1.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.
Files changed (43) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +20 -6
  3. package/dist/Animate/index.d.ts +11 -1
  4. package/dist/Browser/Runtime/index.d.ts +2 -0
  5. package/dist/Browser/Runtime/soundEffects.d.ts +47 -0
  6. package/dist/Browser/Runtime/webSocketClient.d.ts +68 -0
  7. package/dist/Browser/index.d.ts +34 -0
  8. package/dist/Browser/type.d.ts +16 -0
  9. package/dist/Canvas/{LayerGroup → Axis/LayerGroup}/index.d.ts +2 -2
  10. package/dist/Canvas/{LayerGroup → Axis/LayerGroup}/layer.d.ts +9 -6
  11. package/dist/Canvas/Axis/OverlayCreator/index.d.ts +52 -0
  12. package/dist/Canvas/{OverlayGroup → Axis/OverlayGroup}/index.d.ts +2 -2
  13. package/dist/Canvas/{OverlayGroup → Axis/OverlayGroup}/public/overlay.d.ts +3 -3
  14. package/dist/Canvas/{core → Axis/core}/axis.d.ts +1 -1
  15. package/dist/Canvas/{core → Axis/core}/basedata.d.ts +1 -1
  16. package/dist/Canvas/{core → Axis/core}/quikmethod.d.ts +1 -1
  17. package/dist/Canvas/{core → Axis/core}/style.d.ts +1 -1
  18. package/dist/Canvas/{index.d.ts → Axis/index.d.ts} +11 -8
  19. package/dist/Canvas/{index.types.d.ts → Axis/index.types.d.ts} +3 -1
  20. package/dist/Canvas/{public → Axis/public}/basedata.d.ts +5 -5
  21. package/dist/Canvas/Axis/public/viewFit.d.ts +28 -0
  22. package/dist/Canvas/TimeAxis/index.d.ts +153 -0
  23. package/dist/Canvas/TimeAxis/type.d.ts +39 -0
  24. package/dist/index.cjs.js +3 -3
  25. package/dist/index.d.ts +2 -1
  26. package/dist/index.es.js +2689 -1882
  27. package/package.json +5 -5
  28. /package/dist/Canvas/{OverlayGroup → Axis/OverlayGroup}/arc.d.ts +0 -0
  29. /package/dist/Canvas/{OverlayGroup → Axis/OverlayGroup}/arcTo.d.ts +0 -0
  30. /package/dist/Canvas/{OverlayGroup → Axis/OverlayGroup}/bezierCurve.d.ts +0 -0
  31. /package/dist/Canvas/{OverlayGroup → Axis/OverlayGroup}/custom.d.ts +0 -0
  32. /package/dist/Canvas/{OverlayGroup → Axis/OverlayGroup}/ellipse.d.ts +0 -0
  33. /package/dist/Canvas/{OverlayGroup → Axis/OverlayGroup}/line.d.ts +0 -0
  34. /package/dist/Canvas/{OverlayGroup → Axis/OverlayGroup}/point.d.ts +0 -0
  35. /package/dist/Canvas/{OverlayGroup → Axis/OverlayGroup}/polygon.d.ts +0 -0
  36. /package/dist/Canvas/{OverlayGroup → Axis/OverlayGroup}/public/geometricBoundary.d.ts +0 -0
  37. /package/dist/Canvas/{OverlayGroup → Axis/OverlayGroup}/text.d.ts +0 -0
  38. /package/dist/Canvas/{common.type.d.ts → Axis/common.type.d.ts} +0 -0
  39. /package/dist/Canvas/{core → Axis/core}/draw.d.ts +0 -0
  40. /package/dist/Canvas/{core → Axis/core}/event.d.ts +0 -0
  41. /package/dist/Canvas/{public → Axis/public}/eventController.d.ts +0 -0
  42. /package/dist/Canvas/{public → Axis/public}/eventControllerBasedata.d.ts +0 -0
  43. /package/dist/Canvas/{public → Axis/public}/tools.d.ts +0 -0
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2024 ADMINnhanh
3
+ Copyright (c) 2024 nha-nh
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,19 +1,33 @@
1
1
  # nhanh-pure-function
2
2
 
3
- 纯函数工具库,提供了一些常用的纯函数工具,帮助您在 JavaScript/TypeScript 项目中更高效地处理数据。
3
+ JavaScript/TypeScript 工具库,提供纯函数、画布、格式化、校验等常用能力,适用于前端项目的数据处理与可视化场景。
4
4
 
5
5
  ## 安装
6
6
 
7
- 您可以通过 npm 安装该库:
8
-
9
7
  ```bash
10
8
  npm install nhanh-pure-function
11
9
  ```
12
10
 
13
- ## 功能介绍
11
+ ## 模块概览
12
+
13
+ | 模块 | 说明 |
14
+ |------|------|
15
+ | **Constant** | 常量:扩展名与 MIME 映射、单位标签、纸张尺寸、窗口目标等 |
16
+ | **Animate** | 动画:进度调度、振荡器、数值过渡 |
17
+ | **Blob** | 数据转图像 URL(Base64、ArrayBuffer、File 等) |
18
+ | **Browser** | 浏览器:帧率、剪贴板、可打印区域、同源标签管理 |
19
+ | **Canvas/Axis** | 数学坐标轴画布 `_Canvas_Axis`:图层、覆盖物(点/线/多边形/圆弧)、视图适配、覆盖物创建交互 |
20
+ | **Canvas/TimeAxis** | 时间轴画布 `_Canvas_TimeAxis`:时间-像素换算、拖拽、缩放、时间范围绘制 |
21
+ | **Element** | DOM:滚动结束监听、点击外部关闭、拖拽等 |
22
+ | **File** | 文件:读取、下载(含进度)、创建并下载 |
23
+ | **Format** | 格式化:首字母大写、百分比、千位分隔符、文件大小、时间戳、链接名等 |
24
+ | **Math** | 数学:经纬度↔平面坐标、点到线段距离、圆弧点、中点、边界交点等 |
25
+ | **Types** | 类型工具:`RequiredBy`、`PartialBy`、`DeepPartial`、`Mutable` |
26
+ | **Utility** | 工具:空闲执行、等待条件、合并对象、防抖节流、UUID 等 |
27
+ | **Valid** | 校验:数组校验、误差范围、点在多边形内、线段与矩形相交、数据类型、安全上下文、文件类型等 |
28
+ | **_Tip** | 提示流:`info`/`success`/`warning`/`error` 链式注册与执行 |
14
29
 
15
- `nhanh-pure-function` 库旨在提供一系列纯函数,这些函数在处理数据时不会产生副作用,确保函数的输入和输出之间的映射关系是确定的。这使得代码更易于测试、维护和复用。
16
30
 
17
31
  ## 许可证
18
32
 
19
- [MIT](https://opensource.org/licenses/MIT)
33
+ [MIT](https://opensource.org/licenses/MIT)
@@ -40,6 +40,16 @@ export declare function _Animate_CreateOscillator(initialMin: number, initialMax
40
40
  * @param targetValue - 目标值
41
41
  * @param stepCount - 动画步数
42
42
  * @param callback - 每帧回调函数
43
- * @param precision - 数值精度(默认2位小数)
43
+ * @param precision - 数值精度(默认4位小数)
44
44
  */
45
45
  export declare function _Animate_NumericTransition(startValue: number, targetValue: number, stepCount: number, callback: (currentValue: number) => void, precision?: number): void;
46
+ /**
47
+ * 三次贝塞尔缓动(与 CSS `cubic-bezier(x1, y1, x2, y2)` 语义一致)
48
+ * 曲线端点为 (0,0) → (1,1),控制点为 (x1,y1)、(x2,y2)。
49
+ * @param x1 第一个控制点 x
50
+ * @param y1 第一个控制点 y
51
+ * @param x2 第二个控制点 x
52
+ * @param y2 第二个控制点 y
53
+ * @returns 接收归一化时间 `t ∈ [0,1]`,返回缓动后的进度 `∈ [0,1]`(一般情况)
54
+ */
55
+ export declare function _Animate_CubicBezier(x1: number, y1: number, x2: number, y2: number): (t: number) => number;
@@ -0,0 +1,2 @@
1
+ export * from './soundEffects';
2
+ export * from './webSocketClient';
@@ -0,0 +1,47 @@
1
+ /** 资源映射类型 */
2
+ type Resource<T extends string> = Record<T, string>;
3
+ /** 播放配置 */
4
+ interface PlayOptions {
5
+ /** 是否无限循环播放 */
6
+ loop?: boolean;
7
+ /** 循环次数(优先级高于 loop,最少为 1 次) */
8
+ loopCount?: number;
9
+ }
10
+ /** 构造选项 */
11
+ interface SoundEffectsOptions<T extends string> {
12
+ /**
13
+ * 初始化时即 fetch 下载为 Blob,并将 `soundSources` 中对应 key 的地址替换为 blob URL
14
+ */
15
+ holdKeys?: readonly T[];
16
+ }
17
+ /**
18
+ * 音效管理类
19
+ * 负责音效的加载与播放
20
+ */
21
+ export declare class _Browser_SoundEffects<T extends string> {
22
+ /** 音效资源地址映射(preload 成功后对应项会替换为 blob: URL) */
23
+ private soundSources;
24
+ /** 各 key 下载任务,避免重复发起 */
25
+ private readonly preloadTasks;
26
+ constructor(resource: Resource<T>, options?: SoundEffectsOptions<T>);
27
+ /**
28
+ * 下载指定 key 的音频为 Blob,并将 `soundSources[key]` 替换为 `URL.createObjectURL` 结果(与 holdKeys 同一逻辑)
29
+ */
30
+ preload(key: T): Promise<void>;
31
+ preload(keys: readonly T[]): Promise<void>;
32
+ private fetchAndReplaceSource;
33
+ /**
34
+ * 根据 key 播放音效
35
+ * @param key 资源 key
36
+ * @param options 播放配置(循环等)
37
+ */
38
+ play(key: T, options?: PlayOptions): (() => void) | undefined;
39
+ /**
40
+ * 根据 URL 播放音效
41
+ * @param url 音频地址
42
+ * @param options 播放配置(循环等)
43
+ * @returns 停止播放的方法
44
+ */
45
+ playUrl(url: string, options?: PlayOptions): (() => void) | undefined;
46
+ }
47
+ export {};
@@ -0,0 +1,68 @@
1
+ /** ping 配置 */
2
+ interface WebSocketClientPingConfig {
3
+ /** 是否启用 */
4
+ enabled?: boolean;
5
+ /** 间隔(毫秒) */
6
+ interval?: number;
7
+ /** 发送内容 */
8
+ content?: string;
9
+ }
10
+ /** WebSocket 客户端配置 */
11
+ interface WebSocketClientConfig {
12
+ url?: string;
13
+ /** true 启用并采用默认参数,或传入具体配置 */
14
+ ping?: boolean | WebSocketClientPingConfig;
15
+ /** 最大重试次数,默认 3 */
16
+ maxRetryCount?: number;
17
+ /** 重试间隔(毫秒),默认 1000 */
18
+ retryInterval?: number;
19
+ }
20
+ /** WebSocket客户端 */
21
+ export declare class _Browser_WebSocketClient {
22
+ /** WebSocket地址 */
23
+ url?: string;
24
+ /** WebSocket实例 */
25
+ private socket?;
26
+ /** 连接回调 */
27
+ onopen?: (ev: Event) => any;
28
+ /** 接收消息回调 */
29
+ onmessage?: (ev: MessageEvent) => any;
30
+ /** 错误回调 */
31
+ onerror?: (ev: Event) => any;
32
+ /** 关闭回调 */
33
+ onclose?: (ev: CloseEvent) => any;
34
+ /** ping 配置 */
35
+ readonly pingConfig: {
36
+ /** 是否启用 */
37
+ enabled: boolean;
38
+ /** 间隔(毫秒) */
39
+ interval: number;
40
+ /** 发送内容 */
41
+ content: string;
42
+ };
43
+ /** ping 定时器 */
44
+ private pingTimer?;
45
+ /** 重试配置 */
46
+ readonly retryConfig: {
47
+ /** 最大次数 */
48
+ maxCount: number;
49
+ /** 当前次数 */
50
+ currentCount: number;
51
+ /** 间隔(毫秒) */
52
+ interval: number;
53
+ };
54
+ /** 是否准备完毕 */
55
+ get ready(): boolean;
56
+ constructor(config?: WebSocketClientConfig);
57
+ /** 开始ping */
58
+ private startPing;
59
+ /** 开始重试 */
60
+ private startRetry;
61
+ /** 开始 */
62
+ start(url: string): void;
63
+ /** 停止 */
64
+ stop(): void;
65
+ /** 发送信息 */
66
+ send: WebSocket["send"];
67
+ }
68
+ export {};
@@ -1,4 +1,5 @@
1
1
  import { PaperType, WindowTarget } from '../Constant';
2
+ export * from './Runtime';
2
3
  /**
3
4
  * 获取帧率
4
5
  * @param {(fps , frameTime)=>void} callback callback( 帧率 , 每帧时间 )
@@ -66,3 +67,36 @@ export declare class _Browser_SameOriginTabManager {
66
67
  /** 获取所有已经打开的标签页 */
67
68
  static getAllWindows(): Promise<string[]>;
68
69
  }
70
+ /**
71
+ * 无操作(闲置)检测类
72
+ * 监听用户键盘、鼠标操作,更新用户活跃状态
73
+ * 支持注册/触发活跃/闲置状态的回调通知
74
+ */
75
+ export declare class _Browser_IdleDetection {
76
+ /** 用户状态:active(活跃) / idle(闲置) */
77
+ status: "active" | "idle";
78
+ /** 活跃状态回调通知集合(key: 回调标识,value: 回调函数) */
79
+ readonly activeCallbacks: Map<string, () => void>;
80
+ /** 闲置状态回调通知集合(key: 回调标识,value: 回调函数) */
81
+ readonly idleCallbacks: Map<string, () => void>;
82
+ /** 闲置时间(分钟) */
83
+ idleTime: number;
84
+ /** 闲置判定定时器(5分钟无操作触发闲置状态) */
85
+ private timeoutTimer?;
86
+ constructor();
87
+ /**
88
+ * 重置闲置判定定时器
89
+ * 每次用户操作时重置,重新开始5分钟计时
90
+ */
91
+ resetTimeoutTimer(): void;
92
+ /**
93
+ * 激活为活跃状态
94
+ * 触发活跃回调,并重置定时器
95
+ */
96
+ private activate;
97
+ /**
98
+ * 标记为闲置状态
99
+ * 触发闲置回调,并清除定时器
100
+ */
101
+ private markAsIdle;
102
+ }
@@ -0,0 +1,16 @@
1
+ /** 定义消息类型枚举,避免硬编码字符串 */
2
+ export declare enum ChannelMessageType {
3
+ /** 回执消息 */
4
+ RESPONSE = "response",
5
+ /** 询问消息 */
6
+ QUERY = "query"
7
+ }
8
+ /** 基础消息结构 */
9
+ export interface ChannelMessage {
10
+ /** 消息类型 */
11
+ type: ChannelMessageType;
12
+ /** 消息关联的标识键 */
13
+ responseKey: string;
14
+ /** 标签页名称 "*" 表示所有标签页 */
15
+ name: string;
16
+ }
@@ -1,4 +1,4 @@
1
- import { default as _Canvas } from '..';
1
+ import { default as _Canvas_Axis } from '..';
2
2
  import { OverlayType } from '../OverlayGroup';
3
3
  import { default as Layer } from './layer';
4
4
  import { EventHandler, default as EventController } from '../public/eventController';
@@ -14,7 +14,7 @@ export default class LayerGroup extends EventController {
14
14
  defaultHover: EventHandler<"hover">;
15
15
  defaultDragg: EventHandler<"dragg">;
16
16
  defaultDown: EventHandler<"down">;
17
- setMainCanvas(mainCanvas?: _Canvas): void;
17
+ setMainCanvas(mainCanvas?: _Canvas_Axis): void;
18
18
  setNotifyReload(notifyReload?: () => void): void;
19
19
  /** 获取图层 */
20
20
  getLayer(name: string): Layer | undefined;
@@ -1,7 +1,10 @@
1
- import { default as _Canvas } from '..';
1
+ import { default as _Canvas_Axis } from '..';
2
2
  import { default as OverlayGroup, OverlayType } from '../OverlayGroup';
3
3
  import { default as EventController } from '../public/eventController';
4
- type ConstructorOption = ConstructorParameters<typeof EventController>[0];
4
+ type ConstructorOption = ConstructorParameters<typeof EventController>[0] & {
5
+ /** 层级 */
6
+ zIndex?: number;
7
+ };
5
8
  /**
6
9
  * 图层事件触发机制说明:
7
10
  *
@@ -15,15 +18,17 @@ type ConstructorOption = ConstructorParameters<typeof EventController>[0];
15
18
  * 事件触发对象就应该是该 图层 中的 覆盖物,这时就不应该再触发其他 图层 的事件了;
16
19
  */
17
20
  export default class Layer extends EventController {
21
+ private _zIndex;
18
22
  /** 层级 */
19
- zIndex: number;
23
+ get zIndex(): number;
24
+ set zIndex(zIndex: number);
20
25
  protected canvas: HTMLCanvasElement;
21
26
  protected ctx: CanvasRenderingContext2D;
22
27
  /** 是否需要重新绘制 */
23
28
  private isReload;
24
29
  groups: Map<string, OverlayGroup>;
25
30
  constructor(option: ConstructorOption);
26
- setMainCanvas(mainCanvas?: _Canvas): void;
31
+ setMainCanvas(mainCanvas?: _Canvas_Axis): void;
27
32
  setNotifyReload(notifyReload?: () => void): void;
28
33
  setGroupNotifyReload(group: OverlayGroup): void;
29
34
  /** 获取覆盖物组 */
@@ -34,8 +39,6 @@ export default class Layer extends EventController {
34
39
  removeGroup(groups: OverlayGroup | OverlayGroup[]): void;
35
40
  /** 清空覆盖物 */
36
41
  clearGroup(): void;
37
- /** 设置图层的 zIndex 值 */
38
- setzIndex(zIndex: number): void;
39
42
  /** 本次绘制的覆盖物 */
40
43
  private currentDrawOverlays;
41
44
  /** 获取画布 */
@@ -0,0 +1,52 @@
1
+ import { default as _Canvas_Axis } from '..';
2
+ import { default as Line } from '../OverlayGroup/line';
3
+ import { default as Polygon } from '../OverlayGroup/polygon';
4
+ /**
5
+ * 管理单次「创建覆盖物」的交互(从开始绘制到完成/取消)。
6
+ * 覆盖物有两种定位方式:value = 坐标轴上的值 [x,y][],position = 画布上的位置 px;本类通过 overlay.value 定位。
7
+ */
8
+ export default class OverlayCreator {
9
+ /** 绑定的画布实例 */
10
+ private canvas;
11
+ private layerGroup;
12
+ /** 创建中覆盖物的绘制层(置顶以保证可见) */
13
+ private overlayLayer;
14
+ /** 该层内的覆盖物分组,便于统一增删 */
15
+ private overlayGroup;
16
+ /** 当前正在创建的覆盖物(多边形或线),其顶点通过 overlay.value 即坐标轴上的值表示 */
17
+ private overlay?;
18
+ /** 已确定的顶点在坐标轴上的值列表 [x, y][],对应 overlay.value */
19
+ private axisValueList?;
20
+ /** 创建时暂存的其他图层群组的 isInteractive,编辑完成后用于复原 */
21
+ private savedLayerGroupInteractive;
22
+ /**
23
+ * 用户自定义限位器:传入原始 value [x, y](坐标轴上的值),约束到合法范围后返回。
24
+ */
25
+ axisValueLimiter?: (value: [number, number]) => [number, number];
26
+ constructor(canvas: _Canvas_Axis);
27
+ /** 按类型开始创建:多边形或线 */
28
+ create(type: "polygon" | "line"): Line | Polygon | undefined;
29
+ /** 禁用除创建层外的其他图层群组交互,并记录原始 isInteractive 以便复原 */
30
+ private disableOtherLayerGroups;
31
+ /** 复原此前禁用的图层群组的 isInteractive */
32
+ private restoreLayerGroupsInteractive;
33
+ createLine(): Line;
34
+ createPolygon(): Polygon;
35
+ finish?: (overlay?: Polygon | Line) => void;
36
+ /** 从创建层中移除指定覆盖物,不传则清空该层全部 */
37
+ removeOverlays(overlay?: Polygon | Line): void;
38
+ /** 清空创建层并重置当前创建状态 */
39
+ clear(): void;
40
+ /** 销毁实例:清空覆盖物并移除所有事件监听 */
41
+ destroy(): void;
42
+ /** 当前类型完成绘制所需的最少顶点数(多边形 3,线 2) */
43
+ private get minPointCount();
44
+ /** 从鼠标事件得到坐标轴上的 [x, y],若设置了限位器则先限位再返回 */
45
+ private getAxisValueFromEvent;
46
+ /** 鼠标移动:用已确定顶点 + 当前鼠标的坐标轴值更新 overlay.value 预览(至少有一个确定点后才生效) */
47
+ private handleMousemove;
48
+ /** 左键点击:将当前坐标轴值追加为顶点并刷新 overlay.value 预览 */
49
+ private handleClick;
50
+ /** 右键:若顶点数达标则写回 overlay.value 并回调完成,否则移除当前覆盖物并取消创建 */
51
+ private handleContextmenu;
52
+ }
@@ -1,4 +1,4 @@
1
- import { default as _Canvas } from '..';
1
+ import { default as _Canvas_Axis } from '..';
2
2
  import { default as EventController } from '../public/eventController';
3
3
  import { default as Text } from './text';
4
4
  import { default as Point } from './point';
@@ -14,7 +14,7 @@ export default class OverlayGroup extends EventController {
14
14
  overlays: Set<OverlayType>;
15
15
  constructor(option: ConstructorOption);
16
16
  /** 设置主画布 */
17
- setMainCanvas(mainCanvas?: _Canvas): void;
17
+ setMainCanvas(mainCanvas?: _Canvas_Axis): void;
18
18
  /** 设置覆盖物重新绘制方法 */
19
19
  setNotifyReload(notifyReload?: () => void): void;
20
20
  /** 添加覆盖物 */
@@ -1,7 +1,7 @@
1
- import { default as _Canvas } from '../..';
1
+ import { default as _Canvas_Axis } from '../..';
2
2
  import { OverlayType } from '../index';
3
3
  import { EventHandler, default as EventController } from '../../public/eventController';
4
- import { _Type_DeepPartial } from '../../..';
4
+ import { _Type_DeepPartial } from '../../../../';
5
5
  import { BaseLineStyle, PointStyleType } from '../../common.type';
6
6
  type ConstructorOption<T, V> = ConstructorParameters<typeof EventController>[0] & {
7
7
  /** 样式 */
@@ -77,7 +77,7 @@ export default abstract class Overlay<T, V extends [number, number] | [number, n
77
77
  redrawOnIsHoverChange: boolean;
78
78
  /** 默认 hover 事件 */
79
79
  defaultHover: EventHandler<"hover">;
80
- setMainCanvas(mainCanvas?: _Canvas): void;
80
+ setMainCanvas(mainCanvas?: _Canvas_Axis): void;
81
81
  setNotifyReload(notifyReload?: () => void): void;
82
82
  /** 值范围 */
83
83
  private _valueScope?;
@@ -1,5 +1,5 @@
1
1
  import { default as Canvas } from '..';
2
- import { _Type_DeepPartial } from '../..';
2
+ import { _Type_DeepPartial } from '../../../';
3
3
  export default class Axis {
4
4
  /** 画布 */
5
5
  private canvas;
@@ -102,7 +102,7 @@ export default class BaseData extends EventController {
102
102
  /** 绘制坐标轴 */
103
103
  drawAxis: Axis;
104
104
  /** 图层群组 集合 */
105
- protected layerGroups: Map<string, LayerGroup>;
105
+ layerGroups: Map<string, LayerGroup>;
106
106
  constructor(option: ConstructorOption);
107
107
  setNotifyReload(notifyReload?: () => void): void;
108
108
  /** 获取默认中心点位置 */
@@ -1,4 +1,4 @@
1
- import { _Type_DeepPartial } from '../..';
1
+ import { _Type_DeepPartial } from '../../../';
2
2
  import { default as Axis } from './axis';
3
3
  import { default as Event } from './event';
4
4
  import { default as OverlayGroup, OverlayType } from '../OverlayGroup';
@@ -1,4 +1,4 @@
1
- import { _Type_DeepPartial } from '../..';
1
+ import { _Type_DeepPartial } from '../../../';
2
2
  import { KnownStyleKeys, StyleType } from '../common.type';
3
3
  import { default as BaseData } from './basedata';
4
4
  type ConstructorOption = ConstructorParameters<typeof BaseData>[0] & {
@@ -9,11 +9,13 @@ import { default as Polygon } from './OverlayGroup/polygon';
9
9
  import { default as Custom } from './OverlayGroup/custom';
10
10
  import { default as Arc } from './OverlayGroup/arc';
11
11
  import { default as ArcTo } from './OverlayGroup/arcTo';
12
+ import { default as OverlayCreator } from './OverlayCreator';
13
+ import { default as ViewFit } from './public/viewFit';
12
14
  import { DeepArray } from './common.type';
13
15
  export type * from './index.types';
14
16
  type ConstructorOption = ConstructorParameters<typeof QuickMethod>[0] & {
15
17
  /** 轴线显示属性 */
16
- axisShow?: Parameters<_Canvas["toggleAxis"]>[0];
18
+ axisShow?: Parameters<_Canvas_Axis["toggleAxis"]>[0];
17
19
  };
18
20
  /**
19
21
  * 你好啊你好的画布工具类
@@ -21,13 +23,12 @@ type ConstructorOption = ConstructorParameters<typeof QuickMethod>[0] & {
21
23
  *
22
24
  * 使用示例:
23
25
  * - GitHub演示:
24
- * - 基础画布: https://adminnhanh.github.io/nhanh-frontend-view/#/canvas/_Canvas
25
- * - 动态图表(月牙定理): https://adminnhanh.github.io/nhanh-frontend-view/#/math/DynamicDiagram/%E6%9C%88%E7%89%99%E5%AE%9A%E7%90%86
26
- * - 阿里云演示:
27
- * - 基础画布: https://nhanh.xin/#/canvas/_Canvas
28
- * - 动态图表(月牙定理): https://nhanh.xin/#/math/DynamicDiagram/%E6%9C%88%E7%89%99%E5%AE%9A%E7%90%86
26
+ * - 基础画布: https://nha-nh.github.io/canvas/_Canvas_Axis
27
+ * - 动态图表(月牙定理): https://nha-nh.github.io/math/DynamicDiagram/%E6%9C%88%E7%89%99%E5%AE%9A%E7%90%86
29
28
  */
30
- export declare class _Canvas extends QuickMethod {
29
+ export declare class _Canvas_Axis extends QuickMethod {
30
+ /** 视图适配工具:默认缩放、居中计算 */
31
+ static ViewFit: typeof ViewFit;
31
32
  /** 图层群组 */
32
33
  static LayerGroup: typeof LayerGroup;
33
34
  /** 图层 */
@@ -48,6 +49,8 @@ export declare class _Canvas extends QuickMethod {
48
49
  static Arc: typeof Arc;
49
50
  /** 圆角 */
50
51
  static ArcTo: typeof ArcTo;
52
+ /** 按坐标轴值创建覆盖物(多边形/线)的交互管理 */
53
+ overlayCreator: OverlayCreator;
51
54
  constructor(option: ConstructorOption);
52
55
  private initLayerGroups;
53
56
  /** 获取图层群组 集合 */
@@ -67,4 +70,4 @@ export declare class _Canvas extends QuickMethod {
67
70
  /** 销毁 */
68
71
  destroy(): void;
69
72
  }
70
- export default _Canvas;
73
+ export default _Canvas_Axis;
@@ -9,6 +9,8 @@ import { default as Axis } from './core/axis';
9
9
  import { default as Custom } from './OverlayGroup/custom';
10
10
  import { default as Arc } from './OverlayGroup/arc';
11
11
  import { default as ArcTo } from './OverlayGroup/arcTo';
12
+ import { default as OverlayCreatorByAxisValue } from './OverlayCreator';
13
+ import { default as ViewFit } from './public/viewFit';
12
14
  import { EventHandler } from './public/eventController';
13
15
  import { default as Overlay } from './OverlayGroup/public/overlay';
14
- export type { LayerGroup, OverlayGroup, Layer, OverlayType, Overlay, Point, Text, Line, Polygon, Axis, Custom, Arc, ArcTo, EventHandler, };
16
+ export type { LayerGroup, OverlayGroup, Layer, OverlayType, Overlay, Point, Text, Line, Polygon, Axis, Custom, Arc, ArcTo, OverlayCreatorByAxisValue, ViewFit, EventHandler, };
@@ -1,4 +1,4 @@
1
- import { default as _Canvas } from '..';
1
+ import { default as _Canvas_Axis } from '..';
2
2
  declare abstract class Base<T extends Base<T>> {
3
3
  /** 父级 */
4
4
  parent?: T;
@@ -7,15 +7,15 @@ declare abstract class Base<T extends Base<T>> {
7
7
  /** 自定义扩展数据 */
8
8
  extData?: any;
9
9
  /** 主画布 */
10
- mainCanvas?: _Canvas;
10
+ mainCanvas?: _Canvas_Axis;
11
11
  private _isRecalculate;
12
12
  /** 是否需要重新计算坐标 */
13
13
  get isRecalculate(): boolean;
14
14
  set isRecalculate(isRecalculate: boolean);
15
15
  /** 是否是同一个主画布 */
16
- equalsMainCanvas(mainCanvas?: _Canvas): boolean;
16
+ equalsMainCanvas(mainCanvas?: _Canvas_Axis): boolean;
17
17
  /** 设置主画布 */
18
- setMainCanvas(mainCanvas?: _Canvas): void;
18
+ setMainCanvas(mainCanvas?: _Canvas_Axis): void;
19
19
  /** 通知重新加载 */
20
20
  notifyReload?: (needForceExecute?: boolean) => void;
21
21
  /** 设置通知重新加载 */
@@ -47,7 +47,7 @@ interface BaseDataOptions {
47
47
  /** 自定义扩展数据 */
48
48
  extData?: any;
49
49
  /** 主画布 */
50
- mainCanvas?: _Canvas;
50
+ mainCanvas?: _Canvas_Axis;
51
51
  /** 通知重新加载 */
52
52
  notifyReload?: (needForceExecute?: boolean) => void;
53
53
  /** 是否显示 */
@@ -0,0 +1,28 @@
1
+ /**
2
+ * 视图适配工具:根据内容尺寸与容器尺寸计算默认缩放与居中位置,供画布/图像适配使用。
3
+ */
4
+ export default class ViewFit {
5
+ /**
6
+ * 计算默认缩放比例,使图像适配视图容器
7
+ * @param naturalWidth 图像原始宽度
8
+ * @param naturalHeight 图像原始高度
9
+ * @param viewWidth 容器宽度
10
+ * @param viewHeight 容器高度
11
+ * @param step 缩放步长
12
+ * @param factor 每翻一倍对应的增量(factor / step = 10)
13
+ * @returns 缩放比例(步长 0.02),小于1表示缩小,大于1表示放大
14
+ */
15
+ static computeDefaultScale(naturalWidth: number, naturalHeight: number, viewWidth: number, viewHeight: number, step?: number, factor?: number): number;
16
+ /**
17
+ * 计算默认居中偏移,使内容在视图中居中
18
+ * @param naturalWidth 图像/内容原始宽度
19
+ * @param naturalHeight 图像/内容原始高度
20
+ * @param viewWidth 容器宽度
21
+ * @param viewHeight 容器高度
22
+ * @returns 居中时的 left、top 偏移
23
+ */
24
+ static computeDefaultCenter(naturalWidth: number, naturalHeight: number, viewWidth: number, viewHeight: number): {
25
+ left: number;
26
+ top: number;
27
+ };
28
+ }