@bettergi/utils 0.0.9 → 0.0.10

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/dist/flow.d.ts CHANGED
@@ -7,4 +7,4 @@
7
7
  * @returns - true 在超时前条件已满足
8
8
  * - false 在超时后条件仍未满足
9
9
  */
10
- export declare const waitUntil: (condition: (context: Record<string, any>) => boolean, timeout?: number, interval?: number, action?: (context: Record<string, any>) => void) => Promise<boolean>;
10
+ export declare const waitUntil: (condition: (context: Record<string, any>) => boolean, timeout?: number, interval?: number, action?: (context: Record<string, any>) => Promise<void> | void) => Promise<boolean>;
package/dist/flow.js CHANGED
@@ -7,14 +7,14 @@
7
7
  * @returns - true 在超时前条件已满足
8
8
  * - false 在超时后条件仍未满足
9
9
  */
10
- export const waitUntil = async (condition, timeout, interval, action) => {
10
+ export const waitUntil = async (condition, timeout = 3000, interval = 300, action) => {
11
11
  const context = {};
12
- const deadline = Date.now() + (timeout ?? 3 * 1000);
12
+ const deadline = Date.now() + timeout;
13
13
  while (Date.now() < deadline) {
14
14
  if (condition(context))
15
15
  return true;
16
- action?.(context);
17
- await sleep(interval ?? 300);
16
+ await action?.(context);
17
+ await sleep(interval);
18
18
  }
19
19
  return false;
20
20
  };
package/dist/game.js CHANGED
@@ -19,11 +19,11 @@ export const openPaimonMenu = async () => {
19
19
  * @param reverse 是否反向搜索(可选)
20
20
  * @param config 搜索参数(可选)
21
21
  */
22
- export const openMenu = async (name, reverse, config) => {
22
+ export const openMenu = async (name, reverse = false, config = {}) => {
23
23
  // 1.打开派蒙菜单
24
24
  await openPaimonMenu();
25
25
  // 2.搜索菜单按钮
26
- const { x = 50, step = 30, timeout = 3000 } = config || {};
26
+ const { x = 50, step = 30, timeout = 3000 } = config;
27
27
  const findTooltip = () => findTextWithinBounds(name, false, true, 0, 0, x + 150, genshin.height);
28
28
  let result = undefined;
29
29
  const steps = Math.ceil(genshin.height / step);
@@ -52,11 +52,11 @@ export const openMenu = async (name, reverse, config) => {
52
52
  * @param name 菜单页面名称
53
53
  * @param config 菜单页面视图参数
54
54
  */
55
- export const openMenuPage = async (name, config) => {
55
+ export const openMenuPage = async (name, config = {}) => {
56
56
  // 1.打开派蒙菜单
57
57
  await openPaimonMenu();
58
58
  // 2.搜索菜单页面
59
- const { x = 100, y = 330, w = 670, h = 730, lineHeight = 142 } = config || {};
59
+ const { x = 100, y = 330, w = 670, h = 730, lineHeight = 142 } = config;
60
60
  const pageButton = await findTextWithinListView(name, false, true, {
61
61
  x,
62
62
  y,
@@ -75,11 +75,11 @@ export const openMenuPage = async (name, config) => {
75
75
  * @param period 时间段
76
76
  * @param config 时钟参数
77
77
  */
78
- export const setTime = async (period, config) => {
78
+ export const setTime = async (period, config = {}) => {
79
79
  // 1.打开时间页面
80
80
  await openMenu("时间", true);
81
81
  // 2.拨动指针
82
- const { centerX = 1440, centerY = 502, radius = 400, offset = 5 } = config || {};
82
+ const { centerX = 1440, centerY = 502, radius = 400, offset = 5 } = config;
83
83
  const index = ["night", "morning", "noon", "evening"].indexOf(period);
84
84
  const periodsDirections = [
85
85
  () => mouseSlide(centerX, centerY, centerX - offset, centerY + radius),
package/dist/http.js CHANGED
@@ -6,8 +6,8 @@
6
6
  * @param headers 请求头
7
7
  * @returns 响应体内容
8
8
  */
9
- export const requestForBody = async (method, url, body, headers) => {
10
- const resp = await http.request(method, url, body ?? "null", headers ? JSON.stringify(headers) : "null");
9
+ export const requestForBody = async (method, url, body = "null", headers) => {
10
+ const resp = await http.request(method, url, body, headers ? JSON.stringify(headers) : "null");
11
11
  if (resp.status_code >= 200 && resp.status_code < 400) {
12
12
  return resp.body;
13
13
  }
package/dist/mouse.js CHANGED
@@ -10,36 +10,32 @@ const _simulateScroll = async (scrollAmountInClicks, times) => {
10
10
  * @param height 滚动高度
11
11
  * @param algorithm 自定义滚动算法函数,接收高度参数并返回滚动次数(默认算法为每18像素滚动一次)
12
12
  */
13
- export const mouseScrollUp = (height, algorithm) => {
14
- const scrollAlgorithm = algorithm ?? (h => Math.floor(h / 18));
15
- const scrollTimes = scrollAlgorithm(height);
16
- return _simulateScroll(120, scrollTimes);
13
+ export const mouseScrollUp = (height, algorithm = h => Math.floor(h / 18)) => {
14
+ return _simulateScroll(120, algorithm(height));
17
15
  };
18
16
  /**
19
17
  * 鼠标滚轮向下滚动指定高度
20
18
  * @param height 滚动高度
21
19
  * @param algorithm 自定义滚动算法函数,接收高度参数并返回滚动次数(默认算法为每18像素滚动一次)
22
20
  */
23
- export const mouseScrollDown = (height, algorithm) => {
24
- const scrollAlgorithm = algorithm ?? (h => Math.floor(h / 18));
25
- const scrollTimes = scrollAlgorithm(height);
26
- return _simulateScroll(-120, scrollTimes);
21
+ export const mouseScrollDown = (height, algorithm = h => Math.floor(h / 18)) => {
22
+ return _simulateScroll(-120, algorithm(height));
27
23
  };
28
24
  /**
29
25
  * 鼠标滚轮向上滚动指定行数
30
26
  * @param lines 滚动行数
31
27
  * @param lineHeight 行高(默认值为175像素)
32
28
  */
33
- export const mouseScrollUpLines = (lines, lineHeight) => {
34
- return mouseScrollUp(lines * (lineHeight ?? 175));
29
+ export const mouseScrollUpLines = (lines, lineHeight = 175) => {
30
+ return mouseScrollUp(lines * lineHeight);
35
31
  };
36
32
  /**
37
33
  * 鼠标滚轮向下滚动指定行数
38
34
  * @param lines 滚动行数
39
35
  * @param lineHeight 行高(默认值为175像素)
40
36
  */
41
- export const mouseScrollDownLines = (lines, lineHeight) => {
42
- return mouseScrollDown(lines * (lineHeight ?? 175));
37
+ export const mouseScrollDownLines = (lines, lineHeight = 175) => {
38
+ return mouseScrollDown(lines * lineHeight);
43
39
  };
44
40
  /**
45
41
  * 鼠标拖拽滑动到指定位置
package/dist/ocr.js CHANGED
@@ -119,7 +119,7 @@ export const findTextInDirection = (text, contains, ignoreCase, direction) => {
119
119
  * @param timeout 搜索超时
120
120
  * @returns 如果找到匹配的文本区域,则返回该区域,否则返回 undefined
121
121
  */
122
- export const findTextWithinListView = async (text, contains, ignoreCase, listView, timeout) => {
122
+ export const findTextWithinListView = async (text, contains, ignoreCase, listView, timeout = 30 * 1000) => {
123
123
  const { x, y, w, h, maxListItems, lineHeight, padding = 10 } = listView;
124
124
  const find = () => {
125
125
  return findTextWithinBounds(text, contains, ignoreCase, x, y, w, h);
@@ -141,7 +141,7 @@ export const findTextWithinListView = async (text, contains, ignoreCase, listVie
141
141
  return true;
142
142
  }
143
143
  };
144
- const ok = await waitUntil(() => find() != undefined || isBottomTouched(), timeout ?? 30 * 1000, 1000, async () => {
144
+ const ok = await waitUntil(() => find() != undefined || isBottomTouched(), timeout, 1000, async () => {
145
145
  moveMouseTo(x + w - padding, y + padding);
146
146
  await mouseScrollDownLines(maxListItems, lineHeight);
147
147
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bettergi/utils",
3
- "version": "0.0.9",
3
+ "version": "0.0.10",
4
4
  "description": "开发 BetterGI 脚本常用工具集",
5
5
  "type": "module",
6
6
  "author": "Bread Grocery<https://github.com/breadgrocery>",
package/dist/action.d.ts DELETED
@@ -1,10 +0,0 @@
1
- /**
2
- * 等待直到条件满足或超时
3
- * @param condition 等待的条件判断函数,返回 true 表示条件满足
4
- * @param timeout 超时时间(毫秒),默认 5000 毫秒
5
- * @param interval 等待间隔(毫秒),默认 200 毫秒
6
- * @param action 每次等待循环中执行的操作(可选)
7
- * @returns - true 在超时前条件已满足
8
- * - false 在超时后条件仍未满足
9
- */
10
- export declare const waitUntil: (condition: (context: Record<string, any>) => boolean, timeout?: number, interval?: number, action?: (context: Record<string, any>) => void) => Promise<boolean>;
package/dist/action.js DELETED
@@ -1,20 +0,0 @@
1
- /**
2
- * 等待直到条件满足或超时
3
- * @param condition 等待的条件判断函数,返回 true 表示条件满足
4
- * @param timeout 超时时间(毫秒),默认 5000 毫秒
5
- * @param interval 等待间隔(毫秒),默认 200 毫秒
6
- * @param action 每次等待循环中执行的操作(可选)
7
- * @returns - true 在超时前条件已满足
8
- * - false 在超时后条件仍未满足
9
- */
10
- export const waitUntil = async (condition, timeout, interval, action) => {
11
- const context = {};
12
- const deadline = Date.now() + (timeout ?? 5 * 1000);
13
- while (Date.now() < deadline) {
14
- if (condition(context))
15
- return true;
16
- action?.(context);
17
- await sleep(interval ?? 200);
18
- }
19
- return false;
20
- };
package/dist/time.d.ts DELETED
File without changes
package/dist/time.js DELETED
File without changes