rust-rpa 0.2.4 → 0.2.6-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.
Files changed (3) hide show
  1. package/README.md +42 -1
  2. package/index.d.ts +42 -1
  3. package/package.json +5 -5
package/README.md CHANGED
@@ -205,7 +205,7 @@ main();
205
205
  - `setBounds(bounds)` - 设置窗口边界
206
206
  - `toJSON()` - 转为 JSON 对象
207
207
  - `captureImage(options?)` - 截图
208
- - `watchChanges(options?, callback)` - 监听窗口内容变化;返回 `WindowWatcher`(`stop()` / `isRunning()`),回调收到变化后的 `ImageData` 或 `null`(见 `sendImage` 选项)
208
+ - `watchChanges(options?, callback)` - 监听窗口内容变化;返回 `WindowWatcher`(`stop()` / `isRunning()`),回调收到变化后的 `ImageData` 或 `null`(见 `sendImage` 选项);`stableFrames` 选项可过滤光标闪烁等瞬态变化
209
209
  - `recognizeText(options?)` - OCR 识别文字
210
210
  - `findText(text, options?)` - 查找文字
211
211
  - `findIcon(template, options?)` - 查找图标
@@ -591,6 +591,47 @@ if (targetWindow) {
591
591
 
592
592
  ## 更新日志
593
593
 
594
+ ### 0.2.6
595
+
596
+ #### 新功能
597
+
598
+ - **Window.watchChanges 新增 `stableFrames` 选项**: 支持过滤光标闪烁等瞬态变化,仅检测真实内容变化
599
+ - `stableFrames: 0`(默认)- 检测到变化即触发回调,最快响应
600
+ - `stableFrames: N` - 需连续 N 帧与上一帧相比均有变化才触发回调
601
+ - 过滤光标闪烁原理:光标闪烁 ON→OFF 一次变化、OFF→OFF 无变化则计数重置,无法连续 N 帧;而真实内容变化(新消息出现)会持续与旧基线不同,连续 N 帧均有变化
602
+ - 推荐 `stableFrames: 2` 可过滤大多数光标闪烁
603
+ - 示例:`window.watchChanges({ threshold: 0.02, stableFrames: 2 }, callback)`
604
+
605
+ ### 0.2.5
606
+
607
+ #### 改进
608
+
609
+ - **Window.watchChanges 优化**: `threshold` 参数默认值改为 `0.0`,并优化为 `0` 时跳过图像对比
610
+ - `threshold: 0`(默认)- 跳过像素对比,每次轮询直接触发回调,最低延迟
611
+ - `threshold > 0` - 执行降采样对比,变化比例超过阈值才触发回调
612
+ - 适用于已知窗口会变化、需要立即获取截图的场景
613
+
614
+ ### 0.2.5
615
+
616
+ #### 新功能
617
+
618
+ - **findText / waitText / clickText 新增 `index` 参数**: 支持选择第几个匹配的文字结果
619
+ - `index` 默认为 `0`,返回第一个匹配结果
620
+ - 正数表示第 n 个(从 0 开始):`index: 1` 返回第二个
621
+ - 负数表示倒数第 n 个:`index: -1` 返回最后一个,`index: -2` 返回倒数第二个
622
+ - 超出匹配数量范围时返回 `null`
623
+ - 适用场景:页面中存在多个相同文字,需要点击特定位置
624
+ - 示例:`findText('确定', { index: 1 })` 查找第二个「确定」,`clickText('确定', { index: -2 })` 点击倒数第二个「确定」
625
+
626
+ #### 类型定义更新
627
+
628
+ - `FindTextOptions` 新增 `index?: number` 字段
629
+ - `WindowFindTextOptions` 新增 `index?: number` 字段
630
+ - `MonitorFindTextOptions` 新增 `index?: number` 字段
631
+ - `WindowWaitOptions` 新增 `index?: number` 字段
632
+ - `MonitorWaitOptions` 新增 `index?: number` 字段
633
+ - `WaitOptions` 新增 `index?: number` 字段
634
+
594
635
  ### 0.2.4
595
636
 
596
637
  #### 新功能
package/index.d.ts CHANGED
@@ -60,6 +60,8 @@ export interface FindTextOptions {
60
60
  regions?: Array<MatchRegion>
61
61
  /** 排除文字,若同一行中包含此文字则排除该匹配结果 */
62
62
  notText?: string
63
+ /** 匹配索引,默认为 0(第一个匹配)。负数表示倒数:-1 最后一个,-2 倒数第二个 */
64
+ index?: number
63
65
  }
64
66
  /** 文字查找选项(Window 专用) */
65
67
  export interface WindowFindTextOptions {
@@ -73,6 +75,8 @@ export interface WindowFindTextOptions {
73
75
  * - `'screen'`:截取窗口所在显示器的整屏
74
76
  */
75
77
  from?: 'window' | 'screen'
78
+ /** 匹配索引,默认为 0(第一个匹配)。负数表示倒数:-1 最后一个,-2 倒数第二个 */
79
+ index?: number
76
80
  }
77
81
  /** 文字查找选项(Monitor 专用) */
78
82
  export interface MonitorFindTextOptions {
@@ -80,6 +84,8 @@ export interface MonitorFindTextOptions {
80
84
  regions?: Array<MatchRegion>
81
85
  /** 排除文字,若同一行中包含此文字则排除该匹配结果 */
82
86
  notText?: string
87
+ /** 匹配索引,默认为 0(第一个匹配)。负数表示倒数:-1 最后一个,-2 倒数第二个 */
88
+ index?: number
83
89
  }
84
90
  /** 文字识别选项(ImageData 使用) */
85
91
  export interface RecognizeTextOptions {
@@ -118,6 +124,8 @@ export interface WindowWaitOptions {
118
124
  * - `'screen'`:截取窗口所在显示器的整屏
119
125
  */
120
126
  from?: 'window' | 'screen'
127
+ /** 匹配索引,默认为 0(第一个匹配)。负数表示倒数:-1 最后一个,-2 倒数第二个(仅用于 waitText/clickText) */
128
+ index?: number
121
129
  }
122
130
  /** 等待选项(Monitor 专用) */
123
131
  export interface MonitorWaitOptions {
@@ -129,6 +137,8 @@ export interface MonitorWaitOptions {
129
137
  threshold?: number
130
138
  /** 排除文字,若同一行中包含此文字则排除该匹配结果(仅用于 waitText/clickText) */
131
139
  notText?: string
140
+ /** 匹配索引,默认为 0(第一个匹配)。负数表示倒数:-1 最后一个,-2 倒数第二个(仅用于 waitText/clickText) */
141
+ index?: number
132
142
  }
133
143
  /** 等待选项(兼容旧代码,与 WindowWaitOptions 相同) */
134
144
  export interface WaitOptions {
@@ -146,6 +156,8 @@ export interface WaitOptions {
146
156
  * - `'screen'`:截取窗口所在显示器的整屏
147
157
  */
148
158
  from?: 'window' | 'screen'
159
+ /** 匹配索引,默认为 0(第一个匹配)。负数表示倒数:-1 最后一个,-2 倒数第二个(仅用于 waitText/clickText) */
160
+ index?: number
149
161
  }
150
162
  /** 图标匹配结果 */
151
163
  export interface MatchResult {
@@ -246,7 +258,12 @@ export interface CaptureSizeJs {
246
258
  }
247
259
  /** 窗口变化监听的选项 */
248
260
  export interface WindowWatchOptionsJs {
249
- /** 变化检测的灵敏度阈值 (0.0-1.0),默认 0.02 */
261
+ /**
262
+ * 变化检测的灵敏度阈值 (0.0-1.0),默认 0.0
263
+ *
264
+ * - 0.0 表示跳过对比,每次轮询都触发回调(最敏感,最低延迟)
265
+ * - 大于 0.0 时,仅当像素变化比例超过阈值才触发回调
266
+ */
250
267
  threshold?: number
251
268
  /** 图片来源:'window'(默认)或 'screen' */
252
269
  from?: 'window' | 'screen'
@@ -256,6 +273,19 @@ export interface WindowWatchOptionsJs {
256
273
  captureSize?: CaptureSizeJs | null
257
274
  /** 是否在回调中传递截图图像,默认 true */
258
275
  sendImage?: boolean
276
+ /**
277
+ * 变化确认帧数,默认 0
278
+ *
279
+ * - 0 表示检测到变化即触发回调(最快响应)
280
+ * - 大于 0 时,需连续 N 帧与上一帧相比均有变化才触发回调
281
+ *
282
+ * 适用于过滤光标闪烁等瞬态变化:光标闪烁在 ON/OFF 间交替,
283
+ * ON→OFF 一次变化、OFF→OFF 无变化则计数重置,无法连续 N 帧;
284
+ * 而真实内容变化(如新消息出现)会持续与旧基线不同,
285
+ * 连续 N 帧均有变化,通过确认。
286
+ * 推荐 stableFrames=2 可过滤大多数光标闪烁。
287
+ */
288
+ stableFrames?: number
259
289
  }
260
290
  /** 窗口内容变化监听的回调函数签名 */
261
291
  export type WindowChangeCallback = (image: ImageData | null) => void
@@ -1330,6 +1360,17 @@ export declare class Window {
1330
1360
  * watcher.stop();
1331
1361
  * }, 60000);
1332
1362
  * ```
1363
+ *
1364
+ * @example
1365
+ * ```javascript
1366
+ * // 场景 4:忽略光标闪烁,仅检测真实内容变化
1367
+ * const watcher = targetWindow.watchChanges(
1368
+ * { threshold: 0.02, stableFrames: 2 },
1369
+ * (image) => {
1370
+ * console.log('窗口内容发生持久变化');
1371
+ * }
1372
+ * );
1373
+ * ```
1333
1374
  */
1334
1375
  watchChanges(
1335
1376
  options: WindowWatchOptionsJs | null | undefined,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rust-rpa",
3
- "version": "0.2.4",
3
+ "version": "0.2.6-beta.1",
4
4
  "description": "Rust-based RPA automation library for Node.js",
5
5
  "type": "commonjs",
6
6
  "main": "index.js",
@@ -67,9 +67,9 @@
67
67
  "commander": "^14.0.3"
68
68
  },
69
69
  "optionalDependencies": {
70
- "@alibot/rust-rpa-win32-x64-msvc": "0.2.4",
71
- "@alibot/rust-rpa-win32-ia32-msvc": "0.2.4",
72
- "@alibot/rust-rpa-darwin-x64": "0.2.4",
73
- "@alibot/rust-rpa-darwin-arm64": "0.2.4"
70
+ "@alibot/rust-rpa-win32-x64-msvc": "0.2.6-beta.1",
71
+ "@alibot/rust-rpa-win32-ia32-msvc": "0.2.6-beta.1",
72
+ "@alibot/rust-rpa-darwin-x64": "0.2.6-beta.1",
73
+ "@alibot/rust-rpa-darwin-arm64": "0.2.6-beta.1"
74
74
  }
75
75
  }