ms-types 0.0.11 → 0.0.13

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/types/thread.d.ts CHANGED
@@ -1,9 +1,5 @@
1
1
  /**
2
- * 当前线程名称
3
- */
4
- declare let __threadName__: string;
5
- /**
6
- * 线程相关函数
2
+ * 线程模块 包含线程操作、线程回调等功能
7
3
  */
8
4
  declare namespace thread {
9
5
  /**
@@ -11,25 +7,59 @@ declare namespace thread {
11
7
  * @param threadJsFile 线程js文件路径
12
8
  * @param callbackName 回调函数名称
13
9
  * @param callbackFunc 回调函数
14
- * @returns 线程id
10
+ * @returns 线程名称
11
+ * @example
12
+ * thread.execCodeAsync("thread.js", "callback", (data) => {
13
+ * console.log(data)
14
+ * return "1111"
15
+ * })
16
+ *
17
+ * thread.js
18
+ * while (!__shouldExit__) {
19
+ * // 通知主线程并传递数据
20
+ * const data = thread.invokeCallback("callback", "hello world")
21
+ * // 主线程返回数据
22
+ * console.log(data)
23
+ * sleep(1000)
24
+ * }
15
25
  */
16
26
  function execCodeAsync(
17
27
  threadJsFile: string,
18
28
  callbackName: string,
19
- callbackFunc: (data?: any) => void
29
+ callbackFunc: (data?: any) => any
20
30
  ): String | null;
21
31
  /**
22
32
  * 调用线程回调函数
23
- * @param name 线程名称
33
+ * @param name 回调函数名称
24
34
  * @param data 回调数据
35
+ * @returns 回调返回值
36
+ * @example
37
+ * const data = thread.invokeCallback("callback", "hello world")
38
+ * console.log(data)
25
39
  */
26
- function invokeCallback(name: string, data?: any): void;
40
+ function invokeCallback(name: string, data?: any): any;
27
41
  /**
28
42
  * 创建新线程
29
43
  * @param threadJsFile 线程js文件路径
30
- * @returns 线程id
44
+ * @returns 线程对象
45
+ * @example
46
+ * const newThread = thread.newThread("thread.js")
47
+ * newThread.addCallback("callback", (data) => {
48
+ * console.log(data)
49
+ * return "1111"
50
+ * })
31
51
  */
32
52
  function newThread(threadJsFile: string): {
53
+ /**
54
+ * 线程名称
55
+ */
56
+ name: string;
57
+ /**
58
+ * 添加回调函数
59
+ * @param callbackName 回调函数名称
60
+ * @param callbackFunc 回调函数
61
+ * @returns 是否添加成功
62
+ */
33
63
  addCallback: (
34
64
  callbackName: string,
35
65
  callbackFunc: (data?: any) => void
@@ -39,17 +69,33 @@ declare namespace thread {
39
69
  * 取消线程
40
70
  * @param name 线程名称
41
71
  * @returns 是否取消成功
72
+ * @example
73
+ * const newThread = thread.newThread("thread.js")
74
+ * newThread.addCallback("callback", (data) => {
75
+ * console.log(data)
76
+ * return "1111"
77
+ * })
78
+ * thread.cancelThread(newThread.name)
42
79
  */
43
80
  function cancelThread(name: string): boolean;
44
81
  /**
45
82
  * 检查线程是否已取消
46
83
  * @param name 线程名称
47
84
  * @returns 是否已取消
85
+ * @example
86
+ * const newThread = thread.newThread("thread.js")
87
+ * newThread.addCallback("callback", (data) => {
88
+ * console.log(data)
89
+ * return "1111"
90
+ * })
91
+ * thread.isCancelled(newThread.name)
48
92
  */
49
93
  function isCancelled(name: string): boolean;
50
94
  /**
51
95
  * 停止所有线程
52
96
  * @returns 是否停止成功
97
+ * @example
98
+ * thread.stopAll()
53
99
  */
54
100
  function stopAll(): boolean;
55
101
  }
package/types/ui.d.ts CHANGED
@@ -1,31 +1,40 @@
1
1
  /**
2
- * 注册 UI 函数
2
+ * 注册UI函数 网页页面使用,给主进程调用
3
3
  * @param name 函数名称
4
4
  * @param func 函数
5
5
  */
6
6
  declare function registerUIFunc(name: string, func: (data: any) => void): void;
7
7
 
8
8
  /**
9
- * 发送事件
9
+ * 发送事件 网页页面使用 给主进程发送事件
10
10
  * @param event 事件名称
11
11
  * @param data 事件参数
12
12
  */
13
13
  declare function emitEvent(event: string, data: any): void;
14
14
 
15
+ /**
16
+ * UI模块 包含加载html文件、调用js方法等功能
17
+ */
15
18
  declare namespace ui {
16
19
  interface WebView {
17
20
  /**
18
21
  * 显示WebView
22
+ * @example
23
+ * webview.show()
19
24
  */
20
25
  show(): void;
21
26
  /**
22
27
  * 关闭WebView
28
+ * @example
29
+ * webview.close()
23
30
  */
24
31
  close(): void;
25
32
  /**
26
33
  * 调用WebView中的方法
27
34
  * @param key 方法名
28
35
  * @param data 方法参数
36
+ * @example
37
+ * webview.call("jsMethod", "hello world")
29
38
  */
30
39
  call(key: string, data: any): void;
31
40
  }
@@ -34,6 +43,22 @@ declare namespace ui {
34
43
  * @param file 文件名
35
44
  * @param onEvent 事件回调
36
45
  * @returns WebView实例
46
+ * @example
47
+ * const webview = ui.newWebView("index.html", (event, data) => {
48
+ * // 接收网页发送的事件
49
+ * if(event === "page.loaded") {
50
+ * console.log("页面加载完成")
51
+ * } else if(event === "page.close") {
52
+ * console.log("页面关闭")
53
+ * } else if(event === "console.log") {
54
+ * console.log("网页调用console.log", data)
55
+ * } else {
56
+ * // 自定义事件
57
+ * console.log(event, data)
58
+ * }
59
+ * })
60
+ * webview.show()
61
+ * webview.call("jsMethod", "hello world")
37
62
  */
38
63
  function newWebView(
39
64
  file: string,
package/types/utils.d.ts CHANGED
@@ -1,37 +1,44 @@
1
+ /**
2
+ * 工具模块 包含工具函数等功能
3
+ */
1
4
  declare namespace utils {
2
5
  /**
3
6
  * 格式化时间
4
7
  * @param format 格式化字符串
5
8
  * @returns 格式化后的时间字符串
9
+ * @example
10
+ * utils.timeFormat("yyyy-MM-dd hh:mm:ss")
6
11
  */
7
12
  function timeFormat(format: string): string;
8
13
  /**
9
14
  * 读取资源文件
10
15
  * @param fileName 文件名
11
16
  * @returns 文件内容
17
+ * @example
18
+ * utils.readResFile("test.txt")
12
19
  */
13
20
  function readResFile(fileName: string): string | null;
14
21
  /**
15
22
  * 读取资源图片
16
23
  * @param fileName 文件名
17
- * @returns 图片内容
24
+ * @returns 返回 image 模块的 imageId
25
+ * @example
26
+ * utils.readResImage("test.png")
18
27
  */
19
28
  function readResImage(fileName: string): string | null;
20
- /**
21
- * 获取资源文件路径
22
- * @param fileName 文件名
23
- * @returns 资源文件路径
24
- */
25
- function getResFilePath(fileName: string): string;
26
29
  /**
27
30
  * 生成随机数
28
31
  * @param min 最小值
29
32
  * @param max 最大值
30
33
  * @returns 随机数
34
+ * @example
35
+ * utils.random(1, 10)
31
36
  */
32
37
  function random(min: number, max: number): number;
33
38
  /**
34
39
  * 将应用置入前台
40
+ * @example
41
+ * utils.takeMeToFront()
35
42
  */
36
43
  function takeMeToFront(): void;
37
44
  }
@@ -1,5 +1,6 @@
1
- declare const __workerName__: string;
2
-
1
+ /**
2
+ * 工作线程模块 包含工作线程操作、工作线程回调等功能
3
+ */
3
4
  declare namespace workerThread {
4
5
  /**
5
6
  * 创建新线程
package/types/yolo.d.ts CHANGED
@@ -1,53 +1,53 @@
1
1
  /**
2
- * YOLO目标检测模块类型定义
2
+ * YOLO检测结果
3
3
  */
4
- declare namespace yolo {
4
+ declare interface YoloResult {
5
+ /**
6
+ * 检测框的左上角x坐标
7
+ */
8
+ x: number;
9
+ /**
10
+ * 检测框的左上角y坐标
11
+ */
12
+ y: number;
13
+ /**
14
+ * 检测框的右下角x坐标
15
+ */
16
+ ex: number;
17
+ /**
18
+ * 检测框的右下角y坐标
19
+ */
20
+ ey: number;
5
21
  /**
6
- * YOLO检测结果
22
+ * 检测框的中心点x坐标
7
23
  */
8
- type YoloResult = {
9
- /**
10
- * 检测框的左上角x坐标
11
- */
12
- x: number;
13
- /**
14
- * 检测框的左上角y坐标
15
- */
16
- y: number;
17
- /**
18
- * 检测框的右下角x坐标
19
- */
20
- ex: number;
21
- /**
22
- * 检测框的右下角y坐标
23
- */
24
- ey: number;
25
- /**
26
- * 检测框的中心点x坐标
27
- */
28
- centerX: number;
29
- /**
30
- * 检测框的中心点y坐标
31
- */
32
- centerY: number;
33
- /**
34
- * 检测框的宽度
35
- */
36
- width: number;
37
- /**
38
- * 检测框的高度
39
- */
40
- height: number;
41
- /**
42
- * 检测框的置信度
43
- */
44
- confidence: number;
45
- /**
46
- * 检测框的类别ID
47
- */
48
- classId: number;
49
- };
24
+ centerX: number;
25
+ /**
26
+ * 检测框的中心点y坐标
27
+ */
28
+ centerY: number;
29
+ /**
30
+ * 检测框的宽度
31
+ */
32
+ width: number;
33
+ /**
34
+ * 检测框的高度
35
+ */
36
+ height: number;
37
+ /**
38
+ * 检测框的置信度
39
+ */
40
+ confidence: number;
41
+ /**
42
+ * 检测框的类别ID
43
+ */
44
+ classId: number;
45
+ }
50
46
 
47
+ /**
48
+ * YOLO目标检测模块 包含加载模型、目标检测等功能
49
+ */
50
+ declare namespace yolo {
51
51
  /**
52
52
  * 加载YOLOv11模型
53
53
  * @param paramPath ncnn模型的param文件的绝对路径
@@ -55,6 +55,8 @@ declare namespace yolo {
55
55
  * @param nc 模型的标签数量,可在标签集data.yaml中看到
56
56
  * @param useGpu 是否启动gpu,默认用cpu
57
57
  * @returns 加载成功返回模型ID字符串,失败返回null
58
+ * @example
59
+ * const modelId = yolo.loadV11("yolov11n.param", "yolov11n.bin", 80, false)
58
60
  */
59
61
  function loadV11(
60
62
  paramPath: string,
@@ -71,6 +73,8 @@ declare namespace yolo {
71
73
  * @param threshold 置信度,默认0.4,小于这个值的会被过滤掉
72
74
  * @param nmsThreshold 重叠阈值,一般是0.5不需要更改
73
75
  * @returns 检测结果数组
76
+ * @example
77
+ * const results = yolo.detect(modelId, null, 640, 0.4, 0.5)
74
78
  */
75
79
  function detect(
76
80
  modelId: string,
@@ -83,11 +87,15 @@ declare namespace yolo {
83
87
  /**
84
88
  * 释放指定模型资源
85
89
  * @param modelId 模型ID
90
+ * @example
91
+ * yolo.free(modelId)
86
92
  */
87
93
  function free(modelId: string): void;
88
94
 
89
95
  /**
90
96
  * 释放所有模型资源
97
+ * @example
98
+ * yolo.freeAll()
91
99
  */
92
100
  function freeAll(): void;
93
101
  }