assistsx-js 0.0.2001 → 0.0.2002
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/AssistsX.d.ts +1 -1
- package/dist/AssistsX.js +14 -6
- package/dist/AssistsXAsync.d.ts +1 -1
- package/dist/AssistsXAsync.js +2 -1
- package/dist/Node.d.ts +6 -0
- package/dist/Node.js +11 -0
- package/dist/NodeAsync.d.ts +6 -0
- package/dist/NodeAsync.js +11 -0
- package/dist/Step.d.ts +8 -30
- package/dist/Step.js +4 -19
- package/dist/StepAsync.d.ts +0 -6
- package/dist/StepAsync.js +0 -11
- package/dist/Utils.d.ts +1 -0
- package/dist/Utils.js +12 -4
- package/package.json +1 -1
- package/src/AssistsX.ts +13 -6
- package/src/AssistsXAsync.ts +5 -1
- package/src/Node.ts +12 -0
- package/src/NodeAsync.ts +14 -1
- package/src/Step.ts +10 -43
- package/src/StepAsync.ts +0 -12
- package/src/Utils.ts +16 -7
package/dist/AssistsX.d.ts
CHANGED
|
@@ -182,7 +182,7 @@ export declare class AssistsX {
|
|
|
182
182
|
* @param className 类名
|
|
183
183
|
* @returns 父节点
|
|
184
184
|
*/
|
|
185
|
-
static findFirstParentByTags(className: string): Node;
|
|
185
|
+
static findFirstParentByTags(node: Node, className: string): Node;
|
|
186
186
|
/**
|
|
187
187
|
* 获取节点的所有子节点
|
|
188
188
|
* @param node 父节点
|
package/dist/AssistsX.js
CHANGED
|
@@ -6,7 +6,7 @@ import { Node } from "./Node";
|
|
|
6
6
|
import { CallMethod } from "./CallMethod";
|
|
7
7
|
import { CallResponse } from "./CallResponse";
|
|
8
8
|
import { Bounds } from "./Bounds";
|
|
9
|
-
import { generateUUID } from "./Utils";
|
|
9
|
+
import { decodeBase64UTF8, generateUUID } from "./Utils";
|
|
10
10
|
// 回调函数存储对象
|
|
11
11
|
export const callbacks = {};
|
|
12
12
|
// 无障碍事件监听器存储
|
|
@@ -14,10 +14,17 @@ export const accessibilityEventListeners = [];
|
|
|
14
14
|
// 初始化全局回调函数
|
|
15
15
|
if (typeof window !== "undefined" && !window.assistsxCallback) {
|
|
16
16
|
window.assistsxCallback = (data) => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
try {
|
|
18
|
+
console.log(data);
|
|
19
|
+
const json = decodeBase64UTF8(data);
|
|
20
|
+
const response = JSON.parse(json);
|
|
21
|
+
const callback = callbacks[response.callbackId];
|
|
22
|
+
if (callback) {
|
|
23
|
+
callback(json);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
catch (e) {
|
|
27
|
+
console.log(e);
|
|
21
28
|
}
|
|
22
29
|
};
|
|
23
30
|
}
|
|
@@ -301,9 +308,10 @@ export class AssistsX {
|
|
|
301
308
|
* @param className 类名
|
|
302
309
|
* @returns 父节点
|
|
303
310
|
*/
|
|
304
|
-
static findFirstParentByTags(className) {
|
|
311
|
+
static findFirstParentByTags(node, className) {
|
|
305
312
|
const response = this.call(CallMethod.findFirstParentByTags, {
|
|
306
313
|
args: { className },
|
|
314
|
+
node,
|
|
307
315
|
});
|
|
308
316
|
return Node.create(response.getDataOrDefault("{}"));
|
|
309
317
|
}
|
package/dist/AssistsXAsync.d.ts
CHANGED
|
@@ -152,7 +152,7 @@ export declare class AssistsXAsync {
|
|
|
152
152
|
* @param className 类名
|
|
153
153
|
* @returns 父节点
|
|
154
154
|
*/
|
|
155
|
-
static findFirstParentByTags(className: string): Promise<Node>;
|
|
155
|
+
static findFirstParentByTags(node: Node, className: string): Promise<Node>;
|
|
156
156
|
/**
|
|
157
157
|
* 获取节点的所有子节点
|
|
158
158
|
* @param node 父节点
|
package/dist/AssistsXAsync.js
CHANGED
|
@@ -258,9 +258,10 @@ export class AssistsXAsync {
|
|
|
258
258
|
* @param className 类名
|
|
259
259
|
* @returns 父节点
|
|
260
260
|
*/
|
|
261
|
-
static async findFirstParentByTags(className) {
|
|
261
|
+
static async findFirstParentByTags(node, className) {
|
|
262
262
|
const response = await this.asyncCall(CallMethod.findFirstParentByTags, {
|
|
263
263
|
args: { className },
|
|
264
|
+
node,
|
|
264
265
|
});
|
|
265
266
|
return Node.create(response.getDataOrDefault("{}"));
|
|
266
267
|
}
|
package/dist/Node.d.ts
CHANGED
|
@@ -57,6 +57,12 @@ export declare class Node {
|
|
|
57
57
|
stepId: string | undefined;
|
|
58
58
|
});
|
|
59
59
|
get async(): NodeAsync;
|
|
60
|
+
/**
|
|
61
|
+
* 查找第一个匹配标签的父节点
|
|
62
|
+
* @param className 类名
|
|
63
|
+
* @returns 父节点
|
|
64
|
+
*/
|
|
65
|
+
findFirstParentByTags(className: string): Node;
|
|
60
66
|
/**
|
|
61
67
|
* 对节点执行点击手势
|
|
62
68
|
* @param offsetX X轴偏移
|
package/dist/Node.js
CHANGED
|
@@ -21,6 +21,17 @@ export class Node {
|
|
|
21
21
|
get async() {
|
|
22
22
|
return new NodeAsync(this);
|
|
23
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* 查找第一个匹配标签的父节点
|
|
26
|
+
* @param className 类名
|
|
27
|
+
* @returns 父节点
|
|
28
|
+
*/
|
|
29
|
+
findFirstParentByTags(className) {
|
|
30
|
+
Step.assert(this.stepId);
|
|
31
|
+
const node = AssistsX.findFirstParentByTags(this, className);
|
|
32
|
+
Step.assert(this.stepId);
|
|
33
|
+
return node;
|
|
34
|
+
}
|
|
24
35
|
/**
|
|
25
36
|
* 对节点执行点击手势
|
|
26
37
|
* @param offsetX X轴偏移
|
package/dist/NodeAsync.d.ts
CHANGED
|
@@ -11,6 +11,12 @@ export declare class NodeAsync {
|
|
|
11
11
|
* @param node Node实例
|
|
12
12
|
*/
|
|
13
13
|
constructor(node: Node);
|
|
14
|
+
/**
|
|
15
|
+
* 查找第一个匹配标签的父节点
|
|
16
|
+
* @param className 类名
|
|
17
|
+
* @returns 父节点
|
|
18
|
+
*/
|
|
19
|
+
findFirstParentByTags(className: string): Promise<Node>;
|
|
14
20
|
/**
|
|
15
21
|
* 对节点执行点击手势
|
|
16
22
|
* @param offsetX X轴偏移
|
package/dist/NodeAsync.js
CHANGED
|
@@ -9,6 +9,17 @@ export class NodeAsync {
|
|
|
9
9
|
constructor(node) {
|
|
10
10
|
this.node = node;
|
|
11
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* 查找第一个匹配标签的父节点
|
|
14
|
+
* @param className 类名
|
|
15
|
+
* @returns 父节点
|
|
16
|
+
*/
|
|
17
|
+
async findFirstParentByTags(className) {
|
|
18
|
+
Step.assert(this.node.stepId);
|
|
19
|
+
const node = await AssistsXAsync.findFirstParentByTags(this.node, className);
|
|
20
|
+
Step.assert(this.node.stepId);
|
|
21
|
+
return node;
|
|
22
|
+
}
|
|
12
23
|
/**
|
|
13
24
|
* 对节点执行点击手势
|
|
14
25
|
* @param offsetX X轴偏移
|
package/dist/Step.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { Node } from "./Node";
|
|
2
2
|
import { StepAsync } from "./StepAsync";
|
|
3
|
+
export type StepResult = Step | undefined;
|
|
4
|
+
export type StepImpl = (step: Step) => Promise<StepResult>;
|
|
3
5
|
export declare class Step {
|
|
4
6
|
static delayMsDefault: number;
|
|
5
7
|
static readonly repeatCountInfinite: number;
|
|
@@ -16,12 +18,9 @@ export declare class Step {
|
|
|
16
18
|
* @param data 步骤数据
|
|
17
19
|
* @param delayMs 步骤延迟时间(毫秒)
|
|
18
20
|
*/
|
|
19
|
-
static run(impl:
|
|
21
|
+
static run(impl: StepImpl, { tag, data, delayMs, }?: {
|
|
20
22
|
tag?: string | undefined;
|
|
21
23
|
data?: any | undefined;
|
|
22
|
-
backupSteps?: {
|
|
23
|
-
[key: string]: (step: Step) => Promise<Step | undefined>;
|
|
24
|
-
} | undefined;
|
|
25
24
|
delayMs?: number;
|
|
26
25
|
}): Promise<Step>;
|
|
27
26
|
/**
|
|
@@ -70,13 +69,7 @@ export declare class Step {
|
|
|
70
69
|
/**
|
|
71
70
|
* 步骤实现函数
|
|
72
71
|
*/
|
|
73
|
-
impl:
|
|
74
|
-
/**
|
|
75
|
-
* 备份步骤,可用于在指定的步骤中转向其他步骤
|
|
76
|
-
*/
|
|
77
|
-
backupSteps: {
|
|
78
|
-
[key: string]: (step: Step) => Promise<Step | undefined>;
|
|
79
|
-
} | undefined;
|
|
72
|
+
impl: StepImpl;
|
|
80
73
|
/**
|
|
81
74
|
* 构造函数
|
|
82
75
|
* @param stepId 步骤ID
|
|
@@ -85,14 +78,11 @@ export declare class Step {
|
|
|
85
78
|
* @param data 步骤数据
|
|
86
79
|
* @param delayMs 步骤延迟时间(毫秒)
|
|
87
80
|
*/
|
|
88
|
-
constructor({ stepId, impl, tag, data,
|
|
81
|
+
constructor({ stepId, impl, tag, data, delayMs, repeatCountMax, }: {
|
|
89
82
|
stepId: string;
|
|
90
|
-
impl:
|
|
83
|
+
impl: StepImpl;
|
|
91
84
|
tag?: string | undefined;
|
|
92
85
|
data?: any | undefined;
|
|
93
|
-
backupSteps?: {
|
|
94
|
-
[key: string]: (step: Step) => Promise<Step | undefined>;
|
|
95
|
-
} | undefined;
|
|
96
86
|
delayMs?: number;
|
|
97
87
|
repeatCountMax?: number;
|
|
98
88
|
});
|
|
@@ -105,12 +95,9 @@ export declare class Step {
|
|
|
105
95
|
* @param delayMs 步骤延迟时间(毫秒)
|
|
106
96
|
* @returns 新的步骤实例
|
|
107
97
|
*/
|
|
108
|
-
next(impl:
|
|
98
|
+
next(impl: StepImpl, { tag, data, delayMs, repeatCountMax, }?: {
|
|
109
99
|
tag?: string | undefined;
|
|
110
100
|
data?: any | undefined;
|
|
111
|
-
backupSteps?: {
|
|
112
|
-
[key: string]: (step: Step) => Promise<Step | undefined>;
|
|
113
|
-
} | undefined;
|
|
114
101
|
delayMs?: number;
|
|
115
102
|
repeatCountMax?: number;
|
|
116
103
|
}): Step;
|
|
@@ -122,13 +109,10 @@ export declare class Step {
|
|
|
122
109
|
* @param delayMs 步骤延迟时间(毫秒)
|
|
123
110
|
* @returns 当前步骤实例
|
|
124
111
|
*/
|
|
125
|
-
repeat({ stepId, tag, data,
|
|
112
|
+
repeat({ stepId, tag, data, delayMs, repeatCountMax, }?: {
|
|
126
113
|
stepId?: string;
|
|
127
114
|
tag?: string | undefined;
|
|
128
115
|
data?: any | undefined;
|
|
129
|
-
backupSteps?: {
|
|
130
|
-
[key: string]: (step: Step) => Promise<Step | undefined>;
|
|
131
|
-
} | undefined;
|
|
132
116
|
delayMs?: number;
|
|
133
117
|
repeatCountMax?: number;
|
|
134
118
|
}): Step;
|
|
@@ -239,12 +223,6 @@ export declare class Step {
|
|
|
239
223
|
* @returns 文本数组
|
|
240
224
|
*/
|
|
241
225
|
getAllText(): string[];
|
|
242
|
-
/**
|
|
243
|
-
* 查找第一个匹配标签的父节点
|
|
244
|
-
* @param className 类名
|
|
245
|
-
* @returns 父节点
|
|
246
|
-
*/
|
|
247
|
-
findFirstParentByTags(className: string): Node;
|
|
248
226
|
/**
|
|
249
227
|
* 执行点击手势
|
|
250
228
|
* @param x 横坐标
|
package/dist/Step.js
CHANGED
|
@@ -15,7 +15,7 @@ export class Step {
|
|
|
15
15
|
* @param data 步骤数据
|
|
16
16
|
* @param delayMs 步骤延迟时间(毫秒)
|
|
17
17
|
*/
|
|
18
|
-
static async run(impl, { tag, data,
|
|
18
|
+
static async run(impl, { tag, data, delayMs = Step.delayMsDefault, } = {}) {
|
|
19
19
|
var _a;
|
|
20
20
|
const stepStore = useStepStore();
|
|
21
21
|
let implnName = impl.name;
|
|
@@ -30,7 +30,6 @@ export class Step {
|
|
|
30
30
|
impl,
|
|
31
31
|
tag,
|
|
32
32
|
data,
|
|
33
|
-
backupSteps,
|
|
34
33
|
delayMs,
|
|
35
34
|
});
|
|
36
35
|
while (true) {
|
|
@@ -122,7 +121,7 @@ export class Step {
|
|
|
122
121
|
* @param data 步骤数据
|
|
123
122
|
* @param delayMs 步骤延迟时间(毫秒)
|
|
124
123
|
*/
|
|
125
|
-
constructor({ stepId, impl, tag, data,
|
|
124
|
+
constructor({ stepId, impl, tag, data, delayMs = Step.delayMsDefault, repeatCountMax = Step.repeatCountMaxDefault, }) {
|
|
126
125
|
/**
|
|
127
126
|
* 步骤ID
|
|
128
127
|
*/
|
|
@@ -143,7 +142,6 @@ export class Step {
|
|
|
143
142
|
this.stepId = stepId;
|
|
144
143
|
this.data = data;
|
|
145
144
|
this.impl = impl;
|
|
146
|
-
this.backupSteps = backupSteps;
|
|
147
145
|
this.delayMs = delayMs;
|
|
148
146
|
this.repeatCountMax = repeatCountMax;
|
|
149
147
|
}
|
|
@@ -158,14 +156,13 @@ export class Step {
|
|
|
158
156
|
* @param delayMs 步骤延迟时间(毫秒)
|
|
159
157
|
* @returns 新的步骤实例
|
|
160
158
|
*/
|
|
161
|
-
next(impl, { tag, data,
|
|
159
|
+
next(impl, { tag, data, delayMs = Step.delayMsDefault, repeatCountMax = Step.repeatCountMaxDefault, } = {}) {
|
|
162
160
|
Step.assert(this.stepId);
|
|
163
161
|
return new Step({
|
|
164
162
|
stepId: this.stepId,
|
|
165
163
|
impl,
|
|
166
164
|
tag,
|
|
167
165
|
data: data !== null && data !== void 0 ? data : this.data,
|
|
168
|
-
backupSteps: backupSteps !== null && backupSteps !== void 0 ? backupSteps : this.backupSteps,
|
|
169
166
|
delayMs,
|
|
170
167
|
repeatCountMax,
|
|
171
168
|
});
|
|
@@ -178,13 +175,12 @@ export class Step {
|
|
|
178
175
|
* @param delayMs 步骤延迟时间(毫秒)
|
|
179
176
|
* @returns 当前步骤实例
|
|
180
177
|
*/
|
|
181
|
-
repeat({ stepId = this.stepId, tag = this.tag, data = this.data,
|
|
178
|
+
repeat({ stepId = this.stepId, tag = this.tag, data = this.data, delayMs = this.delayMs, repeatCountMax = this.repeatCountMax, } = {}) {
|
|
182
179
|
Step.assert(this.stepId);
|
|
183
180
|
this.repeatCount++;
|
|
184
181
|
this.stepId = stepId;
|
|
185
182
|
this.tag = tag;
|
|
186
183
|
this.data = data;
|
|
187
|
-
this.backupSteps = backupSteps;
|
|
188
184
|
this.delayMs = delayMs;
|
|
189
185
|
this.repeatCountMax = repeatCountMax;
|
|
190
186
|
return this;
|
|
@@ -370,17 +366,6 @@ export class Step {
|
|
|
370
366
|
Step.assert(this.stepId);
|
|
371
367
|
return texts;
|
|
372
368
|
}
|
|
373
|
-
/**
|
|
374
|
-
* 查找第一个匹配标签的父节点
|
|
375
|
-
* @param className 类名
|
|
376
|
-
* @returns 父节点
|
|
377
|
-
*/
|
|
378
|
-
findFirstParentByTags(className) {
|
|
379
|
-
Step.assert(this.stepId);
|
|
380
|
-
const node = AssistsX.findFirstParentByTags(className);
|
|
381
|
-
Step.assert(this.stepId);
|
|
382
|
-
return node;
|
|
383
|
-
}
|
|
384
369
|
/**
|
|
385
370
|
* 执行点击手势
|
|
386
371
|
* @param x 横坐标
|
package/dist/StepAsync.d.ts
CHANGED
|
@@ -102,12 +102,6 @@ export declare class StepAsync {
|
|
|
102
102
|
* @returns 文本数组
|
|
103
103
|
*/
|
|
104
104
|
getAllText(): Promise<string[]>;
|
|
105
|
-
/**
|
|
106
|
-
* 查找第一个匹配标签的父节点
|
|
107
|
-
* @param className 类名
|
|
108
|
-
* @returns 父节点
|
|
109
|
-
*/
|
|
110
|
-
findFirstParentByTags(className: string): Promise<Node>;
|
|
111
105
|
/**
|
|
112
106
|
* 执行点击手势
|
|
113
107
|
* @param x 横坐标
|
package/dist/StepAsync.js
CHANGED
|
@@ -163,17 +163,6 @@ export class StepAsync {
|
|
|
163
163
|
Step.assert(this.step.stepId);
|
|
164
164
|
return texts;
|
|
165
165
|
}
|
|
166
|
-
/**
|
|
167
|
-
* 查找第一个匹配标签的父节点
|
|
168
|
-
* @param className 类名
|
|
169
|
-
* @returns 父节点
|
|
170
|
-
*/
|
|
171
|
-
async findFirstParentByTags(className) {
|
|
172
|
-
Step.assert(this.step.stepId);
|
|
173
|
-
const node = await AssistsXAsync.findFirstParentByTags(className);
|
|
174
|
-
Step.assert(this.step.stepId);
|
|
175
|
-
return node;
|
|
176
|
-
}
|
|
177
166
|
/**
|
|
178
167
|
* 执行点击手势
|
|
179
168
|
* @param x 横坐标
|
package/dist/Utils.d.ts
CHANGED
package/dist/Utils.js
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
// 导出工具函数
|
|
2
2
|
export function sleep(ms) {
|
|
3
|
-
return new Promise(resolve => setTimeout(resolve, ms));
|
|
3
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
4
4
|
}
|
|
5
5
|
// 生成UUID
|
|
6
6
|
export function generateUUID() {
|
|
7
|
-
return
|
|
8
|
-
const r = Math.random() * 16 | 0;
|
|
9
|
-
const v = c ===
|
|
7
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
|
|
8
|
+
const r = (Math.random() * 16) | 0;
|
|
9
|
+
const v = c === "x" ? r : (r & 0x3) | 0x8;
|
|
10
10
|
return v.toString(16);
|
|
11
11
|
});
|
|
12
12
|
}
|
|
13
|
+
export function decodeBase64UTF8(base64) {
|
|
14
|
+
const binary = atob(base64);
|
|
15
|
+
const bytes = new Uint8Array(binary.length);
|
|
16
|
+
for (let i = 0; i < binary.length; i++) {
|
|
17
|
+
bytes[i] = binary.charCodeAt(i);
|
|
18
|
+
}
|
|
19
|
+
return new TextDecoder("utf-8").decode(bytes);
|
|
20
|
+
}
|
package/package.json
CHANGED
package/src/AssistsX.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { Node } from "./Node";
|
|
|
6
6
|
import { CallMethod } from "./CallMethod";
|
|
7
7
|
import { CallResponse } from "./CallResponse";
|
|
8
8
|
import { Bounds } from "./Bounds";
|
|
9
|
-
import { generateUUID } from "./Utils";
|
|
9
|
+
import { decodeBase64UTF8, generateUUID } from "./Utils";
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Web浮动窗口选项接口定义
|
|
@@ -30,10 +30,16 @@ export const accessibilityEventListeners: ((event: any) => void)[] = [];
|
|
|
30
30
|
// 初始化全局回调函数
|
|
31
31
|
if (typeof window !== "undefined" && !window.assistsxCallback) {
|
|
32
32
|
window.assistsxCallback = (data: string) => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
try {
|
|
34
|
+
console.log(data);
|
|
35
|
+
const json = decodeBase64UTF8(data);
|
|
36
|
+
const response = JSON.parse(json);
|
|
37
|
+
const callback = callbacks[response.callbackId];
|
|
38
|
+
if (callback) {
|
|
39
|
+
callback(json);
|
|
40
|
+
}
|
|
41
|
+
} catch (e) {
|
|
42
|
+
console.log(e);
|
|
37
43
|
}
|
|
38
44
|
};
|
|
39
45
|
}
|
|
@@ -411,9 +417,10 @@ export class AssistsX {
|
|
|
411
417
|
* @param className 类名
|
|
412
418
|
* @returns 父节点
|
|
413
419
|
*/
|
|
414
|
-
public static findFirstParentByTags(className: string): Node {
|
|
420
|
+
public static findFirstParentByTags(node: Node, className: string): Node {
|
|
415
421
|
const response = this.call(CallMethod.findFirstParentByTags, {
|
|
416
422
|
args: { className },
|
|
423
|
+
node,
|
|
417
424
|
});
|
|
418
425
|
return Node.create(response.getDataOrDefault("{}"));
|
|
419
426
|
}
|
package/src/AssistsXAsync.ts
CHANGED
|
@@ -347,9 +347,13 @@ export class AssistsXAsync {
|
|
|
347
347
|
* @param className 类名
|
|
348
348
|
* @returns 父节点
|
|
349
349
|
*/
|
|
350
|
-
public static async findFirstParentByTags(
|
|
350
|
+
public static async findFirstParentByTags(
|
|
351
|
+
node: Node,
|
|
352
|
+
className: string
|
|
353
|
+
): Promise<Node> {
|
|
351
354
|
const response = await this.asyncCall(CallMethod.findFirstParentByTags, {
|
|
352
355
|
args: { className },
|
|
356
|
+
node,
|
|
353
357
|
});
|
|
354
358
|
return Node.create(response.getDataOrDefault("{}"));
|
|
355
359
|
}
|
package/src/Node.ts
CHANGED
|
@@ -84,6 +84,18 @@ export class Node {
|
|
|
84
84
|
return new NodeAsync(this);
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
+
/**
|
|
88
|
+
* 查找第一个匹配标签的父节点
|
|
89
|
+
* @param className 类名
|
|
90
|
+
* @returns 父节点
|
|
91
|
+
*/
|
|
92
|
+
public findFirstParentByTags(className: string): Node {
|
|
93
|
+
Step.assert(this.stepId);
|
|
94
|
+
const node = AssistsX.findFirstParentByTags(this, className);
|
|
95
|
+
Step.assert(this.stepId);
|
|
96
|
+
return node;
|
|
97
|
+
}
|
|
98
|
+
|
|
87
99
|
/**
|
|
88
100
|
* 对节点执行点击手势
|
|
89
101
|
* @param offsetX X轴偏移
|
package/src/NodeAsync.ts
CHANGED
|
@@ -18,7 +18,20 @@ export class NodeAsync {
|
|
|
18
18
|
constructor(node: Node) {
|
|
19
19
|
this.node = node;
|
|
20
20
|
}
|
|
21
|
-
|
|
21
|
+
/**
|
|
22
|
+
* 查找第一个匹配标签的父节点
|
|
23
|
+
* @param className 类名
|
|
24
|
+
* @returns 父节点
|
|
25
|
+
*/
|
|
26
|
+
public async findFirstParentByTags(className: string): Promise<Node> {
|
|
27
|
+
Step.assert(this.node.stepId);
|
|
28
|
+
const node = await AssistsXAsync.findFirstParentByTags(
|
|
29
|
+
this.node,
|
|
30
|
+
className
|
|
31
|
+
);
|
|
32
|
+
Step.assert(this.node.stepId);
|
|
33
|
+
return node;
|
|
34
|
+
}
|
|
22
35
|
/**
|
|
23
36
|
* 对节点执行点击手势
|
|
24
37
|
* @param offsetX X轴偏移
|
package/src/Step.ts
CHANGED
|
@@ -10,6 +10,12 @@ import { generateUUID } from "./Utils";
|
|
|
10
10
|
import { StepError } from "./StepError";
|
|
11
11
|
import { StepAsync } from "./StepAsync";
|
|
12
12
|
|
|
13
|
+
// 步骤结果类型,可以是Step实例或undefined
|
|
14
|
+
export type StepResult = Step | undefined;
|
|
15
|
+
|
|
16
|
+
// 步骤实现函数类型
|
|
17
|
+
export type StepImpl = (step: Step) => Promise<StepResult>;
|
|
18
|
+
|
|
13
19
|
export class Step {
|
|
14
20
|
static delayMsDefault: number = 1000;
|
|
15
21
|
static readonly repeatCountInfinite: number = -1;
|
|
@@ -29,18 +35,14 @@ export class Step {
|
|
|
29
35
|
* @param delayMs 步骤延迟时间(毫秒)
|
|
30
36
|
*/
|
|
31
37
|
static async run(
|
|
32
|
-
impl:
|
|
38
|
+
impl: StepImpl,
|
|
33
39
|
{
|
|
34
40
|
tag,
|
|
35
41
|
data,
|
|
36
|
-
backupSteps,
|
|
37
42
|
delayMs = Step.delayMsDefault,
|
|
38
43
|
}: {
|
|
39
44
|
tag?: string | undefined;
|
|
40
45
|
data?: any | undefined;
|
|
41
|
-
backupSteps?:
|
|
42
|
-
| { [key: string]: (step: Step) => Promise<Step | undefined> }
|
|
43
|
-
| undefined;
|
|
44
46
|
delayMs?: number;
|
|
45
47
|
} = {}
|
|
46
48
|
): Promise<Step> {
|
|
@@ -58,7 +60,6 @@ export class Step {
|
|
|
58
60
|
impl,
|
|
59
61
|
tag,
|
|
60
62
|
data,
|
|
61
|
-
backupSteps,
|
|
62
63
|
delayMs,
|
|
63
64
|
});
|
|
64
65
|
while (true) {
|
|
@@ -192,14 +193,7 @@ export class Step {
|
|
|
192
193
|
/**
|
|
193
194
|
* 步骤实现函数
|
|
194
195
|
*/
|
|
195
|
-
impl:
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* 备份步骤,可用于在指定的步骤中转向其他步骤
|
|
199
|
-
*/
|
|
200
|
-
backupSteps:
|
|
201
|
-
| { [key: string]: (step: Step) => Promise<Step | undefined> }
|
|
202
|
-
| undefined;
|
|
196
|
+
impl: StepImpl;
|
|
203
197
|
|
|
204
198
|
/**
|
|
205
199
|
* 构造函数
|
|
@@ -214,17 +208,13 @@ export class Step {
|
|
|
214
208
|
impl,
|
|
215
209
|
tag,
|
|
216
210
|
data,
|
|
217
|
-
backupSteps,
|
|
218
211
|
delayMs = Step.delayMsDefault,
|
|
219
212
|
repeatCountMax = Step.repeatCountMaxDefault,
|
|
220
213
|
}: {
|
|
221
214
|
stepId: string;
|
|
222
|
-
impl:
|
|
215
|
+
impl: StepImpl;
|
|
223
216
|
tag?: string | undefined;
|
|
224
217
|
data?: any | undefined;
|
|
225
|
-
backupSteps?:
|
|
226
|
-
| { [key: string]: (step: Step) => Promise<Step | undefined> }
|
|
227
|
-
| undefined;
|
|
228
218
|
delayMs?: number;
|
|
229
219
|
repeatCountMax?: number;
|
|
230
220
|
}) {
|
|
@@ -232,7 +222,6 @@ export class Step {
|
|
|
232
222
|
this.stepId = stepId;
|
|
233
223
|
this.data = data;
|
|
234
224
|
this.impl = impl;
|
|
235
|
-
this.backupSteps = backupSteps;
|
|
236
225
|
this.delayMs = delayMs;
|
|
237
226
|
this.repeatCountMax = repeatCountMax;
|
|
238
227
|
}
|
|
@@ -249,19 +238,15 @@ export class Step {
|
|
|
249
238
|
* @returns 新的步骤实例
|
|
250
239
|
*/
|
|
251
240
|
next(
|
|
252
|
-
impl:
|
|
241
|
+
impl: StepImpl,
|
|
253
242
|
{
|
|
254
243
|
tag,
|
|
255
244
|
data,
|
|
256
|
-
backupSteps,
|
|
257
245
|
delayMs = Step.delayMsDefault,
|
|
258
246
|
repeatCountMax = Step.repeatCountMaxDefault,
|
|
259
247
|
}: {
|
|
260
248
|
tag?: string | undefined;
|
|
261
249
|
data?: any | undefined;
|
|
262
|
-
backupSteps?:
|
|
263
|
-
| { [key: string]: (step: Step) => Promise<Step | undefined> }
|
|
264
|
-
| undefined;
|
|
265
250
|
delayMs?: number;
|
|
266
251
|
repeatCountMax?: number;
|
|
267
252
|
} = {}
|
|
@@ -272,7 +257,6 @@ export class Step {
|
|
|
272
257
|
impl,
|
|
273
258
|
tag,
|
|
274
259
|
data: data ?? this.data,
|
|
275
|
-
backupSteps: backupSteps ?? this.backupSteps,
|
|
276
260
|
delayMs,
|
|
277
261
|
repeatCountMax,
|
|
278
262
|
});
|
|
@@ -290,16 +274,12 @@ export class Step {
|
|
|
290
274
|
stepId = this.stepId,
|
|
291
275
|
tag = this.tag,
|
|
292
276
|
data = this.data,
|
|
293
|
-
backupSteps = this.backupSteps,
|
|
294
277
|
delayMs = this.delayMs,
|
|
295
278
|
repeatCountMax = this.repeatCountMax,
|
|
296
279
|
}: {
|
|
297
280
|
stepId?: string;
|
|
298
281
|
tag?: string | undefined;
|
|
299
282
|
data?: any | undefined;
|
|
300
|
-
backupSteps?:
|
|
301
|
-
| { [key: string]: (step: Step) => Promise<Step | undefined> }
|
|
302
|
-
| undefined;
|
|
303
283
|
delayMs?: number;
|
|
304
284
|
repeatCountMax?: number;
|
|
305
285
|
} = {}): Step {
|
|
@@ -308,7 +288,6 @@ export class Step {
|
|
|
308
288
|
this.stepId = stepId;
|
|
309
289
|
this.tag = tag;
|
|
310
290
|
this.data = data;
|
|
311
|
-
this.backupSteps = backupSteps;
|
|
312
291
|
this.delayMs = delayMs;
|
|
313
292
|
this.repeatCountMax = repeatCountMax;
|
|
314
293
|
return this;
|
|
@@ -550,18 +529,6 @@ export class Step {
|
|
|
550
529
|
return texts;
|
|
551
530
|
}
|
|
552
531
|
|
|
553
|
-
/**
|
|
554
|
-
* 查找第一个匹配标签的父节点
|
|
555
|
-
* @param className 类名
|
|
556
|
-
* @returns 父节点
|
|
557
|
-
*/
|
|
558
|
-
public findFirstParentByTags(className: string): Node {
|
|
559
|
-
Step.assert(this.stepId);
|
|
560
|
-
const node = AssistsX.findFirstParentByTags(className);
|
|
561
|
-
Step.assert(this.stepId);
|
|
562
|
-
return node;
|
|
563
|
-
}
|
|
564
|
-
|
|
565
532
|
/**
|
|
566
533
|
* 执行点击手势
|
|
567
534
|
* @param x 横坐标
|
package/src/StepAsync.ts
CHANGED
|
@@ -231,18 +231,6 @@ export class StepAsync {
|
|
|
231
231
|
return texts;
|
|
232
232
|
}
|
|
233
233
|
|
|
234
|
-
/**
|
|
235
|
-
* 查找第一个匹配标签的父节点
|
|
236
|
-
* @param className 类名
|
|
237
|
-
* @returns 父节点
|
|
238
|
-
*/
|
|
239
|
-
public async findFirstParentByTags(className: string): Promise<Node> {
|
|
240
|
-
Step.assert(this.step.stepId);
|
|
241
|
-
const node = await AssistsXAsync.findFirstParentByTags(className);
|
|
242
|
-
Step.assert(this.step.stepId);
|
|
243
|
-
return node;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
234
|
/**
|
|
247
235
|
* 执行点击手势
|
|
248
236
|
* @param x 横坐标
|
package/src/Utils.ts
CHANGED
|
@@ -1,13 +1,22 @@
|
|
|
1
1
|
// 导出工具函数
|
|
2
2
|
export function sleep(ms: number): Promise<void> {
|
|
3
|
-
|
|
3
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
// 生成UUID
|
|
7
7
|
export function generateUUID(): string {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
8
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
|
|
9
|
+
const r = (Math.random() * 16) | 0;
|
|
10
|
+
const v = c === "x" ? r : (r & 0x3) | 0x8;
|
|
11
|
+
return v.toString(16);
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function decodeBase64UTF8(base64: string): string {
|
|
16
|
+
const binary = atob(base64);
|
|
17
|
+
const bytes = new Uint8Array(binary.length);
|
|
18
|
+
for (let i = 0; i < binary.length; i++) {
|
|
19
|
+
bytes[i] = binary.charCodeAt(i);
|
|
20
|
+
}
|
|
21
|
+
return new TextDecoder("utf-8").decode(bytes);
|
|
22
|
+
}
|