rust-rpa 0.1.4-beta.4 → 0.1.5-beta.2

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` 指定目标宽高并自动缩放
219
+ - `captureImage(options?: CaptureImageOptions): Promise<ImageData>` - 截取窗口图像;可选 `options.size` 指定目标宽高并自动缩放;`options.from` 为 `'screen'` 时截取窗口所在显示器整屏;`options.region` 指定仅截取逻辑像素区域;`options.auto_size` 为 true 时在 Windows 高 DPI 下自动缩放到逻辑像素尺寸
220
220
 
221
221
  ### Monitor 类
222
222
 
@@ -330,8 +330,20 @@ interface ImageMetadata {
330
330
 
331
331
  **captureImage 选项(Monitor / Window):**
332
332
  ```typescript
333
+ // 截取区域(逻辑像素),仅对 Window.captureImage 有效
334
+ interface CaptureRegion {
335
+ x: number; // 区域左上角 x(相对截图画布左上角)
336
+ y: number; // 区域左上角 y
337
+ width: number; // 区域宽度
338
+ height: number; // 区域高度
339
+ }
340
+
333
341
  interface CaptureImageOptions {
334
342
  size?: { width: number; height: number }; // 可选,截取后缩放到指定宽高
343
+ // 以下仅对 Window.captureImage 有效:
344
+ from?: 'window' | 'screen'; // 默认 'window' 截窗口;'screen' 截窗口所在显示器整屏(可配合 getBounds 与 image.crop 裁剪出窗口)
345
+ region?: CaptureRegion | null; // 仅截取该逻辑像素区域,不填则截全图
346
+ auto_size?: boolean | null; // 为 true 时在 Windows 存在 DPI 缩放时自动将图像缩放到逻辑像素宽高(与 getSize/getBounds 一致)
335
347
  }
336
348
  ```
337
349
 
@@ -528,7 +540,9 @@ if (windows.length > 0) {
528
540
  }
529
541
  ```
530
542
 
531
- **截图选项**:`captureImage(options?)` 接受可选对象 `CaptureImageOptions`,其中 `size?: { width: number, height: number }` 表示截取后缩放到指定宽高,不传则返回原始尺寸。
543
+ **截图选项**:`captureImage(options?)` 接受可选对象 `CaptureImageOptions`:
544
+ - `size?: { width, height }`:截取后缩放到指定宽高,不传则返回原始尺寸。
545
+ - **Window 专用**:`from?: 'window' | 'screen'` 默认截窗口,设为 `'screen'` 可截窗口所在显示器整屏再配合 `getBounds()` 与 `image.crop()` 裁剪;`region?: { x, y, width, height }` 仅截取该逻辑像素区域;`auto_size?: true` 在 Windows 高 DPI 下自动将图像缩放到逻辑像素宽高(与 `getSize`/`getBounds` 一致)。
532
546
 
533
547
  ### 输入自动化
534
548
 
@@ -729,6 +743,14 @@ npm test
729
743
 
730
744
  ## 更新日志
731
745
 
746
+ ### 0.1.5
747
+
748
+ #### 功能
749
+ - **Window.captureImage 选项 `from`**:新增 `'window'`(默认)与 `'screen'`。设为 `'screen'` 时先截取窗口所在显示器整屏,再自动裁剪为当前窗口与显示器的交集区域(超出显示器的部分忽略)。
750
+ - **Window.captureImage 选项 `region`**:新增可选参数,仅截取指定逻辑像素区域 `{ x, y, width, height }`,不填则截取全图。
751
+ - **Window.captureImage 选项 `auto_size`**:新增可选参数。为 `true` 时,在 Windows 存在 DPI 缩放的情况下自动将图像缩放到逻辑像素宽高(与 `getSize`/`getBounds` 一致)。
752
+ - **CaptureImageOptions 处理顺序**:内部先执行 `auto_size`(缩放到逻辑像素),再执行 `region`(按逻辑像素裁剪),最后应用 `size`(若有)。启用 `auto_size` 后,`region` 与逻辑像素坐标一一对应。
753
+
732
754
  ### 0.1.4
733
755
 
734
756
  #### BREAKCHANGE
package/index.d.ts CHANGED
@@ -56,10 +56,31 @@ export interface CaptureSize {
56
56
  /** 目标高度(像素) */
57
57
  height: number
58
58
  }
59
+ /** 截取区域(逻辑像素),仅截取该矩形范围 */
60
+ export interface CaptureRegion {
61
+ /** 区域左上角 x(相对截图画布左上角,逻辑像素) */
62
+ x: number
63
+ /** 区域左上角 y(逻辑像素) */
64
+ y: number
65
+ /** 区域宽度(逻辑像素) */
66
+ width: number
67
+ /** 区域高度(逻辑像素) */
68
+ height: number
69
+ }
59
70
  /** captureImage 的选项对象,便于后续扩展更多参数 */
60
71
  export interface CaptureImageOptions {
61
72
  /** 目标尺寸,配置后会将截取到的图像缩放到指定宽高 */
62
73
  size?: CaptureSize | null
74
+ /**
75
+ * 图片来源(仅对 Window.captureImage 有效):
76
+ * - `'window'`(默认):截取当前窗口
77
+ * - `'screen'`:截取窗口所在显示器的整屏,可用 getBounds() 与显示器范围计算裁剪区域,再通过 image.crop() 得到窗口截图;超出当前显示器范围的部分不会出现在图中
78
+ */
79
+ from?: 'window' | 'screen' | null
80
+ /** 仅截取该区域(逻辑像素),不填则截取全图;仅对 Window.captureImage 有效 */
81
+ region?: CaptureRegion | null
82
+ /** 为 true 时,在 Windows 上若存在 DPI 缩放,则自动将图像缩放到逻辑像素宽高(与 getSize/getBounds 一致);仅对 Window.captureImage 有效 */
83
+ auto_size?: boolean | null
63
84
  }
64
85
  /** 窗口尺寸信息 */
65
86
  export interface WindowSize {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rust-rpa",
3
- "version": "0.1.4-beta.4",
3
+ "version": "0.1.5-beta.2",
4
4
  "description": "Rust-based RPA automation library for Node.js",
5
5
  "type": "commonjs",
6
6
  "main": "index.js",
@@ -32,6 +32,28 @@
32
32
  "engines": {
33
33
  "node": ">= 18"
34
34
  },
35
+ "scripts": {
36
+ "artifacts": "napi artifacts",
37
+ "build": "napi build --platform --release --manifest-path crates/bindings/Cargo.toml && npm run postbuild",
38
+ "build:debug": "napi build --platform --manifest-path crates/bindings/Cargo.toml && npm run postbuild",
39
+ "build:macos-x64": "napi build --platform --release --target x86_64-apple-darwin --manifest-path crates/bindings/Cargo.toml && npm run postbuild",
40
+ "build:macos-arm64": "napi build --platform --release --target aarch64-apple-darwin --manifest-path crates/bindings/Cargo.toml && npm run postbuild",
41
+ "build:macos-universal": "npm run build:macos-x64 && npm run build:macos-arm64",
42
+ "build:windows-x64": "napi build --platform --release --target x86_64-pc-windows-msvc --cross-compile --manifest-path crates/bindings/Cargo.toml && npm run postbuild",
43
+ "build:windows-x86": "napi build --platform --release --target i686-pc-windows-msvc --cross-compile --manifest-path crates/bindings/Cargo.toml && npm run postbuild",
44
+ "build:windows-all": "npm run build:windows-x64 && npm run build:windows-x86",
45
+ "build:all": "npm run build:macos-universal && npm run build:windows-all",
46
+ "postbuild": "node scripts/postbuild.js",
47
+ "test": "vitest run",
48
+ "test:watch": "vitest",
49
+ "version": "napi version"
50
+ },
51
+ "devDependencies": {
52
+ "@napi-rs/cli": "^3.5.1",
53
+ "node-screenshots": "^0.2.8",
54
+ "sharp": "^0.34.5",
55
+ "vitest": "^4.0.18"
56
+ },
35
57
  "files": [
36
58
  "index.js",
37
59
  "index.d.ts",
@@ -41,4 +63,4 @@
41
63
  "dependencies": {
42
64
  "commander": "^14.0.3"
43
65
  }
44
- }
66
+ }
Binary file
Binary file
Binary file
Binary file