ms-types 0.9.35 → 0.9.37

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.
@@ -2,22 +2,33 @@
2
2
  ---@class DotOCR
3
3
  local _DotOCR = {}
4
4
 
5
+ ---@class OCRChar
6
+ ---@field text string 识别出的文本;查找结果中为命中的目标字符串
7
+ ---@field confidence number 识别置信度 (0-1)
8
+ ---@field x integer 文本区域左上角 x 坐标
9
+ ---@field y integer 文本区域左上角 y 坐标
10
+ ---@field ex integer 文本区域右下角 x 坐标
11
+ ---@field ey integer 文本区域右下角 y 坐标
12
+ ---@field width integer 文本区域宽度
13
+ ---@field height integer 文本区域高度
14
+ ---@field centerX integer 文本区域中心点 x 坐标
15
+ ---@field centerY integer 文本区域中心点 y 坐标
16
+
5
17
  --- 点阵 OCR;全局 `dotocr`
6
18
 
7
- --- loadFont
19
+ --- 从资源路径加载字库并缓存
8
20
  ---@param fontPath string
9
- ---@return string|nil
21
+ ---@return string|nil 字库 ID,失败返回 nil
10
22
  function _DotOCR.loadFont(fontPath) return nil end
11
23
 
12
- --- free
24
+ --- 释放指定字库
13
25
  ---@param fontId string
14
26
  function _DotOCR.free(fontId) end
15
27
 
16
- --- freeAll
17
-
28
+ --- 释放全部已加载的点阵字库
18
29
  function _DotOCR.freeAll() end
19
30
 
20
- --- recognizeAbs
31
+ --- 识别文字并返回原图或全屏绝对坐标
21
32
  ---@param fontId string
22
33
  ---@param input string
23
34
  ---@param x integer|nil
@@ -25,10 +36,14 @@ function _DotOCR.freeAll() end
25
36
  ---@param ex integer|nil
26
37
  ---@param ey integer|nil
27
38
  ---@param confidenceThreshold number|nil
28
- ---@return table[]
29
- function _DotOCR.recognizeAbs(fontId, input, x, y, ex, ey, confidenceThreshold) return {} end
39
+ ---@return OCRChar[]
40
+ function _DotOCR.recognizeAbs(fontId, input, x, y, ex, ey, confidenceThreshold)
41
+ ---@type OCRChar[]
42
+ local ret = {}
43
+ return ret
44
+ end
30
45
 
31
- --- findTextAbs
46
+ --- 先识别再按行查找目标串,返回命中位置的绝对坐标
32
47
  ---@param fontId string
33
48
  ---@param input string
34
49
  ---@param targetTexts string[]
@@ -38,8 +53,12 @@ function _DotOCR.recognizeAbs(fontId, input, x, y, ex, ey, confidenceThreshold)
38
53
  ---@param ey integer|nil
39
54
  ---@param confidenceThreshold number|nil
40
55
  ---@param exactMatch boolean|nil
41
- ---@return table[]
42
- function _DotOCR.findTextAbs(fontId, input, targetTexts, x, y, ex, ey, confidenceThreshold, exactMatch) return {} end
56
+ ---@return OCRChar[]
57
+ function _DotOCR.findTextAbs(fontId, input, targetTexts, x, y, ex, ey, confidenceThreshold, exactMatch)
58
+ ---@type OCRChar[]
59
+ local ret = {}
60
+ return ret
61
+ end
43
62
 
44
63
  ---@type DotOCR
45
64
  dotocr = _DotOCR
@@ -19,7 +19,7 @@ function _File.mkdirs(path) return true end
19
19
 
20
20
  --- 读取文件
21
21
  --- @param path string 路径
22
- --- @return string 内容
22
+ --- @return string 内容,失败为空串
23
23
  function _File.readFile(path) return '' end
24
24
 
25
25
  --- 写入文件
@@ -40,7 +40,7 @@ function _File.deleteAllFile(path) return true end
40
40
 
41
41
  --- 读取资源文件(res 目录)
42
42
  --- @param name string 文件名
43
- --- @return string|nil 内容
43
+ --- @return string 内容,失败为空串
44
44
  function _File.readResFile(name) return '' end
45
45
 
46
46
  --- 获取 res 资源的本地文件路径;用完后应调用 cleanupResFile
@@ -74,12 +74,12 @@ function _File.appendLine(path, data) return true end
74
74
  --- 读取指定行
75
75
  --- @param path string 路径
76
76
  --- @param lineNo integer 行号
77
- --- @return string|nil 内容
77
+ --- @return string 内容,失败为空串
78
78
  function _File.readLine(path, lineNo) return '' end
79
79
 
80
80
  --- 读取所有行
81
81
  --- @param path string 路径
82
- --- @return string[] 行列表
82
+ --- @return string[] 行列表,失败为空表
83
83
  function _File.readAllLines(path) return {} end
84
84
 
85
85
  --- 复制文件
@@ -90,7 +90,7 @@ function _File.copy(src, dest) return true end
90
90
 
91
91
  --- 计算文件MD5
92
92
  --- @param path string 路径
93
- --- @return string|nil MD5
93
+ --- @return string MD5 值,失败为空串
94
94
  function _File.fileMD5(path) return '' end
95
95
 
96
96
  ---@type File
@@ -27,8 +27,8 @@ AppName = ''
27
27
  ---@type string
28
28
  AppBundleId = ''
29
29
 
30
- --- 脚本 package.json 内容(表)
31
- ---@type table
30
+ --- 脚本 package.json 内容(动态键值表)
31
+ ---@type table<string, any>
32
32
  PackageJson = {}
33
33
 
34
34
  ---@class CpuThrottleDelay
@@ -63,11 +63,11 @@ function Sleep(ms) end
63
63
  function Time() return 0 end
64
64
 
65
65
  --- 将表转为 JSON 字符串
66
- ---@param data table
66
+ ---@param data table<string, any>|any[]
67
67
  ---@return string
68
68
  function ToJsonString(data) return '' end
69
69
 
70
- --- 启动同 VM 协作协程(不是 OS 线程),返回协程名
70
+ --- 启动协作协程,返回协程名
71
71
  ---@param func function
72
72
  ---@return string
73
73
  function StartThread(func) return '' end
@@ -76,7 +76,7 @@ function StartThread(func) return '' end
76
76
  ---@param threadName string
77
77
  function StopThread(threadName) end
78
78
 
79
- --- 当前协作协程是否应退出。主脚本收到停止后由引擎 hook / Sleep 直接中断,不必轮询本函数。
79
+ --- 当前协程是否应退出
80
80
  ---@return boolean
81
81
  function ShouldInterruptThread() return false end
82
82
 
package/types/lua/hid.lua CHANGED
@@ -268,12 +268,14 @@ function _HID.unlock() return true end
268
268
  --- @return boolean 成功
269
269
  function _HID.takeMeToFront() return true end
270
270
 
271
- --- 当前打开应用信息(iOS18+)
272
- --- @return {name: string, bundleId: string} 信息;无前台应用时为空表
271
+ ---@class HidCurrentAppInfo
272
+ ---@field name string 应用名称
273
+ ---@field bundleId string 应用 Bundle ID
274
+
275
+ --- 当前打开应用信息(iOS18+);无前台应用时为 nil
276
+ --- @return HidCurrentAppInfo|nil
273
277
  function _HID.currentAppInfo()
274
- ---@type table
275
- local ret
276
- return ret
278
+ return nil
277
279
  end
278
280
 
279
281
  ---@type HID
@@ -2,22 +2,40 @@
2
2
  ---@class HotUpdate
3
3
  local _HotUpdate = {}
4
4
 
5
- --- 检查更新
6
- --- @param options {url: string|nil, version: integer|nil, timeout: integer|nil}|nil
7
- --- @return {needUpdate: boolean, data?: table, error?: string} 结果
8
- function _HotUpdate.checkUpdate(options)
9
- return {
10
- needUpdate = true,
11
- data = {version = 1, url = "https://example.com/update.zip"}
12
- }
5
+ ---@class HotUpdateResponse
6
+ ---@field download_url string 新包下载地址
7
+ ---@field version integer 新包版本号
8
+ ---@field download_timeout integer 下载超时(秒)
9
+ ---@field dialog boolean 是否用对话框展示
10
+ ---@field msg string 对话框消息
11
+ ---@field force boolean 对话框模式下是否强制更新
12
+ ---@field md5 string|nil 更新包 MD5
13
+
14
+ ---@class HotUpdateResult
15
+ ---@field needUpdate boolean 是否需要更新
16
+ ---@field error string|nil 检查失败时的错误
17
+ ---@field data HotUpdateResponse|nil 需要更新时的服务器数据
18
+
19
+ ---@class HotUpdateInstallResult
20
+ ---@field updated boolean 是否已安装
21
+ ---@field error string|nil 安装失败时的错误
22
+
23
+ --- 检查更新(无参数)
24
+ ---@return HotUpdateResult
25
+ function _HotUpdate.checkUpdate()
26
+ ---@type HotUpdateResult
27
+ return { needUpdate = false }
13
28
  end
14
29
 
15
- --- 下载并安装
16
- --- @return {updated: boolean, error?: string} 结果
17
- function _HotUpdate.downloadAndInstall() return {updated = true, error = nil} end
30
+ --- 下载并安装;成功后会自动重启脚本
31
+ ---@return HotUpdateInstallResult
32
+ function _HotUpdate.downloadAndInstall()
33
+ ---@type HotUpdateInstallResult
34
+ return { updated = false }
35
+ end
18
36
 
19
- --- 当前版本
20
- --- @return integer 版本号
37
+ --- 当前版本号;失败返回 0
38
+ ---@return integer
21
39
  function _HotUpdate.getCurrentVersion() return 0 end
22
40
 
23
41
  ---@type HotUpdate
@@ -4,7 +4,7 @@ local _Http = {}
4
4
 
5
5
  ---@class HttpRequestOptions
6
6
  ---@field url string @请求地址
7
- ---@field timeout integer|nil @请求超时(毫秒)
7
+ ---@field timeout integer|nil @请求超时(毫秒),默认 30000
8
8
  ---@field method string|nil @请求方法 GET/POST/...
9
9
  ---@field proxy {host:string, port:integer}|nil @代理服务器
10
10
  ---@field followRedirects boolean|nil @是否跟随重定向
@@ -47,7 +47,7 @@ end
47
47
  --- GET 请求(同名:httpGet)
48
48
  --- @param url string
49
49
  --- @param params table<string,string>|nil
50
- --- @param timeout integer|nil
50
+ --- @param timeout integer|nil 默认 30000
51
51
  --- @param headers table<string,string>|nil
52
52
  --- @return string|nil
53
53
  function _Http.httpGet(url, params, timeout, headers) return '' end
@@ -56,7 +56,7 @@ function _Http.httpGet(url, params, timeout, headers) return '' end
56
56
  --- @param url string
57
57
  --- @param params table<string,string>|nil
58
58
  --- @param files table<string,string>|nil
59
- --- @param timeout integer|nil
59
+ --- @param timeout integer|nil 默认 30000
60
60
  --- @param headers table<string,string>|nil
61
61
  --- @return string|nil
62
62
  function _Http.httpPost(url, params, files, timeout, headers) return '' end
@@ -64,7 +64,7 @@ function _Http.httpPost(url, params, files, timeout, headers) return '' end
64
64
  --- POST JSON 请求
65
65
  --- @param url string
66
66
  --- @param json table|nil
67
- --- @param timeout integer|nil
67
+ --- @param timeout integer|nil 默认 30000
68
68
  --- @param headers table<string,string>|nil
69
69
  --- @return string|nil
70
70
  function _Http.postJSON(url, json, timeout, headers) return '' end
@@ -72,7 +72,7 @@ function _Http.postJSON(url, json, timeout, headers) return '' end
72
72
  --- 下载文件(同名:downloadFile)
73
73
  --- @param url string
74
74
  --- @param file string
75
- --- @param timeout integer|nil
75
+ --- @param timeout integer|nil 默认 30000
76
76
  --- @param headers table<string,string>|nil
77
77
  --- @return boolean
78
78
  function _Http.downloadFile(url, file, timeout, headers) return true end
@@ -21,6 +21,12 @@ local _Image = {}
21
21
  ---@field centerY integer 中心y坐标
22
22
  ---@field ex integer 右下角x坐标
23
23
  ---@field ey integer 右下角y坐标
24
+ ---@field scaleX number|nil 仅 method=99:命中时模板横向缩放
25
+ ---@field scaleY number|nil 仅 method=99:命中时模板纵向缩放
26
+
27
+ ---@class FindImageOptions
28
+ ---@field scaleFactors number[]|nil 仅 method=99:模板缩放比例列表
29
+ ---@field orz integer|nil 查找方向 1-8,与 findColor 相同
24
30
 
25
31
  --- 截取屏幕;坐标缺省 0 表示全屏
26
32
  --- @param x integer|nil 左上角 x
@@ -131,9 +137,9 @@ function _Image.cmpColor(id, points, threshold) return true end
131
137
  --- @param ey integer|nil 右下y
132
138
  --- @param threshold number 相似度 0.0-1.0
133
139
  --- @param limit integer|nil 限制个数
134
- --- @param method integer|nil 匹配方法 0|1|3|5|99
140
+ --- @param method integer|nil 匹配方法 0|1|3|5|99,默认 5
135
141
  --- @param rgb boolean|nil 是否使用RGB
136
- --- @param options table|nil 选项。scaleFactors 仅 method=99;orz 为查找方向 1-8(与 findColor 相同)
142
+ --- @param options FindImageOptions|nil 选项。scaleFactors 仅 method=99;orz 为查找方向 1-8
137
143
  --- @return Rect[] 结果矩形列表
138
144
  function _Image.findImage(id, templateImageId, x, y, ex, ey, threshold, limit,
139
145
  method, rgb, options) return {} end
@@ -9,9 +9,11 @@ local _MySQL = {}
9
9
  ---@field password string 密码
10
10
  ---@field database string 数据库名
11
11
  ---@field charset string|nil 字符集
12
+ ---@field connectTimeout integer|nil 连接超时(毫秒),默认 5000
13
+ ---@field queryTimeout integer|nil 查询超时(毫秒),默认 30000
12
14
 
13
15
  ---@class MySQLResult
14
- ---@field rows table[] 结果集
16
+ ---@field rows table<string, any>[] 结果集行
15
17
  ---@field affectedRows integer 受影响的行数
16
18
  ---@field success boolean 是否成功
17
19
  ---@field insertId integer|nil 插入ID
@@ -40,7 +40,7 @@ local _Node = {}
40
40
  ---@field clickCenter fun(self: NodeInfo, duration: integer|nil): boolean 点击中心
41
41
  ---@field clickRandom fun(self: NodeInfo, duration: integer|nil): boolean 点击随机位置
42
42
  ---@field parent fun(self: NodeInfo): NodeInfo|nil 父节点
43
- ---@field child fun(self: NodeInfo, index: integer): NodeInfo|nil 子节点
43
+ ---@field child fun(self: NodeInfo, index: integer): NodeInfo|nil 子节点,index 从 0 开始
44
44
  ---@field allChildren fun(self: NodeInfo): NodeInfo[] 所有子节点
45
45
  ---@field siblings fun(self: NodeInfo): NodeInfo[] 所有兄弟节点
46
46
  ---@field previousSiblings fun(self: NodeInfo): NodeInfo[] 前兄弟节点
@@ -2,15 +2,10 @@
2
2
  ---@class System
3
3
  local _System = {}
4
4
 
5
- ---@class ProcessArguments
6
- ---@field env table<string, any> 环境变量映射(键为字符串,值为任意类型)
7
- ---@field args string[] 启动参数列表
8
-
9
5
  ---@class ActivateAppInfo
10
6
  ---@field name string 应用名称
11
7
  ---@field pid integer 进程 ID
12
8
  ---@field bundleId string 应用 Bundle ID
13
- ---@field processArguments ProcessArguments 启动参数信息
14
9
 
15
10
  ---@class MemoryInfo
16
11
  ---@field used integer 已使用内存(MB)
@@ -20,10 +15,8 @@ local _System = {}
20
15
 
21
16
  --- 启动应用
22
17
  --- @param bundleId string 应用 Bundle ID
23
- --- @param args string[]|nil 启动参数
24
- --- @param env table<string, any>|nil 环境变量
25
18
  --- @return boolean 成功
26
- function _System.startApp(bundleId, args, env) return true end
19
+ function _System.startApp(bundleId) return true end
27
20
 
28
21
  --- 停止应用
29
22
  --- @param bundleId string 应用 Bundle ID
@@ -2,7 +2,14 @@
2
2
  ---@class YoloCls
3
3
  local _YoloCls = {}
4
4
 
5
- --- load
5
+ ---@class YoloClsProbs
6
+ ---@field data number[] 所有类别概率;Lua 下标从 1 起,类别 0 对应 data[1]
7
+ ---@field top1 integer|nil 概率最高的类别 ID;分类失败时为 nil
8
+ ---@field top5 integer[] 概率最高的 5 个类别 ID,按概率从高到低排序
9
+ ---@field top1conf number|nil top1 对应的概率;分类失败时为 nil
10
+ ---@field top5conf number[] top5 对应的概率,顺序与 top5 一致
11
+
12
+ --- 加载 YOLO 分类模型
6
13
  ---@param paramPath string
7
14
  ---@param binPath string
8
15
  ---@param nc integer|nil
@@ -10,14 +17,17 @@ local _YoloCls = {}
10
17
  ---@return string|nil
11
18
  function _YoloCls.load(paramPath, binPath, nc, useGpu) return nil end
12
19
 
13
- --- classify
20
+ --- 图像分类
14
21
  ---@param modelId string
15
22
  ---@param img string
16
23
  ---@param targetSize integer|nil
17
- ---@return table
18
- function _YoloCls.classify(modelId, img, targetSize) return { data = {}, top1 = nil, top5 = {}, top1conf = nil, top5conf = {} } end
24
+ ---@return YoloClsProbs
25
+ function _YoloCls.classify(modelId, img, targetSize)
26
+ ---@type YoloClsProbs
27
+ return { data = {}, top1 = nil, top5 = {}, top1conf = nil, top5conf = {} }
28
+ end
19
29
 
20
- --- classifyRegion
30
+ --- 对指定区域执行图像分类
21
31
  ---@param modelId string
22
32
  ---@param img string
23
33
  ---@param x integer|nil
@@ -25,15 +35,17 @@ function _YoloCls.classify(modelId, img, targetSize) return { data = {}, top1 =
25
35
  ---@param ex integer|nil
26
36
  ---@param ey integer|nil
27
37
  ---@param targetSize integer|nil
28
- ---@return table
29
- function _YoloCls.classifyRegion(modelId, img, x, y, ex, ey, targetSize) return { data = {}, top1 = nil, top5 = {}, top1conf = nil, top5conf = {} } end
38
+ ---@return YoloClsProbs
39
+ function _YoloCls.classifyRegion(modelId, img, x, y, ex, ey, targetSize)
40
+ ---@type YoloClsProbs
41
+ return { data = {}, top1 = nil, top5 = {}, top1conf = nil, top5conf = {} }
42
+ end
30
43
 
31
- --- free
44
+ --- 释放指定模型
32
45
  ---@param modelId string
33
46
  function _YoloCls.free(modelId) end
34
47
 
35
- --- freeAll
36
-
48
+ --- 释放全部模型
37
49
  function _YoloCls.freeAll() end
38
50
 
39
51
  ---@type YoloCls
package/types/opencv.d.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  *
5
5
  * @example
6
6
  * const src = cv.capture()
7
- * const gray = cv.cvtColor(src, { code: cv.COLOR_BGR2GRAY })
7
+ * const gray = cv.cvtColor(src, cv.COLOR_BGR2GRAY)
8
8
  * const edges = cv.Canny(gray, { threshold1: 100, threshold2: 200 })
9
9
  * cv.imwrite('/tmp/e.png', edges)
10
10
  * cv.release(src); cv.release(gray); cv.release(edges)