ms-vite-plugin 1.4.16 → 1.4.18
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/dist/cli.js +6 -301
- package/dist/mcp/doc-tools.js +1 -119
- package/dist/mcp/docs-service.d.ts +1 -27
- package/dist/mcp/docs-service.js +0 -65
- package/dist/mcp/httpapi-docs-service.d.ts +4 -37
- package/dist/mcp/httpapi-docs-service.js +6 -83
- package/dist/mcp/httpapi-tools.d.ts +1 -1
- package/dist/mcp/httpapi-tools.js +7 -157
- package/dist/mcp/tool-utils.d.ts +0 -13
- package/dist/mcp/tool-utils.js +0 -21
- package/dist/mcp/types.d.ts +0 -13
- package/docs/AGENTS.md +24 -32
- package/docs/SKILL.md +26 -37
- package/docs/api/appleocr.md +46 -164
- package/docs/api/image.md +16 -84
- package/docs/api/media.md +6 -7
- package/docs/api/paddleocr.md +77 -123
- package/docs/api/yolo.md +52 -96
- package/docs/apicn/appleocr.md +47 -169
- package/docs/apicn/image.md +15 -81
- package/docs/apicn/media.md +6 -7
- package/docs/apicn/paddleocr.md +77 -130
- package/docs/apicn/yolo.md +52 -101
- package/docs/apipython/appleocr.md +45 -155
- package/docs/apipython/image.md +17 -77
- package/docs/apipython/media.md +7 -8
- package/docs/apipython/paddleocr.md +78 -104
- package/docs/apipython/yolo.md +36 -85
- package/docs/mcp-agent-description.md +32 -58
- package/package.json +1 -1
package/docs/SKILL.md
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: kuaijs-mcp
|
|
3
|
-
description: 快点JS专用开发助手。用于快点JS
|
|
3
|
+
description: 快点JS专用开发助手。用于快点JS项目开发、本地 API 文档读取、iOS 设备自动化、HTTP API 调用、截图、节点 XML、日志查看、OCR、项目运行和打包;MCP 工具和项目自带 ms CLI 都可以使用,但必须依据快点JS文档与项目结构,不臆造 API 或运行机制。
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# 快点JS开发技能
|
|
7
7
|
|
|
8
8
|
## 使用场景
|
|
9
9
|
|
|
10
|
-
当任务涉及快点JS项目开发、快点JS API
|
|
10
|
+
当任务涉及快点JS项目开发、快点JS API、iOS 设备自动化、HTTP API 调用、截图、节点 XML、日志、OCR、项目运行或打包时,使用本技能。
|
|
11
11
|
|
|
12
12
|
你是快点JS专用开发助手,只服务于快点JS这一特定执行环境。必须严格依据快点JS官方 API 文档、当前项目结构、当前 MCP 工具能力和项目自带命令能力回答问题与编写代码。
|
|
13
13
|
|
|
@@ -27,24 +27,22 @@ MCP 工具和项目命令都可以使用。
|
|
|
27
27
|
|
|
28
28
|
优先使用 MCP 的情况:
|
|
29
29
|
|
|
30
|
-
-
|
|
31
|
-
-
|
|
32
|
-
-
|
|
30
|
+
- 获取快点JS本地文档路径。
|
|
31
|
+
- 读取文档后通过 `http_api_call` 调用已确认的 HTTP API。
|
|
32
|
+
- 设置设备、设置工作区、运行项目、截图、抓节点树、读日志、OCR。
|
|
33
33
|
|
|
34
34
|
可以使用命令的情况:
|
|
35
35
|
|
|
36
36
|
- 用户明确要求使用命令。
|
|
37
37
|
- 需要快速验证项目本地 `ms` CLI 能力。
|
|
38
|
-
- 使用项目自带 KuaiJS CLI
|
|
38
|
+
- 使用项目自带 KuaiJS CLI 获取文档路径、调用已确认的 HTTP API、同步、运行、停止、截图、抓节点、查日志、OCR 和图片处理。
|
|
39
39
|
|
|
40
40
|
允许的常用命令示例:
|
|
41
41
|
|
|
42
42
|
```bash
|
|
43
43
|
npx ms --help
|
|
44
44
|
npx ms docs paths
|
|
45
|
-
npx ms
|
|
46
|
-
npx ms http-docs search <query>
|
|
47
|
-
npx ms http-call -i <device-ip> --port <port> --method GET --path <path> --doc-slug <slug>
|
|
45
|
+
npx ms http-call -i <device-ip> --port <port> --method GET --path <path>
|
|
48
46
|
npx ms run -i <device-ip> --port <port>
|
|
49
47
|
npx ms run-ui -i <device-ip> --port <port>
|
|
50
48
|
npx ms screenshot -i <device-ip> --port <port> --format file --output <path>
|
|
@@ -58,7 +56,7 @@ npx ms image-transparent --image <path> --output <path>
|
|
|
58
56
|
npx ms stop -i <device-ip> --port <port>
|
|
59
57
|
```
|
|
60
58
|
|
|
61
|
-
使用 `ms http-call` 调用设备 HTTP API
|
|
59
|
+
使用 `ms http-call` 调用设备 HTTP API 前,必须先直接读取本地 HTTP API 文档,确认接口存在、方法、路径、参数位置和返回结构。
|
|
62
60
|
|
|
63
61
|
## 目录职责
|
|
64
62
|
|
|
@@ -82,40 +80,36 @@ npx ms stop -i <device-ip> --port <port>
|
|
|
82
80
|
|
|
83
81
|
## 文档工作流
|
|
84
82
|
|
|
85
|
-
回答快点JS API
|
|
83
|
+
回答快点JS API 或编写脚本前,先确认语言并直接读取对应语言文档。文档随 `ms-vite-plugin` npm 包发布,路径一定存在,不需要额外的文档查询或读取 API。
|
|
86
84
|
|
|
87
85
|
MCP 入口:
|
|
88
86
|
|
|
89
|
-
1. 使用 `get_docs_paths`
|
|
90
|
-
2.
|
|
91
|
-
3.
|
|
92
|
-
4. 只依据已确认的文档内容回答或编写代码。
|
|
87
|
+
1. 使用 `get_docs_paths` 获取本地文档根目录、语言 API 文档目录和 HTTP API 文档路径。
|
|
88
|
+
2. 直接读取对应 markdown 文件。
|
|
89
|
+
3. 只依据已读取的本地文档内容回答或编写代码。
|
|
93
90
|
|
|
94
91
|
CLI 入口:
|
|
95
92
|
|
|
96
|
-
1. 使用 `npx ms docs paths`
|
|
97
|
-
2.
|
|
98
|
-
3.
|
|
99
|
-
4. 只使用文档中已经确认的 API。
|
|
93
|
+
1. 使用 `npx ms docs paths` 获取同一组本地文档路径。
|
|
94
|
+
2. 直接读取对应 markdown 文件。
|
|
95
|
+
3. 只使用文档中已经确认的 API。
|
|
100
96
|
|
|
101
97
|
## HTTP API 工作流
|
|
102
98
|
|
|
103
|
-
调用设备 HTTP API
|
|
99
|
+
调用设备 HTTP API 前,必须直接读取 HTTP API 文档。
|
|
104
100
|
|
|
105
101
|
MCP 入口:
|
|
106
102
|
|
|
107
|
-
1. 使用 `
|
|
108
|
-
2.
|
|
109
|
-
3.
|
|
110
|
-
4. 使用 `http_api_call` 调用接口,并传入文档返回的 `docSlug`。
|
|
103
|
+
1. 使用 `get_docs_paths` 获取 HTTP API 文档路径。
|
|
104
|
+
2. 直接读取 HTTP API markdown,确认 `method`、`path`、参数位置、参数类型和返回结构。
|
|
105
|
+
3. 使用 `http_api_call` 调用接口,只传 `method`、`path`、`query` 或 `body`。
|
|
111
106
|
|
|
112
107
|
CLI 入口:
|
|
113
108
|
|
|
114
109
|
1. 使用 `npx ms docs paths` 获取 HTTP API 文档路径。
|
|
115
|
-
2.
|
|
116
|
-
3. 使用 `npx ms http-
|
|
117
|
-
4.
|
|
118
|
-
5. 不要把未确认的路径当成可用接口。
|
|
110
|
+
2. 直接读取 HTTP API markdown,确认接口存在和参数要求。
|
|
111
|
+
3. 使用 `npx ms http-call -i <device-ip> --port <port> --method <method> --path <path>` 调用明确存在的接口。
|
|
112
|
+
4. 不要把未确认的路径当成可用接口。
|
|
119
113
|
|
|
120
114
|
## 设备工作流
|
|
121
115
|
|
|
@@ -158,18 +152,13 @@ CLI 入口:
|
|
|
158
152
|
2. 使用 `npx ms run -i <device-ip> --port <port>` 同步并运行。
|
|
159
153
|
3. 使用 `npx ms screenshot ...` 验证界面。
|
|
160
154
|
|
|
161
|
-
`build`、`package`、`run`、`run-ui` 需要在快点JS项目根目录运行,项目根目录必须包含 `package.json` 和 `scripts
|
|
155
|
+
`build`、`package`、`run`、`run-ui` 需要在快点JS项目根目录运行,项目根目录必须包含 `package.json` 和 `scripts/`。文档路径、HTTP API 调用、截图、节点、日志、OCR、图片处理、停止和 WS 状态命令可以在任意目录使用。
|
|
162
156
|
|
|
163
157
|
## 工具分组
|
|
164
158
|
|
|
165
159
|
### 文档
|
|
166
160
|
|
|
167
161
|
- `get_docs_paths`
|
|
168
|
-
- `list_api_docs`
|
|
169
|
-
- `search_api_docs`
|
|
170
|
-
- `read_api_doc`
|
|
171
|
-
- `search_http_api_docs`
|
|
172
|
-
- `read_http_api_doc`
|
|
173
162
|
|
|
174
163
|
### 工作区与运行
|
|
175
164
|
|
|
@@ -198,7 +187,7 @@ CLI 入口:
|
|
|
198
187
|
|
|
199
188
|
- `http_api_call`
|
|
200
189
|
|
|
201
|
-
控制、HID、IME、镜像、配置、当前应用、运行脚本等普通设备 HTTP API 通过 `
|
|
190
|
+
控制、HID、IME、镜像、配置、当前应用、运行脚本等普通设备 HTTP API 通过 `get_docs_paths` 和 `http_api_call` 使用;CLI 入口使用 `ms docs paths` 和 `ms http-call`。
|
|
202
191
|
|
|
203
192
|
使用 `ocr_recognize` 执行 OCR 识别。`ocr_recognize` 支持 `appleocr` 和 `paddleocr`,默认 `appleocr`,识别结果坐标可直接用于点击。
|
|
204
193
|
|
|
@@ -212,7 +201,7 @@ CLI 入口:
|
|
|
212
201
|
|
|
213
202
|
## 禁止事项
|
|
214
203
|
|
|
215
|
-
-
|
|
204
|
+
- 不要在没有读取本地文档的情况下回答 API 用法或编写 API 调用代码。
|
|
216
205
|
- 不要调用 HTTP API 文档中未声明的接口。
|
|
217
206
|
- 不要把完整 URL 传给 `http_api_call.path`。
|
|
218
207
|
- 不要用未确认的通用命令替代 KuaiJS MCP 或项目自带 `ms` CLI。
|
|
@@ -221,4 +210,4 @@ CLI 入口:
|
|
|
221
210
|
|
|
222
211
|
## 文档入口
|
|
223
212
|
|
|
224
|
-
优先直接读取项目本地 `node_modules/ms-vite-plugin/docs/` 文档;也可以使用 MCP
|
|
213
|
+
优先直接读取项目本地 `node_modules/ms-vite-plugin/docs/` 文档;也可以使用 MCP `get_docs_paths` 或 `ms docs paths` 获取具体文档路径。
|
package/docs/api/appleocr.md
CHANGED
|
@@ -59,12 +59,13 @@ interface OCRResult {
|
|
|
59
59
|
|
|
60
60
|
### 文字识别
|
|
61
61
|
|
|
62
|
-
####
|
|
62
|
+
#### recognizeAbs - 执行 OCR 识别,并将结果坐标映射为原图/全屏绝对坐标。
|
|
63
63
|
|
|
64
|
-
|
|
64
|
+
执行 OCR 识别,并将结果坐标映射为原图/全屏绝对坐标。
|
|
65
|
+
传入裁剪区域时,返回坐标会映射回原图或全屏坐标,可直接用于点击。
|
|
65
66
|
|
|
66
67
|
```typescript
|
|
67
|
-
function
|
|
68
|
+
function recognizeAbs(
|
|
68
69
|
input: string,
|
|
69
70
|
x?: number,
|
|
70
71
|
y?: number,
|
|
@@ -76,77 +77,20 @@ function recognize(
|
|
|
76
77
|
|
|
77
78
|
**参数:**
|
|
78
79
|
|
|
79
|
-
| 参数名 | 类型 | 是否必填 | 默认值
|
|
80
|
-
| ----------- | -------- | -------- |
|
|
81
|
-
| `input` | string | 是 |
|
|
82
|
-
| `x` | number | 否 |
|
|
83
|
-
| `y` | number | 否 |
|
|
84
|
-
| `ex` | number | 否 |
|
|
85
|
-
| `ey` | number | 否 |
|
|
86
|
-
| `languages` | string[] | 否 | ["zh-Hans", "en-US"] |
|
|
80
|
+
| 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
|
|
81
|
+
| ----------- | -------- | -------- | ----------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
|
|
82
|
+
| `input` | string | 是 | | 输入源,支持 `"screen"`、图片文件路径、URL 字符串或 imageId |
|
|
83
|
+
| `x` | number | 否 | 0 | 裁剪区域左上角 x 坐标;全屏识别传 0 |
|
|
84
|
+
| `y` | number | 否 | 0 | 裁剪区域左上角 y 坐标;全屏识别传 0 |
|
|
85
|
+
| `ex` | number | 否 | 0 | 裁剪区域右下角 x 坐标;全屏识别传 0 |
|
|
86
|
+
| `ey` | number | 否 | 0 | 裁剪区域右下角 y 坐标;全屏识别传 0 |
|
|
87
|
+
| `languages` | string[] | 否 | `["zh-Hans", "en-US"]` | 识别语言数组,支持 `["en-US", "fr-FR", "it-IT", "de-DE", "es-ES", "pt-BR", "zh-Hans", "zh-Hant"]` |
|
|
87
88
|
|
|
88
89
|
**返回值:**
|
|
89
90
|
|
|
90
|
-
| 类型 | 描述
|
|
91
|
-
| ----------- |
|
|
92
|
-
| OCRResult[] |
|
|
93
|
-
|
|
94
|
-
**使用示例:**
|
|
95
|
-
|
|
96
|
-
```javascript
|
|
97
|
-
// 识别整个屏幕
|
|
98
|
-
const fullScreenResults = appleOcr.recognize("screen", 0, 0, 0, 0);
|
|
99
|
-
logi(`识别到 ${fullScreenResults.length} 个文本区域`);
|
|
100
|
-
fullScreenResults.forEach((result, index) => {
|
|
101
|
-
logi(`文本 ${index + 1}: ${result.text} (置信度: ${result.confidence})`);
|
|
102
|
-
logi(`位置: (${result.x}, ${result.y}) - (${result.ex}, ${result.ey})`);
|
|
103
|
-
logi(`中心点: (${result.centerX}, ${result.centerY})`);
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
// 识别屏幕指定区域
|
|
107
|
-
const regionResults = appleOcr.recognize("screen", 100, 100, 500, 300);
|
|
108
|
-
logi(`指定区域识别结果: ${JSON.stringify(regionResults)}`);
|
|
109
|
-
|
|
110
|
-
// 识别图片文件
|
|
111
|
-
const imageResults = appleOcr.recognize("/path/to/image.png", 0, 0, 800, 600);
|
|
112
|
-
if (imageResults.length > 0) {
|
|
113
|
-
logi("图片文字识别成功");
|
|
114
|
-
imageResults.forEach((result) => {
|
|
115
|
-
logi(`识别文字: ${result.text}`);
|
|
116
|
-
logi(`区域: ${result.width}x${result.height}`);
|
|
117
|
-
});
|
|
118
|
-
} else {
|
|
119
|
-
logi("图片中未识别到文字");
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// 指定识别语言
|
|
123
|
-
const chineseResults = appleOcr.recognize("screen", 0, 0, 1920, 1080, [
|
|
124
|
-
"zh-Hans",
|
|
125
|
-
"en-US",
|
|
126
|
-
]);
|
|
127
|
-
logi(`中英文识别结果: ${JSON.stringify(chineseResults)}`);
|
|
128
|
-
|
|
129
|
-
// 识别当前屏幕
|
|
130
|
-
const screenResults = appleOcr.recognize("screen", 0, 0, 1920, 1080);
|
|
131
|
-
logi(`屏幕识别结果: ${JSON.stringify(screenResults)}`);
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
#### recognizeAbs
|
|
135
|
-
|
|
136
|
-
执行 OCR 识别,并将结果坐标映射为原图/全屏绝对坐标。
|
|
137
|
-
|
|
138
|
-
参数与 `recognize` 相同。传入裁剪区域时,返回坐标可直接用于全屏点击。
|
|
139
|
-
|
|
140
|
-
```typescript
|
|
141
|
-
function recognizeAbs(
|
|
142
|
-
input: string,
|
|
143
|
-
x?: number,
|
|
144
|
-
y?: number,
|
|
145
|
-
ex?: number,
|
|
146
|
-
ey?: number,
|
|
147
|
-
languages?: string[],
|
|
148
|
-
): OCRResult[];
|
|
149
|
-
```
|
|
91
|
+
| 类型 | 描述 |
|
|
92
|
+
| ----------- | ------------------------------------------------ |
|
|
93
|
+
| OCRResult[] | 识别结果数组,坐标为原图或全屏绝对坐标 |
|
|
150
94
|
|
|
151
95
|
**示例:**
|
|
152
96
|
|
|
@@ -159,14 +103,15 @@ if (absResults.length > 0) {
|
|
|
159
103
|
|
|
160
104
|
### 数字识别
|
|
161
105
|
|
|
162
|
-
####
|
|
106
|
+
#### recognizeNumbersAbs - 执行数字 OCR 识别,并将结果坐标映射为原图/全屏绝对坐标。
|
|
163
107
|
|
|
164
|
-
|
|
108
|
+
执行数字 OCR 识别,并将结果坐标映射为原图/全屏绝对坐标。
|
|
109
|
+
传入裁剪区域时,返回坐标会映射回原图或全屏坐标,可直接用于点击。
|
|
165
110
|
|
|
166
111
|
**支持字符**: 0-9 数字、逗号(,)、小数点(.)、加号(+)、减号(-)
|
|
167
112
|
|
|
168
113
|
```typescript
|
|
169
|
-
function
|
|
114
|
+
function recognizeNumbersAbs(
|
|
170
115
|
input: string,
|
|
171
116
|
x?: number,
|
|
172
117
|
y?: number,
|
|
@@ -177,49 +122,19 @@ function recognizeNumbers(
|
|
|
177
122
|
|
|
178
123
|
**参数:**
|
|
179
124
|
|
|
180
|
-
| 参数名 | 类型 | 是否必填 | 默认值 | 描述
|
|
181
|
-
| ------- | ------ | -------- | ------ |
|
|
182
|
-
| `input` | string | 是 |
|
|
183
|
-
| `x` | number | 否 |
|
|
184
|
-
| `y` | number | 否 |
|
|
185
|
-
| `ex` | number | 否 |
|
|
186
|
-
| `ey` | number | 否 |
|
|
125
|
+
| 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
|
|
126
|
+
| ------- | ------ | -------- | ------ | ------------------------------------------- |
|
|
127
|
+
| `input` | string | 是 | | 输入源,支持 `"screen"`、图片文件路径、URL 字符串或 imageId |
|
|
128
|
+
| `x` | number | 否 | 0 | 裁剪区域左上角 x 坐标;全屏识别传 0 |
|
|
129
|
+
| `y` | number | 否 | 0 | 裁剪区域左上角 y 坐标;全屏识别传 0 |
|
|
130
|
+
| `ex` | number | 否 | 0 | 裁剪区域右下角 x 坐标;全屏识别传 0 |
|
|
131
|
+
| `ey` | number | 否 | 0 | 裁剪区域右下角 y 坐标;全屏识别传 0 |
|
|
187
132
|
|
|
188
133
|
**返回值:**
|
|
189
134
|
|
|
190
|
-
| 类型
|
|
191
|
-
|
|
|
192
|
-
|
|
|
193
|
-
|
|
194
|
-
**使用示例:**
|
|
195
|
-
|
|
196
|
-
```javascript
|
|
197
|
-
// 识别屏幕中的数字
|
|
198
|
-
const numberResults = appleOcr.recognizeNumbers("screen", 100, 100, 500, 300);
|
|
199
|
-
logi(`识别到 ${numberResults.length} 个数字区域`);
|
|
200
|
-
|
|
201
|
-
numberResults.forEach((result, index) => {
|
|
202
|
-
logi(`数字 ${index + 1}: ${result.text}`);
|
|
203
|
-
logi(`置信度: ${result.confidence}`);
|
|
204
|
-
logi(`位置: (${result.centerX}, ${result.centerY})`);
|
|
205
|
-
});
|
|
206
|
-
```
|
|
207
|
-
|
|
208
|
-
#### recognizeNumbersAbs
|
|
209
|
-
|
|
210
|
-
执行数字 OCR 识别,并将结果坐标映射为原图/全屏绝对坐标。
|
|
211
|
-
|
|
212
|
-
参数与 `recognizeNumbers` 相同。传入裁剪区域时,返回坐标可直接用于全屏点击。
|
|
213
|
-
|
|
214
|
-
```typescript
|
|
215
|
-
function recognizeNumbersAbs(
|
|
216
|
-
input: string,
|
|
217
|
-
x?: number,
|
|
218
|
-
y?: number,
|
|
219
|
-
ex?: number,
|
|
220
|
-
ey?: number,
|
|
221
|
-
): OCRResult[];
|
|
222
|
-
```
|
|
135
|
+
| 类型 | 描述 |
|
|
136
|
+
| ----------- | ---------------------------------------------------------- |
|
|
137
|
+
| OCRResult[] | 数字识别结果数组,坐标为原图或全屏绝对坐标 |
|
|
223
138
|
|
|
224
139
|
**示例:**
|
|
225
140
|
|
|
@@ -232,12 +147,13 @@ if (absNumberResults.length > 0) {
|
|
|
232
147
|
|
|
233
148
|
### 文本查找
|
|
234
149
|
|
|
235
|
-
####
|
|
150
|
+
#### findTextAbs - 查找目标子串,并将子串结果坐标映射为原图/全屏绝对坐标。
|
|
236
151
|
|
|
237
|
-
|
|
152
|
+
查找目标子串,并将子串结果坐标映射为原图/全屏绝对坐标。
|
|
153
|
+
传入裁剪区域时,返回坐标会映射回原图或全屏坐标,可直接用于点击。
|
|
238
154
|
|
|
239
155
|
```typescript
|
|
240
|
-
function
|
|
156
|
+
function findTextAbs(
|
|
241
157
|
input: string,
|
|
242
158
|
texts: string[],
|
|
243
159
|
x?: number,
|
|
@@ -251,56 +167,22 @@ function findText(
|
|
|
251
167
|
|
|
252
168
|
**参数:**
|
|
253
169
|
|
|
254
|
-
| 参数名
|
|
255
|
-
|
|
|
256
|
-
| `input`
|
|
257
|
-
| `texts`
|
|
258
|
-
| `x`
|
|
259
|
-
| `y`
|
|
260
|
-
| `ex`
|
|
261
|
-
| `ey`
|
|
262
|
-
| `languages`
|
|
263
|
-
| `exactMatch` | boolean
|
|
170
|
+
| 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
|
|
171
|
+
| ------------ | -------- | -------- | ----------------------- | ----------------------------------------------------------------------------------------------------- |
|
|
172
|
+
| `input` | string | 是 | | 输入源,支持 `"screen"`、图片文件路径、URL 字符串或 imageId |
|
|
173
|
+
| `texts` | string[] | 是 | | 要查找的目标文本数组,可匹配识别结果中的子串 |
|
|
174
|
+
| `x` | number | 否 | 0 | 裁剪区域左上角 x 坐标;全屏识别传 0 |
|
|
175
|
+
| `y` | number | 否 | 0 | 裁剪区域左上角 y 坐标;全屏识别传 0 |
|
|
176
|
+
| `ex` | number | 否 | 0 | 裁剪区域右下角 x 坐标;全屏识别传 0 |
|
|
177
|
+
| `ey` | number | 否 | 0 | 裁剪区域右下角 y 坐标;全屏识别传 0 |
|
|
178
|
+
| `languages` | string[] | 否 | `["zh-Hans", "en-US"]` | 识别语言数组 |
|
|
179
|
+
| `exactMatch` | boolean | 否 | false | 是否完整匹配;`false` 表示包含匹配,`true` 要求整条 OCR 识别结果文本等于目标文本 |
|
|
264
180
|
|
|
265
181
|
**返回值:**
|
|
266
182
|
|
|
267
|
-
| 类型
|
|
268
|
-
|
|
|
269
|
-
|
|
|
270
|
-
|
|
271
|
-
**使用示例:**
|
|
272
|
-
|
|
273
|
-
```javascript
|
|
274
|
-
// 在“开始执行”中查找“开始”,返回“开始”子串区域
|
|
275
|
-
const textResults = appleOcr.findText("screen", ["开始"], 0, 0, 100, 100);
|
|
276
|
-
// 不指定 languages 但启用完整匹配时,用 null 占位 languages
|
|
277
|
-
const exactResults = appleOcr.findText("screen", ["开始"], 0, 0, 100, 100, null, true);
|
|
278
|
-
logi(`识别到 ${textResults.length} 个文本区域`);
|
|
279
|
-
textResults.forEach((result, index) => {
|
|
280
|
-
logi(`文本 ${index + 1}: ${result.text} (置信度: ${result.confidence})`);
|
|
281
|
-
logi(`位置: (${result.x}, ${result.y}) - (${result.ex}, ${result.ey})`);
|
|
282
|
-
logi(`中心点: (${result.centerX}, ${result.centerY})`);
|
|
283
|
-
});
|
|
284
|
-
```
|
|
285
|
-
|
|
286
|
-
#### findTextAbs
|
|
287
|
-
|
|
288
|
-
查找目标子串,并将子串结果坐标映射为原图/全屏绝对坐标。
|
|
289
|
-
|
|
290
|
-
参数与 `findText` 相同。传入裁剪区域时,返回坐标可直接用于全屏点击。
|
|
291
|
-
|
|
292
|
-
```typescript
|
|
293
|
-
function findTextAbs(
|
|
294
|
-
input: string,
|
|
295
|
-
texts: string[],
|
|
296
|
-
x?: number,
|
|
297
|
-
y?: number,
|
|
298
|
-
ex?: number,
|
|
299
|
-
ey?: number,
|
|
300
|
-
languages?: string[],
|
|
301
|
-
exactMatch?: boolean,
|
|
302
|
-
): OCRResult[];
|
|
303
|
-
```
|
|
183
|
+
| 类型 | 描述 |
|
|
184
|
+
| ----------- | ---------------------------------------------------------- |
|
|
185
|
+
| OCRResult[] | 命中子串的识别结果数组,坐标为原图或全屏绝对坐标 |
|
|
304
186
|
|
|
305
187
|
**示例:**
|
|
306
188
|
|
package/docs/api/image.md
CHANGED
|
@@ -45,7 +45,7 @@ function captureScreen(
|
|
|
45
45
|
**示例:**
|
|
46
46
|
|
|
47
47
|
```javascript
|
|
48
|
-
//
|
|
48
|
+
// 全屏截图
|
|
49
49
|
const imageId = image.captureScreen();
|
|
50
50
|
// 获取手机文档目录
|
|
51
51
|
const dir = file.getInternalDir("documents");
|
|
@@ -70,74 +70,6 @@ if (imageId) {
|
|
|
70
70
|
}
|
|
71
71
|
```
|
|
72
72
|
|
|
73
|
-
### captureFullScreen - 截取设备全屏。
|
|
74
|
-
|
|
75
|
-
```typescript
|
|
76
|
-
function captureFullScreen(): string | null;
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
**返回值:**
|
|
80
|
-
|
|
81
|
-
| 类型 | 描述 |
|
|
82
|
-
| -------- | -------------------------------- |
|
|
83
|
-
| `string` | 截图的图片 ID,失败时返回 `null` |
|
|
84
|
-
|
|
85
|
-
**示例:**
|
|
86
|
-
|
|
87
|
-
```javascript
|
|
88
|
-
const imageId = image.captureFullScreen();
|
|
89
|
-
// 获取手机文档目录
|
|
90
|
-
const dir = file.getInternalDir("documents");
|
|
91
|
-
if (imageId) {
|
|
92
|
-
logi("截图成功");
|
|
93
|
-
image.saveTo(imageId, `${dir}/screenshot.jpg`);
|
|
94
|
-
image.release(imageId); // 记得释放内存
|
|
95
|
-
} else {
|
|
96
|
-
logi("截图失败");
|
|
97
|
-
}
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
### captureRect - 截取设备指定区域。
|
|
101
|
-
|
|
102
|
-
```typescript
|
|
103
|
-
function captureRect(
|
|
104
|
-
x: number,
|
|
105
|
-
y: number,
|
|
106
|
-
ex: number,
|
|
107
|
-
ey: number,
|
|
108
|
-
): string | null;
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
**参数:**
|
|
112
|
-
|
|
113
|
-
| 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
|
|
114
|
-
| ------ | ------ | -------- | ------ | ----------------- |
|
|
115
|
-
| `x` | number | 是 | - | 区域左上角 X 坐标 |
|
|
116
|
-
| `y` | number | 是 | - | 区域左上角 Y 坐标 |
|
|
117
|
-
| `ex` | number | 是 | - | 区域右下角 X 坐标 |
|
|
118
|
-
| `ey` | number | 是 | - | 区域右下角 Y 坐标 |
|
|
119
|
-
|
|
120
|
-
**返回值:**
|
|
121
|
-
|
|
122
|
-
| 类型 | 描述 |
|
|
123
|
-
| -------- | -------------------------------- |
|
|
124
|
-
| `string` | 截图的图片 ID,失败时返回 `null` |
|
|
125
|
-
|
|
126
|
-
**示例:**
|
|
127
|
-
|
|
128
|
-
```javascript
|
|
129
|
-
const imageId = image.captureRect(100, 100, 200, 200);
|
|
130
|
-
// 获取手机文档目录
|
|
131
|
-
const dir = file.getInternalDir("documents");
|
|
132
|
-
if (imageId) {
|
|
133
|
-
logi("截图成功");
|
|
134
|
-
image.saveTo(imageId, `${dir}/screenshot.jpg`);
|
|
135
|
-
image.release(imageId); // 记得释放内存
|
|
136
|
-
} else {
|
|
137
|
-
logi("截图失败");
|
|
138
|
-
}
|
|
139
|
-
```
|
|
140
|
-
|
|
141
73
|
### readImage - 从文件路径或imageId读取图片。
|
|
142
74
|
|
|
143
75
|
```typescript
|
|
@@ -191,7 +123,7 @@ function saveTo(imageId: string, filePath: string): boolean;
|
|
|
191
123
|
**示例:**
|
|
192
124
|
|
|
193
125
|
```javascript
|
|
194
|
-
const imageId = image.
|
|
126
|
+
const imageId = image.captureScreen();
|
|
195
127
|
// 获取手机文档目录
|
|
196
128
|
const dir = file.getInternalDir("documents");
|
|
197
129
|
if (imageId) {
|
|
@@ -241,7 +173,7 @@ function isRelease(imageId: string): boolean;
|
|
|
241
173
|
**示例:**
|
|
242
174
|
|
|
243
175
|
```javascript
|
|
244
|
-
const imageId = image.
|
|
176
|
+
const imageId = image.captureScreen();
|
|
245
177
|
if (imageId) {
|
|
246
178
|
logi(`释放前: ${image.isRelease(imageId)}`); // false
|
|
247
179
|
image.release(imageId);
|
|
@@ -272,7 +204,7 @@ function getSize(imageId: string): { width: number; height: number } | null;
|
|
|
272
204
|
**示例:**
|
|
273
205
|
|
|
274
206
|
```javascript
|
|
275
|
-
const imageId = image.
|
|
207
|
+
const imageId = image.captureScreen();
|
|
276
208
|
if (imageId) {
|
|
277
209
|
const size = image.getSize(imageId);
|
|
278
210
|
if (size) {
|
|
@@ -305,7 +237,7 @@ function pixel(imageId: string, x: number, y: number): number;
|
|
|
305
237
|
**示例:**
|
|
306
238
|
|
|
307
239
|
```javascript
|
|
308
|
-
const imageId = image.
|
|
240
|
+
const imageId = image.captureScreen();
|
|
309
241
|
if (imageId) {
|
|
310
242
|
const color = image.pixel(imageId, 100, 100);
|
|
311
243
|
const colorHex = image.argb(color);
|
|
@@ -371,7 +303,7 @@ function findColor(
|
|
|
371
303
|
**示例:**
|
|
372
304
|
|
|
373
305
|
```javascript
|
|
374
|
-
const imageId = image.
|
|
306
|
+
const imageId = image.captureScreen();
|
|
375
307
|
if (imageId) {
|
|
376
308
|
// 查找蓝色按钮
|
|
377
309
|
const points = image.findColor(
|
|
@@ -435,7 +367,7 @@ function findMultiColor(
|
|
|
435
367
|
**示例:**
|
|
436
368
|
|
|
437
369
|
```javascript
|
|
438
|
-
const imageId = image.
|
|
370
|
+
const imageId = image.captureScreen();
|
|
439
371
|
if (imageId) {
|
|
440
372
|
// 查找特定的颜色组合(如按钮的特征颜色)
|
|
441
373
|
const points = image.findMultiColor(
|
|
@@ -495,7 +427,7 @@ function countColor(
|
|
|
495
427
|
**示例:**
|
|
496
428
|
|
|
497
429
|
```javascript
|
|
498
|
-
const imageId = image.
|
|
430
|
+
const imageId = image.captureScreen();
|
|
499
431
|
if (imageId) {
|
|
500
432
|
const count = image.countColor(
|
|
501
433
|
imageId,
|
|
@@ -535,7 +467,7 @@ function cmpColor(imageId: string, points: string, threshold: number): boolean;
|
|
|
535
467
|
**示例:**
|
|
536
468
|
|
|
537
469
|
```javascript
|
|
538
|
-
const imageId = image.
|
|
470
|
+
const imageId = image.captureScreen();
|
|
539
471
|
if (imageId) {
|
|
540
472
|
// 检查特定区域是否为预期颜色
|
|
541
473
|
const isMatch = image.cmpColor(
|
|
@@ -664,7 +596,7 @@ function clip(
|
|
|
664
596
|
**示例:**
|
|
665
597
|
|
|
666
598
|
```javascript
|
|
667
|
-
const imageId = image.
|
|
599
|
+
const imageId = image.captureScreen();
|
|
668
600
|
// 获取手机文档目录
|
|
669
601
|
const dir = file.getInternalDir("documents");
|
|
670
602
|
if (imageId) {
|
|
@@ -737,7 +669,7 @@ function gray(imageId: string): string;
|
|
|
737
669
|
**示例:**
|
|
738
670
|
|
|
739
671
|
```javascript
|
|
740
|
-
const imageId = image.
|
|
672
|
+
const imageId = image.captureScreen();
|
|
741
673
|
// 获取手机文档目录
|
|
742
674
|
const dir = file.getInternalDir("documents");
|
|
743
675
|
if (imageId) {
|
|
@@ -770,7 +702,7 @@ function binaryzation(imageId: string, threshold: number): string;
|
|
|
770
702
|
**示例:**
|
|
771
703
|
|
|
772
704
|
```javascript
|
|
773
|
-
const imageId = image.
|
|
705
|
+
const imageId = image.captureScreen();
|
|
774
706
|
// 获取手机文档目录
|
|
775
707
|
const dir = file.getInternalDir("documents");
|
|
776
708
|
if (imageId) {
|
|
@@ -811,7 +743,7 @@ function drawRect(
|
|
|
811
743
|
// 获取手机文档目录
|
|
812
744
|
const dir = file.getInternalDir("documents");
|
|
813
745
|
|
|
814
|
-
const imageId = image.
|
|
746
|
+
const imageId = image.captureScreen();
|
|
815
747
|
if (imageId) {
|
|
816
748
|
image.drawRect(imageId, 100, 100, 200, 100, "#FF0000", 2);
|
|
817
749
|
image.saveTo(imageId, `${dir}/test.jpg`);
|
|
@@ -840,7 +772,7 @@ function scanCode(imageId: string): string | null;
|
|
|
840
772
|
**示例:**
|
|
841
773
|
|
|
842
774
|
```javascript
|
|
843
|
-
const imageId = image.
|
|
775
|
+
const imageId = image.captureScreen();
|
|
844
776
|
if (imageId) {
|
|
845
777
|
const result = image.scanCode(imageId);
|
|
846
778
|
if (result) {
|
|
@@ -910,7 +842,7 @@ function toBase64Format(imageId: string, format: string, q: number): string;
|
|
|
910
842
|
**示例:**
|
|
911
843
|
|
|
912
844
|
```javascript
|
|
913
|
-
const imageId = image.
|
|
845
|
+
const imageId = image.captureScreen();
|
|
914
846
|
if (imageId) {
|
|
915
847
|
const base64 = image.toBase64Format(imageId, "jpg", 90);
|
|
916
848
|
logi(`Base64 数据: ${base64.substring(0, 100)}...`);
|
|
@@ -943,7 +875,7 @@ function getBitmap(imageId: string): any;
|
|
|
943
875
|
**示例:**
|
|
944
876
|
|
|
945
877
|
```javascript
|
|
946
|
-
const imageId = image.
|
|
878
|
+
const imageId = image.captureScreen();
|
|
947
879
|
if (imageId) {
|
|
948
880
|
const bitmap = image.getBitmap(imageId);
|
|
949
881
|
logi(`Bitmap 对象: ${bitmap}`);
|