rust-rpa 0.2.0 → 0.2.1-beta.1
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/README.md +72 -10
- package/index.d.ts +4 -0
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -213,11 +213,11 @@ const windows = Window.all();
|
|
|
213
213
|
- `captureImage(options?: CaptureImageOptions): Promise<ImageData>` - 截取窗口图像;可选 `options.size` 指定目标宽高并自动缩放;`options.from` 为 `'screen'` 时截取窗口所在显示器整屏;`options.region` 指定仅截取逻辑像素区域;`options.autoSize` 默认为 `true`,在 Windows 高 DPI 下自动缩放到逻辑像素尺寸
|
|
214
214
|
- `findIcon(template, options?): Promise<MatchResult | null>` - 在窗口截图中查找模板图标(先截图 autoSize=true,再执行模板匹配),找到返回 MatchResult,未找到返回 null
|
|
215
215
|
- `recognizeText(): Promise<TextRecognitionResult[]>` - 识别窗口截图中的文字(先截图 autoSize=true,再执行 OCR)
|
|
216
|
-
- `findText(text, options?): Promise<TextRecognitionResult | null>` - 在窗口截图中查找指定文字,找到返回位置信息,未找到返回 null(先截图 autoSize=true,再执行 OCR);`options.regions`
|
|
217
|
-
- `waitText(text, options?): Promise<TextRecognitionResult>` - 等待指定文字出现,超时抛出错误;`options.timeout` 指定等待时间(默认 3000ms),`options.regions`
|
|
216
|
+
- `findText(text, options?): Promise<TextRecognitionResult | null>` - 在窗口截图中查找指定文字,找到返回位置信息,未找到返回 null(先截图 autoSize=true,再执行 OCR);`options.regions` 可指定查找区域列表以提升性能;`options.notText` 可排除同一行中包含特定文字的匹配结果
|
|
217
|
+
- `waitText(text, options?): Promise<TextRecognitionResult>` - 等待指定文字出现,超时抛出错误;`options.timeout` 指定等待时间(默认 3000ms),`options.regions` 可指定查找区域,`options.notText` 可排除同一行中包含特定文字的匹配结果
|
|
218
218
|
- `waitIcon(template, options?): Promise<MatchResult>` - 等待指定图标出现,超时抛出错误;`options.timeout` 指定等待时间(默认 3000ms),`options.regions` 可指定查找区域,`options.threshold` 可指定匹配阈值(默认 0.8)
|
|
219
|
-
- `clickText(text, options?): Promise<
|
|
220
|
-
- `clickIcon(template, options?): Promise<
|
|
219
|
+
- `clickText(text, options?): Promise<ClickResult>` - 点击指定文字,先等待文字出现,然后点击文字中心点;返回点击坐标 `{x, y, relX, relY}`;`options.notText` 可排除同一行中包含特定文字的匹配结果
|
|
220
|
+
- `clickIcon(template, options?): Promise<ClickResult>` - 点击指定图标,先等待图标出现,然后点击图标中心点;返回点击坐标 `{x, y, relX, relY}`;`options.threshold` 可指定匹配阈值(默认 0.8)
|
|
221
221
|
|
|
222
222
|
### Monitor 类
|
|
223
223
|
|
|
@@ -247,11 +247,11 @@ const primary = monitors.find(m => m.isPrimary());
|
|
|
247
247
|
- `captureImage(options?: CaptureImageOptions): Promise<ImageData>` - 截取显示器图像;可选 `options.size` 指定目标宽高并自动缩放;`options.autoSize` 默认为 `true`,在 Windows 高 DPI 下自动缩放到逻辑像素尺寸
|
|
248
248
|
- `findIcon(template, options?): Promise<MatchResult | null>` - 在显示器截图中查找模板图标(先截图 autoSize=true,再执行模板匹配),找到返回 MatchResult,未找到返回 null
|
|
249
249
|
- `recognizeText(): Promise<TextRecognitionResult[]>` - 识别显示器截图中的文字(先截图 autoSize=true,再执行 OCR)
|
|
250
|
-
- `findText(text, options?): Promise<TextRecognitionResult | null>` - 在显示器截图中查找指定文字,找到返回位置信息,未找到返回 null(先截图 autoSize=true,再执行 OCR);`options.regions`
|
|
251
|
-
- `waitText(text, options?): Promise<TextRecognitionResult>` - 等待指定文字出现,超时抛出错误;`options.timeout` 指定等待时间(默认 3000ms),`options.regions`
|
|
250
|
+
- `findText(text, options?): Promise<TextRecognitionResult | null>` - 在显示器截图中查找指定文字,找到返回位置信息,未找到返回 null(先截图 autoSize=true,再执行 OCR);`options.regions` 可指定查找区域列表以提升性能;`options.notText` 可排除同一行中包含特定文字的匹配结果
|
|
251
|
+
- `waitText(text, options?): Promise<TextRecognitionResult>` - 等待指定文字出现,超时抛出错误;`options.timeout` 指定等待时间(默认 3000ms),`options.regions` 可指定查找区域,`options.notText` 可排除同一行中包含特定文字的匹配结果
|
|
252
252
|
- `waitIcon(template, options?): Promise<MatchResult>` - 等待指定图标出现,超时抛出错误;`options.timeout` 指定等待时间(默认 3000ms),`options.regions` 可指定查找区域,`options.threshold` 可指定匹配阈值(默认 0.8)
|
|
253
|
-
- `clickText(text, options?): Promise<
|
|
254
|
-
- `clickIcon(template, options?): Promise<
|
|
253
|
+
- `clickText(text, options?): Promise<ClickResult>` - 点击指定文字,先等待文字出现,然后点击文字中心点;返回点击坐标 `{x, y, relX, relY}`;`options.notText` 可排除同一行中包含特定文字的匹配结果
|
|
254
|
+
- `clickIcon(template, options?): Promise<ClickResult>` - 点击指定图标,先等待图标出现,然后点击图标中心点;返回点击坐标 `{x, y, relX, relY}`;`options.threshold` 可指定匹配阈值(默认 0.8)
|
|
255
255
|
|
|
256
256
|
### ImageData 类
|
|
257
257
|
|
|
@@ -282,8 +282,8 @@ const primary = monitors.find(m => m.isPrimary());
|
|
|
282
282
|
- `resize(width, height): Promise<ImageData>` - 缩放图像
|
|
283
283
|
- `grayscale(): Promise<ImageData>` - 转换为灰度图
|
|
284
284
|
- `findIcon(template, options?): Promise<MatchResult | null>` - 查找模板图标,找到返回 MatchResult,未找到返回 null
|
|
285
|
-
- `recognizeText(): Promise<TextRecognitionResult[]>` -
|
|
286
|
-
- `findText(text): Promise<TextRecognitionResult | null>` -
|
|
285
|
+
- `recognizeText(options?): Promise<TextRecognitionResult[]>` - 识别图片中的文字;`options.regions` 可指定识别区域列表
|
|
286
|
+
- `findText(text, options?): Promise<TextRecognitionResult | null>` - 查找指定文字;`options.regions` 可指定查找区域列表;`options.notText` 可排除同一行中包含特定文字的匹配结果
|
|
287
287
|
|
|
288
288
|
**数据访问**
|
|
289
289
|
|
|
@@ -702,6 +702,17 @@ if (targetWindow) {
|
|
|
702
702
|
if (windowFound) {
|
|
703
703
|
console.log(`在窗口中找到"搜索": (${windowFound.x}, ${windowFound.y})`);
|
|
704
704
|
}
|
|
705
|
+
|
|
706
|
+
// 使用 notText 排除同一行的干扰文字
|
|
707
|
+
// 场景:同一行有"确定"和"取消"两个按钮,需要点击"确定"但排除"取消"所在行
|
|
708
|
+
const confirmBtn = await targetWindow.findText('确定', { notText: '取消' });
|
|
709
|
+
if (confirmBtn) {
|
|
710
|
+
console.log(`找到不与"取消"同行的"确定": (${confirmBtn.x}, ${confirmBtn.y})`);
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
// clickText 也支持 notText 参数
|
|
714
|
+
const clickResult = await targetWindow.clickText('发送', { notText: '草稿', timeout: 5000 });
|
|
715
|
+
console.log(`点击位置: (${clickResult.x}, ${clickResult.y})`);
|
|
705
716
|
}
|
|
706
717
|
```
|
|
707
718
|
|
|
@@ -719,6 +730,34 @@ interface TextRecognitionResult {
|
|
|
719
730
|
}
|
|
720
731
|
```
|
|
721
732
|
|
|
733
|
+
**ClickResult 类型:**
|
|
734
|
+
```typescript
|
|
735
|
+
interface ClickResult {
|
|
736
|
+
x: number; // 点击的 x 坐标(屏幕坐标)
|
|
737
|
+
y: number; // 点击的 y 坐标(屏幕坐标)
|
|
738
|
+
relX: number; // 相对于当前窗口/屏幕左上角的 x 坐标
|
|
739
|
+
relY: number; // 相对于当前窗口/屏幕左上角的 y 坐标
|
|
740
|
+
}
|
|
741
|
+
```
|
|
742
|
+
|
|
743
|
+
**FindTextOptions 类型:**
|
|
744
|
+
```typescript
|
|
745
|
+
interface FindTextOptions {
|
|
746
|
+
regions?: Array<{ x: number, y: number, width: number, height: number }>; // 查找区域列表
|
|
747
|
+
notText?: string; // 排除文字,若同一行中包含此文字则排除该匹配结果
|
|
748
|
+
}
|
|
749
|
+
```
|
|
750
|
+
|
|
751
|
+
**WaitOptions 类型:**
|
|
752
|
+
```typescript
|
|
753
|
+
interface WaitOptions {
|
|
754
|
+
regions?: Array<{ x: number, y: number, width: number, height: number }>; // 查找区域列表
|
|
755
|
+
timeout?: number; // 等待超时时间(毫秒),默认 3000
|
|
756
|
+
threshold?: number; // 匹配阈值(仅用于 waitIcon/clickIcon),默认 0.8
|
|
757
|
+
notText?: string; // 排除文字(仅用于 waitText/clickText)
|
|
758
|
+
}
|
|
759
|
+
```
|
|
760
|
+
|
|
722
761
|
## 平台支持
|
|
723
762
|
|
|
724
763
|
| 平台 | 架构 | 状态 | 备注 |
|
|
@@ -762,6 +801,29 @@ interface TextRecognitionResult {
|
|
|
762
801
|
|
|
763
802
|
## 更新日志
|
|
764
803
|
|
|
804
|
+
### 0.2.1
|
|
805
|
+
|
|
806
|
+
#### 新功能
|
|
807
|
+
|
|
808
|
+
- **findText / waitText / clickText 增强**: 新增 `notText` 参数,用于排除同一行中包含特定文字的匹配结果
|
|
809
|
+
- `findText(text, { notText: '排除文字' })` - 查找文字时,如果同一行中包含 `notText` 指定的文字,则排除该匹配结果
|
|
810
|
+
- `waitText(text, { notText: '排除文字' })` - 等待文字时同样支持排除逻辑
|
|
811
|
+
- `clickText(text, { notText: '排除文字' })` - 点击文字时同样支持排除逻辑
|
|
812
|
+
- 适用场景:同一行内可能有多个相似文字,需要精确排除干扰项
|
|
813
|
+
- 同一行判断标准:两个文字区域的垂直方向有超过较小区域高度 50% 的重叠
|
|
814
|
+
|
|
815
|
+
- **clickText / clickIcon 返回值增强**: 返回点击坐标信息 `ClickResult`
|
|
816
|
+
- 返回 `{ x, y, relX, relY }`,包含屏幕坐标和相对坐标
|
|
817
|
+
- 便于调试和验证点击位置
|
|
818
|
+
|
|
819
|
+
- **ImageData.recognizeText 增强**: 新增 `options.regions` 参数,可指定识别区域列表
|
|
820
|
+
|
|
821
|
+
#### 类型定义更新
|
|
822
|
+
|
|
823
|
+
- `FindTextOptions` 新增 `notText?: string` 字段
|
|
824
|
+
- `WaitOptions` 新增 `notText?: string` 字段
|
|
825
|
+
- `ClickResult` 类型:`{ x: number, y: number, relX: number, relY: number }`
|
|
826
|
+
|
|
765
827
|
### 0.2.0
|
|
766
828
|
|
|
767
829
|
#### 新功能
|
package/index.d.ts
CHANGED
|
@@ -38,6 +38,8 @@ export interface MatchOptionsJs {
|
|
|
38
38
|
export interface FindTextOptions {
|
|
39
39
|
/** 查找区域列表,若为空则在全图查找 */
|
|
40
40
|
regions?: Array<MatchRegion>
|
|
41
|
+
/** 排除文字,若同一行中包含此文字则排除该匹配结果 */
|
|
42
|
+
notText?: string
|
|
41
43
|
}
|
|
42
44
|
/** 文字识别选项 */
|
|
43
45
|
export interface RecognizeTextOptions {
|
|
@@ -52,6 +54,8 @@ export interface WaitOptions {
|
|
|
52
54
|
timeout?: number
|
|
53
55
|
/** 匹配阈值 (0.0-1.0),低于此值视为未找到,默认 0.8(仅用于 waitIcon/clickIcon) */
|
|
54
56
|
threshold?: number
|
|
57
|
+
/** 排除文字,若同一行中包含此文字则排除该匹配结果(仅用于 waitText/clickText) */
|
|
58
|
+
notText?: string
|
|
55
59
|
}
|
|
56
60
|
/** 图标匹配结果 */
|
|
57
61
|
export interface MatchResult {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rust-rpa",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1-beta.1",
|
|
4
4
|
"description": "Rust-based RPA automation library for Node.js",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "index.js",
|
|
@@ -69,9 +69,9 @@
|
|
|
69
69
|
"commander": "^14.0.3"
|
|
70
70
|
},
|
|
71
71
|
"optionalDependencies": {
|
|
72
|
-
"@alibot/rust-rpa-win32-x64-msvc": "0.2.
|
|
73
|
-
"@alibot/rust-rpa-win32-ia32-msvc": "0.2.
|
|
74
|
-
"@alibot/rust-rpa-darwin-x64": "0.2.
|
|
75
|
-
"@alibot/rust-rpa-darwin-arm64": "0.2.
|
|
72
|
+
"@alibot/rust-rpa-win32-x64-msvc": "0.2.1-beta.1",
|
|
73
|
+
"@alibot/rust-rpa-win32-ia32-msvc": "0.2.1-beta.1",
|
|
74
|
+
"@alibot/rust-rpa-darwin-x64": "0.2.1-beta.1",
|
|
75
|
+
"@alibot/rust-rpa-darwin-arm64": "0.2.1-beta.1"
|
|
76
76
|
}
|
|
77
77
|
}
|