assistsx-js 0.1.41 → 0.2.0
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 +32 -0
- package/dist/index.cjs +7957 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.mts +4231 -0
- package/dist/index.d.ts +4231 -30
- package/dist/index.global.js +46 -0
- package/dist/index.global.js.map +1 -0
- package/dist/index.js +7879 -30
- package/dist/index.js.map +1 -0
- package/package.json +11 -5
- package/src/{AssistsXAsync.ts → assistsx-async.ts} +8 -8
- package/src/{AssistsX.ts → assistsx.ts} +8 -8
- package/src/barutils/bar-utils.ts +3 -3
- package/src/filesystem/fileio/file-io.ts +2 -2
- package/src/filesystem/fileutils/file-utils.ts +2 -2
- package/src/filesystem/path.ts +2 -2
- package/src/floatingwindow/float.ts +4 -4
- package/src/gallery/gallery.ts +2 -2
- package/src/global.d.ts +6 -1
- package/src/imageutils/image-utils.ts +2 -2
- package/src/ime/ime.ts +2 -2
- package/src/index.ts +21 -20
- package/src/log/log-call-method.ts +28 -0
- package/src/log/log.ts +445 -0
- package/src/mlkit/mlkit.ts +3 -3
- package/src/network/http.ts +2 -2
- package/src/{NodeAsync.ts → node-async.ts} +5 -5
- package/src/{Node.ts → node.ts} +5 -5
- package/src/{StepAsync.ts → step-async.ts} +8 -8
- package/src/{Step.ts → step.ts} +7 -7
- package/dist/AccessibilityEventFilter.d.ts +0 -105
- package/dist/AccessibilityEventFilter.js +0 -89
- package/dist/AppInfo.d.ts +0 -45
- package/dist/AppInfo.js +0 -38
- package/dist/AssistsX.d.ts +0 -484
- package/dist/AssistsX.js +0 -828
- package/dist/AssistsXAsync.d.ts +0 -532
- package/dist/AssistsXAsync.js +0 -874
- package/dist/Bounds.d.ts +0 -48
- package/dist/Bounds.js +0 -68
- package/dist/CallMethod.d.ts +0 -69
- package/dist/CallMethod.js +0 -71
- package/dist/CallResponse.d.ts +0 -10
- package/dist/CallResponse.js +0 -28
- package/dist/DeviceInfo.d.ts +0 -69
- package/dist/DeviceInfo.js +0 -50
- package/dist/Node.d.ts +0 -334
- package/dist/Node.js +0 -369
- package/dist/NodeAsync.d.ts +0 -213
- package/dist/NodeAsync.js +0 -313
- package/dist/NodeClassValue.d.ts +0 -15
- package/dist/NodeClassValue.js +0 -15
- package/dist/Step.d.ts +0 -355
- package/dist/Step.js +0 -689
- package/dist/StepAsync.d.ts +0 -162
- package/dist/StepAsync.js +0 -264
- package/dist/StepError.d.ts +0 -35
- package/dist/StepError.js +0 -26
- package/dist/StepStateStore.d.ts +0 -14
- package/dist/StepStateStore.js +0 -37
- package/dist/Utils.d.ts +0 -3
- package/dist/Utils.js +0 -20
- package/dist/WindowFlags.d.ts +0 -75
- package/dist/WindowFlags.js +0 -97
- package/dist/barutils/BarUtilsCallMethod.d.ts +0 -24
- package/dist/barutils/BarUtilsCallMethod.js +0 -26
- package/dist/barutils/bar-utils.d.ts +0 -41
- package/dist/barutils/bar-utils.js +0 -205
- package/dist/filesystem/fileio/file-io.d.ts +0 -101
- package/dist/filesystem/fileio/file-io.js +0 -235
- package/dist/filesystem/fileutils/file-utils.d.ts +0 -242
- package/dist/filesystem/fileutils/file-utils.js +0 -493
- package/dist/filesystem/path.d.ts +0 -252
- package/dist/filesystem/path.js +0 -589
- package/dist/floatingwindow/FloatCallMethod.d.ts +0 -19
- package/dist/floatingwindow/FloatCallMethod.js +0 -18
- package/dist/floatingwindow/float.d.ts +0 -29
- package/dist/floatingwindow/float.js +0 -149
- package/dist/gallery/gallery.d.ts +0 -60
- package/dist/gallery/gallery.js +0 -142
- package/dist/imageutils/image-utils.d.ts +0 -442
- package/dist/imageutils/image-utils.js +0 -543
- package/dist/ime/ime.d.ts +0 -80
- package/dist/ime/ime.js +0 -141
- package/dist/mlkit/MlkitCallMethod.d.ts +0 -27
- package/dist/mlkit/MlkitCallMethod.js +0 -26
- package/dist/mlkit/mlkit.d.ts +0 -86
- package/dist/mlkit/mlkit.js +0 -169
- package/dist/network/http.d.ts +0 -127
- package/dist/network/http.js +0 -202
- /package/src/{AccessibilityEventFilter.ts → accessibility-event-filter.ts} +0 -0
- /package/src/{AppInfo.ts → app-info.ts} +0 -0
- /package/src/barutils/{BarUtilsCallMethod.ts → bar-utils-call-method.ts} +0 -0
- /package/src/{Bounds.ts → bounds.ts} +0 -0
- /package/src/{CallMethod.ts → call-method.ts} +0 -0
- /package/src/{CallResponse.ts → call-response.ts} +0 -0
- /package/src/{DeviceInfo.ts → device-info.ts} +0 -0
- /package/src/floatingwindow/{FloatCallMethod.ts → float-call-method.ts} +0 -0
- /package/src/mlkit/{MlkitCallMethod.ts → mlkit-call-method.ts} +0 -0
- /package/src/{NodeClassValue.ts → node-class-value.ts} +0 -0
- /package/src/{StepError.ts → step-error.ts} +0 -0
- /package/src/{StepStateStore.ts → step-state-store.ts} +0 -0
- /package/src/{Utils.ts → utils.ts} +0 -0
- /package/src/{WindowFlags.ts → window-flags.ts} +0 -0
package/dist/ime/ime.js
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 输入法相关功能
|
|
3
|
-
* 提供输入法操作相关的功能,如执行编辑器动作(搜索等)
|
|
4
|
-
*/
|
|
5
|
-
import { CallResponse } from "../CallResponse";
|
|
6
|
-
import { decodeBase64UTF8, generateUUID } from "../Utils";
|
|
7
|
-
/**
|
|
8
|
-
* IME 动作 ID 常量
|
|
9
|
-
*/
|
|
10
|
-
export var ImeAction;
|
|
11
|
-
(function (ImeAction) {
|
|
12
|
-
/** 无动作 */
|
|
13
|
-
ImeAction[ImeAction["NONE"] = 0] = "NONE";
|
|
14
|
-
/** 前往 */
|
|
15
|
-
ImeAction[ImeAction["GO"] = 2] = "GO";
|
|
16
|
-
/** 搜索 */
|
|
17
|
-
ImeAction[ImeAction["SEARCH"] = 3] = "SEARCH";
|
|
18
|
-
/** 发送 */
|
|
19
|
-
ImeAction[ImeAction["SEND"] = 4] = "SEND";
|
|
20
|
-
/** 下一步 */
|
|
21
|
-
ImeAction[ImeAction["NEXT"] = 5] = "NEXT";
|
|
22
|
-
/** 完成 */
|
|
23
|
-
ImeAction[ImeAction["DONE"] = 6] = "DONE";
|
|
24
|
-
/** 上一个 */
|
|
25
|
-
ImeAction[ImeAction["PREVIOUS"] = 7] = "PREVIOUS";
|
|
26
|
-
})(ImeAction || (ImeAction = {}));
|
|
27
|
-
// 回调函数存储对象
|
|
28
|
-
const callbacks = new Map();
|
|
29
|
-
// 初始化全局回调函数
|
|
30
|
-
if (typeof window !== "undefined" && !window.assistsxImeCallback) {
|
|
31
|
-
window.assistsxImeCallback = (data) => {
|
|
32
|
-
let callbackId;
|
|
33
|
-
try {
|
|
34
|
-
const json = decodeBase64UTF8(data);
|
|
35
|
-
const response = JSON.parse(json);
|
|
36
|
-
callbackId = response.callbackId;
|
|
37
|
-
if (callbackId) {
|
|
38
|
-
const callback = callbacks.get(callbackId);
|
|
39
|
-
if (callback) {
|
|
40
|
-
callback(json);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
catch (e) {
|
|
45
|
-
console.error("Ime callback error:", e);
|
|
46
|
-
}
|
|
47
|
-
finally {
|
|
48
|
-
if (callbackId) {
|
|
49
|
-
callbacks.delete(callbackId);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
export class Ime {
|
|
55
|
-
/**
|
|
56
|
-
* 执行异步调用
|
|
57
|
-
* @param method 方法名
|
|
58
|
-
* @param args 参数对象
|
|
59
|
-
* @param timeout 超时时间(秒),默认30秒
|
|
60
|
-
* @returns Promise<调用响应>
|
|
61
|
-
*/
|
|
62
|
-
async asyncCall(method, args, timeout = 30) {
|
|
63
|
-
const uuid = generateUUID();
|
|
64
|
-
const params = {
|
|
65
|
-
method,
|
|
66
|
-
arguments: args ? args : undefined,
|
|
67
|
-
callbackId: uuid,
|
|
68
|
-
};
|
|
69
|
-
const promise = new Promise((resolve) => {
|
|
70
|
-
callbacks.set(uuid, (data) => {
|
|
71
|
-
resolve(data);
|
|
72
|
-
});
|
|
73
|
-
setTimeout(() => {
|
|
74
|
-
callbacks.delete(uuid);
|
|
75
|
-
resolve(JSON.stringify(new CallResponse(0, null, uuid)));
|
|
76
|
-
}, timeout * 1000);
|
|
77
|
-
});
|
|
78
|
-
const result = window.assistsxIme.call(JSON.stringify(params));
|
|
79
|
-
const promiseResult = await promise;
|
|
80
|
-
if (typeof promiseResult === "string") {
|
|
81
|
-
const responseData = JSON.parse(promiseResult);
|
|
82
|
-
return new CallResponse(responseData.code, responseData.data, responseData.callbackId);
|
|
83
|
-
}
|
|
84
|
-
throw new Error("Call failed");
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* 执行编辑器动作(如搜索)
|
|
88
|
-
* @param actionId 动作 ID,默认为 ImeAction.SEARCH
|
|
89
|
-
* @param timeout 超时时间(秒),默认30秒
|
|
90
|
-
* @returns Promise<执行结果>
|
|
91
|
-
*/
|
|
92
|
-
async performEditorAction(actionId = ImeAction.SEARCH, timeout) {
|
|
93
|
-
var _a;
|
|
94
|
-
const response = await this.asyncCall("performEditorAction", { actionId }, timeout);
|
|
95
|
-
if (!response.isSuccess()) {
|
|
96
|
-
throw new Error(((_a = response.data) === null || _a === void 0 ? void 0 : _a.message) || "Perform editor action failed");
|
|
97
|
-
}
|
|
98
|
-
return response.data;
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* 跳转到输入法管理页面
|
|
102
|
-
* @param timeout 超时时间(秒),默认30秒
|
|
103
|
-
* @returns Promise<执行结果>
|
|
104
|
-
*/
|
|
105
|
-
async openInputMethodSettings(timeout) {
|
|
106
|
-
var _a;
|
|
107
|
-
const response = await this.asyncCall("openInputMethodSettings", undefined, timeout);
|
|
108
|
-
if (!response.isSuccess()) {
|
|
109
|
-
throw new Error(((_a = response.data) === null || _a === void 0 ? void 0 : _a.message) || "Open input method settings failed");
|
|
110
|
-
}
|
|
111
|
-
return response.data;
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* 检查输入法是否启用
|
|
115
|
-
* @param timeout 超时时间(秒),默认30秒
|
|
116
|
-
* @returns Promise<检查结果>
|
|
117
|
-
*/
|
|
118
|
-
async isInputMethodEnabled(timeout) {
|
|
119
|
-
var _a;
|
|
120
|
-
const response = await this.asyncCall("isInputMethodEnabled", undefined, timeout);
|
|
121
|
-
if (!response.isSuccess()) {
|
|
122
|
-
throw new Error(((_a = response.data) === null || _a === void 0 ? void 0 : _a.message) || "Check input method enabled failed");
|
|
123
|
-
}
|
|
124
|
-
return response.data;
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* 检查当前选中的输入法是否是当前输入法
|
|
128
|
-
* @param timeout 超时时间(秒),默认30秒
|
|
129
|
-
* @returns Promise<检查结果>
|
|
130
|
-
*/
|
|
131
|
-
async isCurrentInputMethod(timeout) {
|
|
132
|
-
var _a;
|
|
133
|
-
const response = await this.asyncCall("isCurrentInputMethod", undefined, timeout);
|
|
134
|
-
if (!response.isSuccess()) {
|
|
135
|
-
throw new Error(((_a = response.data) === null || _a === void 0 ? void 0 : _a.message) || "Check current input method failed");
|
|
136
|
-
}
|
|
137
|
-
return response.data;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
// 导出常量实例
|
|
141
|
-
export const ime = new Ime();
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ML Kit 文字识别相关的方法常量定义
|
|
3
|
-
* 支持识别屏幕中指定词组位置以及识别屏幕文字内容位置
|
|
4
|
-
*/
|
|
5
|
-
export declare const MlkitCallMethod: {
|
|
6
|
-
/**
|
|
7
|
-
* 识别屏幕中指定词组的位置(基于当前截图)
|
|
8
|
-
* 参数:targetText 必填;region 可选 { left, top, right, bottom };rotationDegrees 可选,默认 0
|
|
9
|
-
*/
|
|
10
|
-
readonly findPhrasePositions: "findPhrasePositions";
|
|
11
|
-
/**
|
|
12
|
-
* 识别屏幕中所有文字内容及其位置(基于当前截图)
|
|
13
|
-
* 参数:region 可选 { left, top, right, bottom };rotationDegrees 可选,默认 0
|
|
14
|
-
*/
|
|
15
|
-
readonly getScreenTextPositions: "getScreenTextPositions";
|
|
16
|
-
/**
|
|
17
|
-
* 识别屏幕中指定词组的位置,直接返回 JSON 字符串(基于当前截图)
|
|
18
|
-
* 参数:targetText 必填;region 可选 { left, top, right, bottom };rotationDegrees 可选,默认 0
|
|
19
|
-
*/
|
|
20
|
-
readonly findPhrasePositionsOnScreenAsJson: "findPhrasePositionsOnScreenAsJson";
|
|
21
|
-
/**
|
|
22
|
-
* 识别屏幕中所有文字及其位置,直接返回 JSON 字符串(基于当前截图)
|
|
23
|
-
* 参数:region 可选 { left, top, right, bottom };rotationDegrees 可选,默认 0
|
|
24
|
-
*/
|
|
25
|
-
readonly getScreenTextPositionsAsJson: "getScreenTextPositionsAsJson";
|
|
26
|
-
};
|
|
27
|
-
export type MlkitCallMethodType = (typeof MlkitCallMethod)[keyof typeof MlkitCallMethod];
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ML Kit 文字识别相关的方法常量定义
|
|
3
|
-
* 支持识别屏幕中指定词组位置以及识别屏幕文字内容位置
|
|
4
|
-
*/
|
|
5
|
-
export const MlkitCallMethod = {
|
|
6
|
-
/**
|
|
7
|
-
* 识别屏幕中指定词组的位置(基于当前截图)
|
|
8
|
-
* 参数:targetText 必填;region 可选 { left, top, right, bottom };rotationDegrees 可选,默认 0
|
|
9
|
-
*/
|
|
10
|
-
findPhrasePositions: "findPhrasePositions",
|
|
11
|
-
/**
|
|
12
|
-
* 识别屏幕中所有文字内容及其位置(基于当前截图)
|
|
13
|
-
* 参数:region 可选 { left, top, right, bottom };rotationDegrees 可选,默认 0
|
|
14
|
-
*/
|
|
15
|
-
getScreenTextPositions: "getScreenTextPositions",
|
|
16
|
-
/**
|
|
17
|
-
* 识别屏幕中指定词组的位置,直接返回 JSON 字符串(基于当前截图)
|
|
18
|
-
* 参数:targetText 必填;region 可选 { left, top, right, bottom };rotationDegrees 可选,默认 0
|
|
19
|
-
*/
|
|
20
|
-
findPhrasePositionsOnScreenAsJson: "findPhrasePositionsOnScreenAsJson",
|
|
21
|
-
/**
|
|
22
|
-
* 识别屏幕中所有文字及其位置,直接返回 JSON 字符串(基于当前截图)
|
|
23
|
-
* 参数:region 可选 { left, top, right, bottom };rotationDegrees 可选,默认 0
|
|
24
|
-
*/
|
|
25
|
-
getScreenTextPositionsAsJson: "getScreenTextPositionsAsJson",
|
|
26
|
-
};
|
package/dist/mlkit/mlkit.d.ts
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 识别区域接口,用于限定识别范围
|
|
3
|
-
*/
|
|
4
|
-
export interface MlkitRegion {
|
|
5
|
-
left: number;
|
|
6
|
-
top: number;
|
|
7
|
-
right: number;
|
|
8
|
-
bottom: number;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* 文字位置信息
|
|
12
|
-
*/
|
|
13
|
-
export interface TextPosition {
|
|
14
|
-
text: string;
|
|
15
|
-
left: number;
|
|
16
|
-
top: number;
|
|
17
|
-
right: number;
|
|
18
|
-
bottom: number;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* findPhrasePositions / getScreenTextPositions 返回结果
|
|
22
|
-
*/
|
|
23
|
-
export interface ScreenTextRecognitionResult {
|
|
24
|
-
fullText: string;
|
|
25
|
-
positions: TextPosition[];
|
|
26
|
-
processingTimeMillis: number;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* findPhrasePositionsOnScreenAsJson / getScreenTextPositionsAsJson 返回结果
|
|
30
|
-
*/
|
|
31
|
-
export interface ScreenTextJsonResult {
|
|
32
|
-
jsonResult: string;
|
|
33
|
-
}
|
|
34
|
-
export declare class Mlkit {
|
|
35
|
-
/**
|
|
36
|
-
* 执行异步调用
|
|
37
|
-
* @param method 方法名
|
|
38
|
-
* @param args 参数对象
|
|
39
|
-
* @param timeout 超时时间(秒),默认30秒
|
|
40
|
-
* @returns Promise<调用响应>
|
|
41
|
-
*/
|
|
42
|
-
private asyncCall;
|
|
43
|
-
/**
|
|
44
|
-
* 识别屏幕中指定词组的位置(基于当前截图)
|
|
45
|
-
* @param targetText 要搜索的目标词组(必填)
|
|
46
|
-
* @param options 可选参数:region 识别区域;rotationDegrees 旋转角度,默认 0;timeout 超时时间
|
|
47
|
-
* @returns Promise<识别结果>
|
|
48
|
-
*/
|
|
49
|
-
findPhrasePositions(targetText: string, options?: {
|
|
50
|
-
region?: MlkitRegion;
|
|
51
|
-
rotationDegrees?: number;
|
|
52
|
-
timeout?: number;
|
|
53
|
-
}): Promise<ScreenTextRecognitionResult>;
|
|
54
|
-
/**
|
|
55
|
-
* 识别屏幕中所有文字内容及其位置(基于当前截图)
|
|
56
|
-
* @param options 可选参数:region 识别区域;rotationDegrees 旋转角度,默认 0;timeout 超时时间
|
|
57
|
-
* @returns Promise<识别结果>
|
|
58
|
-
*/
|
|
59
|
-
getScreenTextPositions(options?: {
|
|
60
|
-
region?: MlkitRegion;
|
|
61
|
-
rotationDegrees?: number;
|
|
62
|
-
timeout?: number;
|
|
63
|
-
}): Promise<ScreenTextRecognitionResult>;
|
|
64
|
-
/**
|
|
65
|
-
* 识别屏幕中指定词组的位置,直接返回 JSON 字符串(基于当前截图)
|
|
66
|
-
* @param targetText 要搜索的目标词组(必填)
|
|
67
|
-
* @param options 可选参数:region 识别区域;rotationDegrees 旋转角度,默认 0;timeout 超时时间
|
|
68
|
-
* @returns Promise<JSON 字符串结果>
|
|
69
|
-
*/
|
|
70
|
-
findPhrasePositionsOnScreenAsJson(targetText: string, options?: {
|
|
71
|
-
region?: MlkitRegion;
|
|
72
|
-
rotationDegrees?: number;
|
|
73
|
-
timeout?: number;
|
|
74
|
-
}): Promise<string>;
|
|
75
|
-
/**
|
|
76
|
-
* 识别屏幕中所有文字及其位置,直接返回 JSON 字符串(基于当前截图)
|
|
77
|
-
* @param options 可选参数:region 识别区域;rotationDegrees 旋转角度,默认 0;timeout 超时时间
|
|
78
|
-
* @returns Promise<JSON 字符串结果>
|
|
79
|
-
*/
|
|
80
|
-
getScreenTextPositionsAsJson(options?: {
|
|
81
|
-
region?: MlkitRegion;
|
|
82
|
-
rotationDegrees?: number;
|
|
83
|
-
timeout?: number;
|
|
84
|
-
}): Promise<string>;
|
|
85
|
-
}
|
|
86
|
-
export declare const mlkit: Mlkit;
|
package/dist/mlkit/mlkit.js
DELETED
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ML Kit 文字识别相关功能
|
|
3
|
-
* 提供识别屏幕中指定词组位置、识别屏幕文字内容位置的能力
|
|
4
|
-
*/
|
|
5
|
-
import { CallResponse } from "../CallResponse";
|
|
6
|
-
import { decodeBase64UTF8, generateUUID } from "../Utils";
|
|
7
|
-
import { MlkitCallMethod } from "./MlkitCallMethod";
|
|
8
|
-
// 回调函数存储对象
|
|
9
|
-
const callbacks = new Map();
|
|
10
|
-
// 初始化全局回调函数
|
|
11
|
-
if (typeof window !== "undefined" && !window.assistsxMlkitCallback) {
|
|
12
|
-
window.assistsxMlkitCallback = (data) => {
|
|
13
|
-
let callbackId;
|
|
14
|
-
try {
|
|
15
|
-
const json = decodeBase64UTF8(data);
|
|
16
|
-
const response = JSON.parse(json);
|
|
17
|
-
callbackId = response.callbackId;
|
|
18
|
-
if (callbackId) {
|
|
19
|
-
const callback = callbacks.get(callbackId);
|
|
20
|
-
if (callback) {
|
|
21
|
-
callback(json);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
catch (e) {
|
|
26
|
-
console.error("Mlkit callback error:", e);
|
|
27
|
-
}
|
|
28
|
-
finally {
|
|
29
|
-
if (callbackId) {
|
|
30
|
-
callbacks.delete(callbackId);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
export class Mlkit {
|
|
36
|
-
/**
|
|
37
|
-
* 执行异步调用
|
|
38
|
-
* @param method 方法名
|
|
39
|
-
* @param args 参数对象
|
|
40
|
-
* @param timeout 超时时间(秒),默认30秒
|
|
41
|
-
* @returns Promise<调用响应>
|
|
42
|
-
*/
|
|
43
|
-
async asyncCall(method, args, timeout = 30) {
|
|
44
|
-
const uuid = generateUUID();
|
|
45
|
-
const params = {
|
|
46
|
-
method,
|
|
47
|
-
arguments: args ? args : undefined,
|
|
48
|
-
callbackId: uuid,
|
|
49
|
-
};
|
|
50
|
-
const promise = new Promise((resolve) => {
|
|
51
|
-
callbacks.set(uuid, (data) => {
|
|
52
|
-
resolve(data);
|
|
53
|
-
});
|
|
54
|
-
setTimeout(() => {
|
|
55
|
-
callbacks.delete(uuid);
|
|
56
|
-
resolve(JSON.stringify(new CallResponse(0, null, uuid)));
|
|
57
|
-
}, timeout * 1000);
|
|
58
|
-
});
|
|
59
|
-
const result = window.assistsxMlkit.call(JSON.stringify(params));
|
|
60
|
-
const promiseResult = await promise;
|
|
61
|
-
if (typeof promiseResult === "string") {
|
|
62
|
-
const responseData = JSON.parse(promiseResult);
|
|
63
|
-
return new CallResponse(responseData.code, responseData.data, responseData.callbackId);
|
|
64
|
-
}
|
|
65
|
-
throw new Error("Call failed");
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* 识别屏幕中指定词组的位置(基于当前截图)
|
|
69
|
-
* @param targetText 要搜索的目标词组(必填)
|
|
70
|
-
* @param options 可选参数:region 识别区域;rotationDegrees 旋转角度,默认 0;timeout 超时时间
|
|
71
|
-
* @returns Promise<识别结果>
|
|
72
|
-
*/
|
|
73
|
-
async findPhrasePositions(targetText, options = {}) {
|
|
74
|
-
var _a;
|
|
75
|
-
if (!targetText || targetText.trim() === "") {
|
|
76
|
-
throw new Error("targetText cannot be empty");
|
|
77
|
-
}
|
|
78
|
-
const { region, rotationDegrees = 0, timeout, } = options;
|
|
79
|
-
const response = await this.asyncCall(MlkitCallMethod.findPhrasePositions, {
|
|
80
|
-
targetText: targetText.trim(),
|
|
81
|
-
...(region && {
|
|
82
|
-
left: region.left,
|
|
83
|
-
top: region.top,
|
|
84
|
-
right: region.right,
|
|
85
|
-
bottom: region.bottom,
|
|
86
|
-
}),
|
|
87
|
-
rotationDegrees,
|
|
88
|
-
}, timeout);
|
|
89
|
-
if (!response.isSuccess()) {
|
|
90
|
-
throw new Error(((_a = response.data) === null || _a === void 0 ? void 0 : _a.message) || "Recognition failed");
|
|
91
|
-
}
|
|
92
|
-
return response.data;
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* 识别屏幕中所有文字内容及其位置(基于当前截图)
|
|
96
|
-
* @param options 可选参数:region 识别区域;rotationDegrees 旋转角度,默认 0;timeout 超时时间
|
|
97
|
-
* @returns Promise<识别结果>
|
|
98
|
-
*/
|
|
99
|
-
async getScreenTextPositions(options = {}) {
|
|
100
|
-
var _a;
|
|
101
|
-
const { region, rotationDegrees = 0, timeout, } = options;
|
|
102
|
-
const response = await this.asyncCall(MlkitCallMethod.getScreenTextPositions, {
|
|
103
|
-
...(region && {
|
|
104
|
-
left: region.left,
|
|
105
|
-
top: region.top,
|
|
106
|
-
right: region.right,
|
|
107
|
-
bottom: region.bottom,
|
|
108
|
-
}),
|
|
109
|
-
rotationDegrees,
|
|
110
|
-
}, timeout);
|
|
111
|
-
if (!response.isSuccess()) {
|
|
112
|
-
throw new Error(((_a = response.data) === null || _a === void 0 ? void 0 : _a.message) || "Recognition failed");
|
|
113
|
-
}
|
|
114
|
-
return response.data;
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* 识别屏幕中指定词组的位置,直接返回 JSON 字符串(基于当前截图)
|
|
118
|
-
* @param targetText 要搜索的目标词组(必填)
|
|
119
|
-
* @param options 可选参数:region 识别区域;rotationDegrees 旋转角度,默认 0;timeout 超时时间
|
|
120
|
-
* @returns Promise<JSON 字符串结果>
|
|
121
|
-
*/
|
|
122
|
-
async findPhrasePositionsOnScreenAsJson(targetText, options = {}) {
|
|
123
|
-
var _a;
|
|
124
|
-
if (!targetText || targetText.trim() === "") {
|
|
125
|
-
throw new Error("targetText cannot be empty");
|
|
126
|
-
}
|
|
127
|
-
const { region, rotationDegrees = 0, timeout, } = options;
|
|
128
|
-
const response = await this.asyncCall(MlkitCallMethod.findPhrasePositionsOnScreenAsJson, {
|
|
129
|
-
targetText: targetText.trim(),
|
|
130
|
-
...(region && {
|
|
131
|
-
left: region.left,
|
|
132
|
-
top: region.top,
|
|
133
|
-
right: region.right,
|
|
134
|
-
bottom: region.bottom,
|
|
135
|
-
}),
|
|
136
|
-
rotationDegrees,
|
|
137
|
-
}, timeout);
|
|
138
|
-
if (!response.isSuccess()) {
|
|
139
|
-
throw new Error(((_a = response.data) === null || _a === void 0 ? void 0 : _a.message) || "Recognition failed");
|
|
140
|
-
}
|
|
141
|
-
const data = response.data;
|
|
142
|
-
return data.jsonResult;
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* 识别屏幕中所有文字及其位置,直接返回 JSON 字符串(基于当前截图)
|
|
146
|
-
* @param options 可选参数:region 识别区域;rotationDegrees 旋转角度,默认 0;timeout 超时时间
|
|
147
|
-
* @returns Promise<JSON 字符串结果>
|
|
148
|
-
*/
|
|
149
|
-
async getScreenTextPositionsAsJson(options = {}) {
|
|
150
|
-
var _a;
|
|
151
|
-
const { region, rotationDegrees = 0, timeout, } = options;
|
|
152
|
-
const response = await this.asyncCall(MlkitCallMethod.getScreenTextPositionsAsJson, {
|
|
153
|
-
...(region && {
|
|
154
|
-
left: region.left,
|
|
155
|
-
top: region.top,
|
|
156
|
-
right: region.right,
|
|
157
|
-
bottom: region.bottom,
|
|
158
|
-
}),
|
|
159
|
-
rotationDegrees,
|
|
160
|
-
}, timeout);
|
|
161
|
-
if (!response.isSuccess()) {
|
|
162
|
-
throw new Error(((_a = response.data) === null || _a === void 0 ? void 0 : _a.message) || "Recognition failed");
|
|
163
|
-
}
|
|
164
|
-
const data = response.data;
|
|
165
|
-
return data.jsonResult;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
// 导出常量实例
|
|
169
|
-
export const mlkit = new Mlkit();
|
package/dist/network/http.d.ts
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* HTTP 响应数据接口定义
|
|
3
|
-
*/
|
|
4
|
-
export interface HttpResponse {
|
|
5
|
-
statusCode: number;
|
|
6
|
-
statusMessage: string;
|
|
7
|
-
body: string;
|
|
8
|
-
headers: Record<string, string>;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* HTTP 配置接口定义
|
|
12
|
-
*/
|
|
13
|
-
export interface HttpConfig {
|
|
14
|
-
connectTimeout?: number;
|
|
15
|
-
readTimeout?: number;
|
|
16
|
-
writeTimeout?: number;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* HTTP 下载响应接口定义
|
|
20
|
-
*/
|
|
21
|
-
export interface HttpDownloadResponse {
|
|
22
|
-
statusCode: number;
|
|
23
|
-
statusMessage: string;
|
|
24
|
-
savePath: string;
|
|
25
|
-
fileSize: number;
|
|
26
|
-
saveToGallerySuccess?: boolean;
|
|
27
|
-
galleryUri?: string;
|
|
28
|
-
galleryId?: number;
|
|
29
|
-
galleryType?: string;
|
|
30
|
-
headers: Record<string, string>;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* 文件上传信息接口定义
|
|
34
|
-
*/
|
|
35
|
-
export interface FileUploadInfo {
|
|
36
|
-
filePath: string;
|
|
37
|
-
fieldName?: string;
|
|
38
|
-
fileName?: string;
|
|
39
|
-
contentType?: string;
|
|
40
|
-
}
|
|
41
|
-
export declare class Http {
|
|
42
|
-
/**
|
|
43
|
-
* 执行异步调用
|
|
44
|
-
* @param method 方法名
|
|
45
|
-
* @param args 参数对象
|
|
46
|
-
* @param timeout 超时时间(秒),默认30秒
|
|
47
|
-
* @returns Promise<调用响应>
|
|
48
|
-
*/
|
|
49
|
-
private asyncCall;
|
|
50
|
-
/**
|
|
51
|
-
* 执行 GET 请求
|
|
52
|
-
* @param url 请求 URL
|
|
53
|
-
* @param headers 请求头
|
|
54
|
-
* @param timeout 超时时间(秒),默认30秒
|
|
55
|
-
* @returns Promise<HTTP响应>
|
|
56
|
-
*/
|
|
57
|
-
httpGet(url: string, headers?: Record<string, string>, timeout?: number): Promise<HttpResponse>;
|
|
58
|
-
/**
|
|
59
|
-
* 执行 POST 请求
|
|
60
|
-
* @param url 请求 URL
|
|
61
|
-
* @param body 请求体
|
|
62
|
-
* @param headers 请求头
|
|
63
|
-
* @param timeout 超时时间(秒),默认30秒
|
|
64
|
-
* @returns Promise<HTTP响应>
|
|
65
|
-
*/
|
|
66
|
-
httpPost(url: string, body: string, headers?: Record<string, string>, timeout?: number): Promise<HttpResponse>;
|
|
67
|
-
/**
|
|
68
|
-
* 执行文件上传 POST 请求
|
|
69
|
-
* 支持单个文件和多文件上传,同时支持多个表单字段
|
|
70
|
-
*
|
|
71
|
-
* @param url 请求 URL(必需)
|
|
72
|
-
* @param files 文件数组(必需),每个文件对象包含:
|
|
73
|
-
* - filePath: 文件路径(必需)
|
|
74
|
-
* - fieldName: 字段名(可选,默认 "file")
|
|
75
|
-
* - fileName: 文件名(可选,默认使用文件原名)
|
|
76
|
-
* - contentType: 文件类型(可选,默认 "application/octet-stream")
|
|
77
|
-
* @param formData 表单字段(可选),支持字符串值或字符串数组(同名字段多个值)
|
|
78
|
-
* @param headers 请求头(可选)
|
|
79
|
-
* @param timeout 超时时间(秒),默认30秒
|
|
80
|
-
* @returns Promise<HTTP响应>
|
|
81
|
-
*
|
|
82
|
-
* @example
|
|
83
|
-
* // 单文件上传
|
|
84
|
-
* await http.httpPostFile("https://example.com/upload", [
|
|
85
|
-
* { filePath: "/path/to/file.jpg", fieldName: "file" }
|
|
86
|
-
* ]);
|
|
87
|
-
*
|
|
88
|
-
* @example
|
|
89
|
-
* // 多文件上传
|
|
90
|
-
* await http.httpPostFile("https://example.com/upload", [
|
|
91
|
-
* { filePath: "/path/to/file1.jpg", fieldName: "file1" },
|
|
92
|
-
* { filePath: "/path/to/file2.jpg", fieldName: "file2" }
|
|
93
|
-
* ], { description: "My files" });
|
|
94
|
-
*/
|
|
95
|
-
httpPostFile(url: string, files: FileUploadInfo[], formData?: Record<string, string | string[]>, headers?: Record<string, string>, timeout?: number): Promise<HttpResponse>;
|
|
96
|
-
/**
|
|
97
|
-
* 下载文件
|
|
98
|
-
* @param url 下载 URL
|
|
99
|
-
* @param savePath 保存路径
|
|
100
|
-
* @param headers 请求头
|
|
101
|
-
* @param saveToGallery 是否保存到系统相册(仅支持图片和视频文件),默认 false
|
|
102
|
-
* @param displayName 保存到相册时的显示名称(可选,默认使用文件名)
|
|
103
|
-
* @param timeout 超时时间(秒),默认30秒
|
|
104
|
-
* @returns Promise<下载响应>
|
|
105
|
-
*/
|
|
106
|
-
httpDownload(url: string, savePath: string, headers?: Record<string, string>, saveToGallery?: boolean, displayName?: string, timeout?: number): Promise<HttpDownloadResponse>;
|
|
107
|
-
/**
|
|
108
|
-
* 配置 OkHttpClient
|
|
109
|
-
* @param config 配置选项
|
|
110
|
-
* @param timeout 超时时间(秒),默认30秒
|
|
111
|
-
* @returns Promise<配置信息>
|
|
112
|
-
*/
|
|
113
|
-
httpConfigure(config: HttpConfig, timeout?: number): Promise<HttpConfig>;
|
|
114
|
-
/**
|
|
115
|
-
* 重置 OkHttpClient 配置
|
|
116
|
-
* @param timeout 超时时间(秒),默认30秒
|
|
117
|
-
* @returns Promise<配置信息>
|
|
118
|
-
*/
|
|
119
|
-
httpReset(timeout?: number): Promise<HttpConfig>;
|
|
120
|
-
/**
|
|
121
|
-
* 获取当前配置信息
|
|
122
|
-
* @param timeout 超时时间(秒),默认30秒
|
|
123
|
-
* @returns Promise<配置信息>
|
|
124
|
-
*/
|
|
125
|
-
httpGetConfig(timeout?: number): Promise<HttpConfig>;
|
|
126
|
-
}
|
|
127
|
-
export declare const http: Http;
|