rust-rpa 0.1.5-beta.6 → 0.1.6

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 CHANGED
@@ -216,7 +216,7 @@ const windows = Window.all();
216
216
  - `getBounds(): WindowBounds` - 获取窗口边界(位置和大小)
217
217
  - `setBounds(bounds): Promise<void>` - 设置窗口边界(位置和大小)
218
218
  - `toJSON(): WindowToJson` - 转为 JSON 可序列化对象
219
- - `captureImage(options?: CaptureImageOptions): Promise<ImageData>` - 截取窗口图像;可选 `options.size` 指定目标宽高并自动缩放;`options.from` 为 `'screen'` 时截取窗口所在显示器整屏;`options.region` 指定仅截取逻辑像素区域;`options.auto_size` 为 true 时在 Windows 高 DPI 下自动缩放到逻辑像素尺寸
219
+ - `captureImage(options?: CaptureImageOptions): Promise<ImageData>` - 截取窗口图像;可选 `options.size` 指定目标宽高并自动缩放;`options.from` 为 `'screen'` 时截取窗口所在显示器整屏;`options.region` 指定仅截取逻辑像素区域;`options.autoSize` 为 true 时在 Windows 高 DPI 下自动缩放到逻辑像素尺寸
220
220
 
221
221
  ### Monitor 类
222
222
 
@@ -282,9 +282,10 @@ const primary = monitors.find(m => m.isPrimary());
282
282
 
283
283
  **findIcon 参数:**
284
284
  - `template: ImageData` - 模板图片(要查找的图标)
285
- - `options: MatchOptions` - 可选的匹配选项对象
286
- - `threshold: number` - 匹配阈值 (0.0-1.0),默认 0.8
287
- - `regions: Array<{x, y, width, height}>` - 可选的搜索区域列表,默认为空(全图搜索)
285
+ - `options?: MatchOptions` - 可选的匹配选项对象
286
+ - `threshold?: number` - 匹配阈值 (0.0-1.0),默认 0.8
287
+ - `regions?: Array<{x, y, width, height}>` - 可选的搜索区域列表,默认为空(全图搜索)
288
+ - 区域可超出图片边界,会自动裁剪为与图片的交集范围进行查找
288
289
 
289
290
  **MatchOptions 说明:**
290
291
 
@@ -343,7 +344,7 @@ interface CaptureImageOptions {
343
344
  // 以下仅对 Window.captureImage 有效:
344
345
  from?: 'window' | 'screen'; // 默认 'window' 截窗口;'screen' 截窗口所在显示器整屏(可配合 getBounds 与 image.crop 裁剪出窗口)
345
346
  region?: CaptureRegion | null; // 仅截取该逻辑像素区域,不填则截全图
346
- auto_size?: boolean | null; // 为 true 时在 Windows 存在 DPI 缩放时自动将图像缩放到逻辑像素宽高(与 getSize/getBounds 一致)
347
+ autoSize?: boolean | null; // 为 true 时在 Windows 存在 DPI 缩放时自动将图像缩放到逻辑像素宽高(与 getSize/getBounds 一致)
347
348
  }
348
349
  ```
349
350
 
@@ -353,7 +354,7 @@ interface CaptureImageOptions {
353
354
 
354
355
  #### 静态方法
355
356
 
356
- - `Mouse.moveTo(x, y): Promise<void>` - 移动鼠标到指定坐标
357
+ - `Mouse.moveTo(x, y, duration?): Promise<void>` - 移动鼠标到指定坐标。**duration** 可选,移动动画持续时间(秒),默认为 0(瞬间移动)。如果设置 > 0,鼠标将以平滑动画的方式移动到目标点,动画过程中会触发 mouseMove 事件
357
358
  - `Mouse.click(button?): Promise<void>` - 点击鼠标。**button** 可选,可用枚举 `MouseButton.Left` / `MouseButton.Right` 或字符串 `'left'` / `'right'` 等,默认左键
358
359
  - `Mouse.doubleClick(button?): Promise<void>` - 双击鼠标,button 同上
359
360
  - `Mouse.down(button?): Promise<void>` - 按下鼠标按钮,button 同上
@@ -542,7 +543,7 @@ if (windows.length > 0) {
542
543
 
543
544
  **截图选项**:`captureImage(options?)` 接受可选对象 `CaptureImageOptions`:
544
545
  - `size?: { width, height }`:截取后缩放到指定宽高,不传则返回原始尺寸。
545
- - **Window 专用**:`from?: 'window' | 'screen'` 默认截窗口,设为 `'screen'` 可截窗口所在显示器整屏再配合 `getBounds()` 与 `image.crop()` 裁剪;`region?: { x, y, width, height }` 仅截取该逻辑像素区域;`auto_size?: true` 在 Windows 高 DPI 下自动将图像缩放到逻辑像素宽高(与 `getSize`/`getBounds` 一致)。
546
+ - **Window 专用**:`from?: 'window' | 'screen'` 默认截窗口,设为 `'screen'` 可截窗口所在显示器整屏再配合 `getBounds()` 与 `image.crop()` 裁剪;`region?: { x, y, width, height }` 仅截取该逻辑像素区域;`autoSize?: true` 在 Windows 高 DPI 下自动将图像缩放到逻辑像素宽高(与 `getSize`/`getBounds` 一致)。
546
547
 
547
548
  ### 输入自动化
548
549
 
@@ -550,7 +551,8 @@ if (windows.length > 0) {
550
551
  const { Mouse, MouseButton, Keyboard, Key } = require('rust-rpa');
551
552
 
552
553
  // 鼠标操作
553
- await Mouse.moveTo(100, 200); // 移动鼠标
554
+ await Mouse.moveTo(100, 200); // 瞬间移动鼠标
555
+ await Mouse.moveTo(100, 200, 0.5); // 平滑动画移动,持续 0.5 秒
554
556
  await Mouse.click(MouseButton.Left); // 左键点击
555
557
  await Mouse.click(MouseButton.Right); // 右键点击
556
558
  await Mouse.doubleClick(); // 双击
@@ -746,13 +748,30 @@ npm test
746
748
 
747
749
  ## 更新日志
748
750
 
751
+ ### 0.1.6
752
+
753
+ #### BREAKCHANGE
754
+
755
+ - **Windows 平台鼠标坐标统一为逻辑像素**: `Mouse.moveTo()` 和 `Mouse.position()` 现在统一使用逻辑像素坐标,与 `Window.getBounds()` 等 API 保持一致
756
+ - 此前 Windows 平台上鼠标操作使用物理像素,在高 DPI 缩放环境下与窗口坐标不一致
757
+ - 现在 Windows 平台会自动处理 DPI 缩放,传入和返回的坐标均为逻辑像素
758
+ - macOS 平台不受影响(原本就使用逻辑像素)
759
+
760
+
749
761
  ### 0.1.5
750
762
 
751
763
  #### 功能
764
+ - **`Mouse.moveTo` 增强**: 新增可选 `duration` 参数,支持平滑动画移动
765
+ - `duration` 为移动动画持续时间(秒),默认为 0(瞬间移动)
766
+ - 当 `duration > 0` 时,鼠标以平滑动画方式移动到目标点,使用 easeInOutCubic 缓动函数
767
+ - 动画过程中会触发 mouseMove 事件,网页等应用可正常响应鼠标移动
768
+ - **`findIcon` 参数优化**: `options` 参数中的 `threshold` 和 `regions` 字段均改为可选
769
+ - `threshold` 不传时默认使用 0.8
770
+ - `regions` 中的区域可超出图片边界,会自动裁剪为与图片的交集范围进行查找
752
771
  - **Window.captureImage 选项 `from`**:新增 `'window'`(默认)与 `'screen'`。设为 `'screen'` 时先截取窗口所在显示器整屏,再自动裁剪为当前窗口与显示器的交集区域(超出显示器的部分忽略)。
753
772
  - **Window.captureImage 选项 `region`**:新增可选参数,仅截取指定逻辑像素区域 `{ x, y, width, height }`,不填则截取全图。
754
- - **Window.captureImage 选项 `auto_size`**:新增可选参数。为 `true` 时,在 Windows 存在 DPI 缩放的情况下自动将图像缩放到逻辑像素宽高(与 `getSize`/`getBounds` 一致)。
755
- - **CaptureImageOptions 处理顺序**:内部先执行 `auto_size`(缩放到逻辑像素),再执行 `region`(按逻辑像素裁剪),最后应用 `size`(若有)。启用 `auto_size` 后,`region` 与逻辑像素坐标一一对应。
773
+ - **Window.captureImage 选项 `auto`**:新增可选参数。为 `true` 时,在 Windows 存在 DPI 缩放的情况下自动将图像缩放到逻辑像素宽高(与 `getSize`/`getBounds` 一致)。
774
+ - **CaptureImageOptions 处理顺序**:内部先执行 `autoSize`(缩放到逻辑像素),再执行 `region`(按逻辑像素裁剪),最后应用 `size`(若有)。启用 `autoSize` 后,`region` 与逻辑像素坐标一一对应。
756
775
 
757
776
  ### 0.1.4
758
777
 
package/index.d.ts CHANGED
@@ -29,8 +29,8 @@ export interface ImageMetadata {
29
29
  }
30
30
  /** 匹配选项 */
31
31
  export interface MatchOptionsJs {
32
- /** 匹配阈值 (0.0-1.0),低于此值视为未找到 */
33
- threshold: number
32
+ /** 匹配阈值 (0.0-1.0),低于此值视为未找到,默认 0.8 */
33
+ threshold?: number
34
34
  /** 匹配区域列表,若为空则在整个图片中匹配 */
35
35
  regions?: Array<MatchRegion>
36
36
  }
@@ -147,8 +147,13 @@ export interface MousePosition {
147
147
 
148
148
  /** Mouse 类 - 鼠标控制 */
149
149
  export declare class Mouse {
150
- /** 移动鼠标到指定坐标 */
151
- static moveTo(x: number, y: number): Promise<void>
150
+ /**
151
+ * 移动鼠标到指定坐标
152
+ * @param x - 目标 x 坐标
153
+ * @param y - 目标 y 坐标
154
+ * @param duration - 可选,移动动画持续时间(秒)。默认为 0,表示瞬间移动。如果设置 > 0,鼠标将以平滑动画的方式移动到目标点
155
+ */
156
+ static moveTo(x: number, y: number, duration?: number | null): Promise<void>
152
157
  /** 点击鼠标按钮。button 可选,可用 MouseButton.Left / 'left' 等,默认左键 */
153
158
  static click(button?: MouseButtonType | null): Promise<void>
154
159
  /** 双击鼠标按钮。button 取值同 click */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rust-rpa",
3
- "version": "0.1.5-beta.6",
3
+ "version": "0.1.6",
4
4
  "description": "Rust-based RPA automation library for Node.js",
5
5
  "type": "commonjs",
6
6
  "main": "index.js",
Binary file
Binary file
Binary file
Binary file