@bettergi/utils 0.0.4 → 0.0.5

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
@@ -10,7 +10,7 @@ npm install @bettergi/utils
10
10
 
11
11
  ### 图文识别
12
12
 
13
- > 对 RecognitionObject 代码的封装,对于简单的 OCR 操作,无需写复杂的代码。
13
+ > 对 RecognitionObject 代码的封装,对于简单的找图、找字操作,不再需要编写复杂的代码。
14
14
 
15
15
  ```ts
16
16
  import {
@@ -41,7 +41,7 @@ const t2 = findTextInDirection("师傅", true, true, "east");
41
41
  const t3 = findTextWithinBounds("确认", false, true, 960, 540, 960, 540);
42
42
  ```
43
43
 
44
- ### 行为
44
+ ### 行为流程
45
45
 
46
46
  > 对脚本开发过程中常见工作流的抽象,例如:等待 XXX 完成/出现/消失。
47
47
 
@@ -58,7 +58,44 @@ const done = await waitUntil(
58
58
  if (!done) throw new Error("关闭页面超时");
59
59
  ```
60
60
 
61
- ### 存储
61
+ ### 鼠标操作
62
+
63
+ > 对常见鼠标操作的封装,如鼠标滚动、拖拽等。
64
+
65
+ ```ts
66
+ import {
67
+ mouseScrollDown,
68
+ mouseScrollDownLines,
69
+ mouseScrollUp,
70
+ mouseScrollUpLines,
71
+ mouseSlide,
72
+ mouseSlideX,
73
+ mouseSlideY
74
+ } from "@bettergi/utils";
75
+
76
+ // 鼠标滚轮向上滚动 175 像素
77
+ await mouseScrollUp(175);
78
+
79
+ // 鼠标滚轮向下滚动 175 像素
80
+ await mouseScrollDown(175);
81
+
82
+ // 鼠标滚轮向上滚动 99 行,行高 175(默认:背包物品行高)
83
+ await mouseScrollUpLines(99);
84
+
85
+ // 鼠标滚轮向下滚动 1 行,行高 115(自定义:商店物品行高)
86
+ await mouseScrollDownLines(1, 115);
87
+
88
+ // 鼠标从 (745, 610) 拖拽到 (1280, 610)
89
+ await mouseSlide(745, 610, 1280, 610);
90
+
91
+ // 鼠标从 (745, 610) 向右拖拽 435 像素
92
+ await mouseSlideX(745, 610, 435);
93
+
94
+ // 鼠标从 (1290, 140) 向下拖拽 175 像素
95
+ await mouseSlideY(1290, 140, 175);
96
+ ```
97
+
98
+ ### 数据存储
62
99
 
63
100
  > 对象数据持久化,通过 Proxy 实现自动存储。从而可以无感知地读取/更新数据,而无需考虑如何持久化。
64
101
 
package/dist/mouse.d.ts CHANGED
@@ -22,3 +22,25 @@ export declare const mouseScrollUpLines: (lines: number, lineHeight?: number) =>
22
22
  * @param lineHeight 行高(默认值为175像素)
23
23
  */
24
24
  export declare const mouseScrollDownLines: (lines: number, lineHeight?: number) => Promise<void>;
25
+ /**
26
+ * 鼠标拖拽滑动到指定位置
27
+ * @param x1 起始水平方向偏移量(像素)
28
+ * @param y1 起始垂直方向偏移量(像素)
29
+ * @param x2 终止水平方向偏移量(像素)
30
+ * @param y2 终止垂直方向偏移量(像素)
31
+ */
32
+ export declare const mouseSlide: (x1: number, y1: number, x2: number, y2: number) => Promise<void>;
33
+ /**
34
+ * 鼠标水平拖拽滑动指定距离
35
+ * @param x 起始水平方向偏移量(像素)
36
+ * @param y 起始垂直方向偏移量(像素)
37
+ * @param distance 水平拖拽滑动距离(像素) 正数向右,负数向左
38
+ */
39
+ export declare const mouseSlideX: (x: number, y: number, distance: number) => Promise<void>;
40
+ /**
41
+ * 鼠标垂直拖拽滑动指定距离
42
+ * @param x 起始水平方向偏移量(像素)
43
+ * @param y 起始垂直方向偏移量(像素)
44
+ * @param distance 垂直拖拽滑动距离(像素) 正数向下,负数向上
45
+ */
46
+ export declare const mouseSlideY: (x: number, y: number, distance: number) => Promise<void>;
package/dist/mouse.js CHANGED
@@ -41,3 +41,37 @@ export const mouseScrollUpLines = (lines, lineHeight) => {
41
41
  export const mouseScrollDownLines = (lines, lineHeight) => {
42
42
  return mouseScrollDown(lines * (lineHeight ?? 175));
43
43
  };
44
+ /**
45
+ * 鼠标拖拽滑动到指定位置
46
+ * @param x1 起始水平方向偏移量(像素)
47
+ * @param y1 起始垂直方向偏移量(像素)
48
+ * @param x2 终止水平方向偏移量(像素)
49
+ * @param y2 终止垂直方向偏移量(像素)
50
+ */
51
+ export const mouseSlide = async (x1, y1, x2, y2) => {
52
+ moveMouseTo(x1, y1);
53
+ await sleep(50);
54
+ leftButtonDown();
55
+ await sleep(50);
56
+ moveMouseTo(x2, y2);
57
+ await sleep(50);
58
+ leftButtonUp();
59
+ };
60
+ /**
61
+ * 鼠标水平拖拽滑动指定距离
62
+ * @param x 起始水平方向偏移量(像素)
63
+ * @param y 起始垂直方向偏移量(像素)
64
+ * @param distance 水平拖拽滑动距离(像素) 正数向右,负数向左
65
+ */
66
+ export const mouseSlideX = (x, y, distance) => {
67
+ return mouseSlide(x, y, x + distance, y);
68
+ };
69
+ /**
70
+ * 鼠标垂直拖拽滑动指定距离
71
+ * @param x 起始水平方向偏移量(像素)
72
+ * @param y 起始垂直方向偏移量(像素)
73
+ * @param distance 垂直拖拽滑动距离(像素) 正数向下,负数向上
74
+ */
75
+ export const mouseSlideY = (x, y, distance) => {
76
+ return mouseSlide(x, y, x, y + distance);
77
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bettergi/utils",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "Utils for BetterGI JavaScript Development",
5
5
  "type": "module",
6
6
  "author": "Bread Grocery<https://github.com/breadgrocery>",