ms-types 0.0.11 → 0.0.14

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/system.d.ts CHANGED
@@ -1,3 +1,6 @@
1
+ /**
2
+ * 系统模块 包含系统操作、系统信息等功能
3
+ */
1
4
  declare namespace system {
2
5
  /**
3
6
  * 启动应用
@@ -5,6 +8,11 @@ declare namespace system {
5
8
  * @param args 应用参数
6
9
  * @param env 应用环境变量
7
10
  * @returns 是否启动成功
11
+ * @example
12
+ * const started = system.startApp("cn.magicnode.script, [], {})
13
+ * if (started) {
14
+ * console.log("启动成功")
15
+ * }
8
16
  */
9
17
  function startApp(
10
18
  bundleId: string,
@@ -15,17 +23,32 @@ declare namespace system {
15
23
  * 关闭应用
16
24
  * @param bundleId 应用bundleId
17
25
  * @returns 是否关闭成功
26
+ * @example
27
+ * const stopped = system.stopApp("cn.magicnode.script")
28
+ * if (stopped) {
29
+ * console.log("关闭成功")
30
+ * }
18
31
  */
19
32
  function stopApp(bundleId: string): boolean;
20
33
  /**
21
- * 激活应用
34
+ * 激活应用 没启动就会启动 启动了就会进入前台
22
35
  * @param bundleId 应用bundleId
23
36
  * @returns 是否激活成功
37
+ * @example
38
+ * const activated = system.activateApp("cn.magicnode.script")
39
+ * if (activated) {
40
+ * console.log("激活成功")
41
+ * }
24
42
  */
25
43
  function activateApp(bundleId: string): boolean;
26
44
  /**
27
- * 获取激活应用信息
28
- * @returns 激活应用信息
45
+ * 获取当前在前台的应用信息
46
+ * @returns 当前在前台的应用信息
47
+ * @example
48
+ * const info = system.activateAppInfo()
49
+ * if (info) {
50
+ * console.log(info.name)
51
+ * }
29
52
  */
30
53
  function activateAppInfo(): {
31
54
  bundleId: string;
@@ -39,40 +62,100 @@ declare namespace system {
39
62
  /**
40
63
  * 获取系统是否锁屏
41
64
  * @returns 是否锁屏
65
+ * @example
66
+ * const locked = system.isLocked()
67
+ * if (locked) {
68
+ * console.log("锁屏")
69
+ * }
42
70
  */
43
71
  function isLocked(): boolean;
44
72
  /**
45
73
  * 锁屏
46
74
  * @returns 是否锁屏成功
75
+ * @example
76
+ * const locked = system.lock()
77
+ * if (locked) {
78
+ * console.log("锁屏成功")
79
+ * }
47
80
  */
48
81
  function lock(): boolean;
49
82
  /**
50
- * 解锁
83
+ * 解锁 如果有密码 会停在解锁界面
51
84
  * @returns 是否解锁成功
85
+ * @example
86
+ * const unlocked = system.unlock()
87
+ * if (unlocked) {
88
+ * console.log("解锁成功")
89
+ * }
52
90
  */
53
91
  function unlock(): boolean;
54
92
  /**
55
93
  * 设置剪贴板 APP 在前台运行时才能设置
56
94
  * @param text 剪贴板内容
57
95
  * @returns 是否设置成功
96
+ * @example
97
+ * const set = system.setClipboard("hello")
98
+ * if (set) {
99
+ * console.log("设置成功")
100
+ * }
58
101
  */
59
102
  function setClipboard(text: string): boolean;
60
103
  /**
61
104
  * 获取剪贴板
62
105
  * @returns 剪贴板内容
106
+ * @example
107
+ * const text = system.getClipboard()
108
+ * if (text) {
109
+ * console.log(text)
110
+ * }
63
111
  */
64
112
  function getClipboard(): string | null;
65
113
  /**
66
114
  * 打开URL
67
115
  * @param url URL
68
116
  * @returns 是否打开成功
117
+ * @example
118
+ * const opened = system.openURL("https://www.baidu.com")
119
+ * if (opened) {
120
+ * console.log("打开成功")
121
+ * }
69
122
  */
70
123
  function openURL(url: string): boolean;
71
124
  /**
72
125
  * 通知
73
126
  * @param msg 通知内容
74
127
  * @param title 通知标题
75
- * @param id 通知id
128
+ * @param id 通知id 通知id相同的会被覆盖
129
+ * @example
130
+ * system.notify("通知内容", "通知标题", "1111")
76
131
  */
77
132
  function notify(msg: string, title: string, id: string): void;
133
+ /**
134
+ * 获取内存使用信息
135
+ * @returns 内存使用信息,包含已使用内存、可用内存和总内存(单位:MB)
136
+ * @example
137
+ * const memInfo = system.getMemoryInfo()
138
+ * console.log(`已使用: ${memInfo.used}MB, 可用: ${memInfo.available}MB, 总计: ${memInfo.total}MB`)
139
+ */
140
+ function getMemoryInfo(): {
141
+ used: number;
142
+ available: number;
143
+ total: number;
144
+ };
145
+ /**
146
+ * 获取已使用内存
147
+ * @returns 已使用内存大小(单位:MB)
148
+ * @example
149
+ * const usedMemory = system.getUsedMemory()
150
+ * console.log(`已使用内存: ${usedMemory}MB`)
151
+ */
152
+ function getUsedMemory(): number;
153
+ /**
154
+ * 获取可用内存
155
+ * @returns 可用内存大小(单位:MB)
156
+ * @example
157
+ * const availableMemory = system.getAvailableMemory()
158
+ * console.log(`可用内存: ${availableMemory}MB`)
159
+ */
160
+ function getAvailableMemory(): number;
78
161
  }
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
  }
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
  }
@@ -1,68 +0,0 @@
1
- declare const __workerName__: string;
2
-
3
- declare namespace workerThread {
4
- /**
5
- * 创建新线程
6
- * @param name 线程名称
7
- * @returns 线程id
8
- */
9
- function newWorker(name: string): string;
10
- /**
11
- * 检查线程是否运行
12
- * @param name 线程名称
13
- * @returns 是否运行
14
- */
15
- function isRunning(name: string): boolean;
16
- /**
17
- * 检查线程是否有函数
18
- * @param funcName 函数名称
19
- * @returns 是否有函数
20
- */
21
- function hasWorkerFunction(funcName: string): boolean;
22
- /**
23
- * 添加线程函数
24
- * @param funcName 函数名称
25
- * @param func 函数
26
- * @returns 是否添加成功
27
- */
28
- function addWorkerFunction(
29
- funcName: string,
30
- func: (data: any) => any
31
- ): boolean;
32
- /**
33
- * 移除线程函数
34
- * @param funcName 函数名称
35
- * @returns 是否移除成功
36
- */
37
- function removeWorkerFunction(funcName: string): boolean;
38
- /**
39
- * 调用线程函数
40
- * @param funcName 函数名称
41
- * @param data 数据
42
- * @returns 调用结果
43
- */
44
- function callWorkerFunction(funcName: string, data: any): any;
45
- /**
46
- * 移除线程
47
- * @param name 线程名称
48
- * @returns 是否移除成功
49
- */
50
- function removeWorker(name: string): boolean;
51
- /**
52
- * 检查线程是否取消
53
- * @param name 线程名称
54
- * @returns 是否取消
55
- */
56
- function isCancelled(name: string): boolean;
57
- /**
58
- * 取消线程
59
- * @param name 线程名称
60
- * @returns 是否取消成功
61
- */
62
- function cancelWorker(name: string): boolean;
63
- /**
64
- * 停止所有线程
65
- * @returns 是否停止成功
66
- */
67
- function stopAll(): boolean;
68
- }