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.
Files changed (104) hide show
  1. package/README.md +32 -0
  2. package/dist/index.cjs +7957 -0
  3. package/dist/index.cjs.map +1 -0
  4. package/dist/index.d.mts +4231 -0
  5. package/dist/index.d.ts +4231 -30
  6. package/dist/index.global.js +46 -0
  7. package/dist/index.global.js.map +1 -0
  8. package/dist/index.js +7879 -30
  9. package/dist/index.js.map +1 -0
  10. package/package.json +11 -5
  11. package/src/{AssistsXAsync.ts → assistsx-async.ts} +8 -8
  12. package/src/{AssistsX.ts → assistsx.ts} +8 -8
  13. package/src/barutils/bar-utils.ts +3 -3
  14. package/src/filesystem/fileio/file-io.ts +2 -2
  15. package/src/filesystem/fileutils/file-utils.ts +2 -2
  16. package/src/filesystem/path.ts +2 -2
  17. package/src/floatingwindow/float.ts +4 -4
  18. package/src/gallery/gallery.ts +2 -2
  19. package/src/global.d.ts +6 -1
  20. package/src/imageutils/image-utils.ts +2 -2
  21. package/src/ime/ime.ts +2 -2
  22. package/src/index.ts +21 -20
  23. package/src/log/log-call-method.ts +28 -0
  24. package/src/log/log.ts +445 -0
  25. package/src/mlkit/mlkit.ts +3 -3
  26. package/src/network/http.ts +2 -2
  27. package/src/{NodeAsync.ts → node-async.ts} +5 -5
  28. package/src/{Node.ts → node.ts} +5 -5
  29. package/src/{StepAsync.ts → step-async.ts} +8 -8
  30. package/src/{Step.ts → step.ts} +7 -7
  31. package/dist/AccessibilityEventFilter.d.ts +0 -105
  32. package/dist/AccessibilityEventFilter.js +0 -89
  33. package/dist/AppInfo.d.ts +0 -45
  34. package/dist/AppInfo.js +0 -38
  35. package/dist/AssistsX.d.ts +0 -484
  36. package/dist/AssistsX.js +0 -828
  37. package/dist/AssistsXAsync.d.ts +0 -532
  38. package/dist/AssistsXAsync.js +0 -874
  39. package/dist/Bounds.d.ts +0 -48
  40. package/dist/Bounds.js +0 -68
  41. package/dist/CallMethod.d.ts +0 -69
  42. package/dist/CallMethod.js +0 -71
  43. package/dist/CallResponse.d.ts +0 -10
  44. package/dist/CallResponse.js +0 -28
  45. package/dist/DeviceInfo.d.ts +0 -69
  46. package/dist/DeviceInfo.js +0 -50
  47. package/dist/Node.d.ts +0 -334
  48. package/dist/Node.js +0 -369
  49. package/dist/NodeAsync.d.ts +0 -213
  50. package/dist/NodeAsync.js +0 -313
  51. package/dist/NodeClassValue.d.ts +0 -15
  52. package/dist/NodeClassValue.js +0 -15
  53. package/dist/Step.d.ts +0 -355
  54. package/dist/Step.js +0 -689
  55. package/dist/StepAsync.d.ts +0 -162
  56. package/dist/StepAsync.js +0 -264
  57. package/dist/StepError.d.ts +0 -35
  58. package/dist/StepError.js +0 -26
  59. package/dist/StepStateStore.d.ts +0 -14
  60. package/dist/StepStateStore.js +0 -37
  61. package/dist/Utils.d.ts +0 -3
  62. package/dist/Utils.js +0 -20
  63. package/dist/WindowFlags.d.ts +0 -75
  64. package/dist/WindowFlags.js +0 -97
  65. package/dist/barutils/BarUtilsCallMethod.d.ts +0 -24
  66. package/dist/barutils/BarUtilsCallMethod.js +0 -26
  67. package/dist/barutils/bar-utils.d.ts +0 -41
  68. package/dist/barutils/bar-utils.js +0 -205
  69. package/dist/filesystem/fileio/file-io.d.ts +0 -101
  70. package/dist/filesystem/fileio/file-io.js +0 -235
  71. package/dist/filesystem/fileutils/file-utils.d.ts +0 -242
  72. package/dist/filesystem/fileutils/file-utils.js +0 -493
  73. package/dist/filesystem/path.d.ts +0 -252
  74. package/dist/filesystem/path.js +0 -589
  75. package/dist/floatingwindow/FloatCallMethod.d.ts +0 -19
  76. package/dist/floatingwindow/FloatCallMethod.js +0 -18
  77. package/dist/floatingwindow/float.d.ts +0 -29
  78. package/dist/floatingwindow/float.js +0 -149
  79. package/dist/gallery/gallery.d.ts +0 -60
  80. package/dist/gallery/gallery.js +0 -142
  81. package/dist/imageutils/image-utils.d.ts +0 -442
  82. package/dist/imageutils/image-utils.js +0 -543
  83. package/dist/ime/ime.d.ts +0 -80
  84. package/dist/ime/ime.js +0 -141
  85. package/dist/mlkit/MlkitCallMethod.d.ts +0 -27
  86. package/dist/mlkit/MlkitCallMethod.js +0 -26
  87. package/dist/mlkit/mlkit.d.ts +0 -86
  88. package/dist/mlkit/mlkit.js +0 -169
  89. package/dist/network/http.d.ts +0 -127
  90. package/dist/network/http.js +0 -202
  91. /package/src/{AccessibilityEventFilter.ts → accessibility-event-filter.ts} +0 -0
  92. /package/src/{AppInfo.ts → app-info.ts} +0 -0
  93. /package/src/barutils/{BarUtilsCallMethod.ts → bar-utils-call-method.ts} +0 -0
  94. /package/src/{Bounds.ts → bounds.ts} +0 -0
  95. /package/src/{CallMethod.ts → call-method.ts} +0 -0
  96. /package/src/{CallResponse.ts → call-response.ts} +0 -0
  97. /package/src/{DeviceInfo.ts → device-info.ts} +0 -0
  98. /package/src/floatingwindow/{FloatCallMethod.ts → float-call-method.ts} +0 -0
  99. /package/src/mlkit/{MlkitCallMethod.ts → mlkit-call-method.ts} +0 -0
  100. /package/src/{NodeClassValue.ts → node-class-value.ts} +0 -0
  101. /package/src/{StepError.ts → step-error.ts} +0 -0
  102. /package/src/{StepStateStore.ts → step-state-store.ts} +0 -0
  103. /package/src/{Utils.ts → utils.ts} +0 -0
  104. /package/src/{WindowFlags.ts → window-flags.ts} +0 -0
package/dist/Node.d.ts DELETED
@@ -1,334 +0,0 @@
1
- /**
2
- * 节点类
3
- * 表示界面上的一个可交互元素,包含元素的属性和可执行的操作
4
- */
5
- import { Bounds } from "./Bounds";
6
- import { NodeAsync } from "./NodeAsync";
7
- export declare class Node {
8
- /**
9
- * 节点唯一标识
10
- */
11
- nodeId: string;
12
- /**
13
- * 节点文本内容
14
- */
15
- text: string;
16
- /**
17
- * 节点描述信息
18
- */
19
- des: string;
20
- /**
21
- * 节点视图ID
22
- */
23
- viewId: string;
24
- /**
25
- * 节点类名
26
- */
27
- className: string;
28
- /**
29
- * 是否可滚动
30
- */
31
- isScrollable: boolean;
32
- /**
33
- * 是否可点击
34
- */
35
- isClickable: boolean;
36
- /**
37
- * 是否启用
38
- */
39
- isEnabled: boolean;
40
- /**
41
- * 所属步骤ID
42
- */
43
- stepId: string | undefined;
44
- /**
45
- * 提示文本
46
- */
47
- hintText: string;
48
- /**
49
- * 是否可选择
50
- */
51
- isCheckable: boolean;
52
- /**
53
- * 是否已选中
54
- */
55
- isChecked: boolean;
56
- /**
57
- * 是否可聚焦
58
- */
59
- isFocusable: boolean;
60
- /**
61
- * 是否已聚焦
62
- */
63
- isFocused: boolean;
64
- /**
65
- * 是否可长按
66
- */
67
- isLongClickable: boolean;
68
- /**
69
- * 是否为密码字段
70
- */
71
- isPassword: boolean;
72
- /**
73
- * 是否已选中
74
- */
75
- isSelected: boolean;
76
- /**
77
- * 是否对用户可见
78
- */
79
- isVisibleToUser: boolean;
80
- /**
81
- * 绘制顺序
82
- */
83
- drawingOrder: number;
84
- /**
85
- * 节点在屏幕中的边界
86
- */
87
- bounds: Bounds;
88
- /**
89
- * 节点在屏幕中的边界
90
- * @deprecated 请使用 bounds 字段替代
91
- */
92
- get boundsInScreen(): Bounds;
93
- /**
94
- * 构造函数
95
- * @param params 节点参数对象
96
- */
97
- constructor(params: {
98
- nodeId: string;
99
- text: string;
100
- des: string;
101
- viewId: string;
102
- className: string;
103
- isScrollable: boolean;
104
- isClickable: boolean;
105
- isEnabled: boolean;
106
- stepId: string | undefined;
107
- hintText: string;
108
- isCheckable: boolean;
109
- isChecked: boolean;
110
- isFocusable: boolean;
111
- isFocused: boolean;
112
- isLongClickable: boolean;
113
- isPassword: boolean;
114
- isSelected: boolean;
115
- isVisibleToUser: boolean;
116
- drawingOrder: number;
117
- /** @deprecated 请使用 bounds 替代 */
118
- boundsInScreen?: Bounds | any;
119
- bounds?: Bounds | any;
120
- });
121
- get async(): NodeAsync;
122
- /**
123
- * 查找第一个匹配标签的父节点
124
- * @param className 类名
125
- * @returns 父节点
126
- */
127
- findFirstParentByTags(className: string): Node;
128
- /**
129
- * 对节点执行点击手势
130
- * @param offsetX X轴偏移
131
- * @param offsetY Y轴偏移
132
- * @param switchWindowIntervalDelay 窗口切换延迟
133
- * @param clickDuration 点击持续时间
134
- * @returns 是否点击成功
135
- */
136
- clickNodeByGesture({ offsetX, offsetY, switchWindowIntervalDelay, clickDuration, }?: {
137
- offsetX?: number;
138
- offsetY?: number;
139
- switchWindowIntervalDelay?: number;
140
- clickDuration?: number;
141
- }): Promise<boolean>;
142
- /**
143
- * 对节点执行双击手势
144
- * @param offsetX X轴偏移
145
- * @param offsetY Y轴偏移
146
- * @param switchWindowIntervalDelay 窗口切换延迟
147
- * @param clickDuration 点击持续时间
148
- * @param clickInterval 点击间隔
149
- * @returns 是否双击成功
150
- */
151
- doubleClickNodeByGesture({ offsetX, offsetY, switchWindowIntervalDelay, clickDuration, clickInterval, }?: {
152
- offsetX?: number;
153
- offsetY?: number;
154
- switchWindowIntervalDelay?: number;
155
- clickDuration?: number;
156
- clickInterval?: number;
157
- }): Promise<boolean>;
158
- longPressNodeByGestureAutoPaste(text: string, { matchedPackageName, matchedText, timeoutMillis, longPressDuration, }?: {
159
- matchedPackageName?: string;
160
- matchedText?: string;
161
- timeoutMillis?: number;
162
- longPressDuration?: number;
163
- }): Promise<boolean>;
164
- /**
165
- * 在当前节点范围内通过标签查找节点
166
- * @param className 类名
167
- * @param filterText 文本过滤
168
- * @param filterViewId 视图ID过滤
169
- * @param filterDes 描述过滤
170
- * @returns 节点数组
171
- */
172
- findByTags(className: string, { filterText, filterViewId, filterDes, }?: {
173
- filterText?: string;
174
- filterViewId?: string;
175
- filterDes?: string;
176
- }): Node[];
177
- /**
178
- * 在当前节点范围内通过ID查找节点
179
- * @param id 节点ID
180
- * @param filterClass 类名过滤
181
- * @param filterText 文本过滤
182
- * @param filterDes 描述过滤
183
- * @returns 节点数组
184
- */
185
- findById(id: string, { filterClass, filterText, filterDes, }?: {
186
- filterClass?: string;
187
- filterText?: string;
188
- filterDes?: string;
189
- }): Node[];
190
- /**
191
- * 在当前节点范围内通过文本查找节点
192
- * @param text 要查找的文本
193
- * @param filterClass 类名过滤
194
- * @param filterViewId 视图ID过滤
195
- * @param filterDes 描述过滤
196
- * @returns 节点数组
197
- */
198
- findByText(text: string, { filterClass, filterViewId, filterDes, }?: {
199
- filterClass?: string;
200
- filterViewId?: string;
201
- filterDes?: string;
202
- }): Node[];
203
- /**
204
- * 向前滚动节点
205
- * @returns 是否滚动成功
206
- */
207
- scrollForward(): boolean;
208
- /**
209
- * 向后滚动节点
210
- * @returns 是否滚动成功
211
- */
212
- scrollBackward(): boolean;
213
- /**
214
- * 检查节点是否可见
215
- * @param compareNode 比较节点
216
- * @param isFullyByCompareNode 是否完全可见
217
- * @returns 是否可见
218
- */
219
- isVisible({ compareNode, isFullyByCompareNode, }?: {
220
- compareNode?: Node;
221
- isFullyByCompareNode?: boolean;
222
- }): boolean;
223
- /**
224
- * 对节点进行截图
225
- * @param overlayHiddenScreenshotDelayMillis 截图延迟时间(毫秒)
226
- * @returns 截图路径
227
- */
228
- takeScreenshot(overlayHiddenScreenshotDelayMillis?: number): Promise<string>;
229
- /**
230
- * 保存节点截图到文件
231
- * @param options 截图保存选项
232
- * @param options.filePath 文件路径(可选,不提供则自动生成)
233
- * @param options.format 图片格式,支持 "PNG"、"JPEG"、"JPG"、"WEBP",默认为 "PNG"
234
- * @param options.overlayHiddenScreenshotDelayMillis 截图延迟时间(毫秒),默认为 250
235
- * @returns 保存的文件路径
236
- */
237
- takeScreenshotToFile(options?: {
238
- filePath?: string;
239
- format?: "PNG" | "JPEG" | "JPG" | "WEBP";
240
- overlayHiddenScreenshotDelayMillis?: number;
241
- }): Promise<string>;
242
- /**
243
- * 设置节点文本
244
- * @param text 要设置的文本
245
- * @returns 是否设置成功
246
- */
247
- setNodeText(text: string): boolean;
248
- paste(text: string): boolean;
249
- focus(): boolean;
250
- /**
251
- * 点击节点
252
- * @returns 是否点击成功
253
- */
254
- click(): boolean;
255
- /**
256
- * 长按节点
257
- * @returns 是否长按成功
258
- */
259
- longClick(): boolean;
260
- /**
261
- * 查找第一个可点击的父节点
262
- * @returns 可点击的父节点
263
- */
264
- findFirstParentClickable(): Node;
265
- /**
266
- * 获取节点在屏幕中的边界
267
- * @returns 边界对象
268
- */
269
- getBoundsInScreen(): Bounds;
270
- /**
271
- * 获取节点的所有子节点
272
- * @returns 子节点数组
273
- */
274
- getNodes(): Node[];
275
- /**
276
- * 获取节点的直接子节点
277
- * @returns 子节点数组
278
- */
279
- getChildren(): Node[];
280
- /**
281
- * 从JSON字符串创建节点实例
282
- * @param json JSON字符串
283
- * @returns 节点实例
284
- */
285
- static fromJSON(json: string): Node;
286
- /**
287
- * 从普通对象创建节点实例
288
- * @param data 对象数据
289
- * @returns 节点实例
290
- */
291
- static from(data: any): Node;
292
- /**
293
- * JSON.parse的reviver函数,用于将解析的JSON对象转换为Node实例
294
- * @param key 属性键
295
- * @param value 属性值
296
- * @returns 转换后的值
297
- */
298
- static reviver(key: string, value: any): any;
299
- /**
300
- * 创建新的节点实例
301
- * @param params 节点参数对象
302
- * @returns 节点实例
303
- */
304
- static create(params: {
305
- nodeId: string;
306
- text: string;
307
- des: string;
308
- viewId: string;
309
- className: string;
310
- isScrollable: boolean;
311
- isClickable: boolean;
312
- isEnabled: boolean;
313
- stepId: string | undefined;
314
- hintText: string;
315
- isCheckable: boolean;
316
- isChecked: boolean;
317
- isFocusable: boolean;
318
- isFocused: boolean;
319
- isLongClickable: boolean;
320
- isPassword: boolean;
321
- isSelected: boolean;
322
- isVisibleToUser: boolean;
323
- drawingOrder: number;
324
- bounds?: Bounds;
325
- /** @deprecated 请使用 bounds 替代 */
326
- boundsInScreen?: Bounds;
327
- }): Node;
328
- /**
329
- * 从JSON数组创建节点数组
330
- * @param array JSON数组
331
- * @returns 节点数组
332
- */
333
- static fromJSONArray(array: Array<any>): Node[];
334
- }
package/dist/Node.js DELETED
@@ -1,369 +0,0 @@
1
- /**
2
- * 节点类
3
- * 表示界面上的一个可交互元素,包含元素的属性和可执行的操作
4
- */
5
- import { Bounds } from "./Bounds";
6
- import { AssistsX } from "./AssistsX";
7
- import { AssistsXAsync } from "./AssistsXAsync";
8
- import { Step } from "./Step";
9
- import { NodeAsync } from "./NodeAsync";
10
- // 将接口改造为类
11
- export class Node {
12
- /**
13
- * 节点在屏幕中的边界
14
- * @deprecated 请使用 bounds 字段替代
15
- */
16
- get boundsInScreen() {
17
- return this.bounds;
18
- }
19
- /**
20
- * 构造函数
21
- * @param params 节点参数对象
22
- */
23
- constructor(params) {
24
- var _a;
25
- this.nodeId = params.nodeId;
26
- this.text = params.text;
27
- this.des = params.des;
28
- this.viewId = params.viewId;
29
- this.className = params.className;
30
- this.isScrollable = params.isScrollable;
31
- this.isClickable = params.isClickable;
32
- this.isEnabled = params.isEnabled;
33
- this.stepId = params.stepId;
34
- this.hintText = params.hintText;
35
- this.isCheckable = params.isCheckable;
36
- this.isChecked = params.isChecked;
37
- this.isFocusable = params.isFocusable;
38
- this.isFocused = params.isFocused;
39
- this.isLongClickable = params.isLongClickable;
40
- this.isPassword = params.isPassword;
41
- this.isSelected = params.isSelected;
42
- this.isVisibleToUser = params.isVisibleToUser;
43
- this.drawingOrder = params.drawingOrder;
44
- // 优先使用 bounds,兼容旧的 boundsInScreen;确保为 Bounds 实例
45
- const rawBounds = (_a = params.bounds) !== null && _a !== void 0 ? _a : params.boundsInScreen;
46
- this.bounds = rawBounds instanceof Bounds ? rawBounds : Bounds.fromData(rawBounds);
47
- }
48
- get async() {
49
- return new NodeAsync(this);
50
- }
51
- /**
52
- * 查找第一个匹配标签的父节点
53
- * @param className 类名
54
- * @returns 父节点
55
- */
56
- findFirstParentByTags(className) {
57
- Step.assert(this.stepId);
58
- const node = AssistsX.findFirstParentByTags(this, className);
59
- Step.assert(this.stepId);
60
- return node;
61
- }
62
- /**
63
- * 对节点执行点击手势
64
- * @param offsetX X轴偏移
65
- * @param offsetY Y轴偏移
66
- * @param switchWindowIntervalDelay 窗口切换延迟
67
- * @param clickDuration 点击持续时间
68
- * @returns 是否点击成功
69
- */
70
- async clickNodeByGesture({ offsetX, offsetY, switchWindowIntervalDelay, clickDuration, } = {}) {
71
- Step.assert(this.stepId);
72
- const result = await AssistsX.clickNodeByGesture(this, {
73
- offsetX,
74
- offsetY,
75
- switchWindowIntervalDelay,
76
- clickDuration,
77
- });
78
- Step.assert(this.stepId);
79
- return result;
80
- }
81
- /**
82
- * 对节点执行双击手势
83
- * @param offsetX X轴偏移
84
- * @param offsetY Y轴偏移
85
- * @param switchWindowIntervalDelay 窗口切换延迟
86
- * @param clickDuration 点击持续时间
87
- * @param clickInterval 点击间隔
88
- * @returns 是否双击成功
89
- */
90
- async doubleClickNodeByGesture({ offsetX, offsetY, switchWindowIntervalDelay, clickDuration, clickInterval, } = {}) {
91
- Step.assert(this.stepId);
92
- const result = await AssistsX.doubleClickNodeByGesture(this, {
93
- offsetX,
94
- offsetY,
95
- switchWindowIntervalDelay,
96
- clickDuration,
97
- clickInterval,
98
- });
99
- Step.assert(this.stepId);
100
- return result;
101
- }
102
- async longPressNodeByGestureAutoPaste(text, { matchedPackageName, matchedText, timeoutMillis, longPressDuration, } = { matchedText: "粘贴", timeoutMillis: 1500, longPressDuration: 600 }) {
103
- Step.assert(this.stepId);
104
- const result = await AssistsX.longPressNodeByGestureAutoPaste(this, text, {
105
- matchedPackageName,
106
- matchedText,
107
- timeoutMillis,
108
- longPressDuration,
109
- });
110
- Step.assert(this.stepId);
111
- return result;
112
- }
113
- /**
114
- * 在当前节点范围内通过标签查找节点
115
- * @param className 类名
116
- * @param filterText 文本过滤
117
- * @param filterViewId 视图ID过滤
118
- * @param filterDes 描述过滤
119
- * @returns 节点数组
120
- */
121
- findByTags(className, { filterText, filterViewId, filterDes, } = {}) {
122
- Step.assert(this.stepId);
123
- const result = AssistsX.findByTags(className, {
124
- filterText,
125
- filterViewId,
126
- filterDes,
127
- node: this,
128
- });
129
- Step.assignIdsToNodes(result, this.stepId);
130
- Step.assert(this.stepId);
131
- return result;
132
- }
133
- /**
134
- * 在当前节点范围内通过ID查找节点
135
- * @param id 节点ID
136
- * @param filterClass 类名过滤
137
- * @param filterText 文本过滤
138
- * @param filterDes 描述过滤
139
- * @returns 节点数组
140
- */
141
- findById(id, { filterClass, filterText, filterDes, } = {}) {
142
- Step.assert(this.stepId);
143
- const result = AssistsX.findById(id, {
144
- filterClass,
145
- filterText,
146
- filterDes,
147
- node: this,
148
- });
149
- Step.assignIdsToNodes(result, this.stepId);
150
- Step.assert(this.stepId);
151
- return result;
152
- }
153
- /**
154
- * 在当前节点范围内通过文本查找节点
155
- * @param text 要查找的文本
156
- * @param filterClass 类名过滤
157
- * @param filterViewId 视图ID过滤
158
- * @param filterDes 描述过滤
159
- * @returns 节点数组
160
- */
161
- findByText(text, { filterClass, filterViewId, filterDes, } = {}) {
162
- Step.assert(this.stepId);
163
- const result = AssistsX.findByText(text, {
164
- filterClass,
165
- filterViewId,
166
- filterDes,
167
- node: this,
168
- });
169
- Step.assignIdsToNodes(result, this.stepId);
170
- Step.assert(this.stepId);
171
- return result;
172
- }
173
- /**
174
- * 向前滚动节点
175
- * @returns 是否滚动成功
176
- */
177
- scrollForward() {
178
- Step.assert(this.stepId);
179
- const response = AssistsX.scrollForward(this);
180
- Step.assert(this.stepId);
181
- return response;
182
- }
183
- /**
184
- * 向后滚动节点
185
- * @returns 是否滚动成功
186
- */
187
- scrollBackward() {
188
- Step.assert(this.stepId);
189
- const response = AssistsX.scrollBackward(this);
190
- Step.assert(this.stepId);
191
- return response;
192
- }
193
- /**
194
- * 检查节点是否可见
195
- * @param compareNode 比较节点
196
- * @param isFullyByCompareNode 是否完全可见
197
- * @returns 是否可见
198
- */
199
- isVisible({ compareNode, isFullyByCompareNode, } = {}) {
200
- Step.assert(this.stepId);
201
- const response = AssistsX.isVisible(this, {
202
- compareNode,
203
- isFullyByCompareNode,
204
- });
205
- Step.assert(this.stepId);
206
- return response;
207
- }
208
- /**
209
- * 对节点进行截图
210
- * @param overlayHiddenScreenshotDelayMillis 截图延迟时间(毫秒)
211
- * @returns 截图路径
212
- */
213
- async takeScreenshot(overlayHiddenScreenshotDelayMillis = 250) {
214
- Step.assert(this.stepId);
215
- const result = await AssistsX.takeScreenshotNodes([this], overlayHiddenScreenshotDelayMillis);
216
- Step.assert(this.stepId);
217
- return result[0];
218
- }
219
- /**
220
- * 保存节点截图到文件
221
- * @param options 截图保存选项
222
- * @param options.filePath 文件路径(可选,不提供则自动生成)
223
- * @param options.format 图片格式,支持 "PNG"、"JPEG"、"JPG"、"WEBP",默认为 "PNG"
224
- * @param options.overlayHiddenScreenshotDelayMillis 截图延迟时间(毫秒),默认为 250
225
- * @returns 保存的文件路径
226
- */
227
- async takeScreenshotToFile(options = {}) {
228
- Step.assert(this.stepId);
229
- const result = await AssistsXAsync.takeScreenshotToFile({
230
- nodes: [this],
231
- ...options,
232
- });
233
- Step.assert(this.stepId);
234
- return result[0];
235
- }
236
- /**
237
- * 设置节点文本
238
- * @param text 要设置的文本
239
- * @returns 是否设置成功
240
- */
241
- setNodeText(text) {
242
- Step.assert(this.stepId);
243
- const result = AssistsX.setNodeText(this, text);
244
- Step.assert(this.stepId);
245
- return result;
246
- }
247
- paste(text) {
248
- Step.assert(this.stepId);
249
- const result = AssistsX.paste(this, text);
250
- Step.assert(this.stepId);
251
- return result;
252
- }
253
- focus() {
254
- Step.assert(this.stepId);
255
- const result = AssistsX.focus(this);
256
- Step.assert(this.stepId);
257
- return result;
258
- }
259
- /**
260
- * 点击节点
261
- * @returns 是否点击成功
262
- */
263
- click() {
264
- Step.assert(this.stepId);
265
- const result = AssistsX.click(this);
266
- Step.assert(this.stepId);
267
- return result;
268
- }
269
- /**
270
- * 长按节点
271
- * @returns 是否长按成功
272
- */
273
- longClick() {
274
- Step.assert(this.stepId);
275
- const result = AssistsX.longClick(this);
276
- Step.assert(this.stepId);
277
- return result;
278
- }
279
- /**
280
- * 查找第一个可点击的父节点
281
- * @returns 可点击的父节点
282
- */
283
- findFirstParentClickable() {
284
- Step.assert(this.stepId);
285
- const result = AssistsX.findFirstParentClickable(this);
286
- Step.assert(this.stepId);
287
- Step.assignIdsToNodes([result], this.stepId);
288
- return result;
289
- }
290
- /**
291
- * 获取节点在屏幕中的边界
292
- * @returns 边界对象
293
- */
294
- getBoundsInScreen() {
295
- Step.assert(this.stepId);
296
- const result = AssistsX.getBoundsInScreen(this);
297
- Step.assert(this.stepId);
298
- return result;
299
- }
300
- /**
301
- * 获取节点的所有子节点
302
- * @returns 子节点数组
303
- */
304
- getNodes() {
305
- Step.assert(this.stepId);
306
- const result = AssistsX.getNodes(this);
307
- Step.assert(this.stepId);
308
- Step.assignIdsToNodes(result, this.stepId);
309
- return result;
310
- }
311
- /**
312
- * 获取节点的直接子节点
313
- * @returns 子节点数组
314
- */
315
- getChildren() {
316
- Step.assert(this.stepId);
317
- const result = AssistsX.getChildren(this);
318
- Step.assert(this.stepId);
319
- Step.assignIdsToNodes(result, this.stepId);
320
- return result;
321
- }
322
- /**
323
- * 从JSON字符串创建节点实例
324
- * @param json JSON字符串
325
- * @returns 节点实例
326
- */
327
- static fromJSON(json) {
328
- const data = JSON.parse(json);
329
- return new Node(data);
330
- }
331
- /**
332
- * 从普通对象创建节点实例
333
- * @param data 对象数据
334
- * @returns 节点实例
335
- */
336
- static from(data) {
337
- return new Node(data);
338
- }
339
- /**
340
- * JSON.parse的reviver函数,用于将解析的JSON对象转换为Node实例
341
- * @param key 属性键
342
- * @param value 属性值
343
- * @returns 转换后的值
344
- */
345
- static reviver(key, value) {
346
- return key === "" ? new Node(value) : value;
347
- }
348
- /**
349
- * 创建新的节点实例
350
- * @param params 节点参数对象
351
- * @returns 节点实例
352
- */
353
- static create(params) {
354
- return new Node(params);
355
- }
356
- /**
357
- * 从JSON数组创建节点数组
358
- * @param array JSON数组
359
- * @returns 节点数组
360
- */
361
- static fromJSONArray(array) {
362
- // 如果 array 不是数组,抛出详细异常
363
- if (!Array.isArray(array)) {
364
- throw new Error(`Node.fromJSONArray: Expected array, but got ${typeof array}. ` +
365
- `Value: ${JSON.stringify(array)}`);
366
- }
367
- return array.map((data) => new Node(data));
368
- }
369
- }