@bettergi/utils 0.1.23 → 0.1.25

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Bread Grocery
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -273,4 +273,7 @@ const shuffled = shuffleArray(arr);
273
273
 
274
274
  // 深度合并多个对象:{ x: 1, y: { a: 2, b: 4, c: 5 }, d: 6 }
275
275
  const result = deepMerge({ x: 1, y: { a: 2, b: 3 } }, { y: { b: 4, c: 5 }, d: 6 });
276
+
277
+ // 同步休眠3秒
278
+ sleepSync(3000);
276
279
  ```
package/dist/misc.d.ts CHANGED
@@ -15,3 +15,8 @@ export declare const shuffleArray: <T>(array: T[]) => T[];
15
15
  * @returns 合并后的对象副本
16
16
  */
17
17
  export declare const deepMerge: (...objects: any[]) => any;
18
+ /**
19
+ * 同步休眠执行指定时长
20
+ * @param duration - 休眠时长(毫秒)
21
+ */
22
+ export declare const sleepSync: (duration: number) => void;
package/dist/misc.js CHANGED
@@ -39,3 +39,10 @@ export const deepMerge = (...objects) => {
39
39
  }, result);
40
40
  }, {});
41
41
  };
42
+ /**
43
+ * 同步休眠执行指定时长
44
+ * @param duration - 休眠时长(毫秒)
45
+ */
46
+ export const sleepSync = (duration) => {
47
+ duration > 0 && Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, duration);
48
+ };
package/dist/ocr.js CHANGED
@@ -235,12 +235,20 @@ export const findWithinListView = async (condition, listView, retryOptions, samp
235
235
  }
236
236
  };
237
237
  })();
238
- const isFoundOrReachedBottom = await waitForAction(() => condition(captureListViewRegion())?.isExist() || isReachedBottom(), async () => {
238
+ let targetRegion;
239
+ await waitForAction(() => {
240
+ targetRegion = condition(captureListViewRegion());
241
+ return targetRegion?.isExist() || isReachedBottom();
242
+ }, async () => {
239
243
  moveMouseTo(x + w - paddingX, y + paddingY); // 移动到滚动条附近
240
244
  await sleep(50);
241
245
  await mouseScrollDownLines(scrollLines, lineHeight); // 滚动指定行数
242
246
  }, { maxAttempts, retryInterval });
243
- return isFoundOrReachedBottom ? condition(captureListViewRegion()) : undefined;
247
+ if (targetRegion?.isExist()) {
248
+ const { item1, item2 } = targetRegion.convertPositionToGameCaptureRegion(0, 0);
249
+ Object.assign(targetRegion, { x: item1, y: item2 });
250
+ return targetRegion;
251
+ }
244
252
  };
245
253
  /**
246
254
  * 在列表视图中滚动搜索文本
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bettergi/utils",
3
- "version": "0.1.23",
3
+ "version": "0.1.25",
4
4
  "description": "开发 BetterGI 脚本常用工具集",
5
5
  "type": "module",
6
6
  "author": "Bread Grocery<https://github.com/breadgrocery>",
@@ -28,13 +28,16 @@
28
28
  "bettergi",
29
29
  "utils"
30
30
  ],
31
- "scripts": {
32
- "dev": "tsc --watch",
33
- "build": "rimraf dist && tsc"
31
+ "dependencies": {
32
+ "@bettergi/types": "^0.1.7"
34
33
  },
35
34
  "devDependencies": {
36
- "@bettergi/types": "workspace:^",
37
35
  "rimraf": "^6.1.2",
38
36
  "typescript": "^5.9.3"
37
+ },
38
+ "scripts": {
39
+ "dev": "tsc --watch",
40
+ "build": "rimraf dist && tsc",
41
+ "release": "pnpm build && pnpm publish --access public"
39
42
  }
40
- }
43
+ }