@bettergi/utils 0.1.11 → 0.1.12

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
@@ -50,20 +50,26 @@ await navigateToTab(() => {
50
50
  // 在整个画面内搜索图片,找不到返回 undefined
51
51
  const i1 = findImage("assets/关闭.png", { use3Channels: true }); // 匹配颜色
52
52
 
53
- // 在指定方向上搜索图片,找不到返回 undefined
54
- const i2 = findImageInDirection("assets/关闭.png", "north-east");
55
-
56
53
  // 在指定区域内搜索图片,找不到返回 undefined
57
- const i3 = findImageWithinBounds("assets/关闭.png", 960, 0, 960, 1080);
54
+ const i2 = findImageWithinBounds("assets/关闭.png", 960, 0, 960, 1080);
55
+
56
+ // 在指定坐标范围内搜索图片,找不到返回 undefined
57
+ const i3 = findImageBetweenCoordinates("assets/关闭.png", 960, 0, 1920, 1080);
58
+
59
+ // 在指定方向上搜索图片,找不到返回 undefined
60
+ const i4 = findImageInDirection("assets/关闭.png", "north-east");
58
61
 
59
62
  // 在整个画面内搜索文本(不包含、忽略大小写),找不到返回 undefined
60
63
  const t1 = findText("购买");
61
64
 
62
- // 在指定方向上搜索文本(包含、忽略大小写),找不到返回 undefined
63
- const t2 = findTextInDirection("师傅", "east", { contains: true, ignoreCase: true });
64
-
65
65
  // 在指定区域内搜索文本(不包含、忽略大小写),找不到返回 undefined
66
- const t3 = findTextWithinBounds("确认", 960, 540, 960, 540);
66
+ const t2 = findTextWithinBounds("确认", 960, 540, 960, 540);
67
+
68
+ // 在指定坐标范围内搜索文本(不包含、忽略大小写),找不到返回 undefined
69
+ const t3 = findTextBetweenCoordinates("确认", 960, 540, 1920, 1080);
70
+
71
+ // 在指定方向上搜索文本(包含、忽略大小写),找不到返回 undefined
72
+ const t4 = findTextInDirection("师傅", "east", { contains: true, ignoreCase: true });
67
73
  ```
68
74
 
69
75
  ### 行为流程
@@ -119,7 +125,7 @@ await mouseScrollUpLines(99);
119
125
  await mouseScrollDownLines(1, 115);
120
126
  ```
121
127
 
122
- ### 数据存储
128
+ ### 状态管理和持久化
123
129
 
124
130
  > 对象数据持久化,通过 Proxy 实现自动存储。从而可以无感知地读取/更新数据,而无需考虑如何持久化。
125
131
 
package/dist/mouse.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  export type MouseWaypointsOptions = {
2
2
  /** 是否按住鼠标左键拖动 */
3
3
  shouldDrag?: boolean;
4
+ /** 移动延时(毫秒) */
5
+ delay?: number;
4
6
  /** 超时时间(毫秒,默认: 不超时) */
5
7
  timeout?: number;
6
8
  };
package/dist/mouse.js CHANGED
@@ -4,7 +4,7 @@
4
4
  * @param options 鼠标移动选项
5
5
  */
6
6
  export const mouseMoveAlongWaypoints = async (waypoints, options) => {
7
- const { shouldDrag = false, timeout = 0 } = options || {};
7
+ const { shouldDrag = false, delay = 50, timeout = 0 } = options || {};
8
8
  try {
9
9
  const startTime = Date.now();
10
10
  for (let i = 0; i < waypoints.length; i++) {
@@ -13,9 +13,9 @@ export const mouseMoveAlongWaypoints = async (waypoints, options) => {
13
13
  leftButtonDown();
14
14
  moveMouseTo(Math.trunc(waypoints[i].x), Math.trunc(waypoints[i].y));
15
15
  // 等待指定延迟
16
- const delay = Math.trunc(waypoints[i].delay || 50);
17
- if (delay > 0)
18
- await sleep(delay);
16
+ const duration = Math.trunc(waypoints[i].delay || delay);
17
+ if (duration > 0)
18
+ await sleep(duration);
19
19
  // 超时检查
20
20
  if (timeout > 0 && Date.now() - startTime > timeout)
21
21
  return false;
package/dist/ocr.d.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  import { RetryOptions } from "./workflow";
2
+ /** 识别对象实例 */
2
3
  export type ROInstance = InstanceType<typeof RecognitionObject>;
4
+ /** 识别对象配置 */
3
5
  export type ROConfig = Partial<{
4
- [K in keyof ROInstance]: ROInstance[K];
6
+ [K in keyof ROInstance as ROInstance[K] extends Function ? never : K]: ROInstance[K];
5
7
  }>;
6
8
  export type MatchDirection = "north" /** 上半边 */ | "north-east" /** 右上四分之一 */ | "east" /** 右半边 */ | "south-east" /** 右下四分之一 */ | "south" /** 下半边 */ | "south-west" /** 左下四分之一 */ | "west" /** 左半边 */ | "north-west"; /** 左上四分之一 */
7
9
  /**
@@ -22,6 +24,17 @@ export declare const findImage: (path: string, config?: ROConfig) => Region | un
22
24
  * @returns 如果找到匹配的图片区域,则返回该区域
23
25
  */
24
26
  export declare const findImageWithinBounds: (path: string, x: number, y: number, w: number, h: number, config?: ROConfig) => Region | undefined;
27
+ /**
28
+ * 在指定坐标范围内搜索图片
29
+ * @param path 图片路径
30
+ * @param left 左边界偏移量(像素)
31
+ * @param top 上边界偏移量(像素)
32
+ * @param right 右边界偏移量(像素)
33
+ * @param bottom 下边界偏移量(像素)
34
+ * @param config 识别对象配置
35
+ * @returns 如果找到匹配的图片区域,则返回该区域
36
+ */
37
+ export declare const findImageBetweenCoordinates: (path: string, left: number, top: number, right: number, bottom: number, config?: ROConfig) => Region | undefined;
25
38
  /**
26
39
  * 在指定方向上搜索图片
27
40
  * @param path 图片路径
@@ -57,6 +70,18 @@ export declare const findText: (text: string, options?: TextMatchOptions, config
57
70
  * @returns 如果找到匹配的文本区域,则返回该区域
58
71
  */
59
72
  export declare const findTextWithinBounds: (text: string, x: number, y: number, w: number, h: number, options?: TextMatchOptions, config?: ROConfig) => Region | undefined;
73
+ /**
74
+ * 在指定坐标范围内搜索文本
75
+ * @param text 待搜索文本
76
+ * @param left 左边界偏移量(像素)
77
+ * @param top 上边界偏移量(像素)
78
+ * @param right 右边界偏移量(像素)
79
+ * @param bottom 下边界偏移量(像素)
80
+ * @param options 搜索选项
81
+ * @param config 识别对象配置
82
+ * @returns 如果找到匹配的文本区域,则返回该区域
83
+ */
84
+ export declare const findTextBetweenCoordinates: (text: string, left: number, top: number, right: number, bottom: number, options?: TextMatchOptions, config?: ROConfig) => Region | undefined;
60
85
  /**
61
86
  * 在指定方向上搜索文本
62
87
  * @param text 待搜索文本
package/dist/ocr.js CHANGED
@@ -65,6 +65,19 @@ export const findImageWithinBounds = (path, x, y, w, h, config = {}) => {
65
65
  ir.dispose();
66
66
  }
67
67
  };
68
+ /**
69
+ * 在指定坐标范围内搜索图片
70
+ * @param path 图片路径
71
+ * @param left 左边界偏移量(像素)
72
+ * @param top 上边界偏移量(像素)
73
+ * @param right 右边界偏移量(像素)
74
+ * @param bottom 下边界偏移量(像素)
75
+ * @param config 识别对象配置
76
+ * @returns 如果找到匹配的图片区域,则返回该区域
77
+ */
78
+ export const findImageBetweenCoordinates = (path, left, top, right, bottom, config = {}) => {
79
+ return findImageWithinBounds(path, left, top, right - left, bottom - top, config);
80
+ };
68
81
  /**
69
82
  * 在指定方向上搜索图片
70
83
  * @param path 图片路径
@@ -134,6 +147,20 @@ export const findTextWithinBounds = (text, x, y, w, h, options, config = {}) =>
134
147
  ir.dispose();
135
148
  }
136
149
  };
150
+ /**
151
+ * 在指定坐标范围内搜索文本
152
+ * @param text 待搜索文本
153
+ * @param left 左边界偏移量(像素)
154
+ * @param top 上边界偏移量(像素)
155
+ * @param right 右边界偏移量(像素)
156
+ * @param bottom 下边界偏移量(像素)
157
+ * @param options 搜索选项
158
+ * @param config 识别对象配置
159
+ * @returns 如果找到匹配的文本区域,则返回该区域
160
+ */
161
+ export const findTextBetweenCoordinates = (text, left, top, right, bottom, options, config = {}) => {
162
+ return findTextWithinBounds(text, left, top, right - left, bottom - top, options, config);
163
+ };
137
164
  /**
138
165
  * 在指定方向上搜索文本
139
166
  * @param text 待搜索文本
@@ -179,6 +206,7 @@ export const findTextWithinListView = async (text, listView, matchOptions, retry
179
206
  };
180
207
  const isTextFoundOrBottomReached = await waitForAction(() => findTargetText() != undefined || isReachedBottom(), async () => {
181
208
  moveMouseTo(x + w - paddingX, y + paddingY); // 移动到滚动条附近
209
+ await sleep(50);
182
210
  await mouseScrollDownLines(scrollLines, lineHeight); // 滚动指定行数
183
211
  }, { maxAttempts, retryInterval });
184
212
  return isTextFoundOrBottomReached ? findTargetText() : undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bettergi/utils",
3
- "version": "0.1.11",
3
+ "version": "0.1.12",
4
4
  "description": "开发 BetterGI 脚本常用工具集",
5
5
  "type": "module",
6
6
  "author": "Bread Grocery<https://github.com/breadgrocery>",