@midscene/web 0.7.2 → 0.7.3-beta-20241029030944.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/dist/es/appium.js +2237 -1999
- package/dist/es/chrome-extension.js +1427 -0
- package/dist/es/debug.js +149 -125
- package/dist/es/index.js +2673 -2390
- package/dist/es/midscene-playground.js +1807 -1666
- package/dist/es/playground.js +1325 -1666
- package/dist/es/playwright-report.js +482 -384
- package/dist/es/playwright.js +1573 -1384
- package/dist/es/puppeteer.js +1412 -1244
- package/dist/es/utils.js +599 -0
- package/dist/lib/appium.js +2236 -1983
- package/dist/lib/chrome-extension.js +1427 -0
- package/dist/lib/debug.js +148 -146
- package/dist/lib/index.js +2672 -2374
- package/dist/lib/midscene-playground.js +1807 -1645
- package/dist/lib/playground.js +1324 -1659
- package/dist/lib/playwright-report.js +482 -391
- package/dist/lib/playwright.js +1572 -1384
- package/dist/lib/puppeteer.js +1411 -1243
- package/dist/lib/utils.js +599 -0
- package/dist/script/htmlElement.js +11 -10
- package/dist/script/htmlElementDebug.js +11 -10
- package/dist/types/appium.d.ts +3 -3
- package/dist/types/chrome-extension.d.ts +16 -0
- package/dist/types/debug.d.ts +3 -2
- package/dist/types/index.d.ts +3 -3
- package/dist/types/{page-ad820b3c.d.ts → page-80b32690.d.ts} +69 -10
- package/dist/types/playground.d.ts +7 -21
- package/dist/types/playwright.d.ts +3 -4
- package/dist/types/puppeteer.d.ts +3 -3
- package/dist/types/{tasks-82c1054b.d.ts → tasks-5fdaaf80.d.ts} +6 -6
- package/dist/types/utils.d.ts +7 -0
- package/package.json +14 -4
- package/static/index.html +10 -6
package/dist/es/appium.js
CHANGED
|
@@ -1,2061 +1,2299 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if (__propIsEnum.call(b, prop))
|
|
19
|
-
__defNormalProp(a, prop, b[prop]);
|
|
20
|
-
}
|
|
21
|
-
return a;
|
|
22
|
-
};
|
|
23
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
25
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
26
|
-
}) : x)(function(x) {
|
|
27
|
-
if (typeof require !== "undefined")
|
|
28
|
-
return require.apply(this, arguments);
|
|
29
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
30
|
-
});
|
|
31
|
-
var __commonJS = (cb, mod) => function __require2() {
|
|
32
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
33
|
-
};
|
|
34
|
-
var __copyProps = (to, from, except, desc) => {
|
|
35
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
36
|
-
for (let key of __getOwnPropNames(from))
|
|
37
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
38
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
39
|
-
}
|
|
40
|
-
return to;
|
|
41
|
-
};
|
|
42
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
43
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
44
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
45
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
46
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
47
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
48
|
-
mod
|
|
49
|
-
));
|
|
50
|
-
|
|
51
|
-
// ../../node_modules/.pnpm/dayjs@1.11.11/node_modules/dayjs/dayjs.min.js
|
|
52
|
-
var require_dayjs_min = __commonJS({
|
|
53
|
-
"../../node_modules/.pnpm/dayjs@1.11.11/node_modules/dayjs/dayjs.min.js"(exports, module) {
|
|
1
|
+
(function(global1, factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("@midscene/core/utils"), require("assert"), require("@midscene/core"), require("fs"), require("path"), require("@midscene/shared/fs"), require("@midscene/shared/utils"), require("@midscene/shared/constants"), require("@midscene/shared/img"), require("@xmldom/xmldom"));
|
|
3
|
+
else if (typeof define === "function" && define.amd) define([
|
|
4
|
+
"exports",
|
|
5
|
+
"@midscene/core/utils",
|
|
6
|
+
"assert",
|
|
7
|
+
"@midscene/core",
|
|
8
|
+
"fs",
|
|
9
|
+
"path",
|
|
10
|
+
"@midscene/shared/fs",
|
|
11
|
+
"@midscene/shared/utils",
|
|
12
|
+
"@midscene/shared/constants",
|
|
13
|
+
"@midscene/shared/img",
|
|
14
|
+
"@xmldom/xmldom"
|
|
15
|
+
], factory);
|
|
16
|
+
else if (global1 = typeof globalThis !== "undefined" ? globalThis : global1 || self) factory(global1.appium = {}, global1.utils, global1.assert, global1.core, global1.fs, global1.path, global1.fs, global1.utils, global1.constants, global1.img, global1.xmldom);
|
|
17
|
+
})(this, function(exports, _utils, _assert, _core, _fs, _path, _fs1, _utils1, _constants, _img, _xmldom) {
|
|
54
18
|
"use strict";
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
return -t2(n2, e2);
|
|
71
|
-
var r2 = 12 * (n2.year() - e2.year()) + (n2.month() - e2.month()), i2 = e2.clone().add(r2, c), s2 = n2 - i2 < 0, u2 = e2.clone().add(r2 + (s2 ? -1 : 1), c);
|
|
72
|
-
return +(-(r2 + (n2 - i2) / (s2 ? i2 - u2 : u2 - i2)) || 0);
|
|
73
|
-
}, a: function(t2) {
|
|
74
|
-
return t2 < 0 ? Math.ceil(t2) || 0 : Math.floor(t2);
|
|
75
|
-
}, p: function(t2) {
|
|
76
|
-
return { M: c, y: h, w: o, d: a, D: d, h: u, m: s, s: i, ms: r, Q: f }[t2] || String(t2 || "").toLowerCase().replace(/s$/, "");
|
|
77
|
-
}, u: function(t2) {
|
|
78
|
-
return void 0 === t2;
|
|
79
|
-
} }, g = "en", D = {};
|
|
80
|
-
D[g] = M;
|
|
81
|
-
var p = "$isDayjsObject", S = function(t2) {
|
|
82
|
-
return t2 instanceof _ || !(!t2 || !t2[p]);
|
|
83
|
-
}, w = function t2(e2, n2, r2) {
|
|
84
|
-
var i2;
|
|
85
|
-
if (!e2)
|
|
86
|
-
return g;
|
|
87
|
-
if ("string" == typeof e2) {
|
|
88
|
-
var s2 = e2.toLowerCase();
|
|
89
|
-
D[s2] && (i2 = s2), n2 && (D[s2] = n2, i2 = s2);
|
|
90
|
-
var u2 = e2.split("-");
|
|
91
|
-
if (!i2 && u2.length > 1)
|
|
92
|
-
return t2(u2[0]);
|
|
93
|
-
} else {
|
|
94
|
-
var a2 = e2.name;
|
|
95
|
-
D[a2] = e2, i2 = a2;
|
|
96
|
-
}
|
|
97
|
-
return !r2 && i2 && (g = i2), i2 || !r2 && g;
|
|
98
|
-
}, O = function(t2, e2) {
|
|
99
|
-
if (S(t2))
|
|
100
|
-
return t2.clone();
|
|
101
|
-
var n2 = "object" == typeof e2 ? e2 : {};
|
|
102
|
-
return n2.date = t2, n2.args = arguments, new _(n2);
|
|
103
|
-
}, b = v;
|
|
104
|
-
b.l = w, b.i = S, b.w = function(t2, e2) {
|
|
105
|
-
return O(t2, { locale: e2.$L, utc: e2.$u, x: e2.$x, $offset: e2.$offset });
|
|
106
|
-
};
|
|
107
|
-
var _ = function() {
|
|
108
|
-
function M2(t2) {
|
|
109
|
-
this.$L = w(t2.locale, null, true), this.parse(t2), this.$x = this.$x || t2.x || {}, this[p] = true;
|
|
19
|
+
Object.defineProperty(exports, "__esModule", {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
function _export(target, all) {
|
|
23
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
get: all[name]
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
_export(exports, {
|
|
29
|
+
AppiumAgent: function() {
|
|
30
|
+
return PageAgent;
|
|
31
|
+
},
|
|
32
|
+
AppiumPage: function() {
|
|
33
|
+
return Page;
|
|
110
34
|
}
|
|
111
|
-
var m2 = M2.prototype;
|
|
112
|
-
return m2.parse = function(t2) {
|
|
113
|
-
this.$d = function(t3) {
|
|
114
|
-
var e2 = t3.date, n2 = t3.utc;
|
|
115
|
-
if (null === e2)
|
|
116
|
-
return /* @__PURE__ */ new Date(NaN);
|
|
117
|
-
if (b.u(e2))
|
|
118
|
-
return /* @__PURE__ */ new Date();
|
|
119
|
-
if (e2 instanceof Date)
|
|
120
|
-
return new Date(e2);
|
|
121
|
-
if ("string" == typeof e2 && !/Z$/i.test(e2)) {
|
|
122
|
-
var r2 = e2.match($);
|
|
123
|
-
if (r2) {
|
|
124
|
-
var i2 = r2[2] - 1 || 0, s2 = (r2[7] || "0").substring(0, 3);
|
|
125
|
-
return n2 ? new Date(Date.UTC(r2[1], i2, r2[3] || 1, r2[4] || 0, r2[5] || 0, r2[6] || 0, s2)) : new Date(r2[1], i2, r2[3] || 1, r2[4] || 0, r2[5] || 0, r2[6] || 0, s2);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
return new Date(e2);
|
|
129
|
-
}(t2), this.init();
|
|
130
|
-
}, m2.init = function() {
|
|
131
|
-
var t2 = this.$d;
|
|
132
|
-
this.$y = t2.getFullYear(), this.$M = t2.getMonth(), this.$D = t2.getDate(), this.$W = t2.getDay(), this.$H = t2.getHours(), this.$m = t2.getMinutes(), this.$s = t2.getSeconds(), this.$ms = t2.getMilliseconds();
|
|
133
|
-
}, m2.$utils = function() {
|
|
134
|
-
return b;
|
|
135
|
-
}, m2.isValid = function() {
|
|
136
|
-
return !(this.$d.toString() === l);
|
|
137
|
-
}, m2.isSame = function(t2, e2) {
|
|
138
|
-
var n2 = O(t2);
|
|
139
|
-
return this.startOf(e2) <= n2 && n2 <= this.endOf(e2);
|
|
140
|
-
}, m2.isAfter = function(t2, e2) {
|
|
141
|
-
return O(t2) < this.startOf(e2);
|
|
142
|
-
}, m2.isBefore = function(t2, e2) {
|
|
143
|
-
return this.endOf(e2) < O(t2);
|
|
144
|
-
}, m2.$g = function(t2, e2, n2) {
|
|
145
|
-
return b.u(t2) ? this[e2] : this.set(n2, t2);
|
|
146
|
-
}, m2.unix = function() {
|
|
147
|
-
return Math.floor(this.valueOf() / 1e3);
|
|
148
|
-
}, m2.valueOf = function() {
|
|
149
|
-
return this.$d.getTime();
|
|
150
|
-
}, m2.startOf = function(t2, e2) {
|
|
151
|
-
var n2 = this, r2 = !!b.u(e2) || e2, f2 = b.p(t2), l2 = function(t3, e3) {
|
|
152
|
-
var i2 = b.w(n2.$u ? Date.UTC(n2.$y, e3, t3) : new Date(n2.$y, e3, t3), n2);
|
|
153
|
-
return r2 ? i2 : i2.endOf(a);
|
|
154
|
-
}, $2 = function(t3, e3) {
|
|
155
|
-
return b.w(n2.toDate()[t3].apply(n2.toDate("s"), (r2 ? [0, 0, 0, 0] : [23, 59, 59, 999]).slice(e3)), n2);
|
|
156
|
-
}, y2 = this.$W, M3 = this.$M, m3 = this.$D, v2 = "set" + (this.$u ? "UTC" : "");
|
|
157
|
-
switch (f2) {
|
|
158
|
-
case h:
|
|
159
|
-
return r2 ? l2(1, 0) : l2(31, 11);
|
|
160
|
-
case c:
|
|
161
|
-
return r2 ? l2(1, M3) : l2(0, M3 + 1);
|
|
162
|
-
case o:
|
|
163
|
-
var g2 = this.$locale().weekStart || 0, D2 = (y2 < g2 ? y2 + 7 : y2) - g2;
|
|
164
|
-
return l2(r2 ? m3 - D2 : m3 + (6 - D2), M3);
|
|
165
|
-
case a:
|
|
166
|
-
case d:
|
|
167
|
-
return $2(v2 + "Hours", 0);
|
|
168
|
-
case u:
|
|
169
|
-
return $2(v2 + "Minutes", 1);
|
|
170
|
-
case s:
|
|
171
|
-
return $2(v2 + "Seconds", 2);
|
|
172
|
-
case i:
|
|
173
|
-
return $2(v2 + "Milliseconds", 3);
|
|
174
|
-
default:
|
|
175
|
-
return this.clone();
|
|
176
|
-
}
|
|
177
|
-
}, m2.endOf = function(t2) {
|
|
178
|
-
return this.startOf(t2, false);
|
|
179
|
-
}, m2.$set = function(t2, e2) {
|
|
180
|
-
var n2, o2 = b.p(t2), f2 = "set" + (this.$u ? "UTC" : ""), l2 = (n2 = {}, n2[a] = f2 + "Date", n2[d] = f2 + "Date", n2[c] = f2 + "Month", n2[h] = f2 + "FullYear", n2[u] = f2 + "Hours", n2[s] = f2 + "Minutes", n2[i] = f2 + "Seconds", n2[r] = f2 + "Milliseconds", n2)[o2], $2 = o2 === a ? this.$D + (e2 - this.$W) : e2;
|
|
181
|
-
if (o2 === c || o2 === h) {
|
|
182
|
-
var y2 = this.clone().set(d, 1);
|
|
183
|
-
y2.$d[l2]($2), y2.init(), this.$d = y2.set(d, Math.min(this.$D, y2.daysInMonth())).$d;
|
|
184
|
-
} else
|
|
185
|
-
l2 && this.$d[l2]($2);
|
|
186
|
-
return this.init(), this;
|
|
187
|
-
}, m2.set = function(t2, e2) {
|
|
188
|
-
return this.clone().$set(t2, e2);
|
|
189
|
-
}, m2.get = function(t2) {
|
|
190
|
-
return this[b.p(t2)]();
|
|
191
|
-
}, m2.add = function(r2, f2) {
|
|
192
|
-
var d2, l2 = this;
|
|
193
|
-
r2 = Number(r2);
|
|
194
|
-
var $2 = b.p(f2), y2 = function(t2) {
|
|
195
|
-
var e2 = O(l2);
|
|
196
|
-
return b.w(e2.date(e2.date() + Math.round(t2 * r2)), l2);
|
|
197
|
-
};
|
|
198
|
-
if ($2 === c)
|
|
199
|
-
return this.set(c, this.$M + r2);
|
|
200
|
-
if ($2 === h)
|
|
201
|
-
return this.set(h, this.$y + r2);
|
|
202
|
-
if ($2 === a)
|
|
203
|
-
return y2(1);
|
|
204
|
-
if ($2 === o)
|
|
205
|
-
return y2(7);
|
|
206
|
-
var M3 = (d2 = {}, d2[s] = e, d2[u] = n, d2[i] = t, d2)[$2] || 1, m3 = this.$d.getTime() + r2 * M3;
|
|
207
|
-
return b.w(m3, this);
|
|
208
|
-
}, m2.subtract = function(t2, e2) {
|
|
209
|
-
return this.add(-1 * t2, e2);
|
|
210
|
-
}, m2.format = function(t2) {
|
|
211
|
-
var e2 = this, n2 = this.$locale();
|
|
212
|
-
if (!this.isValid())
|
|
213
|
-
return n2.invalidDate || l;
|
|
214
|
-
var r2 = t2 || "YYYY-MM-DDTHH:mm:ssZ", i2 = b.z(this), s2 = this.$H, u2 = this.$m, a2 = this.$M, o2 = n2.weekdays, c2 = n2.months, f2 = n2.meridiem, h2 = function(t3, n3, i3, s3) {
|
|
215
|
-
return t3 && (t3[n3] || t3(e2, r2)) || i3[n3].slice(0, s3);
|
|
216
|
-
}, d2 = function(t3) {
|
|
217
|
-
return b.s(s2 % 12 || 12, t3, "0");
|
|
218
|
-
}, $2 = f2 || function(t3, e3, n3) {
|
|
219
|
-
var r3 = t3 < 12 ? "AM" : "PM";
|
|
220
|
-
return n3 ? r3.toLowerCase() : r3;
|
|
221
|
-
};
|
|
222
|
-
return r2.replace(y, function(t3, r3) {
|
|
223
|
-
return r3 || function(t4) {
|
|
224
|
-
switch (t4) {
|
|
225
|
-
case "YY":
|
|
226
|
-
return String(e2.$y).slice(-2);
|
|
227
|
-
case "YYYY":
|
|
228
|
-
return b.s(e2.$y, 4, "0");
|
|
229
|
-
case "M":
|
|
230
|
-
return a2 + 1;
|
|
231
|
-
case "MM":
|
|
232
|
-
return b.s(a2 + 1, 2, "0");
|
|
233
|
-
case "MMM":
|
|
234
|
-
return h2(n2.monthsShort, a2, c2, 3);
|
|
235
|
-
case "MMMM":
|
|
236
|
-
return h2(c2, a2);
|
|
237
|
-
case "D":
|
|
238
|
-
return e2.$D;
|
|
239
|
-
case "DD":
|
|
240
|
-
return b.s(e2.$D, 2, "0");
|
|
241
|
-
case "d":
|
|
242
|
-
return String(e2.$W);
|
|
243
|
-
case "dd":
|
|
244
|
-
return h2(n2.weekdaysMin, e2.$W, o2, 2);
|
|
245
|
-
case "ddd":
|
|
246
|
-
return h2(n2.weekdaysShort, e2.$W, o2, 3);
|
|
247
|
-
case "dddd":
|
|
248
|
-
return o2[e2.$W];
|
|
249
|
-
case "H":
|
|
250
|
-
return String(s2);
|
|
251
|
-
case "HH":
|
|
252
|
-
return b.s(s2, 2, "0");
|
|
253
|
-
case "h":
|
|
254
|
-
return d2(1);
|
|
255
|
-
case "hh":
|
|
256
|
-
return d2(2);
|
|
257
|
-
case "a":
|
|
258
|
-
return $2(s2, u2, true);
|
|
259
|
-
case "A":
|
|
260
|
-
return $2(s2, u2, false);
|
|
261
|
-
case "m":
|
|
262
|
-
return String(u2);
|
|
263
|
-
case "mm":
|
|
264
|
-
return b.s(u2, 2, "0");
|
|
265
|
-
case "s":
|
|
266
|
-
return String(e2.$s);
|
|
267
|
-
case "ss":
|
|
268
|
-
return b.s(e2.$s, 2, "0");
|
|
269
|
-
case "SSS":
|
|
270
|
-
return b.s(e2.$ms, 3, "0");
|
|
271
|
-
case "Z":
|
|
272
|
-
return i2;
|
|
273
|
-
}
|
|
274
|
-
return null;
|
|
275
|
-
}(t3) || i2.replace(":", "");
|
|
276
|
-
});
|
|
277
|
-
}, m2.utcOffset = function() {
|
|
278
|
-
return 15 * -Math.round(this.$d.getTimezoneOffset() / 15);
|
|
279
|
-
}, m2.diff = function(r2, d2, l2) {
|
|
280
|
-
var $2, y2 = this, M3 = b.p(d2), m3 = O(r2), v2 = (m3.utcOffset() - this.utcOffset()) * e, g2 = this - m3, D2 = function() {
|
|
281
|
-
return b.m(y2, m3);
|
|
282
|
-
};
|
|
283
|
-
switch (M3) {
|
|
284
|
-
case h:
|
|
285
|
-
$2 = D2() / 12;
|
|
286
|
-
break;
|
|
287
|
-
case c:
|
|
288
|
-
$2 = D2();
|
|
289
|
-
break;
|
|
290
|
-
case f:
|
|
291
|
-
$2 = D2() / 3;
|
|
292
|
-
break;
|
|
293
|
-
case o:
|
|
294
|
-
$2 = (g2 - v2) / 6048e5;
|
|
295
|
-
break;
|
|
296
|
-
case a:
|
|
297
|
-
$2 = (g2 - v2) / 864e5;
|
|
298
|
-
break;
|
|
299
|
-
case u:
|
|
300
|
-
$2 = g2 / n;
|
|
301
|
-
break;
|
|
302
|
-
case s:
|
|
303
|
-
$2 = g2 / e;
|
|
304
|
-
break;
|
|
305
|
-
case i:
|
|
306
|
-
$2 = g2 / t;
|
|
307
|
-
break;
|
|
308
|
-
default:
|
|
309
|
-
$2 = g2;
|
|
310
|
-
}
|
|
311
|
-
return l2 ? $2 : b.a($2);
|
|
312
|
-
}, m2.daysInMonth = function() {
|
|
313
|
-
return this.endOf(c).$D;
|
|
314
|
-
}, m2.$locale = function() {
|
|
315
|
-
return D[this.$L];
|
|
316
|
-
}, m2.locale = function(t2, e2) {
|
|
317
|
-
if (!t2)
|
|
318
|
-
return this.$L;
|
|
319
|
-
var n2 = this.clone(), r2 = w(t2, e2, true);
|
|
320
|
-
return r2 && (n2.$L = r2), n2;
|
|
321
|
-
}, m2.clone = function() {
|
|
322
|
-
return b.w(this.$d, this);
|
|
323
|
-
}, m2.toDate = function() {
|
|
324
|
-
return new Date(this.valueOf());
|
|
325
|
-
}, m2.toJSON = function() {
|
|
326
|
-
return this.isValid() ? this.toISOString() : null;
|
|
327
|
-
}, m2.toISOString = function() {
|
|
328
|
-
return this.$d.toISOString();
|
|
329
|
-
}, m2.toString = function() {
|
|
330
|
-
return this.$d.toUTCString();
|
|
331
|
-
}, M2;
|
|
332
|
-
}(), k = _.prototype;
|
|
333
|
-
return O.prototype = k, [["$ms", r], ["$s", i], ["$m", s], ["$H", u], ["$W", a], ["$M", c], ["$y", h], ["$D", d]].forEach(function(t2) {
|
|
334
|
-
k[t2[1]] = function(e2) {
|
|
335
|
-
return this.$g(e2, t2[0], t2[1]);
|
|
336
|
-
};
|
|
337
|
-
}), O.extend = function(t2, e2) {
|
|
338
|
-
return t2.$i || (t2(e2, _, O), t2.$i = true), O;
|
|
339
|
-
}, O.locale = w, O.isDayjs = S, O.unix = function(t2) {
|
|
340
|
-
return O(1e3 * t2);
|
|
341
|
-
}, O.en = D[g], O.Ls = D, O.p = {}, O;
|
|
342
35
|
});
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
"use strict";
|
|
350
|
-
(function() {
|
|
351
|
-
"use strict";
|
|
352
|
-
var ERROR = "input is invalid type";
|
|
353
|
-
var WINDOW = typeof window === "object";
|
|
354
|
-
var root = WINDOW ? window : {};
|
|
355
|
-
if (root.JS_SHA256_NO_WINDOW) {
|
|
356
|
-
WINDOW = false;
|
|
357
|
-
}
|
|
358
|
-
var WEB_WORKER = !WINDOW && typeof self === "object";
|
|
359
|
-
var NODE_JS = !root.JS_SHA256_NO_NODE_JS && typeof process === "object" && process.versions && process.versions.node;
|
|
360
|
-
if (NODE_JS) {
|
|
361
|
-
root = global;
|
|
362
|
-
} else if (WEB_WORKER) {
|
|
363
|
-
root = self;
|
|
364
|
-
}
|
|
365
|
-
var COMMON_JS = !root.JS_SHA256_NO_COMMON_JS && typeof module === "object" && module.exports;
|
|
366
|
-
var AMD = typeof define === "function" && define.amd;
|
|
367
|
-
var ARRAY_BUFFER = !root.JS_SHA256_NO_ARRAY_BUFFER && typeof ArrayBuffer !== "undefined";
|
|
368
|
-
var HEX_CHARS = "0123456789abcdef".split("");
|
|
369
|
-
var EXTRA = [-2147483648, 8388608, 32768, 128];
|
|
370
|
-
var SHIFT = [24, 16, 8, 0];
|
|
371
|
-
var K = [
|
|
372
|
-
1116352408,
|
|
373
|
-
1899447441,
|
|
374
|
-
3049323471,
|
|
375
|
-
3921009573,
|
|
376
|
-
961987163,
|
|
377
|
-
1508970993,
|
|
378
|
-
2453635748,
|
|
379
|
-
2870763221,
|
|
380
|
-
3624381080,
|
|
381
|
-
310598401,
|
|
382
|
-
607225278,
|
|
383
|
-
1426881987,
|
|
384
|
-
1925078388,
|
|
385
|
-
2162078206,
|
|
386
|
-
2614888103,
|
|
387
|
-
3248222580,
|
|
388
|
-
3835390401,
|
|
389
|
-
4022224774,
|
|
390
|
-
264347078,
|
|
391
|
-
604807628,
|
|
392
|
-
770255983,
|
|
393
|
-
1249150122,
|
|
394
|
-
1555081692,
|
|
395
|
-
1996064986,
|
|
396
|
-
2554220882,
|
|
397
|
-
2821834349,
|
|
398
|
-
2952996808,
|
|
399
|
-
3210313671,
|
|
400
|
-
3336571891,
|
|
401
|
-
3584528711,
|
|
402
|
-
113926993,
|
|
403
|
-
338241895,
|
|
404
|
-
666307205,
|
|
405
|
-
773529912,
|
|
406
|
-
1294757372,
|
|
407
|
-
1396182291,
|
|
408
|
-
1695183700,
|
|
409
|
-
1986661051,
|
|
410
|
-
2177026350,
|
|
411
|
-
2456956037,
|
|
412
|
-
2730485921,
|
|
413
|
-
2820302411,
|
|
414
|
-
3259730800,
|
|
415
|
-
3345764771,
|
|
416
|
-
3516065817,
|
|
417
|
-
3600352804,
|
|
418
|
-
4094571909,
|
|
419
|
-
275423344,
|
|
420
|
-
430227734,
|
|
421
|
-
506948616,
|
|
422
|
-
659060556,
|
|
423
|
-
883997877,
|
|
424
|
-
958139571,
|
|
425
|
-
1322822218,
|
|
426
|
-
1537002063,
|
|
427
|
-
1747873779,
|
|
428
|
-
1955562222,
|
|
429
|
-
2024104815,
|
|
430
|
-
2227730452,
|
|
431
|
-
2361852424,
|
|
432
|
-
2428436474,
|
|
433
|
-
2756734187,
|
|
434
|
-
3204031479,
|
|
435
|
-
3329325298
|
|
436
|
-
];
|
|
437
|
-
var OUTPUT_TYPES = ["hex", "array", "digest", "arrayBuffer"];
|
|
438
|
-
var blocks = [];
|
|
439
|
-
if (root.JS_SHA256_NO_NODE_JS || !Array.isArray) {
|
|
440
|
-
Array.isArray = function(obj) {
|
|
441
|
-
return Object.prototype.toString.call(obj) === "[object Array]";
|
|
442
|
-
};
|
|
443
|
-
}
|
|
444
|
-
if (ARRAY_BUFFER && (root.JS_SHA256_NO_ARRAY_BUFFER_IS_VIEW || !ArrayBuffer.isView)) {
|
|
445
|
-
ArrayBuffer.isView = function(obj) {
|
|
446
|
-
return typeof obj === "object" && obj.buffer && obj.buffer.constructor === ArrayBuffer;
|
|
447
|
-
};
|
|
448
|
-
}
|
|
449
|
-
var createOutputMethod = function(outputType, is224) {
|
|
450
|
-
return function(message) {
|
|
451
|
-
return new Sha256(is224, true).update(message)[outputType]();
|
|
36
|
+
_assert = /*#__PURE__*/ _interop_require_default(_assert);
|
|
37
|
+
_fs = /*#__PURE__*/ _interop_require_wildcard(_fs);
|
|
38
|
+
_path = /*#__PURE__*/ _interop_require_wildcard(_path);
|
|
39
|
+
function _interop_require_default(obj) {
|
|
40
|
+
return obj && obj.__esModule ? obj : {
|
|
41
|
+
default: obj
|
|
452
42
|
};
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
43
|
+
}
|
|
44
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
45
|
+
if (typeof WeakMap !== "function") return null;
|
|
46
|
+
var cacheBabelInterop = new WeakMap();
|
|
47
|
+
var cacheNodeInterop = new WeakMap();
|
|
48
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
49
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
50
|
+
})(nodeInterop);
|
|
51
|
+
}
|
|
52
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
53
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
54
|
+
return obj;
|
|
55
|
+
}
|
|
56
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
57
|
+
return {
|
|
58
|
+
default: obj
|
|
59
|
+
};
|
|
458
60
|
}
|
|
459
|
-
|
|
460
|
-
|
|
61
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
62
|
+
if (cache && cache.has(obj)) {
|
|
63
|
+
return cache.get(obj);
|
|
64
|
+
}
|
|
65
|
+
var newObj = {
|
|
66
|
+
__proto__: null
|
|
461
67
|
};
|
|
462
|
-
|
|
463
|
-
|
|
68
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
69
|
+
for(var key in obj){
|
|
70
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
71
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
72
|
+
if (desc && (desc.get || desc.set)) {
|
|
73
|
+
Object.defineProperty(newObj, key, desc);
|
|
74
|
+
} else {
|
|
75
|
+
newObj[key] = obj[key];
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
newObj.default = obj;
|
|
80
|
+
if (cache) {
|
|
81
|
+
cache.set(obj, newObj);
|
|
82
|
+
}
|
|
83
|
+
return newObj;
|
|
84
|
+
}
|
|
85
|
+
var __create = Object.create;
|
|
86
|
+
var __defProp = Object.defineProperty;
|
|
87
|
+
var __defProps = Object.defineProperties;
|
|
88
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
89
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
90
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
91
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
92
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
93
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
94
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
95
|
+
var __defNormalProp = (obj, key, value)=>key in obj ? __defProp(obj, key, {
|
|
96
|
+
enumerable: true,
|
|
97
|
+
configurable: true,
|
|
98
|
+
writable: true,
|
|
99
|
+
value
|
|
100
|
+
}) : obj[key] = value;
|
|
101
|
+
var __spreadValues = (a, b)=>{
|
|
102
|
+
for(var prop in b || (b = {}))if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]);
|
|
103
|
+
if (__getOwnPropSymbols) for (var prop of __getOwnPropSymbols(b)){
|
|
104
|
+
if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]);
|
|
105
|
+
}
|
|
106
|
+
return a;
|
|
107
|
+
};
|
|
108
|
+
var __spreadProps = (a, b)=>__defProps(a, __getOwnPropDescs(b));
|
|
109
|
+
var __require = /* @__PURE__ */ ((x)=>typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
110
|
+
get: (a, b)=>(typeof require !== "undefined" ? require : a)[b]
|
|
111
|
+
}) : x)(function(x) {
|
|
112
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
113
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
114
|
+
});
|
|
115
|
+
var __commonJS = (cb, mod)=>function __require2() {
|
|
116
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = {
|
|
117
|
+
exports: {}
|
|
118
|
+
}).exports, mod), mod.exports;
|
|
464
119
|
};
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
120
|
+
var __copyProps = (to, from, except, desc)=>{
|
|
121
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
122
|
+
for (let key of __getOwnPropNames(from))if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
123
|
+
get: ()=>from[key],
|
|
124
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
125
|
+
});
|
|
468
126
|
}
|
|
469
|
-
return
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
127
|
+
return to;
|
|
128
|
+
};
|
|
129
|
+
var __toESM = (mod, isNodeMode, target)=>(target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(// If the importer is in node compatibility mode or this is not an ESM
|
|
130
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
131
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
132
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
133
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
134
|
+
value: mod,
|
|
135
|
+
enumerable: true
|
|
136
|
+
}) : target, mod));
|
|
137
|
+
var __async = (__this, __arguments, generator)=>{
|
|
138
|
+
return new Promise((resolve, reject)=>{
|
|
139
|
+
var fulfilled = (value)=>{
|
|
140
|
+
try {
|
|
141
|
+
step(generator.next(value));
|
|
142
|
+
} catch (e) {
|
|
143
|
+
reject(e);
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
var rejected = (value)=>{
|
|
147
|
+
try {
|
|
148
|
+
step(generator.throw(value));
|
|
149
|
+
} catch (e) {
|
|
150
|
+
reject(e);
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
var step = (x)=>x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
154
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
155
|
+
});
|
|
156
|
+
};
|
|
157
|
+
// ../../node_modules/.pnpm/dayjs@1.11.11/node_modules/dayjs/dayjs.min.js
|
|
158
|
+
var require_dayjs_min = __commonJS({
|
|
159
|
+
"../../node_modules/.pnpm/dayjs@1.11.11/node_modules/dayjs/dayjs.min.js" (exports, module1) {
|
|
160
|
+
"use strict";
|
|
161
|
+
!function(t, e) {
|
|
162
|
+
"object" == typeof exports && "undefined" != typeof module1 ? module1.exports = e() : "function" == typeof define && define.amd ? define(e) : (t = "undefined" != typeof globalThis ? globalThis : t || self).dayjs = e();
|
|
163
|
+
}(exports, function() {
|
|
164
|
+
"use strict";
|
|
165
|
+
var t = 1e3, e = 6e4, n = 36e5, r = "millisecond", i = "second", s = "minute", u = "hour", a = "day", o = "week", c = "month", f = "quarter", h = "year", d = "date", l = "Invalid Date", $ = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/, y = /\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g, M = {
|
|
166
|
+
name: "en",
|
|
167
|
+
weekdays: "Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),
|
|
168
|
+
months: "January_February_March_April_May_June_July_August_September_October_November_December".split("_"),
|
|
169
|
+
ordinal: function(t2) {
|
|
170
|
+
var e2 = [
|
|
171
|
+
"th",
|
|
172
|
+
"st",
|
|
173
|
+
"nd",
|
|
174
|
+
"rd"
|
|
175
|
+
], n2 = t2 % 100;
|
|
176
|
+
return "[" + t2 + (e2[(n2 - 20) % 10] || e2[n2] || e2[0]) + "]";
|
|
177
|
+
}
|
|
178
|
+
}, m = function(t2, e2, n2) {
|
|
179
|
+
var r2 = String(t2);
|
|
180
|
+
return !r2 || r2.length >= e2 ? t2 : "" + Array(e2 + 1 - r2.length).join(n2) + t2;
|
|
181
|
+
}, v = {
|
|
182
|
+
s: m,
|
|
183
|
+
z: function(t2) {
|
|
184
|
+
var e2 = -t2.utcOffset(), n2 = Math.abs(e2), r2 = Math.floor(n2 / 60), i2 = n2 % 60;
|
|
185
|
+
return (e2 <= 0 ? "+" : "-") + m(r2, 2, "0") + ":" + m(i2, 2, "0");
|
|
186
|
+
},
|
|
187
|
+
m: function t2(e2, n2) {
|
|
188
|
+
if (e2.date() < n2.date()) return -t2(n2, e2);
|
|
189
|
+
var r2 = 12 * (n2.year() - e2.year()) + (n2.month() - e2.month()), i2 = e2.clone().add(r2, c), s2 = n2 - i2 < 0, u2 = e2.clone().add(r2 + (s2 ? -1 : 1), c);
|
|
190
|
+
return +(-(r2 + (n2 - i2) / (s2 ? i2 - u2 : u2 - i2)) || 0);
|
|
191
|
+
},
|
|
192
|
+
a: function(t2) {
|
|
193
|
+
return t2 < 0 ? Math.ceil(t2) || 0 : Math.floor(t2);
|
|
194
|
+
},
|
|
195
|
+
p: function(t2) {
|
|
196
|
+
return ({
|
|
197
|
+
M: c,
|
|
198
|
+
y: h,
|
|
199
|
+
w: o,
|
|
200
|
+
d: a,
|
|
201
|
+
D: d,
|
|
202
|
+
h: u,
|
|
203
|
+
m: s,
|
|
204
|
+
s: i,
|
|
205
|
+
ms: r,
|
|
206
|
+
Q: f
|
|
207
|
+
})[t2] || String(t2 || "").toLowerCase().replace(/s$/, "");
|
|
208
|
+
},
|
|
209
|
+
u: function(t2) {
|
|
210
|
+
return void 0 === t2;
|
|
211
|
+
}
|
|
212
|
+
}, g = "en", D = {};
|
|
213
|
+
D[g] = M;
|
|
214
|
+
var p = "$isDayjsObject", S = function(t2) {
|
|
215
|
+
return t2 instanceof _ || !(!t2 || !t2[p]);
|
|
216
|
+
}, w = function t2(e2, n2, r2) {
|
|
217
|
+
var i2;
|
|
218
|
+
if (!e2) return g;
|
|
219
|
+
if ("string" == typeof e2) {
|
|
220
|
+
var s2 = e2.toLowerCase();
|
|
221
|
+
D[s2] && (i2 = s2), n2 && (D[s2] = n2, i2 = s2);
|
|
222
|
+
var u2 = e2.split("-");
|
|
223
|
+
if (!i2 && u2.length > 1) return t2(u2[0]);
|
|
224
|
+
} else {
|
|
225
|
+
var a2 = e2.name;
|
|
226
|
+
D[a2] = e2, i2 = a2;
|
|
227
|
+
}
|
|
228
|
+
return !r2 && i2 && (g = i2), i2 || !r2 && g;
|
|
229
|
+
}, O = function(t2, e2) {
|
|
230
|
+
if (S(t2)) return t2.clone();
|
|
231
|
+
var n2 = "object" == typeof e2 ? e2 : {};
|
|
232
|
+
return n2.date = t2, n2.args = arguments, new _(n2);
|
|
233
|
+
}, b = v;
|
|
234
|
+
b.l = w, b.i = S, b.w = function(t2, e2) {
|
|
235
|
+
return O(t2, {
|
|
236
|
+
locale: e2.$L,
|
|
237
|
+
utc: e2.$u,
|
|
238
|
+
x: e2.$x,
|
|
239
|
+
$offset: e2.$offset
|
|
240
|
+
});
|
|
241
|
+
};
|
|
242
|
+
var _ = function() {
|
|
243
|
+
function M2(t2) {
|
|
244
|
+
this.$L = w(t2.locale, null, true), this.parse(t2), this.$x = this.$x || t2.x || {}, this[p] = true;
|
|
245
|
+
}
|
|
246
|
+
var m2 = M2.prototype;
|
|
247
|
+
return m2.parse = function(t2) {
|
|
248
|
+
this.$d = function(t3) {
|
|
249
|
+
var e2 = t3.date, n2 = t3.utc;
|
|
250
|
+
if (null === e2) return /* @__PURE__ */ new Date(NaN);
|
|
251
|
+
if (b.u(e2)) return /* @__PURE__ */ new Date();
|
|
252
|
+
if (e2 instanceof Date) return new Date(e2);
|
|
253
|
+
if ("string" == typeof e2 && !/Z$/i.test(e2)) {
|
|
254
|
+
var r2 = e2.match($);
|
|
255
|
+
if (r2) {
|
|
256
|
+
var i2 = r2[2] - 1 || 0, s2 = (r2[7] || "0").substring(0, 3);
|
|
257
|
+
return n2 ? new Date(Date.UTC(r2[1], i2, r2[3] || 1, r2[4] || 0, r2[5] || 0, r2[6] || 0, s2)) : new Date(r2[1], i2, r2[3] || 1, r2[4] || 0, r2[5] || 0, r2[6] || 0, s2);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return new Date(e2);
|
|
261
|
+
}(t2), this.init();
|
|
262
|
+
}, m2.init = function() {
|
|
263
|
+
var t2 = this.$d;
|
|
264
|
+
this.$y = t2.getFullYear(), this.$M = t2.getMonth(), this.$D = t2.getDate(), this.$W = t2.getDay(), this.$H = t2.getHours(), this.$m = t2.getMinutes(), this.$s = t2.getSeconds(), this.$ms = t2.getMilliseconds();
|
|
265
|
+
}, m2.$utils = function() {
|
|
266
|
+
return b;
|
|
267
|
+
}, m2.isValid = function() {
|
|
268
|
+
return !(this.$d.toString() === l);
|
|
269
|
+
}, m2.isSame = function(t2, e2) {
|
|
270
|
+
var n2 = O(t2);
|
|
271
|
+
return this.startOf(e2) <= n2 && n2 <= this.endOf(e2);
|
|
272
|
+
}, m2.isAfter = function(t2, e2) {
|
|
273
|
+
return O(t2) < this.startOf(e2);
|
|
274
|
+
}, m2.isBefore = function(t2, e2) {
|
|
275
|
+
return this.endOf(e2) < O(t2);
|
|
276
|
+
}, m2.$g = function(t2, e2, n2) {
|
|
277
|
+
return b.u(t2) ? this[e2] : this.set(n2, t2);
|
|
278
|
+
}, m2.unix = function() {
|
|
279
|
+
return Math.floor(this.valueOf() / 1e3);
|
|
280
|
+
}, m2.valueOf = function() {
|
|
281
|
+
return this.$d.getTime();
|
|
282
|
+
}, m2.startOf = function(t2, e2) {
|
|
283
|
+
var n2 = this, r2 = !!b.u(e2) || e2, f2 = b.p(t2), l2 = function(t3, e3) {
|
|
284
|
+
var i2 = b.w(n2.$u ? Date.UTC(n2.$y, e3, t3) : new Date(n2.$y, e3, t3), n2);
|
|
285
|
+
return r2 ? i2 : i2.endOf(a);
|
|
286
|
+
}, $2 = function(t3, e3) {
|
|
287
|
+
return b.w(n2.toDate()[t3].apply(n2.toDate("s"), (r2 ? [
|
|
288
|
+
0,
|
|
289
|
+
0,
|
|
290
|
+
0,
|
|
291
|
+
0
|
|
292
|
+
] : [
|
|
293
|
+
23,
|
|
294
|
+
59,
|
|
295
|
+
59,
|
|
296
|
+
999
|
|
297
|
+
]).slice(e3)), n2);
|
|
298
|
+
}, y2 = this.$W, M3 = this.$M, m3 = this.$D, v2 = "set" + (this.$u ? "UTC" : "");
|
|
299
|
+
switch(f2){
|
|
300
|
+
case h:
|
|
301
|
+
return r2 ? l2(1, 0) : l2(31, 11);
|
|
302
|
+
case c:
|
|
303
|
+
return r2 ? l2(1, M3) : l2(0, M3 + 1);
|
|
304
|
+
case o:
|
|
305
|
+
var g2 = this.$locale().weekStart || 0, D2 = (y2 < g2 ? y2 + 7 : y2) - g2;
|
|
306
|
+
return l2(r2 ? m3 - D2 : m3 + (6 - D2), M3);
|
|
307
|
+
case a:
|
|
308
|
+
case d:
|
|
309
|
+
return $2(v2 + "Hours", 0);
|
|
310
|
+
case u:
|
|
311
|
+
return $2(v2 + "Minutes", 1);
|
|
312
|
+
case s:
|
|
313
|
+
return $2(v2 + "Seconds", 2);
|
|
314
|
+
case i:
|
|
315
|
+
return $2(v2 + "Milliseconds", 3);
|
|
316
|
+
default:
|
|
317
|
+
return this.clone();
|
|
318
|
+
}
|
|
319
|
+
}, m2.endOf = function(t2) {
|
|
320
|
+
return this.startOf(t2, false);
|
|
321
|
+
}, m2.$set = function(t2, e2) {
|
|
322
|
+
var n2, o2 = b.p(t2), f2 = "set" + (this.$u ? "UTC" : ""), l2 = (n2 = {}, n2[a] = f2 + "Date", n2[d] = f2 + "Date", n2[c] = f2 + "Month", n2[h] = f2 + "FullYear", n2[u] = f2 + "Hours", n2[s] = f2 + "Minutes", n2[i] = f2 + "Seconds", n2[r] = f2 + "Milliseconds", n2)[o2], $2 = o2 === a ? this.$D + (e2 - this.$W) : e2;
|
|
323
|
+
if (o2 === c || o2 === h) {
|
|
324
|
+
var y2 = this.clone().set(d, 1);
|
|
325
|
+
y2.$d[l2]($2), y2.init(), this.$d = y2.set(d, Math.min(this.$D, y2.daysInMonth())).$d;
|
|
326
|
+
} else l2 && this.$d[l2]($2);
|
|
327
|
+
return this.init(), this;
|
|
328
|
+
}, m2.set = function(t2, e2) {
|
|
329
|
+
return this.clone().$set(t2, e2);
|
|
330
|
+
}, m2.get = function(t2) {
|
|
331
|
+
return this[b.p(t2)]();
|
|
332
|
+
}, m2.add = function(r2, f2) {
|
|
333
|
+
var d2, l2 = this;
|
|
334
|
+
r2 = Number(r2);
|
|
335
|
+
var $2 = b.p(f2), y2 = function(t2) {
|
|
336
|
+
var e2 = O(l2);
|
|
337
|
+
return b.w(e2.date(e2.date() + Math.round(t2 * r2)), l2);
|
|
338
|
+
};
|
|
339
|
+
if ($2 === c) return this.set(c, this.$M + r2);
|
|
340
|
+
if ($2 === h) return this.set(h, this.$y + r2);
|
|
341
|
+
if ($2 === a) return y2(1);
|
|
342
|
+
if ($2 === o) return y2(7);
|
|
343
|
+
var M3 = (d2 = {}, d2[s] = e, d2[u] = n, d2[i] = t, d2)[$2] || 1, m3 = this.$d.getTime() + r2 * M3;
|
|
344
|
+
return b.w(m3, this);
|
|
345
|
+
}, m2.subtract = function(t2, e2) {
|
|
346
|
+
return this.add(-1 * t2, e2);
|
|
347
|
+
}, m2.format = function(t2) {
|
|
348
|
+
var e2 = this, n2 = this.$locale();
|
|
349
|
+
if (!this.isValid()) return n2.invalidDate || l;
|
|
350
|
+
var r2 = t2 || "YYYY-MM-DDTHH:mm:ssZ", i2 = b.z(this), s2 = this.$H, u2 = this.$m, a2 = this.$M, o2 = n2.weekdays, c2 = n2.months, f2 = n2.meridiem, h2 = function(t3, n3, i3, s3) {
|
|
351
|
+
return t3 && (t3[n3] || t3(e2, r2)) || i3[n3].slice(0, s3);
|
|
352
|
+
}, d2 = function(t3) {
|
|
353
|
+
return b.s(s2 % 12 || 12, t3, "0");
|
|
354
|
+
}, $2 = f2 || function(t3, e3, n3) {
|
|
355
|
+
var r3 = t3 < 12 ? "AM" : "PM";
|
|
356
|
+
return n3 ? r3.toLowerCase() : r3;
|
|
357
|
+
};
|
|
358
|
+
return r2.replace(y, function(t3, r3) {
|
|
359
|
+
return r3 || function(t4) {
|
|
360
|
+
switch(t4){
|
|
361
|
+
case "YY":
|
|
362
|
+
return String(e2.$y).slice(-2);
|
|
363
|
+
case "YYYY":
|
|
364
|
+
return b.s(e2.$y, 4, "0");
|
|
365
|
+
case "M":
|
|
366
|
+
return a2 + 1;
|
|
367
|
+
case "MM":
|
|
368
|
+
return b.s(a2 + 1, 2, "0");
|
|
369
|
+
case "MMM":
|
|
370
|
+
return h2(n2.monthsShort, a2, c2, 3);
|
|
371
|
+
case "MMMM":
|
|
372
|
+
return h2(c2, a2);
|
|
373
|
+
case "D":
|
|
374
|
+
return e2.$D;
|
|
375
|
+
case "DD":
|
|
376
|
+
return b.s(e2.$D, 2, "0");
|
|
377
|
+
case "d":
|
|
378
|
+
return String(e2.$W);
|
|
379
|
+
case "dd":
|
|
380
|
+
return h2(n2.weekdaysMin, e2.$W, o2, 2);
|
|
381
|
+
case "ddd":
|
|
382
|
+
return h2(n2.weekdaysShort, e2.$W, o2, 3);
|
|
383
|
+
case "dddd":
|
|
384
|
+
return o2[e2.$W];
|
|
385
|
+
case "H":
|
|
386
|
+
return String(s2);
|
|
387
|
+
case "HH":
|
|
388
|
+
return b.s(s2, 2, "0");
|
|
389
|
+
case "h":
|
|
390
|
+
return d2(1);
|
|
391
|
+
case "hh":
|
|
392
|
+
return d2(2);
|
|
393
|
+
case "a":
|
|
394
|
+
return $2(s2, u2, true);
|
|
395
|
+
case "A":
|
|
396
|
+
return $2(s2, u2, false);
|
|
397
|
+
case "m":
|
|
398
|
+
return String(u2);
|
|
399
|
+
case "mm":
|
|
400
|
+
return b.s(u2, 2, "0");
|
|
401
|
+
case "s":
|
|
402
|
+
return String(e2.$s);
|
|
403
|
+
case "ss":
|
|
404
|
+
return b.s(e2.$s, 2, "0");
|
|
405
|
+
case "SSS":
|
|
406
|
+
return b.s(e2.$ms, 3, "0");
|
|
407
|
+
case "Z":
|
|
408
|
+
return i2;
|
|
409
|
+
}
|
|
410
|
+
return null;
|
|
411
|
+
}(t3) || i2.replace(":", "");
|
|
412
|
+
});
|
|
413
|
+
}, m2.utcOffset = function() {
|
|
414
|
+
return 15 * -Math.round(this.$d.getTimezoneOffset() / 15);
|
|
415
|
+
}, m2.diff = function(r2, d2, l2) {
|
|
416
|
+
var $2, y2 = this, M3 = b.p(d2), m3 = O(r2), v2 = (m3.utcOffset() - this.utcOffset()) * e, g2 = this - m3, D2 = function() {
|
|
417
|
+
return b.m(y2, m3);
|
|
418
|
+
};
|
|
419
|
+
switch(M3){
|
|
420
|
+
case h:
|
|
421
|
+
$2 = D2() / 12;
|
|
422
|
+
break;
|
|
423
|
+
case c:
|
|
424
|
+
$2 = D2();
|
|
425
|
+
break;
|
|
426
|
+
case f:
|
|
427
|
+
$2 = D2() / 3;
|
|
428
|
+
break;
|
|
429
|
+
case o:
|
|
430
|
+
$2 = (g2 - v2) / 6048e5;
|
|
431
|
+
break;
|
|
432
|
+
case a:
|
|
433
|
+
$2 = (g2 - v2) / 864e5;
|
|
434
|
+
break;
|
|
435
|
+
case u:
|
|
436
|
+
$2 = g2 / n;
|
|
437
|
+
break;
|
|
438
|
+
case s:
|
|
439
|
+
$2 = g2 / e;
|
|
440
|
+
break;
|
|
441
|
+
case i:
|
|
442
|
+
$2 = g2 / t;
|
|
443
|
+
break;
|
|
444
|
+
default:
|
|
445
|
+
$2 = g2;
|
|
446
|
+
}
|
|
447
|
+
return l2 ? $2 : b.a($2);
|
|
448
|
+
}, m2.daysInMonth = function() {
|
|
449
|
+
return this.endOf(c).$D;
|
|
450
|
+
}, m2.$locale = function() {
|
|
451
|
+
return D[this.$L];
|
|
452
|
+
}, m2.locale = function(t2, e2) {
|
|
453
|
+
if (!t2) return this.$L;
|
|
454
|
+
var n2 = this.clone(), r2 = w(t2, e2, true);
|
|
455
|
+
return r2 && (n2.$L = r2), n2;
|
|
456
|
+
}, m2.clone = function() {
|
|
457
|
+
return b.w(this.$d, this);
|
|
458
|
+
}, m2.toDate = function() {
|
|
459
|
+
return new Date(this.valueOf());
|
|
460
|
+
}, m2.toJSON = function() {
|
|
461
|
+
return this.isValid() ? this.toISOString() : null;
|
|
462
|
+
}, m2.toISOString = function() {
|
|
463
|
+
return this.$d.toISOString();
|
|
464
|
+
}, m2.toString = function() {
|
|
465
|
+
return this.$d.toUTCString();
|
|
466
|
+
}, M2;
|
|
467
|
+
}(), k = _.prototype;
|
|
468
|
+
return O.prototype = k, [
|
|
469
|
+
[
|
|
470
|
+
"$ms",
|
|
471
|
+
r
|
|
472
|
+
],
|
|
473
|
+
[
|
|
474
|
+
"$s",
|
|
475
|
+
i
|
|
476
|
+
],
|
|
477
|
+
[
|
|
478
|
+
"$m",
|
|
479
|
+
s
|
|
480
|
+
],
|
|
481
|
+
[
|
|
482
|
+
"$H",
|
|
483
|
+
u
|
|
484
|
+
],
|
|
485
|
+
[
|
|
486
|
+
"$W",
|
|
487
|
+
a
|
|
488
|
+
],
|
|
489
|
+
[
|
|
490
|
+
"$M",
|
|
491
|
+
c
|
|
492
|
+
],
|
|
493
|
+
[
|
|
494
|
+
"$y",
|
|
495
|
+
h
|
|
496
|
+
],
|
|
497
|
+
[
|
|
498
|
+
"$D",
|
|
499
|
+
d
|
|
500
|
+
]
|
|
501
|
+
].forEach(function(t2) {
|
|
502
|
+
k[t2[1]] = function(e2) {
|
|
503
|
+
return this.$g(e2, t2[0], t2[1]);
|
|
504
|
+
};
|
|
505
|
+
}), O.extend = function(t2, e2) {
|
|
506
|
+
return t2.$i || (t2(e2, _, O), t2.$i = true), O;
|
|
507
|
+
}, O.locale = w, O.isDayjs = S, O.unix = function(t2) {
|
|
508
|
+
return O(1e3 * t2);
|
|
509
|
+
}, O.en = D[g], O.Ls = D, O.p = {}, O;
|
|
510
|
+
});
|
|
482
511
|
}
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
512
|
+
});
|
|
513
|
+
// ../../node_modules/.pnpm/js-sha256@0.11.0/node_modules/js-sha256/src/sha256.js
|
|
514
|
+
var require_sha256 = __commonJS({
|
|
515
|
+
"../../node_modules/.pnpm/js-sha256@0.11.0/node_modules/js-sha256/src/sha256.js" (exports, module1) {
|
|
516
|
+
"use strict";
|
|
517
|
+
(function() {
|
|
518
|
+
"use strict";
|
|
519
|
+
var ERROR = "input is invalid type";
|
|
520
|
+
var WINDOW = typeof window === "object";
|
|
521
|
+
var root = WINDOW ? window : {};
|
|
522
|
+
if (root.JS_SHA256_NO_WINDOW) {
|
|
523
|
+
WINDOW = false;
|
|
524
|
+
}
|
|
525
|
+
var WEB_WORKER = !WINDOW && typeof self === "object";
|
|
526
|
+
var NODE_JS = !root.JS_SHA256_NO_NODE_JS && typeof process === "object" && process.versions && process.versions.node;
|
|
527
|
+
if (NODE_JS) {
|
|
528
|
+
root = global;
|
|
529
|
+
} else if (WEB_WORKER) {
|
|
530
|
+
root = self;
|
|
531
|
+
}
|
|
532
|
+
var COMMON_JS = !root.JS_SHA256_NO_COMMON_JS && typeof module1 === "object" && module1.exports;
|
|
533
|
+
var AMD = typeof define === "function" && define.amd;
|
|
534
|
+
var ARRAY_BUFFER = !root.JS_SHA256_NO_ARRAY_BUFFER && typeof ArrayBuffer !== "undefined";
|
|
535
|
+
var HEX_CHARS = "0123456789abcdef".split("");
|
|
536
|
+
var EXTRA = [
|
|
537
|
+
-2147483648,
|
|
538
|
+
8388608,
|
|
539
|
+
32768,
|
|
540
|
+
128
|
|
541
|
+
];
|
|
542
|
+
var SHIFT = [
|
|
543
|
+
24,
|
|
544
|
+
16,
|
|
545
|
+
8,
|
|
546
|
+
0
|
|
547
|
+
];
|
|
548
|
+
var K = [
|
|
549
|
+
1116352408,
|
|
550
|
+
1899447441,
|
|
551
|
+
3049323471,
|
|
552
|
+
3921009573,
|
|
553
|
+
961987163,
|
|
554
|
+
1508970993,
|
|
555
|
+
2453635748,
|
|
556
|
+
2870763221,
|
|
557
|
+
3624381080,
|
|
558
|
+
310598401,
|
|
559
|
+
607225278,
|
|
560
|
+
1426881987,
|
|
561
|
+
1925078388,
|
|
562
|
+
2162078206,
|
|
563
|
+
2614888103,
|
|
564
|
+
3248222580,
|
|
565
|
+
3835390401,
|
|
566
|
+
4022224774,
|
|
567
|
+
264347078,
|
|
568
|
+
604807628,
|
|
569
|
+
770255983,
|
|
570
|
+
1249150122,
|
|
571
|
+
1555081692,
|
|
572
|
+
1996064986,
|
|
573
|
+
2554220882,
|
|
574
|
+
2821834349,
|
|
575
|
+
2952996808,
|
|
576
|
+
3210313671,
|
|
577
|
+
3336571891,
|
|
578
|
+
3584528711,
|
|
579
|
+
113926993,
|
|
580
|
+
338241895,
|
|
581
|
+
666307205,
|
|
582
|
+
773529912,
|
|
583
|
+
1294757372,
|
|
584
|
+
1396182291,
|
|
585
|
+
1695183700,
|
|
586
|
+
1986661051,
|
|
587
|
+
2177026350,
|
|
588
|
+
2456956037,
|
|
589
|
+
2730485921,
|
|
590
|
+
2820302411,
|
|
591
|
+
3259730800,
|
|
592
|
+
3345764771,
|
|
593
|
+
3516065817,
|
|
594
|
+
3600352804,
|
|
595
|
+
4094571909,
|
|
596
|
+
275423344,
|
|
597
|
+
430227734,
|
|
598
|
+
506948616,
|
|
599
|
+
659060556,
|
|
600
|
+
883997877,
|
|
601
|
+
958139571,
|
|
602
|
+
1322822218,
|
|
603
|
+
1537002063,
|
|
604
|
+
1747873779,
|
|
605
|
+
1955562222,
|
|
606
|
+
2024104815,
|
|
607
|
+
2227730452,
|
|
608
|
+
2361852424,
|
|
609
|
+
2428436474,
|
|
610
|
+
2756734187,
|
|
611
|
+
3204031479,
|
|
612
|
+
3329325298
|
|
613
|
+
];
|
|
614
|
+
var OUTPUT_TYPES = [
|
|
615
|
+
"hex",
|
|
616
|
+
"array",
|
|
617
|
+
"digest",
|
|
618
|
+
"arrayBuffer"
|
|
619
|
+
];
|
|
620
|
+
var blocks = [];
|
|
621
|
+
if (root.JS_SHA256_NO_NODE_JS || !Array.isArray) {
|
|
622
|
+
Array.isArray = function(obj) {
|
|
623
|
+
return Object.prototype.toString.call(obj) === "[object Array]";
|
|
624
|
+
};
|
|
625
|
+
}
|
|
626
|
+
if (ARRAY_BUFFER && (root.JS_SHA256_NO_ARRAY_BUFFER_IS_VIEW || !ArrayBuffer.isView)) {
|
|
627
|
+
ArrayBuffer.isView = function(obj) {
|
|
628
|
+
return typeof obj === "object" && obj.buffer && obj.buffer.constructor === ArrayBuffer;
|
|
629
|
+
};
|
|
630
|
+
}
|
|
631
|
+
var createOutputMethod = function(outputType, is224) {
|
|
632
|
+
return function(message) {
|
|
633
|
+
return new Sha256(is224, true).update(message)[outputType]();
|
|
634
|
+
};
|
|
635
|
+
};
|
|
636
|
+
var createMethod = function(is224) {
|
|
637
|
+
var method = createOutputMethod("hex", is224);
|
|
638
|
+
if (NODE_JS) {
|
|
639
|
+
method = nodeWrap(method, is224);
|
|
640
|
+
}
|
|
641
|
+
method.create = function() {
|
|
642
|
+
return new Sha256(is224);
|
|
643
|
+
};
|
|
644
|
+
method.update = function(message) {
|
|
645
|
+
return method.create().update(message);
|
|
646
|
+
};
|
|
647
|
+
for(var i = 0; i < OUTPUT_TYPES.length; ++i){
|
|
648
|
+
var type = OUTPUT_TYPES[i];
|
|
649
|
+
method[type] = createOutputMethod(type, is224);
|
|
650
|
+
}
|
|
651
|
+
return method;
|
|
652
|
+
};
|
|
653
|
+
var nodeWrap = function(method, is224) {
|
|
654
|
+
var crypto = __require("crypto");
|
|
655
|
+
var Buffer2 = __require("buffer").Buffer;
|
|
656
|
+
var algorithm = is224 ? "sha224" : "sha256";
|
|
657
|
+
var bufferFrom;
|
|
658
|
+
if (Buffer2.from && !root.JS_SHA256_NO_BUFFER_FROM) {
|
|
659
|
+
bufferFrom = Buffer2.from;
|
|
660
|
+
} else {
|
|
661
|
+
bufferFrom = function(message) {
|
|
662
|
+
return new Buffer2(message);
|
|
663
|
+
};
|
|
664
|
+
}
|
|
665
|
+
var nodeMethod = function(message) {
|
|
666
|
+
if (typeof message === "string") {
|
|
667
|
+
return crypto.createHash(algorithm).update(message, "utf8").digest("hex");
|
|
668
|
+
} else {
|
|
669
|
+
if (message === null || message === void 0) {
|
|
670
|
+
throw new Error(ERROR);
|
|
671
|
+
} else if (message.constructor === ArrayBuffer) {
|
|
672
|
+
message = new Uint8Array(message);
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
if (Array.isArray(message) || ArrayBuffer.isView(message) || message.constructor === Buffer2) {
|
|
676
|
+
return crypto.createHash(algorithm).update(bufferFrom(message)).digest("hex");
|
|
677
|
+
} else {
|
|
678
|
+
return method(message);
|
|
679
|
+
}
|
|
680
|
+
};
|
|
681
|
+
return nodeMethod;
|
|
682
|
+
};
|
|
683
|
+
var createHmacOutputMethod = function(outputType, is224) {
|
|
684
|
+
return function(key, message) {
|
|
685
|
+
return new HmacSha256(key, is224, true).update(message)[outputType]();
|
|
686
|
+
};
|
|
687
|
+
};
|
|
688
|
+
var createHmacMethod = function(is224) {
|
|
689
|
+
var method = createHmacOutputMethod("hex", is224);
|
|
690
|
+
method.create = function(key) {
|
|
691
|
+
return new HmacSha256(key, is224);
|
|
692
|
+
};
|
|
693
|
+
method.update = function(key, message) {
|
|
694
|
+
return method.create(key).update(message);
|
|
695
|
+
};
|
|
696
|
+
for(var i = 0; i < OUTPUT_TYPES.length; ++i){
|
|
697
|
+
var type = OUTPUT_TYPES[i];
|
|
698
|
+
method[type] = createHmacOutputMethod(type, is224);
|
|
699
|
+
}
|
|
700
|
+
return method;
|
|
701
|
+
};
|
|
702
|
+
function Sha256(is224, sharedMemory) {
|
|
703
|
+
if (sharedMemory) {
|
|
704
|
+
blocks[0] = blocks[16] = blocks[1] = blocks[2] = blocks[3] = blocks[4] = blocks[5] = blocks[6] = blocks[7] = blocks[8] = blocks[9] = blocks[10] = blocks[11] = blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
|
|
705
|
+
this.blocks = blocks;
|
|
706
|
+
} else {
|
|
707
|
+
this.blocks = [
|
|
708
|
+
0,
|
|
709
|
+
0,
|
|
710
|
+
0,
|
|
711
|
+
0,
|
|
712
|
+
0,
|
|
713
|
+
0,
|
|
714
|
+
0,
|
|
715
|
+
0,
|
|
716
|
+
0,
|
|
717
|
+
0,
|
|
718
|
+
0,
|
|
719
|
+
0,
|
|
720
|
+
0,
|
|
721
|
+
0,
|
|
722
|
+
0,
|
|
723
|
+
0,
|
|
724
|
+
0
|
|
725
|
+
];
|
|
726
|
+
}
|
|
727
|
+
if (is224) {
|
|
728
|
+
this.h0 = 3238371032;
|
|
729
|
+
this.h1 = 914150663;
|
|
730
|
+
this.h2 = 812702999;
|
|
731
|
+
this.h3 = 4144912697;
|
|
732
|
+
this.h4 = 4290775857;
|
|
733
|
+
this.h5 = 1750603025;
|
|
734
|
+
this.h6 = 1694076839;
|
|
735
|
+
this.h7 = 3204075428;
|
|
736
|
+
} else {
|
|
737
|
+
this.h0 = 1779033703;
|
|
738
|
+
this.h1 = 3144134277;
|
|
739
|
+
this.h2 = 1013904242;
|
|
740
|
+
this.h3 = 2773480762;
|
|
741
|
+
this.h4 = 1359893119;
|
|
742
|
+
this.h5 = 2600822924;
|
|
743
|
+
this.h6 = 528734635;
|
|
744
|
+
this.h7 = 1541459225;
|
|
745
|
+
}
|
|
746
|
+
this.block = this.start = this.bytes = this.hBytes = 0;
|
|
747
|
+
this.finalized = this.hashed = false;
|
|
748
|
+
this.first = true;
|
|
749
|
+
this.is224 = is224;
|
|
750
|
+
}
|
|
751
|
+
Sha256.prototype.update = function(message) {
|
|
752
|
+
if (this.finalized) {
|
|
753
|
+
return;
|
|
754
|
+
}
|
|
755
|
+
var notString, type = typeof message;
|
|
756
|
+
if (type !== "string") {
|
|
757
|
+
if (type === "object") {
|
|
758
|
+
if (message === null) {
|
|
759
|
+
throw new Error(ERROR);
|
|
760
|
+
} else if (ARRAY_BUFFER && message.constructor === ArrayBuffer) {
|
|
761
|
+
message = new Uint8Array(message);
|
|
762
|
+
} else if (!Array.isArray(message)) {
|
|
763
|
+
if (!ARRAY_BUFFER || !ArrayBuffer.isView(message)) {
|
|
764
|
+
throw new Error(ERROR);
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
} else {
|
|
768
|
+
throw new Error(ERROR);
|
|
769
|
+
}
|
|
770
|
+
notString = true;
|
|
771
|
+
}
|
|
772
|
+
var code, index = 0, i, length = message.length, blocks2 = this.blocks;
|
|
773
|
+
while(index < length){
|
|
774
|
+
if (this.hashed) {
|
|
775
|
+
this.hashed = false;
|
|
776
|
+
blocks2[0] = this.block;
|
|
777
|
+
this.block = blocks2[16] = blocks2[1] = blocks2[2] = blocks2[3] = blocks2[4] = blocks2[5] = blocks2[6] = blocks2[7] = blocks2[8] = blocks2[9] = blocks2[10] = blocks2[11] = blocks2[12] = blocks2[13] = blocks2[14] = blocks2[15] = 0;
|
|
778
|
+
}
|
|
779
|
+
if (notString) {
|
|
780
|
+
for(i = this.start; index < length && i < 64; ++index){
|
|
781
|
+
blocks2[i >>> 2] |= message[index] << SHIFT[i++ & 3];
|
|
782
|
+
}
|
|
783
|
+
} else {
|
|
784
|
+
for(i = this.start; index < length && i < 64; ++index){
|
|
785
|
+
code = message.charCodeAt(index);
|
|
786
|
+
if (code < 128) {
|
|
787
|
+
blocks2[i >>> 2] |= code << SHIFT[i++ & 3];
|
|
788
|
+
} else if (code < 2048) {
|
|
789
|
+
blocks2[i >>> 2] |= (192 | code >>> 6) << SHIFT[i++ & 3];
|
|
790
|
+
blocks2[i >>> 2] |= (128 | code & 63) << SHIFT[i++ & 3];
|
|
791
|
+
} else if (code < 55296 || code >= 57344) {
|
|
792
|
+
blocks2[i >>> 2] |= (224 | code >>> 12) << SHIFT[i++ & 3];
|
|
793
|
+
blocks2[i >>> 2] |= (128 | code >>> 6 & 63) << SHIFT[i++ & 3];
|
|
794
|
+
blocks2[i >>> 2] |= (128 | code & 63) << SHIFT[i++ & 3];
|
|
795
|
+
} else {
|
|
796
|
+
code = 65536 + ((code & 1023) << 10 | message.charCodeAt(++index) & 1023);
|
|
797
|
+
blocks2[i >>> 2] |= (240 | code >>> 18) << SHIFT[i++ & 3];
|
|
798
|
+
blocks2[i >>> 2] |= (128 | code >>> 12 & 63) << SHIFT[i++ & 3];
|
|
799
|
+
blocks2[i >>> 2] |= (128 | code >>> 6 & 63) << SHIFT[i++ & 3];
|
|
800
|
+
blocks2[i >>> 2] |= (128 | code & 63) << SHIFT[i++ & 3];
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
this.lastByteIndex = i;
|
|
805
|
+
this.bytes += i - this.start;
|
|
806
|
+
if (i >= 64) {
|
|
807
|
+
this.block = blocks2[16];
|
|
808
|
+
this.start = i - 64;
|
|
809
|
+
this.hash();
|
|
810
|
+
this.hashed = true;
|
|
811
|
+
} else {
|
|
812
|
+
this.start = i;
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
if (this.bytes > 4294967295) {
|
|
816
|
+
this.hBytes += this.bytes / 4294967296 << 0;
|
|
817
|
+
this.bytes = this.bytes % 4294967296;
|
|
818
|
+
}
|
|
819
|
+
return this;
|
|
820
|
+
};
|
|
821
|
+
Sha256.prototype.finalize = function() {
|
|
822
|
+
if (this.finalized) {
|
|
823
|
+
return;
|
|
824
|
+
}
|
|
825
|
+
this.finalized = true;
|
|
826
|
+
var blocks2 = this.blocks, i = this.lastByteIndex;
|
|
827
|
+
blocks2[16] = this.block;
|
|
828
|
+
blocks2[i >>> 2] |= EXTRA[i & 3];
|
|
829
|
+
this.block = blocks2[16];
|
|
830
|
+
if (i >= 56) {
|
|
831
|
+
if (!this.hashed) {
|
|
832
|
+
this.hash();
|
|
833
|
+
}
|
|
834
|
+
blocks2[0] = this.block;
|
|
835
|
+
blocks2[16] = blocks2[1] = blocks2[2] = blocks2[3] = blocks2[4] = blocks2[5] = blocks2[6] = blocks2[7] = blocks2[8] = blocks2[9] = blocks2[10] = blocks2[11] = blocks2[12] = blocks2[13] = blocks2[14] = blocks2[15] = 0;
|
|
836
|
+
}
|
|
837
|
+
blocks2[14] = this.hBytes << 3 | this.bytes >>> 29;
|
|
838
|
+
blocks2[15] = this.bytes << 3;
|
|
839
|
+
this.hash();
|
|
840
|
+
};
|
|
841
|
+
Sha256.prototype.hash = function() {
|
|
842
|
+
var a = this.h0, b = this.h1, c = this.h2, d = this.h3, e = this.h4, f = this.h5, g = this.h6, h = this.h7, blocks2 = this.blocks, j, s0, s1, maj, t1, t2, ch, ab, da, cd, bc;
|
|
843
|
+
for(j = 16; j < 64; ++j){
|
|
844
|
+
t1 = blocks2[j - 15];
|
|
845
|
+
s0 = (t1 >>> 7 | t1 << 25) ^ (t1 >>> 18 | t1 << 14) ^ t1 >>> 3;
|
|
846
|
+
t1 = blocks2[j - 2];
|
|
847
|
+
s1 = (t1 >>> 17 | t1 << 15) ^ (t1 >>> 19 | t1 << 13) ^ t1 >>> 10;
|
|
848
|
+
blocks2[j] = blocks2[j - 16] + s0 + blocks2[j - 7] + s1 << 0;
|
|
849
|
+
}
|
|
850
|
+
bc = b & c;
|
|
851
|
+
for(j = 0; j < 64; j += 4){
|
|
852
|
+
if (this.first) {
|
|
853
|
+
if (this.is224) {
|
|
854
|
+
ab = 300032;
|
|
855
|
+
t1 = blocks2[0] - 1413257819;
|
|
856
|
+
h = t1 - 150054599 << 0;
|
|
857
|
+
d = t1 + 24177077 << 0;
|
|
858
|
+
} else {
|
|
859
|
+
ab = 704751109;
|
|
860
|
+
t1 = blocks2[0] - 210244248;
|
|
861
|
+
h = t1 - 1521486534 << 0;
|
|
862
|
+
d = t1 + 143694565 << 0;
|
|
863
|
+
}
|
|
864
|
+
this.first = false;
|
|
865
|
+
} else {
|
|
866
|
+
s0 = (a >>> 2 | a << 30) ^ (a >>> 13 | a << 19) ^ (a >>> 22 | a << 10);
|
|
867
|
+
s1 = (e >>> 6 | e << 26) ^ (e >>> 11 | e << 21) ^ (e >>> 25 | e << 7);
|
|
868
|
+
ab = a & b;
|
|
869
|
+
maj = ab ^ a & c ^ bc;
|
|
870
|
+
ch = e & f ^ ~e & g;
|
|
871
|
+
t1 = h + s1 + ch + K[j] + blocks2[j];
|
|
872
|
+
t2 = s0 + maj;
|
|
873
|
+
h = d + t1 << 0;
|
|
874
|
+
d = t1 + t2 << 0;
|
|
875
|
+
}
|
|
876
|
+
s0 = (d >>> 2 | d << 30) ^ (d >>> 13 | d << 19) ^ (d >>> 22 | d << 10);
|
|
877
|
+
s1 = (h >>> 6 | h << 26) ^ (h >>> 11 | h << 21) ^ (h >>> 25 | h << 7);
|
|
878
|
+
da = d & a;
|
|
879
|
+
maj = da ^ d & b ^ ab;
|
|
880
|
+
ch = h & e ^ ~h & f;
|
|
881
|
+
t1 = g + s1 + ch + K[j + 1] + blocks2[j + 1];
|
|
882
|
+
t2 = s0 + maj;
|
|
883
|
+
g = c + t1 << 0;
|
|
884
|
+
c = t1 + t2 << 0;
|
|
885
|
+
s0 = (c >>> 2 | c << 30) ^ (c >>> 13 | c << 19) ^ (c >>> 22 | c << 10);
|
|
886
|
+
s1 = (g >>> 6 | g << 26) ^ (g >>> 11 | g << 21) ^ (g >>> 25 | g << 7);
|
|
887
|
+
cd = c & d;
|
|
888
|
+
maj = cd ^ c & a ^ da;
|
|
889
|
+
ch = g & h ^ ~g & e;
|
|
890
|
+
t1 = f + s1 + ch + K[j + 2] + blocks2[j + 2];
|
|
891
|
+
t2 = s0 + maj;
|
|
892
|
+
f = b + t1 << 0;
|
|
893
|
+
b = t1 + t2 << 0;
|
|
894
|
+
s0 = (b >>> 2 | b << 30) ^ (b >>> 13 | b << 19) ^ (b >>> 22 | b << 10);
|
|
895
|
+
s1 = (f >>> 6 | f << 26) ^ (f >>> 11 | f << 21) ^ (f >>> 25 | f << 7);
|
|
896
|
+
bc = b & c;
|
|
897
|
+
maj = bc ^ b & d ^ cd;
|
|
898
|
+
ch = f & g ^ ~f & h;
|
|
899
|
+
t1 = e + s1 + ch + K[j + 3] + blocks2[j + 3];
|
|
900
|
+
t2 = s0 + maj;
|
|
901
|
+
e = a + t1 << 0;
|
|
902
|
+
a = t1 + t2 << 0;
|
|
903
|
+
this.chromeBugWorkAround = true;
|
|
904
|
+
}
|
|
905
|
+
this.h0 = this.h0 + a << 0;
|
|
906
|
+
this.h1 = this.h1 + b << 0;
|
|
907
|
+
this.h2 = this.h2 + c << 0;
|
|
908
|
+
this.h3 = this.h3 + d << 0;
|
|
909
|
+
this.h4 = this.h4 + e << 0;
|
|
910
|
+
this.h5 = this.h5 + f << 0;
|
|
911
|
+
this.h6 = this.h6 + g << 0;
|
|
912
|
+
this.h7 = this.h7 + h << 0;
|
|
913
|
+
};
|
|
914
|
+
Sha256.prototype.hex = function() {
|
|
915
|
+
this.finalize();
|
|
916
|
+
var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3, h4 = this.h4, h5 = this.h5, h6 = this.h6, h7 = this.h7;
|
|
917
|
+
var hex = HEX_CHARS[h0 >>> 28 & 15] + HEX_CHARS[h0 >>> 24 & 15] + HEX_CHARS[h0 >>> 20 & 15] + HEX_CHARS[h0 >>> 16 & 15] + HEX_CHARS[h0 >>> 12 & 15] + HEX_CHARS[h0 >>> 8 & 15] + HEX_CHARS[h0 >>> 4 & 15] + HEX_CHARS[h0 & 15] + HEX_CHARS[h1 >>> 28 & 15] + HEX_CHARS[h1 >>> 24 & 15] + HEX_CHARS[h1 >>> 20 & 15] + HEX_CHARS[h1 >>> 16 & 15] + HEX_CHARS[h1 >>> 12 & 15] + HEX_CHARS[h1 >>> 8 & 15] + HEX_CHARS[h1 >>> 4 & 15] + HEX_CHARS[h1 & 15] + HEX_CHARS[h2 >>> 28 & 15] + HEX_CHARS[h2 >>> 24 & 15] + HEX_CHARS[h2 >>> 20 & 15] + HEX_CHARS[h2 >>> 16 & 15] + HEX_CHARS[h2 >>> 12 & 15] + HEX_CHARS[h2 >>> 8 & 15] + HEX_CHARS[h2 >>> 4 & 15] + HEX_CHARS[h2 & 15] + HEX_CHARS[h3 >>> 28 & 15] + HEX_CHARS[h3 >>> 24 & 15] + HEX_CHARS[h3 >>> 20 & 15] + HEX_CHARS[h3 >>> 16 & 15] + HEX_CHARS[h3 >>> 12 & 15] + HEX_CHARS[h3 >>> 8 & 15] + HEX_CHARS[h3 >>> 4 & 15] + HEX_CHARS[h3 & 15] + HEX_CHARS[h4 >>> 28 & 15] + HEX_CHARS[h4 >>> 24 & 15] + HEX_CHARS[h4 >>> 20 & 15] + HEX_CHARS[h4 >>> 16 & 15] + HEX_CHARS[h4 >>> 12 & 15] + HEX_CHARS[h4 >>> 8 & 15] + HEX_CHARS[h4 >>> 4 & 15] + HEX_CHARS[h4 & 15] + HEX_CHARS[h5 >>> 28 & 15] + HEX_CHARS[h5 >>> 24 & 15] + HEX_CHARS[h5 >>> 20 & 15] + HEX_CHARS[h5 >>> 16 & 15] + HEX_CHARS[h5 >>> 12 & 15] + HEX_CHARS[h5 >>> 8 & 15] + HEX_CHARS[h5 >>> 4 & 15] + HEX_CHARS[h5 & 15] + HEX_CHARS[h6 >>> 28 & 15] + HEX_CHARS[h6 >>> 24 & 15] + HEX_CHARS[h6 >>> 20 & 15] + HEX_CHARS[h6 >>> 16 & 15] + HEX_CHARS[h6 >>> 12 & 15] + HEX_CHARS[h6 >>> 8 & 15] + HEX_CHARS[h6 >>> 4 & 15] + HEX_CHARS[h6 & 15];
|
|
918
|
+
if (!this.is224) {
|
|
919
|
+
hex += HEX_CHARS[h7 >>> 28 & 15] + HEX_CHARS[h7 >>> 24 & 15] + HEX_CHARS[h7 >>> 20 & 15] + HEX_CHARS[h7 >>> 16 & 15] + HEX_CHARS[h7 >>> 12 & 15] + HEX_CHARS[h7 >>> 8 & 15] + HEX_CHARS[h7 >>> 4 & 15] + HEX_CHARS[h7 & 15];
|
|
920
|
+
}
|
|
921
|
+
return hex;
|
|
922
|
+
};
|
|
923
|
+
Sha256.prototype.toString = Sha256.prototype.hex;
|
|
924
|
+
Sha256.prototype.digest = function() {
|
|
925
|
+
this.finalize();
|
|
926
|
+
var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3, h4 = this.h4, h5 = this.h5, h6 = this.h6, h7 = this.h7;
|
|
927
|
+
var arr = [
|
|
928
|
+
h0 >>> 24 & 255,
|
|
929
|
+
h0 >>> 16 & 255,
|
|
930
|
+
h0 >>> 8 & 255,
|
|
931
|
+
h0 & 255,
|
|
932
|
+
h1 >>> 24 & 255,
|
|
933
|
+
h1 >>> 16 & 255,
|
|
934
|
+
h1 >>> 8 & 255,
|
|
935
|
+
h1 & 255,
|
|
936
|
+
h2 >>> 24 & 255,
|
|
937
|
+
h2 >>> 16 & 255,
|
|
938
|
+
h2 >>> 8 & 255,
|
|
939
|
+
h2 & 255,
|
|
940
|
+
h3 >>> 24 & 255,
|
|
941
|
+
h3 >>> 16 & 255,
|
|
942
|
+
h3 >>> 8 & 255,
|
|
943
|
+
h3 & 255,
|
|
944
|
+
h4 >>> 24 & 255,
|
|
945
|
+
h4 >>> 16 & 255,
|
|
946
|
+
h4 >>> 8 & 255,
|
|
947
|
+
h4 & 255,
|
|
948
|
+
h5 >>> 24 & 255,
|
|
949
|
+
h5 >>> 16 & 255,
|
|
950
|
+
h5 >>> 8 & 255,
|
|
951
|
+
h5 & 255,
|
|
952
|
+
h6 >>> 24 & 255,
|
|
953
|
+
h6 >>> 16 & 255,
|
|
954
|
+
h6 >>> 8 & 255,
|
|
955
|
+
h6 & 255
|
|
956
|
+
];
|
|
957
|
+
if (!this.is224) {
|
|
958
|
+
arr.push(h7 >>> 24 & 255, h7 >>> 16 & 255, h7 >>> 8 & 255, h7 & 255);
|
|
959
|
+
}
|
|
960
|
+
return arr;
|
|
961
|
+
};
|
|
962
|
+
Sha256.prototype.array = Sha256.prototype.digest;
|
|
963
|
+
Sha256.prototype.arrayBuffer = function() {
|
|
964
|
+
this.finalize();
|
|
965
|
+
var buffer = new ArrayBuffer(this.is224 ? 28 : 32);
|
|
966
|
+
var dataView = new DataView(buffer);
|
|
967
|
+
dataView.setUint32(0, this.h0);
|
|
968
|
+
dataView.setUint32(4, this.h1);
|
|
969
|
+
dataView.setUint32(8, this.h2);
|
|
970
|
+
dataView.setUint32(12, this.h3);
|
|
971
|
+
dataView.setUint32(16, this.h4);
|
|
972
|
+
dataView.setUint32(20, this.h5);
|
|
973
|
+
dataView.setUint32(24, this.h6);
|
|
974
|
+
if (!this.is224) {
|
|
975
|
+
dataView.setUint32(28, this.h7);
|
|
976
|
+
}
|
|
977
|
+
return buffer;
|
|
978
|
+
};
|
|
979
|
+
function HmacSha256(key, is224, sharedMemory) {
|
|
980
|
+
var i, type = typeof key;
|
|
981
|
+
if (type === "string") {
|
|
982
|
+
var bytes = [], length = key.length, index = 0, code;
|
|
983
|
+
for(i = 0; i < length; ++i){
|
|
984
|
+
code = key.charCodeAt(i);
|
|
985
|
+
if (code < 128) {
|
|
986
|
+
bytes[index++] = code;
|
|
987
|
+
} else if (code < 2048) {
|
|
988
|
+
bytes[index++] = 192 | code >>> 6;
|
|
989
|
+
bytes[index++] = 128 | code & 63;
|
|
990
|
+
} else if (code < 55296 || code >= 57344) {
|
|
991
|
+
bytes[index++] = 224 | code >>> 12;
|
|
992
|
+
bytes[index++] = 128 | code >>> 6 & 63;
|
|
993
|
+
bytes[index++] = 128 | code & 63;
|
|
994
|
+
} else {
|
|
995
|
+
code = 65536 + ((code & 1023) << 10 | key.charCodeAt(++i) & 1023);
|
|
996
|
+
bytes[index++] = 240 | code >>> 18;
|
|
997
|
+
bytes[index++] = 128 | code >>> 12 & 63;
|
|
998
|
+
bytes[index++] = 128 | code >>> 6 & 63;
|
|
999
|
+
bytes[index++] = 128 | code & 63;
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
key = bytes;
|
|
1003
|
+
} else {
|
|
1004
|
+
if (type === "object") {
|
|
1005
|
+
if (key === null) {
|
|
1006
|
+
throw new Error(ERROR);
|
|
1007
|
+
} else if (ARRAY_BUFFER && key.constructor === ArrayBuffer) {
|
|
1008
|
+
key = new Uint8Array(key);
|
|
1009
|
+
} else if (!Array.isArray(key)) {
|
|
1010
|
+
if (!ARRAY_BUFFER || !ArrayBuffer.isView(key)) {
|
|
1011
|
+
throw new Error(ERROR);
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
} else {
|
|
1015
|
+
throw new Error(ERROR);
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
if (key.length > 64) {
|
|
1019
|
+
key = new Sha256(is224, true).update(key).array();
|
|
1020
|
+
}
|
|
1021
|
+
var oKeyPad = [], iKeyPad = [];
|
|
1022
|
+
for(i = 0; i < 64; ++i){
|
|
1023
|
+
var b = key[i] || 0;
|
|
1024
|
+
oKeyPad[i] = 92 ^ b;
|
|
1025
|
+
iKeyPad[i] = 54 ^ b;
|
|
1026
|
+
}
|
|
1027
|
+
Sha256.call(this, is224, sharedMemory);
|
|
1028
|
+
this.update(iKeyPad);
|
|
1029
|
+
this.oKeyPad = oKeyPad;
|
|
1030
|
+
this.inner = true;
|
|
1031
|
+
this.sharedMemory = sharedMemory;
|
|
1032
|
+
}
|
|
1033
|
+
HmacSha256.prototype = new Sha256();
|
|
1034
|
+
HmacSha256.prototype.finalize = function() {
|
|
1035
|
+
Sha256.prototype.finalize.call(this);
|
|
1036
|
+
if (this.inner) {
|
|
1037
|
+
this.inner = false;
|
|
1038
|
+
var innerHash = this.array();
|
|
1039
|
+
Sha256.call(this, this.is224, this.sharedMemory);
|
|
1040
|
+
this.update(this.oKeyPad);
|
|
1041
|
+
this.update(innerHash);
|
|
1042
|
+
Sha256.prototype.finalize.call(this);
|
|
1043
|
+
}
|
|
1044
|
+
};
|
|
1045
|
+
var exports2 = createMethod();
|
|
1046
|
+
exports2.sha256 = exports2;
|
|
1047
|
+
exports2.sha224 = createMethod(true);
|
|
1048
|
+
exports2.sha256.hmac = createHmacMethod();
|
|
1049
|
+
exports2.sha224.hmac = createHmacMethod(true);
|
|
1050
|
+
if (COMMON_JS) {
|
|
1051
|
+
module1.exports = exports2;
|
|
1052
|
+
} else {
|
|
1053
|
+
root.sha256 = exports2.sha256;
|
|
1054
|
+
root.sha224 = exports2.sha224;
|
|
1055
|
+
if (AMD) {
|
|
1056
|
+
define(function() {
|
|
1057
|
+
return exports2;
|
|
1058
|
+
});
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
})();
|
|
1062
|
+
}
|
|
1063
|
+
});
|
|
1064
|
+
// src/common/utils.ts
|
|
1065
|
+
var import_dayjs = __toESM(require_dayjs_min());
|
|
1066
|
+
// src/web-element.ts
|
|
1067
|
+
var WebElementInfo = class {
|
|
1068
|
+
constructor({ content, rect, page, locator, id, attributes, indexId }){
|
|
1069
|
+
this.content = content;
|
|
1070
|
+
this.rect = rect;
|
|
1071
|
+
this.center = [
|
|
1072
|
+
Math.floor(rect.left + rect.width / 2),
|
|
1073
|
+
Math.floor(rect.top + rect.height / 2)
|
|
1074
|
+
];
|
|
1075
|
+
this.page = page;
|
|
1076
|
+
this.locator = locator;
|
|
1077
|
+
this.id = id;
|
|
1078
|
+
this.attributes = attributes;
|
|
1079
|
+
this.indexId = indexId;
|
|
1080
|
+
}
|
|
1081
|
+
};
|
|
1082
|
+
// src/common/utils.ts
|
|
1083
|
+
function parseContextFromWebPage(page, _opt) {
|
|
1084
|
+
return __async(this, null, function*() {
|
|
1085
|
+
(0, _assert.default)(page, "page is required");
|
|
1086
|
+
if (page._forceUsePageContext) {
|
|
1087
|
+
return yield page._forceUsePageContext();
|
|
1088
|
+
}
|
|
1089
|
+
const url = page.url();
|
|
1090
|
+
let screenshotBase64;
|
|
1091
|
+
let elementsInfo;
|
|
1092
|
+
yield Promise.all([
|
|
1093
|
+
page.screenshotBase64().then((base64)=>{
|
|
1094
|
+
screenshotBase64 = base64;
|
|
1095
|
+
}),
|
|
1096
|
+
page.getElementInfos().then((snapshot)=>__async(this, null, function*() {
|
|
1097
|
+
elementsInfo = yield alignElements(snapshot, page);
|
|
1098
|
+
}))
|
|
1099
|
+
]);
|
|
1100
|
+
(0, _assert.default)(screenshotBase64, "screenshotBase64 is required");
|
|
1101
|
+
const elementsPositionInfoWithoutText = elementsInfo.filter((elementInfo)=>{
|
|
1102
|
+
if (elementInfo.attributes.nodeType === _constants.NodeType.TEXT) {
|
|
1103
|
+
return false;
|
|
1104
|
+
}
|
|
1105
|
+
return true;
|
|
1106
|
+
});
|
|
1107
|
+
const size = yield page.size();
|
|
1108
|
+
const width = size.width;
|
|
1109
|
+
const height = size.height;
|
|
1110
|
+
const screenshotBase64WithElementMarker = (_opt == null ? void 0 : _opt.ignoreMarker) ? void 0 : yield (0, _img.compositeElementInfoImg)({
|
|
1111
|
+
inputImgBase64: screenshotBase64,
|
|
1112
|
+
elementsPositionInfo: elementsPositionInfoWithoutText,
|
|
1113
|
+
size: {
|
|
1114
|
+
width,
|
|
1115
|
+
height
|
|
1116
|
+
}
|
|
1117
|
+
});
|
|
1118
|
+
return {
|
|
1119
|
+
content: elementsInfo,
|
|
1120
|
+
size: {
|
|
1121
|
+
width,
|
|
1122
|
+
height
|
|
1123
|
+
},
|
|
1124
|
+
screenshotBase64,
|
|
1125
|
+
screenshotBase64WithElementMarker,
|
|
1126
|
+
url
|
|
1127
|
+
};
|
|
1128
|
+
});
|
|
1129
|
+
}
|
|
1130
|
+
var sizeThreshold = 3;
|
|
1131
|
+
function alignElements(elements, page) {
|
|
1132
|
+
return __async(this, null, function*() {
|
|
1133
|
+
const validElements = elements.filter((item)=>{
|
|
1134
|
+
return item.rect.height >= sizeThreshold && item.rect.width >= sizeThreshold;
|
|
1135
|
+
});
|
|
1136
|
+
const textsAligned = [];
|
|
1137
|
+
for (const item of validElements){
|
|
1138
|
+
const { rect, id, content, attributes, locator, indexId } = item;
|
|
1139
|
+
textsAligned.push(new WebElementInfo({
|
|
1140
|
+
rect,
|
|
1141
|
+
locator,
|
|
1142
|
+
id,
|
|
1143
|
+
content,
|
|
1144
|
+
attributes,
|
|
1145
|
+
page,
|
|
1146
|
+
indexId
|
|
1147
|
+
}));
|
|
1148
|
+
}
|
|
1149
|
+
return textsAligned;
|
|
1150
|
+
});
|
|
1151
|
+
}
|
|
1152
|
+
function reportFileName(tag = "web") {
|
|
1153
|
+
const dateTimeInFileName = (0, import_dayjs.default)().format("YYYY-MM-DD_HH-mm-ss-SSS");
|
|
1154
|
+
return `${tag}-${dateTimeInFileName}`;
|
|
1155
|
+
}
|
|
1156
|
+
function printReportMsg(filepath) {
|
|
1157
|
+
console.log("Midscene - report file updated:", filepath);
|
|
1158
|
+
}
|
|
1159
|
+
function getCurrentExecutionFile(trace) {
|
|
1160
|
+
const error = new Error();
|
|
1161
|
+
const stackTrace = trace || error.stack;
|
|
1162
|
+
const pkgDir = process.cwd() || "";
|
|
1163
|
+
if (stackTrace) {
|
|
1164
|
+
const stackLines = stackTrace.split("\n");
|
|
1165
|
+
for (const line of stackLines){
|
|
1166
|
+
if (line.includes(".spec.") || line.includes(".test.") || line.includes(".ts") || line.includes(".js")) {
|
|
1167
|
+
const match = line.match(/(?:at\s+)?(.*?\.(?:spec|test)\.[jt]s)/);
|
|
1168
|
+
if (match == null ? void 0 : match[1]) {
|
|
1169
|
+
const targetFileName = match[1].replace(pkgDir, "").trim().replace("at ", "");
|
|
1170
|
+
return targetFileName;
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
491
1173
|
}
|
|
492
|
-
}
|
|
493
|
-
if (Array.isArray(message) || ArrayBuffer.isView(message) || message.constructor === Buffer2) {
|
|
494
|
-
return crypto.createHash(algorithm).update(bufferFrom(message)).digest("hex");
|
|
495
|
-
} else {
|
|
496
|
-
return method(message);
|
|
497
|
-
}
|
|
498
|
-
};
|
|
499
|
-
return nodeMethod;
|
|
500
|
-
};
|
|
501
|
-
var createHmacOutputMethod = function(outputType, is224) {
|
|
502
|
-
return function(key, message) {
|
|
503
|
-
return new HmacSha256(key, is224, true).update(message)[outputType]();
|
|
504
|
-
};
|
|
505
|
-
};
|
|
506
|
-
var createHmacMethod = function(is224) {
|
|
507
|
-
var method = createHmacOutputMethod("hex", is224);
|
|
508
|
-
method.create = function(key) {
|
|
509
|
-
return new HmacSha256(key, is224);
|
|
510
|
-
};
|
|
511
|
-
method.update = function(key, message) {
|
|
512
|
-
return method.create(key).update(message);
|
|
513
|
-
};
|
|
514
|
-
for (var i = 0; i < OUTPUT_TYPES.length; ++i) {
|
|
515
|
-
var type = OUTPUT_TYPES[i];
|
|
516
|
-
method[type] = createHmacOutputMethod(type, is224);
|
|
517
1174
|
}
|
|
518
|
-
return
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
1175
|
+
return false;
|
|
1176
|
+
}
|
|
1177
|
+
var testFileIndex = /* @__PURE__ */ new Map();
|
|
1178
|
+
function generateCacheId(fileName) {
|
|
1179
|
+
let taskFile = fileName || getCurrentExecutionFile();
|
|
1180
|
+
if (!taskFile) {
|
|
1181
|
+
taskFile = (0, _utils1.uuid)();
|
|
1182
|
+
console.warn("Midscene - using random UUID for cache id. Cache may be invalid.");
|
|
526
1183
|
}
|
|
527
|
-
if (
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
this.h4 = 4290775857;
|
|
533
|
-
this.h5 = 1750603025;
|
|
534
|
-
this.h6 = 1694076839;
|
|
535
|
-
this.h7 = 3204075428;
|
|
1184
|
+
if (testFileIndex.has(taskFile)) {
|
|
1185
|
+
const currentIndex = testFileIndex.get(taskFile);
|
|
1186
|
+
if (currentIndex !== void 0) {
|
|
1187
|
+
testFileIndex.set(taskFile, currentIndex + 1);
|
|
1188
|
+
}
|
|
536
1189
|
} else {
|
|
537
|
-
|
|
538
|
-
this.h1 = 3144134277;
|
|
539
|
-
this.h2 = 1013904242;
|
|
540
|
-
this.h3 = 2773480762;
|
|
541
|
-
this.h4 = 1359893119;
|
|
542
|
-
this.h5 = 2600822924;
|
|
543
|
-
this.h6 = 528734635;
|
|
544
|
-
this.h7 = 1541459225;
|
|
1190
|
+
testFileIndex.set(taskFile, 1);
|
|
545
1191
|
}
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
1192
|
+
return `${taskFile}-${testFileIndex.get(taskFile)}`;
|
|
1193
|
+
}
|
|
1194
|
+
// src/common/task-cache.ts
|
|
1195
|
+
var TaskCache = class {
|
|
1196
|
+
getCacheGroupByPrompt(aiActionPrompt) {
|
|
1197
|
+
const { aiTasks = [] } = this.cache || {
|
|
1198
|
+
aiTasks: []
|
|
1199
|
+
};
|
|
1200
|
+
const index = aiTasks.findIndex((item)=>item.prompt === aiActionPrompt);
|
|
1201
|
+
const newCacheGroup = [];
|
|
1202
|
+
this.newCache.aiTasks.push({
|
|
1203
|
+
prompt: aiActionPrompt,
|
|
1204
|
+
tasks: newCacheGroup
|
|
1205
|
+
});
|
|
1206
|
+
return {
|
|
1207
|
+
readCache: (pageContext, type, actionPrompt)=>{
|
|
1208
|
+
if (index === -1) {
|
|
1209
|
+
return false;
|
|
1210
|
+
}
|
|
1211
|
+
if (type === "plan") {
|
|
1212
|
+
return this.readCache(pageContext, type, actionPrompt, aiTasks[index].tasks);
|
|
1213
|
+
}
|
|
1214
|
+
return this.readCache(pageContext, type, actionPrompt, aiTasks[index].tasks);
|
|
1215
|
+
},
|
|
1216
|
+
saveCache: (cache)=>{
|
|
1217
|
+
newCacheGroup.push(cache);
|
|
1218
|
+
this.writeCacheToFile();
|
|
1219
|
+
}
|
|
1220
|
+
};
|
|
554
1221
|
}
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
1222
|
+
readCache(pageContext, type, userPrompt, cacheGroup) {
|
|
1223
|
+
var _a;
|
|
1224
|
+
if (cacheGroup.length > 0) {
|
|
1225
|
+
const index = cacheGroup.findIndex((item)=>item.prompt === userPrompt);
|
|
1226
|
+
if (index === -1) {
|
|
1227
|
+
return false;
|
|
1228
|
+
}
|
|
1229
|
+
const taskRes = cacheGroup.splice(index, 1)[0];
|
|
1230
|
+
if ((taskRes == null ? void 0 : taskRes.type) === "locate" && !((_a = taskRes.response) == null ? void 0 : _a.elements.every((element)=>{
|
|
1231
|
+
const findIndex = pageContext.content.findIndex((contentElement)=>contentElement.id === element.id);
|
|
1232
|
+
if (findIndex === -1) {
|
|
1233
|
+
return false;
|
|
1234
|
+
}
|
|
1235
|
+
return true;
|
|
1236
|
+
}))) {
|
|
1237
|
+
return false;
|
|
1238
|
+
}
|
|
1239
|
+
if (taskRes && taskRes.type === type && taskRes.prompt === userPrompt && this.pageContextEqual(taskRes.pageContext, pageContext)) {
|
|
1240
|
+
return taskRes.response;
|
|
1241
|
+
}
|
|
566
1242
|
}
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
1243
|
+
return false;
|
|
1244
|
+
}
|
|
1245
|
+
pageContextEqual(taskPageContext, pageContext) {
|
|
1246
|
+
return taskPageContext.size.width === pageContext.size.width && taskPageContext.size.height === pageContext.size.height;
|
|
571
1247
|
}
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
1248
|
+
/**
|
|
1249
|
+
* Generate task cache data.
|
|
1250
|
+
* This method is mainly used to create or obtain some cached data for tasks, and it returns a new cache object.
|
|
1251
|
+
* In the cache object, it may contain task-related information, states, or other necessary data.
|
|
1252
|
+
* It is assumed that the `newCache` property already exists in the current class or object and is a data structure used to store task cache.
|
|
1253
|
+
* @returns {Object} Returns a new cache object, which may include task cache data.
|
|
1254
|
+
*/ generateTaskCache() {
|
|
1255
|
+
return this.newCache;
|
|
1256
|
+
}
|
|
1257
|
+
readCacheFromFile() {
|
|
1258
|
+
if (_utils1.ifInBrowser) {
|
|
1259
|
+
return void 0;
|
|
1260
|
+
}
|
|
1261
|
+
const cacheFile = (0, _path.join)((0, _utils.getLogDirByType)("cache"), `${this.cacheId}.json`);
|
|
1262
|
+
if (process.env.MIDSCENE_CACHE === "true" && (0, _fs.existsSync)(cacheFile)) {
|
|
1263
|
+
try {
|
|
1264
|
+
const data = (0, _fs.readFileSync)(cacheFile, "utf8");
|
|
1265
|
+
const jsonData = JSON.parse(data);
|
|
1266
|
+
if (!this.midscenePkgInfo) {
|
|
1267
|
+
return void 0;
|
|
1268
|
+
}
|
|
1269
|
+
if (jsonData.pkgName !== this.midscenePkgInfo.name || jsonData.pkgVersion !== this.midscenePkgInfo.version) {
|
|
1270
|
+
return void 0;
|
|
1271
|
+
}
|
|
1272
|
+
return jsonData;
|
|
1273
|
+
} catch (err) {
|
|
1274
|
+
return void 0;
|
|
1275
|
+
}
|
|
582
1276
|
}
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
blocks2[i >>> 2] |= (192 | code >>> 6) << SHIFT[i++ & 3];
|
|
590
|
-
blocks2[i >>> 2] |= (128 | code & 63) << SHIFT[i++ & 3];
|
|
591
|
-
} else if (code < 55296 || code >= 57344) {
|
|
592
|
-
blocks2[i >>> 2] |= (224 | code >>> 12) << SHIFT[i++ & 3];
|
|
593
|
-
blocks2[i >>> 2] |= (128 | code >>> 6 & 63) << SHIFT[i++ & 3];
|
|
594
|
-
blocks2[i >>> 2] |= (128 | code & 63) << SHIFT[i++ & 3];
|
|
595
|
-
} else {
|
|
596
|
-
code = 65536 + ((code & 1023) << 10 | message.charCodeAt(++index) & 1023);
|
|
597
|
-
blocks2[i >>> 2] |= (240 | code >>> 18) << SHIFT[i++ & 3];
|
|
598
|
-
blocks2[i >>> 2] |= (128 | code >>> 12 & 63) << SHIFT[i++ & 3];
|
|
599
|
-
blocks2[i >>> 2] |= (128 | code >>> 6 & 63) << SHIFT[i++ & 3];
|
|
600
|
-
blocks2[i >>> 2] |= (128 | code & 63) << SHIFT[i++ & 3];
|
|
601
|
-
}
|
|
1277
|
+
return void 0;
|
|
1278
|
+
}
|
|
1279
|
+
writeCacheToFile() {
|
|
1280
|
+
const midscenePkgInfo = (0, _fs1.getRunningPkgInfo)();
|
|
1281
|
+
if (!midscenePkgInfo) {
|
|
1282
|
+
return;
|
|
602
1283
|
}
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
}
|
|
1284
|
+
(0, _utils.writeLogFile)({
|
|
1285
|
+
fileName: `${this.cacheId}`,
|
|
1286
|
+
fileExt: "json",
|
|
1287
|
+
fileContent: (0, _utils.stringifyDumpData)(__spreadValues({
|
|
1288
|
+
pkgName: midscenePkgInfo.name,
|
|
1289
|
+
pkgVersion: midscenePkgInfo.version,
|
|
1290
|
+
cacheId: this.cacheId
|
|
1291
|
+
}, this.newCache), 2),
|
|
1292
|
+
type: "cache"
|
|
1293
|
+
});
|
|
614
1294
|
}
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
1295
|
+
constructor(opts){
|
|
1296
|
+
this.midscenePkgInfo = (0, _fs1.getRunningPkgInfo)();
|
|
1297
|
+
this.cacheId = generateCacheId(opts == null ? void 0 : opts.fileName);
|
|
1298
|
+
this.cache = this.readCacheFromFile() || {
|
|
1299
|
+
aiTasks: []
|
|
1300
|
+
};
|
|
1301
|
+
this.newCache = {
|
|
1302
|
+
aiTasks: []
|
|
1303
|
+
};
|
|
618
1304
|
}
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
1305
|
+
};
|
|
1306
|
+
// src/common/tasks.ts
|
|
1307
|
+
var PageTaskExecutor = class {
|
|
1308
|
+
recordScreenshot(timing) {
|
|
1309
|
+
return __async(this, null, function*() {
|
|
1310
|
+
const base64 = yield this.page.screenshotBase64();
|
|
1311
|
+
const item = {
|
|
1312
|
+
type: "screenshot",
|
|
1313
|
+
ts: Date.now(),
|
|
1314
|
+
screenshot: base64,
|
|
1315
|
+
timing
|
|
1316
|
+
};
|
|
1317
|
+
return item;
|
|
1318
|
+
});
|
|
624
1319
|
}
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
1320
|
+
wrapExecutorWithScreenshot(taskApply) {
|
|
1321
|
+
const taskWithScreenshot = __spreadProps(__spreadValues({}, taskApply), {
|
|
1322
|
+
executor: (param, context, ...args)=>__async(this, null, function*() {
|
|
1323
|
+
const recorder = [];
|
|
1324
|
+
const { task } = context;
|
|
1325
|
+
task.recorder = recorder;
|
|
1326
|
+
const shot = yield this.recordScreenshot(`before ${task.type}`);
|
|
1327
|
+
recorder.push(shot);
|
|
1328
|
+
const result = yield taskApply.executor(param, context, ...args);
|
|
1329
|
+
if (taskApply.type === "Action") {
|
|
1330
|
+
yield (0, _utils.sleep)(1e3);
|
|
1331
|
+
const shot2 = yield this.recordScreenshot("after Action");
|
|
1332
|
+
recorder.push(shot2);
|
|
1333
|
+
}
|
|
1334
|
+
return result;
|
|
1335
|
+
})
|
|
1336
|
+
});
|
|
1337
|
+
return taskWithScreenshot;
|
|
636
1338
|
}
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
1339
|
+
convertPlanToExecutable(plans, cacheGroup) {
|
|
1340
|
+
return __async(this, null, function*() {
|
|
1341
|
+
const tasks = plans.map((plan2)=>{
|
|
1342
|
+
if (plan2.type === "Locate") {
|
|
1343
|
+
const taskFind = {
|
|
1344
|
+
type: "Insight",
|
|
1345
|
+
subType: "Locate",
|
|
1346
|
+
param: plan2.param,
|
|
1347
|
+
executor: (param, taskContext)=>__async(this, null, function*() {
|
|
1348
|
+
const { task } = taskContext;
|
|
1349
|
+
let insightDump;
|
|
1350
|
+
const dumpCollector = (dump)=>{
|
|
1351
|
+
insightDump = dump;
|
|
1352
|
+
};
|
|
1353
|
+
this.insight.onceDumpUpdatedFn = dumpCollector;
|
|
1354
|
+
const pageContext = yield this.insight.contextRetrieverFn();
|
|
1355
|
+
const locateCache = cacheGroup == null ? void 0 : cacheGroup.readCache(pageContext, "locate", param.prompt);
|
|
1356
|
+
let locateResult;
|
|
1357
|
+
const callAI = this.insight.aiVendorFn;
|
|
1358
|
+
const element = yield this.insight.locate(param.prompt, {
|
|
1359
|
+
quickAnswer: plan2.quickAnswer,
|
|
1360
|
+
callAI: (...message)=>__async(this, null, function*() {
|
|
1361
|
+
if (locateCache) {
|
|
1362
|
+
locateResult = locateCache;
|
|
1363
|
+
return Promise.resolve(locateCache);
|
|
1364
|
+
}
|
|
1365
|
+
locateResult = yield callAI(...message);
|
|
1366
|
+
(0, _assert.default)(locateResult);
|
|
1367
|
+
return locateResult;
|
|
1368
|
+
})
|
|
1369
|
+
});
|
|
1370
|
+
if (locateResult) {
|
|
1371
|
+
cacheGroup == null ? void 0 : cacheGroup.saveCache({
|
|
1372
|
+
type: "locate",
|
|
1373
|
+
pageContext: {
|
|
1374
|
+
url: pageContext.url,
|
|
1375
|
+
size: pageContext.size
|
|
1376
|
+
},
|
|
1377
|
+
prompt: param.prompt,
|
|
1378
|
+
response: locateResult
|
|
1379
|
+
});
|
|
1380
|
+
}
|
|
1381
|
+
if (!element) {
|
|
1382
|
+
task.log = {
|
|
1383
|
+
dump: insightDump
|
|
1384
|
+
};
|
|
1385
|
+
throw new Error(`Element not found: ${param.prompt}`);
|
|
1386
|
+
}
|
|
1387
|
+
return {
|
|
1388
|
+
output: {
|
|
1389
|
+
element
|
|
1390
|
+
},
|
|
1391
|
+
log: {
|
|
1392
|
+
dump: insightDump
|
|
1393
|
+
},
|
|
1394
|
+
cache: {
|
|
1395
|
+
hit: Boolean(locateCache)
|
|
1396
|
+
}
|
|
1397
|
+
};
|
|
1398
|
+
})
|
|
1399
|
+
};
|
|
1400
|
+
return taskFind;
|
|
1401
|
+
}
|
|
1402
|
+
if (plan2.type === "Assert" || plan2.type === "AssertWithoutThrow") {
|
|
1403
|
+
const assertPlan = plan2;
|
|
1404
|
+
const taskAssert = {
|
|
1405
|
+
type: "Insight",
|
|
1406
|
+
subType: "Assert",
|
|
1407
|
+
param: assertPlan.param,
|
|
1408
|
+
executor: (param, taskContext)=>__async(this, null, function*() {
|
|
1409
|
+
const { task } = taskContext;
|
|
1410
|
+
let insightDump;
|
|
1411
|
+
const dumpCollector = (dump)=>{
|
|
1412
|
+
insightDump = dump;
|
|
1413
|
+
};
|
|
1414
|
+
this.insight.onceDumpUpdatedFn = dumpCollector;
|
|
1415
|
+
const assertion = yield this.insight.assert(assertPlan.param.assertion);
|
|
1416
|
+
if (!assertion.pass) {
|
|
1417
|
+
if (plan2.type === "Assert") {
|
|
1418
|
+
task.output = assertion;
|
|
1419
|
+
task.log = {
|
|
1420
|
+
dump: insightDump
|
|
1421
|
+
};
|
|
1422
|
+
throw new Error(assertion.thought || "Assertion failed without reason");
|
|
1423
|
+
}
|
|
1424
|
+
task.error = assertion.thought;
|
|
1425
|
+
}
|
|
1426
|
+
return {
|
|
1427
|
+
output: assertion,
|
|
1428
|
+
log: {
|
|
1429
|
+
dump: insightDump
|
|
1430
|
+
}
|
|
1431
|
+
};
|
|
1432
|
+
})
|
|
1433
|
+
};
|
|
1434
|
+
return taskAssert;
|
|
1435
|
+
}
|
|
1436
|
+
if (plan2.type === "Input") {
|
|
1437
|
+
const taskActionInput = {
|
|
1438
|
+
type: "Action",
|
|
1439
|
+
subType: "Input",
|
|
1440
|
+
param: plan2.param,
|
|
1441
|
+
executor: (_0, _1)=>__async(this, [
|
|
1442
|
+
_0,
|
|
1443
|
+
_1
|
|
1444
|
+
], function*(taskParam, { element }) {
|
|
1445
|
+
if (element) {
|
|
1446
|
+
yield this.page.clearInput(element);
|
|
1447
|
+
if (taskParam.value === "") {
|
|
1448
|
+
return;
|
|
1449
|
+
}
|
|
1450
|
+
yield this.page.keyboard.type(taskParam.value);
|
|
1451
|
+
}
|
|
1452
|
+
})
|
|
1453
|
+
};
|
|
1454
|
+
return taskActionInput;
|
|
1455
|
+
}
|
|
1456
|
+
if (plan2.type === "KeyboardPress") {
|
|
1457
|
+
const taskActionKeyboardPress = {
|
|
1458
|
+
type: "Action",
|
|
1459
|
+
subType: "KeyboardPress",
|
|
1460
|
+
param: plan2.param,
|
|
1461
|
+
executor: (taskParam)=>__async(this, null, function*() {
|
|
1462
|
+
(0, _assert.default)(taskParam.value, "No key to press");
|
|
1463
|
+
yield this.page.keyboard.press(taskParam.value);
|
|
1464
|
+
})
|
|
1465
|
+
};
|
|
1466
|
+
return taskActionKeyboardPress;
|
|
1467
|
+
}
|
|
1468
|
+
if (plan2.type === "Tap") {
|
|
1469
|
+
const taskActionTap = {
|
|
1470
|
+
type: "Action",
|
|
1471
|
+
subType: "Tap",
|
|
1472
|
+
executor: (_0, _1)=>__async(this, [
|
|
1473
|
+
_0,
|
|
1474
|
+
_1
|
|
1475
|
+
], function*(param, { element }) {
|
|
1476
|
+
(0, _assert.default)(element, "Element not found, cannot tap");
|
|
1477
|
+
yield this.page.mouse.click(element.center[0], element.center[1]);
|
|
1478
|
+
})
|
|
1479
|
+
};
|
|
1480
|
+
return taskActionTap;
|
|
1481
|
+
}
|
|
1482
|
+
if (plan2.type === "Hover") {
|
|
1483
|
+
const taskActionHover = {
|
|
1484
|
+
type: "Action",
|
|
1485
|
+
subType: "Hover",
|
|
1486
|
+
executor: (_0, _1)=>__async(this, [
|
|
1487
|
+
_0,
|
|
1488
|
+
_1
|
|
1489
|
+
], function*(param, { element }) {
|
|
1490
|
+
(0, _assert.default)(element, "Element not found, cannot hover");
|
|
1491
|
+
yield this.page.mouse.move(element.center[0], element.center[1]);
|
|
1492
|
+
})
|
|
1493
|
+
};
|
|
1494
|
+
return taskActionHover;
|
|
1495
|
+
}
|
|
1496
|
+
if (plan2.type === "Scroll") {
|
|
1497
|
+
const taskActionScroll = {
|
|
1498
|
+
type: "Action",
|
|
1499
|
+
subType: "Scroll",
|
|
1500
|
+
param: plan2.param,
|
|
1501
|
+
executor: (taskParam)=>__async(this, null, function*() {
|
|
1502
|
+
const scrollToEventName = taskParam.scrollType;
|
|
1503
|
+
switch(scrollToEventName){
|
|
1504
|
+
case "scrollUntilTop":
|
|
1505
|
+
yield this.page.scrollUntilTop();
|
|
1506
|
+
break;
|
|
1507
|
+
case "scrollUntilBottom":
|
|
1508
|
+
yield this.page.scrollUntilBottom();
|
|
1509
|
+
break;
|
|
1510
|
+
case "scrollUpOneScreen":
|
|
1511
|
+
yield this.page.scrollUpOneScreen();
|
|
1512
|
+
break;
|
|
1513
|
+
case "scrollDownOneScreen":
|
|
1514
|
+
yield this.page.scrollDownOneScreen();
|
|
1515
|
+
break;
|
|
1516
|
+
default:
|
|
1517
|
+
console.error("Unknown scroll event type:", scrollToEventName);
|
|
1518
|
+
}
|
|
1519
|
+
})
|
|
1520
|
+
};
|
|
1521
|
+
return taskActionScroll;
|
|
1522
|
+
}
|
|
1523
|
+
if (plan2.type === "Sleep") {
|
|
1524
|
+
const taskActionSleep = {
|
|
1525
|
+
type: "Action",
|
|
1526
|
+
subType: "Sleep",
|
|
1527
|
+
param: plan2.param,
|
|
1528
|
+
executor: (taskParam)=>__async(this, null, function*() {
|
|
1529
|
+
yield (0, _utils.sleep)(taskParam.timeMs || 3e3);
|
|
1530
|
+
})
|
|
1531
|
+
};
|
|
1532
|
+
return taskActionSleep;
|
|
1533
|
+
}
|
|
1534
|
+
if (plan2.type === "Error") {
|
|
1535
|
+
const taskActionError = {
|
|
1536
|
+
type: "Action",
|
|
1537
|
+
subType: "Error",
|
|
1538
|
+
param: plan2.param,
|
|
1539
|
+
executor: (taskParam)=>__async(this, null, function*() {
|
|
1540
|
+
(0, _assert.default)(taskParam.thought, "An error occurred, but no thought provided");
|
|
1541
|
+
throw new Error(taskParam.thought);
|
|
1542
|
+
})
|
|
1543
|
+
};
|
|
1544
|
+
return taskActionError;
|
|
1545
|
+
}
|
|
1546
|
+
throw new Error(`Unknown or Unsupported task type: ${plan2.type}`);
|
|
1547
|
+
}).map((task)=>{
|
|
1548
|
+
return this.wrapExecutorWithScreenshot(task);
|
|
1549
|
+
});
|
|
1550
|
+
return tasks;
|
|
1551
|
+
});
|
|
649
1552
|
}
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
1553
|
+
action(userPrompt) {
|
|
1554
|
+
return __async(this, null, function*() {
|
|
1555
|
+
const taskExecutor = new _core.Executor(userPrompt);
|
|
1556
|
+
const cacheGroup = this.taskCache.getCacheGroupByPrompt(userPrompt);
|
|
1557
|
+
let plans = [];
|
|
1558
|
+
const planningTask = {
|
|
1559
|
+
type: "Planning",
|
|
1560
|
+
param: {
|
|
1561
|
+
userPrompt
|
|
1562
|
+
},
|
|
1563
|
+
executor: (param)=>__async(this, null, function*() {
|
|
1564
|
+
const pageContext = yield this.insight.contextRetrieverFn();
|
|
1565
|
+
let planResult;
|
|
1566
|
+
const planCache = cacheGroup.readCache(pageContext, "plan", userPrompt);
|
|
1567
|
+
if (planCache) {
|
|
1568
|
+
planResult = planCache;
|
|
1569
|
+
} else {
|
|
1570
|
+
planResult = yield (0, _core.plan)(param.userPrompt, {
|
|
1571
|
+
context: pageContext
|
|
1572
|
+
});
|
|
1573
|
+
}
|
|
1574
|
+
(0, _assert.default)(planResult.plans.length > 0, "No plans found");
|
|
1575
|
+
plans = planResult.plans;
|
|
1576
|
+
cacheGroup.saveCache({
|
|
1577
|
+
type: "plan",
|
|
1578
|
+
pageContext: {
|
|
1579
|
+
url: pageContext.url,
|
|
1580
|
+
size: pageContext.size
|
|
1581
|
+
},
|
|
1582
|
+
prompt: userPrompt,
|
|
1583
|
+
response: planResult
|
|
1584
|
+
});
|
|
1585
|
+
return {
|
|
1586
|
+
output: planResult,
|
|
1587
|
+
cache: {
|
|
1588
|
+
hit: Boolean(planCache)
|
|
1589
|
+
}
|
|
1590
|
+
};
|
|
1591
|
+
})
|
|
1592
|
+
};
|
|
1593
|
+
yield taskExecutor.append(this.wrapExecutorWithScreenshot(planningTask));
|
|
1594
|
+
let output = yield taskExecutor.flush();
|
|
1595
|
+
if (taskExecutor.isInErrorState()) {
|
|
1596
|
+
return {
|
|
1597
|
+
output,
|
|
1598
|
+
executor: taskExecutor
|
|
1599
|
+
};
|
|
1600
|
+
}
|
|
1601
|
+
const executables = yield this.convertPlanToExecutable(plans, cacheGroup);
|
|
1602
|
+
yield taskExecutor.append(executables);
|
|
1603
|
+
output = yield taskExecutor.flush();
|
|
1604
|
+
return {
|
|
1605
|
+
output,
|
|
1606
|
+
executor: taskExecutor
|
|
1607
|
+
};
|
|
1608
|
+
});
|
|
704
1609
|
}
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
1610
|
+
query(demand) {
|
|
1611
|
+
return __async(this, null, function*() {
|
|
1612
|
+
const description = typeof demand === "string" ? demand : JSON.stringify(demand);
|
|
1613
|
+
const taskExecutor = new _core.Executor(description);
|
|
1614
|
+
const queryTask = {
|
|
1615
|
+
type: "Insight",
|
|
1616
|
+
subType: "Query",
|
|
1617
|
+
param: {
|
|
1618
|
+
dataDemand: demand
|
|
1619
|
+
},
|
|
1620
|
+
executor: (param)=>__async(this, null, function*() {
|
|
1621
|
+
let insightDump;
|
|
1622
|
+
const dumpCollector = (dump)=>{
|
|
1623
|
+
insightDump = dump;
|
|
1624
|
+
};
|
|
1625
|
+
this.insight.onceDumpUpdatedFn = dumpCollector;
|
|
1626
|
+
const data = yield this.insight.extract(param.dataDemand);
|
|
1627
|
+
return {
|
|
1628
|
+
output: data,
|
|
1629
|
+
log: {
|
|
1630
|
+
dump: insightDump
|
|
1631
|
+
}
|
|
1632
|
+
};
|
|
1633
|
+
})
|
|
1634
|
+
};
|
|
1635
|
+
yield taskExecutor.append(this.wrapExecutorWithScreenshot(queryTask));
|
|
1636
|
+
const output = yield taskExecutor.flush();
|
|
1637
|
+
return {
|
|
1638
|
+
output,
|
|
1639
|
+
executor: taskExecutor
|
|
1640
|
+
};
|
|
1641
|
+
});
|
|
720
1642
|
}
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
h3 >>> 16 & 255,
|
|
742
|
-
h3 >>> 8 & 255,
|
|
743
|
-
h3 & 255,
|
|
744
|
-
h4 >>> 24 & 255,
|
|
745
|
-
h4 >>> 16 & 255,
|
|
746
|
-
h4 >>> 8 & 255,
|
|
747
|
-
h4 & 255,
|
|
748
|
-
h5 >>> 24 & 255,
|
|
749
|
-
h5 >>> 16 & 255,
|
|
750
|
-
h5 >>> 8 & 255,
|
|
751
|
-
h5 & 255,
|
|
752
|
-
h6 >>> 24 & 255,
|
|
753
|
-
h6 >>> 16 & 255,
|
|
754
|
-
h6 >>> 8 & 255,
|
|
755
|
-
h6 & 255
|
|
756
|
-
];
|
|
757
|
-
if (!this.is224) {
|
|
758
|
-
arr.push(h7 >>> 24 & 255, h7 >>> 16 & 255, h7 >>> 8 & 255, h7 & 255);
|
|
1643
|
+
assert(assertion) {
|
|
1644
|
+
return __async(this, null, function*() {
|
|
1645
|
+
const description = `assert: ${assertion}`;
|
|
1646
|
+
const taskExecutor = new _core.Executor(description);
|
|
1647
|
+
const assertionPlan = {
|
|
1648
|
+
type: "Assert",
|
|
1649
|
+
param: {
|
|
1650
|
+
assertion
|
|
1651
|
+
}
|
|
1652
|
+
};
|
|
1653
|
+
const assertTask = yield this.convertPlanToExecutable([
|
|
1654
|
+
assertionPlan
|
|
1655
|
+
]);
|
|
1656
|
+
yield taskExecutor.append(this.wrapExecutorWithScreenshot(assertTask[0]));
|
|
1657
|
+
const output = yield taskExecutor.flush();
|
|
1658
|
+
return {
|
|
1659
|
+
output,
|
|
1660
|
+
executor: taskExecutor
|
|
1661
|
+
};
|
|
1662
|
+
});
|
|
759
1663
|
}
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
1664
|
+
waitFor(assertion, opt) {
|
|
1665
|
+
return __async(this, null, function*() {
|
|
1666
|
+
const description = `waitFor: ${assertion}`;
|
|
1667
|
+
const taskExecutor = new _core.Executor(description);
|
|
1668
|
+
const { timeoutMs, checkIntervalMs } = opt;
|
|
1669
|
+
(0, _assert.default)(assertion, "No assertion for waitFor");
|
|
1670
|
+
(0, _assert.default)(timeoutMs, "No timeoutMs for waitFor");
|
|
1671
|
+
(0, _assert.default)(checkIntervalMs, "No checkIntervalMs for waitFor");
|
|
1672
|
+
const overallStartTime = Date.now();
|
|
1673
|
+
let startTime = Date.now();
|
|
1674
|
+
let errorThought = "";
|
|
1675
|
+
while(Date.now() - overallStartTime < timeoutMs){
|
|
1676
|
+
startTime = Date.now();
|
|
1677
|
+
const assertPlan = {
|
|
1678
|
+
type: "AssertWithoutThrow",
|
|
1679
|
+
param: {
|
|
1680
|
+
assertion
|
|
1681
|
+
}
|
|
1682
|
+
};
|
|
1683
|
+
const assertTask = yield this.convertPlanToExecutable([
|
|
1684
|
+
assertPlan
|
|
1685
|
+
]);
|
|
1686
|
+
yield taskExecutor.append(this.wrapExecutorWithScreenshot(assertTask[0]));
|
|
1687
|
+
const output = yield taskExecutor.flush();
|
|
1688
|
+
if (output == null ? void 0 : output.pass) {
|
|
1689
|
+
return {
|
|
1690
|
+
output: void 0,
|
|
1691
|
+
executor: taskExecutor
|
|
1692
|
+
};
|
|
1693
|
+
}
|
|
1694
|
+
errorThought = (output == null ? void 0 : output.thought) || "unknown error";
|
|
1695
|
+
const now = Date.now();
|
|
1696
|
+
if (now - startTime < checkIntervalMs) {
|
|
1697
|
+
const timeRemaining = checkIntervalMs - (now - startTime);
|
|
1698
|
+
const sleepPlan = {
|
|
1699
|
+
type: "Sleep",
|
|
1700
|
+
param: {
|
|
1701
|
+
timeMs: timeRemaining
|
|
1702
|
+
}
|
|
1703
|
+
};
|
|
1704
|
+
const sleepTask = yield this.convertPlanToExecutable([
|
|
1705
|
+
sleepPlan
|
|
1706
|
+
]);
|
|
1707
|
+
yield taskExecutor.append(this.wrapExecutorWithScreenshot(sleepTask[0]));
|
|
1708
|
+
yield taskExecutor.flush();
|
|
1709
|
+
}
|
|
1710
|
+
}
|
|
1711
|
+
const errorPlan = {
|
|
1712
|
+
type: "Error",
|
|
1713
|
+
param: {
|
|
1714
|
+
thought: `waitFor timeout: ${errorThought}`
|
|
1715
|
+
}
|
|
1716
|
+
};
|
|
1717
|
+
const errorTask = yield this.convertPlanToExecutable([
|
|
1718
|
+
errorPlan
|
|
1719
|
+
]);
|
|
1720
|
+
yield taskExecutor.append(errorTask[0]);
|
|
1721
|
+
yield taskExecutor.flush();
|
|
1722
|
+
return {
|
|
1723
|
+
output: void 0,
|
|
1724
|
+
executor: taskExecutor
|
|
1725
|
+
};
|
|
1726
|
+
});
|
|
776
1727
|
}
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
if (code < 128) {
|
|
786
|
-
bytes[index++] = code;
|
|
787
|
-
} else if (code < 2048) {
|
|
788
|
-
bytes[index++] = 192 | code >>> 6;
|
|
789
|
-
bytes[index++] = 128 | code & 63;
|
|
790
|
-
} else if (code < 55296 || code >= 57344) {
|
|
791
|
-
bytes[index++] = 224 | code >>> 12;
|
|
792
|
-
bytes[index++] = 128 | code >>> 6 & 63;
|
|
793
|
-
bytes[index++] = 128 | code & 63;
|
|
794
|
-
} else {
|
|
795
|
-
code = 65536 + ((code & 1023) << 10 | key.charCodeAt(++i) & 1023);
|
|
796
|
-
bytes[index++] = 240 | code >>> 18;
|
|
797
|
-
bytes[index++] = 128 | code >>> 12 & 63;
|
|
798
|
-
bytes[index++] = 128 | code >>> 6 & 63;
|
|
799
|
-
bytes[index++] = 128 | code & 63;
|
|
800
|
-
}
|
|
801
|
-
}
|
|
802
|
-
key = bytes;
|
|
803
|
-
} else {
|
|
804
|
-
if (type === "object") {
|
|
805
|
-
if (key === null) {
|
|
806
|
-
throw new Error(ERROR);
|
|
807
|
-
} else if (ARRAY_BUFFER && key.constructor === ArrayBuffer) {
|
|
808
|
-
key = new Uint8Array(key);
|
|
809
|
-
} else if (!Array.isArray(key)) {
|
|
810
|
-
if (!ARRAY_BUFFER || !ArrayBuffer.isView(key)) {
|
|
811
|
-
throw new Error(ERROR);
|
|
812
|
-
}
|
|
813
|
-
}
|
|
814
|
-
} else {
|
|
815
|
-
throw new Error(ERROR);
|
|
816
|
-
}
|
|
1728
|
+
constructor(page, opts){
|
|
1729
|
+
this.page = page;
|
|
1730
|
+
this.insight = new _core.Insight(()=>__async(this, null, function*() {
|
|
1731
|
+
return yield parseContextFromWebPage(page);
|
|
1732
|
+
}));
|
|
1733
|
+
this.taskCache = new TaskCache({
|
|
1734
|
+
fileName: opts == null ? void 0 : opts.cacheId
|
|
1735
|
+
});
|
|
817
1736
|
}
|
|
818
|
-
|
|
819
|
-
|
|
1737
|
+
};
|
|
1738
|
+
// src/common/agent.ts
|
|
1739
|
+
var PageAgent = class {
|
|
1740
|
+
appendExecutionDump(execution) {
|
|
1741
|
+
const currentDump = this.dump;
|
|
1742
|
+
currentDump.executions.push(execution);
|
|
820
1743
|
}
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
iKeyPad[i] = 54 ^ b;
|
|
1744
|
+
dumpDataString() {
|
|
1745
|
+
this.dump.groupName = this.opts.groupName;
|
|
1746
|
+
this.dump.groupDescription = this.opts.groupDescription;
|
|
1747
|
+
return (0, _utils.stringifyDumpData)(this.dump);
|
|
826
1748
|
}
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
Sha256.call(this, this.is224, this.sharedMemory);
|
|
840
|
-
this.update(this.oKeyPad);
|
|
841
|
-
this.update(innerHash);
|
|
842
|
-
Sha256.prototype.finalize.call(this);
|
|
1749
|
+
writeOutActionDumps() {
|
|
1750
|
+
const { generateReport, autoPrintReportMsg } = this.opts;
|
|
1751
|
+
this.reportFile = (0, _utils.writeLogFile)({
|
|
1752
|
+
fileName: this.reportFileName,
|
|
1753
|
+
fileExt: _utils.groupedActionDumpFileExt,
|
|
1754
|
+
fileContent: this.dumpDataString(),
|
|
1755
|
+
type: "dump",
|
|
1756
|
+
generateReport
|
|
1757
|
+
});
|
|
1758
|
+
if (generateReport && autoPrintReportMsg && this.reportFile) {
|
|
1759
|
+
printReportMsg(this.reportFile);
|
|
1760
|
+
}
|
|
843
1761
|
}
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
if (AMD) {
|
|
856
|
-
define(function() {
|
|
857
|
-
return exports2;
|
|
858
|
-
});
|
|
1762
|
+
aiAction(taskPrompt) {
|
|
1763
|
+
return __async(this, null, function*() {
|
|
1764
|
+
const { executor } = yield this.taskExecutor.action(taskPrompt);
|
|
1765
|
+
this.appendExecutionDump(executor.dump());
|
|
1766
|
+
this.writeOutActionDumps();
|
|
1767
|
+
if (executor.isInErrorState()) {
|
|
1768
|
+
const errorTask = executor.latestErrorTask();
|
|
1769
|
+
throw new Error(`${errorTask == null ? void 0 : errorTask.error}
|
|
1770
|
+
${errorTask == null ? void 0 : errorTask.errorStack}`);
|
|
1771
|
+
}
|
|
1772
|
+
});
|
|
859
1773
|
}
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
// src/common/tasks.ts
|
|
873
|
-
import assert2 from "assert";
|
|
874
|
-
import {
|
|
875
|
-
Executor,
|
|
876
|
-
Insight,
|
|
877
|
-
plan
|
|
878
|
-
} from "@midscene/core";
|
|
879
|
-
import { sleep } from "@midscene/core/utils";
|
|
880
|
-
import { base64Encoded as base64Encoded2 } from "@midscene/shared/img";
|
|
881
|
-
|
|
882
|
-
// src/common/task-cache.ts
|
|
883
|
-
import { existsSync, readFileSync as readFileSync2 } from "fs";
|
|
884
|
-
import { join } from "path";
|
|
885
|
-
import {
|
|
886
|
-
getLogDirByType,
|
|
887
|
-
stringifyDumpData,
|
|
888
|
-
writeLogFile
|
|
889
|
-
} from "@midscene/core/utils";
|
|
890
|
-
import { getMidscenePkgInfo } from "@midscene/shared/fs";
|
|
891
|
-
|
|
892
|
-
// src/common/utils.ts
|
|
893
|
-
var import_dayjs = __toESM(require_dayjs_min());
|
|
894
|
-
import assert from "assert";
|
|
895
|
-
import { randomUUID } from "crypto";
|
|
896
|
-
import { readFileSync } from "fs";
|
|
897
|
-
import path from "path";
|
|
898
|
-
import { NodeType } from "@midscene/shared/constants";
|
|
899
|
-
import { findNearestPackageJson } from "@midscene/shared/fs";
|
|
900
|
-
import {
|
|
901
|
-
base64Encoded,
|
|
902
|
-
imageInfoOfBase64
|
|
903
|
-
} from "@midscene/shared/img";
|
|
904
|
-
import { compositeElementInfoImg } from "@midscene/shared/img";
|
|
905
|
-
|
|
906
|
-
// src/web-element.ts
|
|
907
|
-
var WebElementInfo = class {
|
|
908
|
-
constructor({
|
|
909
|
-
content,
|
|
910
|
-
rect,
|
|
911
|
-
page,
|
|
912
|
-
locator,
|
|
913
|
-
id,
|
|
914
|
-
attributes,
|
|
915
|
-
indexId
|
|
916
|
-
}) {
|
|
917
|
-
this.content = content;
|
|
918
|
-
this.rect = rect;
|
|
919
|
-
this.center = [
|
|
920
|
-
Math.floor(rect.left + rect.width / 2),
|
|
921
|
-
Math.floor(rect.top + rect.height / 2)
|
|
922
|
-
];
|
|
923
|
-
this.page = page;
|
|
924
|
-
this.locator = locator;
|
|
925
|
-
this.id = id;
|
|
926
|
-
this.attributes = attributes;
|
|
927
|
-
this.indexId = indexId;
|
|
928
|
-
}
|
|
929
|
-
};
|
|
930
|
-
|
|
931
|
-
// src/common/utils.ts
|
|
932
|
-
async function parseContextFromWebPage(page, _opt) {
|
|
933
|
-
assert(page, "page is required");
|
|
934
|
-
if (page._forceUsePageContext) {
|
|
935
|
-
return await page._forceUsePageContext();
|
|
936
|
-
}
|
|
937
|
-
const url = page.url();
|
|
938
|
-
const file = await page.screenshot();
|
|
939
|
-
const screenshotBase64 = base64Encoded(file);
|
|
940
|
-
const captureElementSnapshot = await page.getElementInfos();
|
|
941
|
-
const elementsInfo = await alignElements(captureElementSnapshot, page);
|
|
942
|
-
const elementsPositionInfoWithoutText = elementsInfo.filter((elementInfo) => {
|
|
943
|
-
if (elementInfo.attributes.nodeType === NodeType.TEXT) {
|
|
944
|
-
return false;
|
|
945
|
-
}
|
|
946
|
-
return true;
|
|
947
|
-
});
|
|
948
|
-
const size = await imageInfoOfBase64(screenshotBase64);
|
|
949
|
-
const screenshotBase64WithElementMarker = await compositeElementInfoImg({
|
|
950
|
-
inputImgBase64: screenshotBase64.split(";base64,").pop(),
|
|
951
|
-
elementsPositionInfo: elementsPositionInfoWithoutText
|
|
952
|
-
});
|
|
953
|
-
return {
|
|
954
|
-
content: elementsInfo,
|
|
955
|
-
size,
|
|
956
|
-
screenshotBase64,
|
|
957
|
-
screenshotBase64WithElementMarker: `data:image/png;base64,${screenshotBase64WithElementMarker}`,
|
|
958
|
-
url
|
|
959
|
-
};
|
|
960
|
-
}
|
|
961
|
-
var sizeThreshold = 3;
|
|
962
|
-
async function alignElements(elements, page) {
|
|
963
|
-
const validElements = elements.filter((item) => {
|
|
964
|
-
return item.rect.height >= sizeThreshold && item.rect.width >= sizeThreshold;
|
|
965
|
-
});
|
|
966
|
-
const textsAligned = [];
|
|
967
|
-
for (const item of validElements) {
|
|
968
|
-
const { rect, id, content, attributes, locator, indexId } = item;
|
|
969
|
-
textsAligned.push(
|
|
970
|
-
new WebElementInfo({
|
|
971
|
-
rect,
|
|
972
|
-
locator,
|
|
973
|
-
id,
|
|
974
|
-
content,
|
|
975
|
-
attributes,
|
|
976
|
-
page,
|
|
977
|
-
indexId
|
|
978
|
-
})
|
|
979
|
-
);
|
|
980
|
-
}
|
|
981
|
-
return textsAligned;
|
|
982
|
-
}
|
|
983
|
-
function reportFileName(tag = "web") {
|
|
984
|
-
const dateTimeInFileName = (0, import_dayjs.default)().format("YYYY-MM-DD_HH-mm-ss-SSS");
|
|
985
|
-
return `${tag}-${dateTimeInFileName}`;
|
|
986
|
-
}
|
|
987
|
-
function printReportMsg(filepath) {
|
|
988
|
-
console.log("Midscene - report file updated:", filepath);
|
|
989
|
-
}
|
|
990
|
-
function getCurrentExecutionFile(trace) {
|
|
991
|
-
const error = new Error();
|
|
992
|
-
const stackTrace = trace || error.stack;
|
|
993
|
-
const pkgDir = process.cwd() || "";
|
|
994
|
-
if (stackTrace) {
|
|
995
|
-
const stackLines = stackTrace.split("\n");
|
|
996
|
-
for (const line of stackLines) {
|
|
997
|
-
if (line.includes(".spec.") || line.includes(".test.") || line.includes(".ts") || line.includes(".js")) {
|
|
998
|
-
const match = line.match(/(?:at\s+)?(.*?\.(?:spec|test)\.[jt]s)/);
|
|
999
|
-
if (match == null ? void 0 : match[1]) {
|
|
1000
|
-
const targetFileName = match[1].replace(pkgDir, "").trim().replace("at ", "");
|
|
1001
|
-
return targetFileName;
|
|
1774
|
+
aiQuery(demand) {
|
|
1775
|
+
return __async(this, null, function*() {
|
|
1776
|
+
const { output, executor } = yield this.taskExecutor.query(demand);
|
|
1777
|
+
this.appendExecutionDump(executor.dump());
|
|
1778
|
+
this.writeOutActionDumps();
|
|
1779
|
+
if (executor.isInErrorState()) {
|
|
1780
|
+
const errorTask = executor.latestErrorTask();
|
|
1781
|
+
throw new Error(`${errorTask == null ? void 0 : errorTask.error}
|
|
1782
|
+
${errorTask == null ? void 0 : errorTask.errorStack}`);
|
|
1783
|
+
}
|
|
1784
|
+
return output;
|
|
1785
|
+
});
|
|
1002
1786
|
}
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
}
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
readCache: (pageContext, type, actionPrompt) => {
|
|
1050
|
-
if (index === -1) {
|
|
1051
|
-
return false;
|
|
1787
|
+
aiAssert(assertion, msg, opt) {
|
|
1788
|
+
return __async(this, null, function*() {
|
|
1789
|
+
var _a;
|
|
1790
|
+
const { output, executor } = yield this.taskExecutor.assert(assertion);
|
|
1791
|
+
this.appendExecutionDump(executor.dump());
|
|
1792
|
+
this.writeOutActionDumps();
|
|
1793
|
+
if (output && (opt == null ? void 0 : opt.keepRawResponse)) {
|
|
1794
|
+
return output;
|
|
1795
|
+
}
|
|
1796
|
+
if (!(output == null ? void 0 : output.pass)) {
|
|
1797
|
+
const errMsg = msg || `Assertion failed: ${assertion}`;
|
|
1798
|
+
const reasonMsg = `Reason: ${(output == null ? void 0 : output.thought) || ((_a = executor.latestErrorTask()) == null ? void 0 : _a.error) || "(no_reason)"}`;
|
|
1799
|
+
throw new Error(`${errMsg}
|
|
1800
|
+
${reasonMsg}`);
|
|
1801
|
+
}
|
|
1802
|
+
});
|
|
1803
|
+
}
|
|
1804
|
+
aiWaitFor(assertion, opt) {
|
|
1805
|
+
return __async(this, null, function*() {
|
|
1806
|
+
const { executor } = yield this.taskExecutor.waitFor(assertion, {
|
|
1807
|
+
timeoutMs: (opt == null ? void 0 : opt.timeoutMs) || 15 * 1e3,
|
|
1808
|
+
checkIntervalMs: (opt == null ? void 0 : opt.checkIntervalMs) || 3 * 1e3,
|
|
1809
|
+
assertion
|
|
1810
|
+
});
|
|
1811
|
+
this.appendExecutionDump(executor.dump());
|
|
1812
|
+
this.writeOutActionDumps();
|
|
1813
|
+
if (executor.isInErrorState()) {
|
|
1814
|
+
const errorTask = executor.latestErrorTask();
|
|
1815
|
+
throw new Error(`${errorTask == null ? void 0 : errorTask.error}
|
|
1816
|
+
${errorTask == null ? void 0 : errorTask.errorStack}`);
|
|
1817
|
+
}
|
|
1818
|
+
});
|
|
1819
|
+
}
|
|
1820
|
+
ai(taskPrompt, type = "action") {
|
|
1821
|
+
return __async(this, null, function*() {
|
|
1822
|
+
if (type === "action") {
|
|
1823
|
+
return this.aiAction(taskPrompt);
|
|
1824
|
+
}
|
|
1825
|
+
if (type === "query") {
|
|
1826
|
+
return this.aiQuery(taskPrompt);
|
|
1827
|
+
}
|
|
1828
|
+
if (type === "assert") {
|
|
1829
|
+
return this.aiAssert(taskPrompt);
|
|
1830
|
+
}
|
|
1831
|
+
throw new Error(`Unknown type: ${type}, only support 'action', 'query', 'assert'`);
|
|
1832
|
+
});
|
|
1052
1833
|
}
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1834
|
+
constructor(page, opts){
|
|
1835
|
+
this.page = page;
|
|
1836
|
+
this.opts = Object.assign({
|
|
1837
|
+
generateReport: true,
|
|
1838
|
+
autoPrintReportMsg: true,
|
|
1839
|
+
groupName: "Midscene Report",
|
|
1840
|
+
groupDescription: ""
|
|
1841
|
+
}, opts || {});
|
|
1842
|
+
this.dump = {
|
|
1843
|
+
groupName: this.opts.groupName,
|
|
1844
|
+
groupDescription: this.opts.groupDescription,
|
|
1845
|
+
executions: []
|
|
1846
|
+
};
|
|
1847
|
+
this.taskExecutor = new PageTaskExecutor(this.page, {
|
|
1848
|
+
cacheId: opts == null ? void 0 : opts.cacheId
|
|
1849
|
+
});
|
|
1850
|
+
this.reportFileName = reportFileName((opts == null ? void 0 : opts.testId) || "web");
|
|
1060
1851
|
}
|
|
1061
|
-
return this.readCache(
|
|
1062
|
-
pageContext,
|
|
1063
|
-
type,
|
|
1064
|
-
actionPrompt,
|
|
1065
|
-
aiTasks[index].tasks
|
|
1066
|
-
);
|
|
1067
|
-
},
|
|
1068
|
-
saveCache: (cache) => {
|
|
1069
|
-
newCacheGroup.push(cache);
|
|
1070
|
-
this.writeCacheToFile();
|
|
1071
|
-
}
|
|
1072
1852
|
};
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
var
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
);
|
|
1086
|
-
|
|
1087
|
-
|
|
1853
|
+
// src/extractor/util.ts
|
|
1854
|
+
var import_js_sha256 = __toESM(require_sha256());
|
|
1855
|
+
var frameId = 0;
|
|
1856
|
+
function getFrameId() {
|
|
1857
|
+
return frameId;
|
|
1858
|
+
}
|
|
1859
|
+
function midsceneGenerateHash(content, rect) {
|
|
1860
|
+
const combined = JSON.stringify({
|
|
1861
|
+
content,
|
|
1862
|
+
rect,
|
|
1863
|
+
_midscene_frame_id: getFrameId()
|
|
1864
|
+
});
|
|
1865
|
+
const hashHex = (0, import_js_sha256.default)(combined);
|
|
1866
|
+
return hashHex.slice(0, 10);
|
|
1867
|
+
}
|
|
1868
|
+
// src/extractor/client-extractor.ts
|
|
1869
|
+
function getNodeAttributes2(node) {
|
|
1870
|
+
var _a;
|
|
1871
|
+
const attrs = {};
|
|
1872
|
+
if (node && node.nodeType === 1) {
|
|
1873
|
+
const element = node;
|
|
1874
|
+
for(let i = 0; i < element.attributes.length; i++){
|
|
1875
|
+
const attr = element.attributes[i];
|
|
1876
|
+
attrs[attr.nodeName] = (_a = attr.nodeValue) != null ? _a : "";
|
|
1877
|
+
}
|
|
1088
1878
|
}
|
|
1089
|
-
return
|
|
1090
|
-
}))) {
|
|
1091
|
-
return false;
|
|
1092
|
-
}
|
|
1093
|
-
if (taskRes && taskRes.type === type && taskRes.prompt === userPrompt && this.pageContextEqual(taskRes.pageContext, pageContext)) {
|
|
1094
|
-
return taskRes.response;
|
|
1095
|
-
}
|
|
1879
|
+
return attrs;
|
|
1096
1880
|
}
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
if (process.env.MIDSCENE_CACHE === "true" && existsSync(cacheFile)) {
|
|
1115
|
-
try {
|
|
1116
|
-
const data = readFileSync2(cacheFile, "utf8");
|
|
1117
|
-
const jsonData = JSON.parse(data);
|
|
1118
|
-
if (jsonData.pkgName !== this.midscenePkgInfo.name || jsonData.pkgVersion !== this.midscenePkgInfo.version) {
|
|
1119
|
-
return void 0;
|
|
1881
|
+
function getRect2(attributes) {
|
|
1882
|
+
var _a, _b, _c, _d;
|
|
1883
|
+
const x = Math.round(Number.parseFloat((_a = attributes.x) != null ? _a : "0"));
|
|
1884
|
+
const y = Math.round(Number.parseFloat((_b = attributes.y) != null ? _b : "0"));
|
|
1885
|
+
const width = Math.round(Number.parseFloat((_c = attributes.width) != null ? _c : "0"));
|
|
1886
|
+
const height = Math.round(Number.parseFloat((_d = attributes.height) != null ? _d : "0"));
|
|
1887
|
+
return {
|
|
1888
|
+
left: Math.max(0, Math.floor(x)),
|
|
1889
|
+
top: Math.max(0, Math.floor(y)),
|
|
1890
|
+
width: Math.max(0, width),
|
|
1891
|
+
height: Math.max(0, height)
|
|
1892
|
+
};
|
|
1893
|
+
}
|
|
1894
|
+
function validTextNodeContent(node) {
|
|
1895
|
+
var _a;
|
|
1896
|
+
if (node.nodeType === 3) {
|
|
1897
|
+
return ((_a = node.nodeValue) == null ? void 0 : _a.trim()) || "";
|
|
1120
1898
|
}
|
|
1121
|
-
return
|
|
1122
|
-
} catch (err) {
|
|
1123
|
-
return void 0;
|
|
1124
|
-
}
|
|
1899
|
+
return "";
|
|
1125
1900
|
}
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
const midscenePkgInfo = getMidscenePkgInfo(__dirname);
|
|
1130
|
-
writeLogFile({
|
|
1131
|
-
fileName: `${this.cacheId}`,
|
|
1132
|
-
fileExt: "json",
|
|
1133
|
-
fileContent: stringifyDumpData(
|
|
1134
|
-
__spreadValues({
|
|
1135
|
-
pkgName: midscenePkgInfo.name,
|
|
1136
|
-
pkgVersion: midscenePkgInfo.version,
|
|
1137
|
-
cacheId: this.cacheId
|
|
1138
|
-
}, this.newCache),
|
|
1139
|
-
2
|
|
1140
|
-
),
|
|
1141
|
-
type: "cache"
|
|
1142
|
-
});
|
|
1143
|
-
}
|
|
1144
|
-
};
|
|
1145
|
-
|
|
1146
|
-
// src/common/tasks.ts
|
|
1147
|
-
var PageTaskExecutor = class {
|
|
1148
|
-
constructor(page, opts) {
|
|
1149
|
-
this.page = page;
|
|
1150
|
-
this.insight = new Insight(async () => {
|
|
1151
|
-
return await parseContextFromWebPage(page);
|
|
1152
|
-
});
|
|
1153
|
-
this.taskCache = new TaskCache({
|
|
1154
|
-
fileName: opts == null ? void 0 : opts.cacheId
|
|
1155
|
-
});
|
|
1156
|
-
}
|
|
1157
|
-
async recordScreenshot(timing) {
|
|
1158
|
-
const file = await this.page.screenshot();
|
|
1159
|
-
const item = {
|
|
1160
|
-
type: "screenshot",
|
|
1161
|
-
ts: Date.now(),
|
|
1162
|
-
screenshot: base64Encoded2(file),
|
|
1163
|
-
timing
|
|
1164
|
-
};
|
|
1165
|
-
return item;
|
|
1166
|
-
}
|
|
1167
|
-
wrapExecutorWithScreenshot(taskApply) {
|
|
1168
|
-
const taskWithScreenshot = __spreadProps(__spreadValues({}, taskApply), {
|
|
1169
|
-
executor: async (param, context, ...args) => {
|
|
1170
|
-
const recorder = [];
|
|
1171
|
-
const { task } = context;
|
|
1172
|
-
task.recorder = recorder;
|
|
1173
|
-
const shot = await this.recordScreenshot(`before ${task.type}`);
|
|
1174
|
-
recorder.push(shot);
|
|
1175
|
-
const result = await taskApply.executor(param, context, ...args);
|
|
1176
|
-
if (taskApply.type === "Action") {
|
|
1177
|
-
await sleep(1e3);
|
|
1178
|
-
const shot2 = await this.recordScreenshot("after Action");
|
|
1179
|
-
recorder.push(shot2);
|
|
1901
|
+
function getXPathForElement(element) {
|
|
1902
|
+
if (element.nodeType !== 1) {
|
|
1903
|
+
return "";
|
|
1180
1904
|
}
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
async convertPlanToExecutable(plans, cacheGroup) {
|
|
1187
|
-
const tasks = plans.map((plan2) => {
|
|
1188
|
-
if (plan2.type === "Locate") {
|
|
1189
|
-
const taskFind = {
|
|
1190
|
-
type: "Insight",
|
|
1191
|
-
subType: "Locate",
|
|
1192
|
-
param: plan2.param,
|
|
1193
|
-
executor: async (param, taskContext) => {
|
|
1194
|
-
const { task } = taskContext;
|
|
1195
|
-
let insightDump;
|
|
1196
|
-
const dumpCollector = (dump) => {
|
|
1197
|
-
insightDump = dump;
|
|
1198
|
-
};
|
|
1199
|
-
this.insight.onceDumpUpdatedFn = dumpCollector;
|
|
1200
|
-
const pageContext = await this.insight.contextRetrieverFn();
|
|
1201
|
-
const locateCache = cacheGroup == null ? void 0 : cacheGroup.readCache(
|
|
1202
|
-
pageContext,
|
|
1203
|
-
"locate",
|
|
1204
|
-
param.prompt
|
|
1205
|
-
);
|
|
1206
|
-
let locateResult;
|
|
1207
|
-
const callAI = this.insight.aiVendorFn;
|
|
1208
|
-
const element = await this.insight.locate(param.prompt, {
|
|
1209
|
-
quickAnswer: plan2.quickAnswer,
|
|
1210
|
-
callAI: async (...message) => {
|
|
1211
|
-
if (locateCache) {
|
|
1212
|
-
locateResult = locateCache;
|
|
1213
|
-
return Promise.resolve(locateCache);
|
|
1905
|
+
const getIndex = (sib, name)=>{
|
|
1906
|
+
let count = 1;
|
|
1907
|
+
for(let cur = sib.previousSibling; cur; cur = cur.previousSibling){
|
|
1908
|
+
if (cur.nodeType === 1 && cur.nodeName === name) {
|
|
1909
|
+
count++;
|
|
1214
1910
|
}
|
|
1215
|
-
locateResult = await callAI(...message);
|
|
1216
|
-
assert2(locateResult);
|
|
1217
|
-
return locateResult;
|
|
1218
|
-
}
|
|
1219
|
-
});
|
|
1220
|
-
if (locateResult) {
|
|
1221
|
-
cacheGroup == null ? void 0 : cacheGroup.saveCache({
|
|
1222
|
-
type: "locate",
|
|
1223
|
-
pageContext: {
|
|
1224
|
-
url: pageContext.url,
|
|
1225
|
-
size: pageContext.size
|
|
1226
|
-
},
|
|
1227
|
-
prompt: param.prompt,
|
|
1228
|
-
response: locateResult
|
|
1229
|
-
});
|
|
1230
1911
|
}
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1912
|
+
return count;
|
|
1913
|
+
};
|
|
1914
|
+
const buildAttributePart = (elem)=>{
|
|
1915
|
+
const attributes = [
|
|
1916
|
+
"id",
|
|
1917
|
+
"resource-id",
|
|
1918
|
+
"content-desc",
|
|
1919
|
+
"class"
|
|
1920
|
+
];
|
|
1921
|
+
for (const attr of attributes){
|
|
1922
|
+
if (elem.hasAttribute(attr)) {
|
|
1923
|
+
const value = elem.getAttribute(attr);
|
|
1924
|
+
if (value && value.trim() !== "") {
|
|
1925
|
+
return `[@${attr}="${value}"]`;
|
|
1926
|
+
}
|
|
1927
|
+
}
|
|
1236
1928
|
}
|
|
1237
|
-
return
|
|
1238
|
-
output: {
|
|
1239
|
-
element
|
|
1240
|
-
},
|
|
1241
|
-
log: {
|
|
1242
|
-
dump: insightDump
|
|
1243
|
-
},
|
|
1244
|
-
cache: {
|
|
1245
|
-
hit: Boolean(locateCache)
|
|
1246
|
-
}
|
|
1247
|
-
};
|
|
1248
|
-
}
|
|
1929
|
+
return "";
|
|
1249
1930
|
};
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
const assertPlan = plan2;
|
|
1254
|
-
const taskAssert = {
|
|
1255
|
-
type: "Insight",
|
|
1256
|
-
subType: "Assert",
|
|
1257
|
-
param: assertPlan.param,
|
|
1258
|
-
executor: async (param, taskContext) => {
|
|
1259
|
-
const { task } = taskContext;
|
|
1260
|
-
let insightDump;
|
|
1261
|
-
const dumpCollector = (dump) => {
|
|
1262
|
-
insightDump = dump;
|
|
1263
|
-
};
|
|
1264
|
-
this.insight.onceDumpUpdatedFn = dumpCollector;
|
|
1265
|
-
const assertion = await this.insight.assert(
|
|
1266
|
-
assertPlan.param.assertion
|
|
1267
|
-
);
|
|
1268
|
-
if (!assertion.pass) {
|
|
1269
|
-
if (plan2.type === "Assert") {
|
|
1270
|
-
task.output = assertion;
|
|
1271
|
-
task.log = {
|
|
1272
|
-
dump: insightDump
|
|
1273
|
-
};
|
|
1274
|
-
throw new Error(
|
|
1275
|
-
assertion.thought || "Assertion failed without reason"
|
|
1276
|
-
);
|
|
1277
|
-
}
|
|
1278
|
-
task.error = assertion.thought;
|
|
1931
|
+
const getPath = (node, path2 = "")=>{
|
|
1932
|
+
if (node.parentNode) {
|
|
1933
|
+
path2 = getPath(node.parentNode, path2);
|
|
1279
1934
|
}
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1935
|
+
if (node.nodeType === 1) {
|
|
1936
|
+
const elem = node;
|
|
1937
|
+
const tagName = elem.nodeName.toLowerCase();
|
|
1938
|
+
let part = `/${tagName}`;
|
|
1939
|
+
const attributePart = buildAttributePart(elem);
|
|
1940
|
+
if (attributePart) {
|
|
1941
|
+
part += attributePart;
|
|
1942
|
+
} else {
|
|
1943
|
+
const index = getIndex(node, node.nodeName);
|
|
1944
|
+
if (index > 1) {
|
|
1945
|
+
part += `[${index}]`;
|
|
1946
|
+
}
|
|
1947
|
+
}
|
|
1948
|
+
path2 += part;
|
|
1949
|
+
}
|
|
1950
|
+
return path2;
|
|
1287
1951
|
};
|
|
1288
|
-
return
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
const
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
executor: async (taskParam, { element }) => {
|
|
1296
|
-
if (element) {
|
|
1297
|
-
await this.page.clearInput(element);
|
|
1298
|
-
if (taskParam.value === "") {
|
|
1952
|
+
return getPath(element);
|
|
1953
|
+
}
|
|
1954
|
+
function extractTextWithPosition2(initNode) {
|
|
1955
|
+
const elementInfoArray = [];
|
|
1956
|
+
let nodeIndex = 1;
|
|
1957
|
+
function dfs(node, parentNode = null) {
|
|
1958
|
+
if (!node) {
|
|
1299
1959
|
return;
|
|
1300
|
-
}
|
|
1301
|
-
await this.page.keyboard.type(taskParam.value);
|
|
1302
1960
|
}
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
}
|
|
1316
|
-
};
|
|
1317
|
-
return taskActionKeyboardPress;
|
|
1318
|
-
}
|
|
1319
|
-
if (plan2.type === "Tap") {
|
|
1320
|
-
const taskActionTap = {
|
|
1321
|
-
type: "Action",
|
|
1322
|
-
subType: "Tap",
|
|
1323
|
-
executor: async (param, { element }) => {
|
|
1324
|
-
assert2(element, "Element not found, cannot tap");
|
|
1325
|
-
await this.page.mouse.click(
|
|
1326
|
-
element.center[0],
|
|
1327
|
-
element.center[1]
|
|
1328
|
-
);
|
|
1329
|
-
}
|
|
1330
|
-
};
|
|
1331
|
-
return taskActionTap;
|
|
1332
|
-
}
|
|
1333
|
-
if (plan2.type === "Hover") {
|
|
1334
|
-
const taskActionHover = {
|
|
1335
|
-
type: "Action",
|
|
1336
|
-
subType: "Hover",
|
|
1337
|
-
executor: async (param, { element }) => {
|
|
1338
|
-
assert2(element, "Element not found, cannot hover");
|
|
1339
|
-
await this.page.mouse.move(
|
|
1340
|
-
element.center[0],
|
|
1341
|
-
element.center[1]
|
|
1342
|
-
);
|
|
1343
|
-
}
|
|
1344
|
-
};
|
|
1345
|
-
return taskActionHover;
|
|
1346
|
-
}
|
|
1347
|
-
if (plan2.type === "Scroll") {
|
|
1348
|
-
const taskActionScroll = {
|
|
1349
|
-
type: "Action",
|
|
1350
|
-
subType: "Scroll",
|
|
1351
|
-
param: plan2.param,
|
|
1352
|
-
executor: async (taskParam) => {
|
|
1353
|
-
const scrollToEventName = taskParam.scrollType;
|
|
1354
|
-
switch (scrollToEventName) {
|
|
1355
|
-
case "scrollUntilTop":
|
|
1356
|
-
await this.page.scrollUntilTop();
|
|
1357
|
-
break;
|
|
1358
|
-
case "scrollUntilBottom":
|
|
1359
|
-
await this.page.scrollUntilBottom();
|
|
1360
|
-
break;
|
|
1361
|
-
case "scrollUpOneScreen":
|
|
1362
|
-
await this.page.scrollUpOneScreen();
|
|
1363
|
-
break;
|
|
1364
|
-
case "scrollDownOneScreen":
|
|
1365
|
-
await this.page.scrollDownOneScreen();
|
|
1366
|
-
break;
|
|
1367
|
-
default:
|
|
1368
|
-
console.error(
|
|
1369
|
-
"Unknown scroll event type:",
|
|
1370
|
-
scrollToEventName
|
|
1371
|
-
);
|
|
1961
|
+
const currentNodeDes = {
|
|
1962
|
+
node,
|
|
1963
|
+
children: []
|
|
1964
|
+
};
|
|
1965
|
+
if (parentNode) {
|
|
1966
|
+
parentNode.children.push(currentNodeDes);
|
|
1967
|
+
}
|
|
1968
|
+
collectElementInfo(node);
|
|
1969
|
+
if (node.childNodes && node.childNodes.length > 0) {
|
|
1970
|
+
for(let i = 0; i < node.childNodes.length; i++){
|
|
1971
|
+
dfs(node.childNodes[i], currentNodeDes);
|
|
1972
|
+
}
|
|
1372
1973
|
}
|
|
1373
|
-
}
|
|
1374
|
-
};
|
|
1375
|
-
return taskActionScroll;
|
|
1376
|
-
}
|
|
1377
|
-
if (plan2.type === "Sleep") {
|
|
1378
|
-
const taskActionSleep = {
|
|
1379
|
-
type: "Action",
|
|
1380
|
-
subType: "Sleep",
|
|
1381
|
-
param: plan2.param,
|
|
1382
|
-
executor: async (taskParam) => {
|
|
1383
|
-
await sleep(taskParam.timeMs || 3e3);
|
|
1384
|
-
}
|
|
1385
|
-
};
|
|
1386
|
-
return taskActionSleep;
|
|
1387
|
-
}
|
|
1388
|
-
if (plan2.type === "Error") {
|
|
1389
|
-
const taskActionError = {
|
|
1390
|
-
type: "Action",
|
|
1391
|
-
subType: "Error",
|
|
1392
|
-
param: plan2.param,
|
|
1393
|
-
executor: async (taskParam) => {
|
|
1394
|
-
assert2(
|
|
1395
|
-
taskParam.thought,
|
|
1396
|
-
"An error occurred, but no thought provided"
|
|
1397
|
-
);
|
|
1398
|
-
throw new Error(taskParam.thought);
|
|
1399
|
-
}
|
|
1400
|
-
};
|
|
1401
|
-
return taskActionError;
|
|
1402
|
-
}
|
|
1403
|
-
throw new Error(`Unknown or Unsupported task type: ${plan2.type}`);
|
|
1404
|
-
}).map((task) => {
|
|
1405
|
-
return this.wrapExecutorWithScreenshot(task);
|
|
1406
|
-
});
|
|
1407
|
-
return tasks;
|
|
1408
|
-
}
|
|
1409
|
-
async action(userPrompt) {
|
|
1410
|
-
const taskExecutor = new Executor(userPrompt);
|
|
1411
|
-
const cacheGroup = this.taskCache.getCacheGroupByPrompt(userPrompt);
|
|
1412
|
-
let plans = [];
|
|
1413
|
-
const planningTask = {
|
|
1414
|
-
type: "Planning",
|
|
1415
|
-
param: {
|
|
1416
|
-
userPrompt
|
|
1417
|
-
},
|
|
1418
|
-
executor: async (param) => {
|
|
1419
|
-
const pageContext = await this.insight.contextRetrieverFn();
|
|
1420
|
-
let planResult;
|
|
1421
|
-
const planCache = cacheGroup.readCache(pageContext, "plan", userPrompt);
|
|
1422
|
-
if (planCache) {
|
|
1423
|
-
planResult = planCache;
|
|
1424
|
-
} else {
|
|
1425
|
-
planResult = await plan(param.userPrompt, {
|
|
1426
|
-
context: pageContext
|
|
1427
|
-
});
|
|
1428
1974
|
}
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
}
|
|
1485
|
-
};
|
|
1486
|
-
await taskExecutor.append(this.wrapExecutorWithScreenshot(queryTask));
|
|
1487
|
-
const output = await taskExecutor.flush();
|
|
1488
|
-
return {
|
|
1489
|
-
output,
|
|
1490
|
-
executor: taskExecutor
|
|
1491
|
-
};
|
|
1492
|
-
}
|
|
1493
|
-
async assert(assertion) {
|
|
1494
|
-
const description = `assert: ${assertion}`;
|
|
1495
|
-
const taskExecutor = new Executor(description);
|
|
1496
|
-
const assertionPlan = {
|
|
1497
|
-
type: "Assert",
|
|
1498
|
-
param: {
|
|
1499
|
-
assertion
|
|
1500
|
-
}
|
|
1501
|
-
};
|
|
1502
|
-
const assertTask = await this.convertPlanToExecutable([assertionPlan]);
|
|
1503
|
-
await taskExecutor.append(this.wrapExecutorWithScreenshot(assertTask[0]));
|
|
1504
|
-
const output = await taskExecutor.flush();
|
|
1505
|
-
return {
|
|
1506
|
-
output,
|
|
1507
|
-
executor: taskExecutor
|
|
1508
|
-
};
|
|
1509
|
-
}
|
|
1510
|
-
async waitFor(assertion, opt) {
|
|
1511
|
-
const description = `waitFor: ${assertion}`;
|
|
1512
|
-
const taskExecutor = new Executor(description);
|
|
1513
|
-
const { timeoutMs, checkIntervalMs } = opt;
|
|
1514
|
-
assert2(assertion, "No assertion for waitFor");
|
|
1515
|
-
assert2(timeoutMs, "No timeoutMs for waitFor");
|
|
1516
|
-
assert2(checkIntervalMs, "No checkIntervalMs for waitFor");
|
|
1517
|
-
const overallStartTime = Date.now();
|
|
1518
|
-
let startTime = Date.now();
|
|
1519
|
-
let errorThought = "";
|
|
1520
|
-
while (Date.now() - overallStartTime < timeoutMs) {
|
|
1521
|
-
startTime = Date.now();
|
|
1522
|
-
const assertPlan = {
|
|
1523
|
-
type: "AssertWithoutThrow",
|
|
1524
|
-
param: {
|
|
1525
|
-
assertion
|
|
1975
|
+
function collectElementInfo(node) {
|
|
1976
|
+
const attributes = getNodeAttributes2(node);
|
|
1977
|
+
const rect = getRect2(attributes);
|
|
1978
|
+
const nodeHashId = midsceneGenerateHash(attributes.placeholder, rect);
|
|
1979
|
+
const text = validTextNodeContent(node);
|
|
1980
|
+
let nodeType;
|
|
1981
|
+
switch(node.nodeName.toUpperCase()){
|
|
1982
|
+
case "TEXT":
|
|
1983
|
+
nodeType = _constants.NodeType.TEXT;
|
|
1984
|
+
break;
|
|
1985
|
+
case "IMAGE":
|
|
1986
|
+
nodeType = _constants.NodeType.IMG;
|
|
1987
|
+
break;
|
|
1988
|
+
case "BUTTON":
|
|
1989
|
+
nodeType = _constants.NodeType.BUTTON;
|
|
1990
|
+
break;
|
|
1991
|
+
case "SEARCHINPUT":
|
|
1992
|
+
case "TEXTINPUT":
|
|
1993
|
+
case "INPUT":
|
|
1994
|
+
nodeType = _constants.NodeType.FORM_ITEM;
|
|
1995
|
+
break;
|
|
1996
|
+
case "NAV":
|
|
1997
|
+
case "LIST":
|
|
1998
|
+
case "CELL":
|
|
1999
|
+
nodeType = _constants.NodeType.CONTAINER;
|
|
2000
|
+
break;
|
|
2001
|
+
default:
|
|
2002
|
+
if (attributes.id === "android:id/input" || attributes.id === "android:id/inputArea") {
|
|
2003
|
+
nodeType = _constants.NodeType.FORM_ITEM;
|
|
2004
|
+
} else {
|
|
2005
|
+
nodeType = _constants.NodeType.CONTAINER;
|
|
2006
|
+
}
|
|
2007
|
+
break;
|
|
2008
|
+
}
|
|
2009
|
+
const xpath = getXPathForElement(node);
|
|
2010
|
+
const elementInfo = {
|
|
2011
|
+
id: nodeHashId,
|
|
2012
|
+
indexId: nodeIndex++,
|
|
2013
|
+
nodeHashId,
|
|
2014
|
+
locator: xpath,
|
|
2015
|
+
attributes: __spreadValues({
|
|
2016
|
+
nodeType
|
|
2017
|
+
}, attributes),
|
|
2018
|
+
content: text,
|
|
2019
|
+
rect,
|
|
2020
|
+
center: [
|
|
2021
|
+
Math.round(rect.left + rect.width / 2),
|
|
2022
|
+
Math.round(rect.top + rect.height / 2)
|
|
2023
|
+
],
|
|
2024
|
+
nodeType,
|
|
2025
|
+
nodePath: ""
|
|
2026
|
+
};
|
|
2027
|
+
if (elementInfo.nodeType !== _constants.NodeType.CONTAINER) {
|
|
2028
|
+
elementInfoArray.push(elementInfo);
|
|
2029
|
+
}
|
|
1526
2030
|
}
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
if (output == null ? void 0 : output.pass) {
|
|
1532
|
-
return {
|
|
1533
|
-
output: void 0,
|
|
1534
|
-
executor: taskExecutor
|
|
2031
|
+
const rootNode = initNode;
|
|
2032
|
+
const rootDescriptor = {
|
|
2033
|
+
node: rootNode,
|
|
2034
|
+
children: []
|
|
1535
2035
|
};
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
const now = Date.now();
|
|
1539
|
-
if (now - startTime < checkIntervalMs) {
|
|
1540
|
-
const timeRemaining = checkIntervalMs - (now - startTime);
|
|
1541
|
-
const sleepPlan = {
|
|
1542
|
-
type: "Sleep",
|
|
1543
|
-
param: {
|
|
1544
|
-
timeMs: timeRemaining
|
|
1545
|
-
}
|
|
1546
|
-
};
|
|
1547
|
-
const sleepTask = await this.convertPlanToExecutable([sleepPlan]);
|
|
1548
|
-
await taskExecutor.append(
|
|
1549
|
-
this.wrapExecutorWithScreenshot(sleepTask[0])
|
|
1550
|
-
);
|
|
1551
|
-
await taskExecutor.flush();
|
|
1552
|
-
}
|
|
1553
|
-
}
|
|
1554
|
-
const errorPlan = {
|
|
1555
|
-
type: "Error",
|
|
1556
|
-
param: {
|
|
1557
|
-
thought: `waitFor timeout: ${errorThought}`
|
|
1558
|
-
}
|
|
1559
|
-
};
|
|
1560
|
-
const errorTask = await this.convertPlanToExecutable([errorPlan]);
|
|
1561
|
-
await taskExecutor.append(errorTask[0]);
|
|
1562
|
-
await taskExecutor.flush();
|
|
1563
|
-
return {
|
|
1564
|
-
output: void 0,
|
|
1565
|
-
executor: taskExecutor
|
|
1566
|
-
};
|
|
1567
|
-
}
|
|
1568
|
-
};
|
|
1569
|
-
|
|
1570
|
-
// src/common/agent.ts
|
|
1571
|
-
var PageAgent = class {
|
|
1572
|
-
constructor(page, opts) {
|
|
1573
|
-
this.page = page;
|
|
1574
|
-
this.opts = Object.assign(
|
|
1575
|
-
{
|
|
1576
|
-
generateReport: true,
|
|
1577
|
-
autoPrintReportMsg: true,
|
|
1578
|
-
groupName: "Midscene Report",
|
|
1579
|
-
groupDescription: ""
|
|
1580
|
-
},
|
|
1581
|
-
opts || {}
|
|
1582
|
-
);
|
|
1583
|
-
this.dump = {
|
|
1584
|
-
groupName: this.opts.groupName,
|
|
1585
|
-
groupDescription: this.opts.groupDescription,
|
|
1586
|
-
executions: []
|
|
1587
|
-
};
|
|
1588
|
-
this.taskExecutor = new PageTaskExecutor(this.page, {
|
|
1589
|
-
cacheId: opts == null ? void 0 : opts.cacheId
|
|
1590
|
-
});
|
|
1591
|
-
this.reportFileName = reportFileName((opts == null ? void 0 : opts.testId) || "web");
|
|
1592
|
-
}
|
|
1593
|
-
appendExecutionDump(execution) {
|
|
1594
|
-
const currentDump = this.dump;
|
|
1595
|
-
currentDump.executions.push(execution);
|
|
1596
|
-
}
|
|
1597
|
-
dumpDataString() {
|
|
1598
|
-
this.dump.groupName = this.opts.groupName;
|
|
1599
|
-
this.dump.groupDescription = this.opts.groupDescription;
|
|
1600
|
-
return stringifyDumpData2(this.dump);
|
|
1601
|
-
}
|
|
1602
|
-
writeOutActionDumps() {
|
|
1603
|
-
const { generateReport, autoPrintReportMsg } = this.opts;
|
|
1604
|
-
this.reportFile = writeLogFile2({
|
|
1605
|
-
fileName: this.reportFileName,
|
|
1606
|
-
fileExt: groupedActionDumpFileExt,
|
|
1607
|
-
fileContent: this.dumpDataString(),
|
|
1608
|
-
type: "dump",
|
|
1609
|
-
generateReport
|
|
1610
|
-
});
|
|
1611
|
-
if (generateReport && autoPrintReportMsg) {
|
|
1612
|
-
printReportMsg(this.reportFile);
|
|
1613
|
-
}
|
|
1614
|
-
}
|
|
1615
|
-
async aiAction(taskPrompt) {
|
|
1616
|
-
const { executor } = await this.taskExecutor.action(taskPrompt);
|
|
1617
|
-
this.appendExecutionDump(executor.dump());
|
|
1618
|
-
this.writeOutActionDumps();
|
|
1619
|
-
if (executor.isInErrorState()) {
|
|
1620
|
-
const errorTask = executor.latestErrorTask();
|
|
1621
|
-
throw new Error(`${errorTask == null ? void 0 : errorTask.error}
|
|
1622
|
-
${errorTask == null ? void 0 : errorTask.errorStack}`);
|
|
1623
|
-
}
|
|
1624
|
-
}
|
|
1625
|
-
async aiQuery(demand) {
|
|
1626
|
-
const { output, executor } = await this.taskExecutor.query(demand);
|
|
1627
|
-
this.appendExecutionDump(executor.dump());
|
|
1628
|
-
this.writeOutActionDumps();
|
|
1629
|
-
if (executor.isInErrorState()) {
|
|
1630
|
-
const errorTask = executor.latestErrorTask();
|
|
1631
|
-
throw new Error(`${errorTask == null ? void 0 : errorTask.error}
|
|
1632
|
-
${errorTask == null ? void 0 : errorTask.errorStack}`);
|
|
1633
|
-
}
|
|
1634
|
-
return output;
|
|
1635
|
-
}
|
|
1636
|
-
async aiAssert(assertion, msg, opt) {
|
|
1637
|
-
const { output, executor } = await this.taskExecutor.assert(assertion);
|
|
1638
|
-
this.appendExecutionDump(executor.dump());
|
|
1639
|
-
this.writeOutActionDumps();
|
|
1640
|
-
if (opt == null ? void 0 : opt.keepRawResponse) {
|
|
1641
|
-
return output;
|
|
1642
|
-
}
|
|
1643
|
-
if (!(output == null ? void 0 : output.pass)) {
|
|
1644
|
-
const errMsg = msg || `Assertion failed: ${assertion}`;
|
|
1645
|
-
const reasonMsg = `Reason: ${(output == null ? void 0 : output.thought) || "(no_reason)"}`;
|
|
1646
|
-
throw new Error(`${errMsg}
|
|
1647
|
-
${reasonMsg}`);
|
|
1648
|
-
}
|
|
1649
|
-
}
|
|
1650
|
-
async aiWaitFor(assertion, opt) {
|
|
1651
|
-
const { executor } = await this.taskExecutor.waitFor(assertion, {
|
|
1652
|
-
timeoutMs: (opt == null ? void 0 : opt.timeoutMs) || 15 * 1e3,
|
|
1653
|
-
checkIntervalMs: (opt == null ? void 0 : opt.checkIntervalMs) || 3 * 1e3,
|
|
1654
|
-
assertion
|
|
1655
|
-
});
|
|
1656
|
-
this.appendExecutionDump(executor.dump());
|
|
1657
|
-
this.writeOutActionDumps();
|
|
1658
|
-
if (executor.isInErrorState()) {
|
|
1659
|
-
const errorTask = executor.latestErrorTask();
|
|
1660
|
-
throw new Error(`${errorTask == null ? void 0 : errorTask.error}
|
|
1661
|
-
${errorTask == null ? void 0 : errorTask.errorStack}`);
|
|
1662
|
-
}
|
|
1663
|
-
}
|
|
1664
|
-
async ai(taskPrompt, type = "action") {
|
|
1665
|
-
if (type === "action") {
|
|
1666
|
-
return this.aiAction(taskPrompt);
|
|
1667
|
-
}
|
|
1668
|
-
if (type === "query") {
|
|
1669
|
-
return this.aiQuery(taskPrompt);
|
|
1670
|
-
}
|
|
1671
|
-
if (type === "assert") {
|
|
1672
|
-
return this.aiAssert(taskPrompt);
|
|
1673
|
-
}
|
|
1674
|
-
throw new Error(
|
|
1675
|
-
`Unknown type: ${type}, only support 'action', 'query', 'assert'`
|
|
1676
|
-
);
|
|
1677
|
-
}
|
|
1678
|
-
};
|
|
1679
|
-
|
|
1680
|
-
// src/appium/page.ts
|
|
1681
|
-
import fs from "fs";
|
|
1682
|
-
import { getTmpFile } from "@midscene/core/utils";
|
|
1683
|
-
import { resizeImg } from "@midscene/shared/img";
|
|
1684
|
-
import { DOMParser } from "@xmldom/xmldom";
|
|
1685
|
-
|
|
1686
|
-
// src/extractor/web-extractor.ts
|
|
1687
|
-
import {
|
|
1688
|
-
CONTAINER_MINI_HEIGHT,
|
|
1689
|
-
CONTAINER_MINI_WIDTH,
|
|
1690
|
-
NodeType as NodeType2
|
|
1691
|
-
} from "@midscene/shared/constants";
|
|
1692
|
-
|
|
1693
|
-
// src/extractor/util.ts
|
|
1694
|
-
var import_js_sha256 = __toESM(require_sha256());
|
|
1695
|
-
var frameId = 0;
|
|
1696
|
-
function getFrameId() {
|
|
1697
|
-
return frameId;
|
|
1698
|
-
}
|
|
1699
|
-
function midsceneGenerateHash(content, rect) {
|
|
1700
|
-
const combined = JSON.stringify({
|
|
1701
|
-
content,
|
|
1702
|
-
rect,
|
|
1703
|
-
_midscene_frame_id: getFrameId()
|
|
1704
|
-
});
|
|
1705
|
-
const hashHex = (0, import_js_sha256.default)(combined);
|
|
1706
|
-
return hashHex.slice(0, 10);
|
|
1707
|
-
}
|
|
1708
|
-
|
|
1709
|
-
// src/extractor/constants.ts
|
|
1710
|
-
import {
|
|
1711
|
-
NodeType as NodeType3,
|
|
1712
|
-
TEXT_MAX_SIZE,
|
|
1713
|
-
TEXT_SIZE_THRESHOLD
|
|
1714
|
-
} from "@midscene/shared/constants";
|
|
1715
|
-
|
|
1716
|
-
// src/extractor/client-extractor.ts
|
|
1717
|
-
function getNodeAttributes2(node) {
|
|
1718
|
-
var _a;
|
|
1719
|
-
const attrs = {};
|
|
1720
|
-
if (node && node.nodeType === 1) {
|
|
1721
|
-
const element = node;
|
|
1722
|
-
for (let i = 0; i < element.attributes.length; i++) {
|
|
1723
|
-
const attr = element.attributes[i];
|
|
1724
|
-
attrs[attr.nodeName] = (_a = attr.nodeValue) != null ? _a : "";
|
|
2036
|
+
dfs(rootNode, rootDescriptor);
|
|
2037
|
+
return elementInfoArray;
|
|
1725
2038
|
}
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
function getRect2(attributes) {
|
|
1730
|
-
var _a, _b, _c, _d;
|
|
1731
|
-
const x = Math.round(Number.parseFloat((_a = attributes.x) != null ? _a : "0"));
|
|
1732
|
-
const y = Math.round(Number.parseFloat((_b = attributes.y) != null ? _b : "0"));
|
|
1733
|
-
const width = Math.round(Number.parseFloat((_c = attributes.width) != null ? _c : "0"));
|
|
1734
|
-
const height = Math.round(Number.parseFloat((_d = attributes.height) != null ? _d : "0"));
|
|
1735
|
-
return {
|
|
1736
|
-
left: Math.max(0, Math.floor(x)),
|
|
1737
|
-
top: Math.max(0, Math.floor(y)),
|
|
1738
|
-
width: Math.max(0, width),
|
|
1739
|
-
height: Math.max(0, height)
|
|
1740
|
-
};
|
|
1741
|
-
}
|
|
1742
|
-
function validTextNodeContent(node) {
|
|
1743
|
-
var _a;
|
|
1744
|
-
if (node.nodeType === 3) {
|
|
1745
|
-
return ((_a = node.nodeValue) == null ? void 0 : _a.trim()) || "";
|
|
1746
|
-
}
|
|
1747
|
-
return "";
|
|
1748
|
-
}
|
|
1749
|
-
function getXPathForElement(element) {
|
|
1750
|
-
if (element.nodeType !== 1) {
|
|
1751
|
-
return "";
|
|
1752
|
-
}
|
|
1753
|
-
const getIndex = (sib, name) => {
|
|
1754
|
-
let count = 1;
|
|
1755
|
-
for (let cur = sib.previousSibling; cur; cur = cur.previousSibling) {
|
|
1756
|
-
if (cur.nodeType === 1 && cur.nodeName === name) {
|
|
1757
|
-
count++;
|
|
1758
|
-
}
|
|
2039
|
+
// src/appium/page.ts
|
|
2040
|
+
function buttonToNumber(button) {
|
|
2041
|
+
return button === "left" ? 0 : button === "middle" ? 1 : 2;
|
|
1759
2042
|
}
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
2043
|
+
var Page = class {
|
|
2044
|
+
getElementInfos() {
|
|
2045
|
+
return __async(this, null, function*() {
|
|
2046
|
+
const pageSource = yield this.browser.getPageSource();
|
|
2047
|
+
const { width, height } = yield this.browser.getWindowSize();
|
|
2048
|
+
const parser = new _xmldom.DOMParser();
|
|
2049
|
+
const doc = parser.parseFromString(pageSource, "text/xml");
|
|
2050
|
+
const infos = extractTextWithPosition2(doc).filter((element)=>element.rect.height !== height && element.rect.width !== width && element.rect.left !== 0 && element.rect.top !== 0 && element.attributes.visible === "true");
|
|
2051
|
+
return infos;
|
|
2052
|
+
});
|
|
1769
2053
|
}
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
const getPath = (node, path2 = "") => {
|
|
1775
|
-
if (node.parentNode) {
|
|
1776
|
-
path2 = getPath(node.parentNode, path2);
|
|
1777
|
-
}
|
|
1778
|
-
if (node.nodeType === 1) {
|
|
1779
|
-
const elem = node;
|
|
1780
|
-
const tagName = elem.nodeName.toLowerCase();
|
|
1781
|
-
let part = `/${tagName}`;
|
|
1782
|
-
const attributePart = buildAttributePart(elem);
|
|
1783
|
-
if (attributePart) {
|
|
1784
|
-
part += attributePart;
|
|
1785
|
-
} else {
|
|
1786
|
-
const index = getIndex(node, node.nodeName);
|
|
1787
|
-
if (index > 1) {
|
|
1788
|
-
part += `[${index}]`;
|
|
2054
|
+
size() {
|
|
2055
|
+
return __async(this, null, function*() {
|
|
2056
|
+
return this.browser.getWindowSize();
|
|
2057
|
+
});
|
|
1789
2058
|
}
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
2059
|
+
screenshotBase64() {
|
|
2060
|
+
return __async(this, null, function*() {
|
|
2061
|
+
const { width, height } = yield this.size();
|
|
2062
|
+
const path2 = (0, _utils.getTmpFile)("png");
|
|
2063
|
+
const screenshotBuffer = yield this.browser.saveScreenshot(path2);
|
|
2064
|
+
const resizedScreenshotBuffer = yield (0, _img.resizeImg)(screenshotBuffer, {
|
|
2065
|
+
width,
|
|
2066
|
+
height
|
|
2067
|
+
});
|
|
2068
|
+
_fs.default.writeFileSync(path2, resizedScreenshotBuffer);
|
|
2069
|
+
return (0, _img.base64Encoded)(path2);
|
|
2070
|
+
});
|
|
2071
|
+
}
|
|
2072
|
+
get mouse() {
|
|
2073
|
+
return {
|
|
2074
|
+
click: (x, y, options)=>this.mouseClick(x, y, (options == null ? void 0 : options.button) || "left"),
|
|
2075
|
+
wheel: (deltaX, deltaY)=>this.mouseWheel(deltaX, deltaY),
|
|
2076
|
+
move: (x, y)=>this.mouseMove(x, y)
|
|
2077
|
+
};
|
|
2078
|
+
}
|
|
2079
|
+
// Object that includes keyboard and mouse operations
|
|
2080
|
+
get keyboard() {
|
|
2081
|
+
return {
|
|
2082
|
+
type: (text)=>this.keyboardType(text),
|
|
2083
|
+
press: (key)=>this.keyboardPress(key)
|
|
2084
|
+
};
|
|
2085
|
+
}
|
|
2086
|
+
clearInput(element) {
|
|
2087
|
+
return __async(this, null, function*() {
|
|
2088
|
+
if (!element) {
|
|
2089
|
+
return;
|
|
2090
|
+
}
|
|
2091
|
+
const ele = yield this.browser.$(element.locator);
|
|
2092
|
+
const blank = " ";
|
|
2093
|
+
yield this.keyboardType(blank);
|
|
2094
|
+
yield ele.clearValue();
|
|
2095
|
+
});
|
|
2096
|
+
}
|
|
2097
|
+
url() {
|
|
2098
|
+
var _a;
|
|
2099
|
+
const platformName = (_a = this.browser.capabilities.platformName) == null ? void 0 : _a.toLowerCase();
|
|
2100
|
+
if (platformName === "ios") {
|
|
2101
|
+
const bundleId = this.browser.capabilities.bundleId;
|
|
2102
|
+
return bundleId;
|
|
2103
|
+
}
|
|
2104
|
+
if (platformName === "android") {
|
|
2105
|
+
const appActivity = this.browser.capabilities.appActivity;
|
|
2106
|
+
return appActivity;
|
|
2107
|
+
}
|
|
2108
|
+
return "";
|
|
2109
|
+
}
|
|
2110
|
+
// Scroll to top element
|
|
2111
|
+
scrollUntilTop() {
|
|
2112
|
+
return __async(this, null, function*() {
|
|
2113
|
+
const { height } = yield this.browser.getWindowSize();
|
|
2114
|
+
yield this.mouseWheel(0, height, 100);
|
|
2115
|
+
});
|
|
2116
|
+
}
|
|
2117
|
+
// Scroll to bottom element
|
|
2118
|
+
scrollUntilBottom() {
|
|
2119
|
+
return __async(this, null, function*() {
|
|
2120
|
+
const { height } = yield this.browser.getWindowSize();
|
|
2121
|
+
yield this.mouseWheel(0, -height, 100);
|
|
2122
|
+
});
|
|
2123
|
+
}
|
|
2124
|
+
// Scroll up one screen
|
|
2125
|
+
scrollUpOneScreen() {
|
|
2126
|
+
return __async(this, null, function*() {
|
|
2127
|
+
const { height } = yield this.browser.getWindowSize();
|
|
2128
|
+
yield this.mouseWheel(0, height, 1e3);
|
|
2129
|
+
});
|
|
2130
|
+
}
|
|
2131
|
+
// Scroll down one screen
|
|
2132
|
+
scrollDownOneScreen() {
|
|
2133
|
+
return __async(this, null, function*() {
|
|
2134
|
+
const { height } = yield this.browser.getWindowSize();
|
|
2135
|
+
yield this.mouseWheel(0, -height, 1e3);
|
|
2136
|
+
});
|
|
2137
|
+
}
|
|
2138
|
+
keyboardType(text) {
|
|
2139
|
+
return __async(this, null, function*() {
|
|
2140
|
+
const actions = [];
|
|
2141
|
+
for (const char of text){
|
|
2142
|
+
actions.push({
|
|
2143
|
+
type: "keyDown",
|
|
2144
|
+
value: char
|
|
2145
|
+
});
|
|
2146
|
+
actions.push({
|
|
2147
|
+
type: "keyUp",
|
|
2148
|
+
value: char
|
|
2149
|
+
});
|
|
2150
|
+
}
|
|
2151
|
+
if (!actions.length) {
|
|
2152
|
+
return;
|
|
2153
|
+
}
|
|
2154
|
+
yield this.browser.performActions([
|
|
2155
|
+
{
|
|
2156
|
+
type: "key",
|
|
2157
|
+
id: "keyboard",
|
|
2158
|
+
actions
|
|
2159
|
+
}
|
|
2160
|
+
]);
|
|
2161
|
+
});
|
|
2162
|
+
}
|
|
2163
|
+
keyboardPress(key) {
|
|
2164
|
+
return __async(this, null, function*() {
|
|
2165
|
+
yield this.browser.performActions([
|
|
2166
|
+
{
|
|
2167
|
+
type: "key",
|
|
2168
|
+
id: "keyboard",
|
|
2169
|
+
actions: [
|
|
2170
|
+
{
|
|
2171
|
+
type: "keyDown",
|
|
2172
|
+
value: key
|
|
2173
|
+
},
|
|
2174
|
+
{
|
|
2175
|
+
type: "keyUp",
|
|
2176
|
+
value: key
|
|
2177
|
+
}
|
|
2178
|
+
]
|
|
2179
|
+
}
|
|
2180
|
+
]);
|
|
2181
|
+
});
|
|
2182
|
+
}
|
|
2183
|
+
mouseClick(x, y, button = "left") {
|
|
2184
|
+
return __async(this, null, function*() {
|
|
2185
|
+
yield this.mouseMove(x, y);
|
|
2186
|
+
yield this.browser.performActions([
|
|
2187
|
+
{
|
|
2188
|
+
type: "pointer",
|
|
2189
|
+
id: "mouse",
|
|
2190
|
+
parameters: {
|
|
2191
|
+
pointerType: "mouse"
|
|
2192
|
+
},
|
|
2193
|
+
actions: [
|
|
2194
|
+
{
|
|
2195
|
+
type: "pointerMove",
|
|
2196
|
+
duration: 0,
|
|
2197
|
+
x,
|
|
2198
|
+
y
|
|
2199
|
+
},
|
|
2200
|
+
{
|
|
2201
|
+
type: "pointerDown",
|
|
2202
|
+
button: buttonToNumber(button)
|
|
2203
|
+
},
|
|
2204
|
+
{
|
|
2205
|
+
type: "pause",
|
|
2206
|
+
duration: 100
|
|
2207
|
+
},
|
|
2208
|
+
{
|
|
2209
|
+
type: "pointerUp",
|
|
2210
|
+
button: buttonToNumber(button)
|
|
2211
|
+
}
|
|
2212
|
+
]
|
|
2213
|
+
}
|
|
2214
|
+
]);
|
|
2215
|
+
});
|
|
2216
|
+
}
|
|
2217
|
+
mouseMove(x, y) {
|
|
2218
|
+
return __async(this, null, function*() {
|
|
2219
|
+
yield this.browser.performActions([
|
|
2220
|
+
{
|
|
2221
|
+
type: "pointer",
|
|
2222
|
+
id: "mouse",
|
|
2223
|
+
parameters: {
|
|
2224
|
+
pointerType: "mouse"
|
|
2225
|
+
},
|
|
2226
|
+
actions: [
|
|
2227
|
+
{
|
|
2228
|
+
type: "pointerMove",
|
|
2229
|
+
duration: 0,
|
|
2230
|
+
x,
|
|
2231
|
+
y
|
|
2232
|
+
}
|
|
2233
|
+
]
|
|
2234
|
+
}
|
|
2235
|
+
]);
|
|
2236
|
+
});
|
|
2237
|
+
}
|
|
2238
|
+
mouseWheel(deltaX, deltaY, duration = 1e3) {
|
|
2239
|
+
return __async(this, null, function*() {
|
|
2240
|
+
const n = 4;
|
|
2241
|
+
const windowSize = yield this.browser.getWindowSize();
|
|
2242
|
+
const startX = deltaX < 0 ? (n - 1) * (windowSize.width / n) : windowSize.width / n;
|
|
2243
|
+
const startY = deltaY < 0 ? (n - 1) * (windowSize.height / n) : windowSize.height / n;
|
|
2244
|
+
const maxNegativeDeltaX = startX;
|
|
2245
|
+
const maxPositiveDeltaX = (n - 1) * (windowSize.width / n);
|
|
2246
|
+
const maxNegativeDeltaY = startY;
|
|
2247
|
+
const maxPositiveDeltaY = (n - 1) * (windowSize.height / n);
|
|
2248
|
+
deltaX = Math.max(-maxNegativeDeltaX, Math.min(deltaX, maxPositiveDeltaX));
|
|
2249
|
+
deltaY = Math.max(-maxNegativeDeltaY, Math.min(deltaY, maxPositiveDeltaY));
|
|
2250
|
+
yield this.browser.performActions([
|
|
2251
|
+
{
|
|
2252
|
+
type: "pointer",
|
|
2253
|
+
id: "finger1",
|
|
2254
|
+
parameters: {
|
|
2255
|
+
pointerType: "touch"
|
|
2256
|
+
},
|
|
2257
|
+
actions: [
|
|
2258
|
+
{
|
|
2259
|
+
type: "pointerMove",
|
|
2260
|
+
duration: 0,
|
|
2261
|
+
x: startX,
|
|
2262
|
+
y: startY
|
|
2263
|
+
},
|
|
2264
|
+
{
|
|
2265
|
+
type: "pointerDown",
|
|
2266
|
+
button: 0
|
|
2267
|
+
},
|
|
2268
|
+
{
|
|
2269
|
+
type: "pause",
|
|
2270
|
+
duration
|
|
2271
|
+
},
|
|
2272
|
+
{
|
|
2273
|
+
type: "pointerMove",
|
|
2274
|
+
duration,
|
|
2275
|
+
origin: "pointer",
|
|
2276
|
+
// Use 'pointer' as the starting point
|
|
2277
|
+
x: deltaX,
|
|
2278
|
+
// X offset relative to the starting point
|
|
2279
|
+
y: deltaY
|
|
2280
|
+
},
|
|
2281
|
+
{
|
|
2282
|
+
type: "pointerUp",
|
|
2283
|
+
button: 0
|
|
2284
|
+
}
|
|
2285
|
+
]
|
|
2286
|
+
}
|
|
2287
|
+
]);
|
|
2288
|
+
});
|
|
2289
|
+
}
|
|
2290
|
+
constructor(browser){
|
|
2291
|
+
this.pageType = "appium";
|
|
2292
|
+
this.browser = browser;
|
|
1846
2293
|
}
|
|
1847
|
-
break;
|
|
1848
|
-
}
|
|
1849
|
-
const xpath = getXPathForElement(node);
|
|
1850
|
-
const elementInfo = {
|
|
1851
|
-
id: nodeHashId,
|
|
1852
|
-
indexId: nodeIndex++,
|
|
1853
|
-
nodeHashId,
|
|
1854
|
-
locator: xpath,
|
|
1855
|
-
attributes: __spreadValues({
|
|
1856
|
-
nodeType
|
|
1857
|
-
}, attributes),
|
|
1858
|
-
content: text,
|
|
1859
|
-
rect,
|
|
1860
|
-
center: [
|
|
1861
|
-
Math.round(rect.left + rect.width / 2),
|
|
1862
|
-
Math.round(rect.top + rect.height / 2)
|
|
1863
|
-
],
|
|
1864
|
-
nodeType,
|
|
1865
|
-
nodePath: ""
|
|
1866
|
-
};
|
|
1867
|
-
if (elementInfo.nodeType !== NodeType3.CONTAINER) {
|
|
1868
|
-
elementInfoArray.push(elementInfo);
|
|
1869
|
-
}
|
|
1870
|
-
}
|
|
1871
|
-
const rootNode = initNode;
|
|
1872
|
-
const rootDescriptor = { node: rootNode, children: [] };
|
|
1873
|
-
dfs(rootNode, rootDescriptor);
|
|
1874
|
-
return elementInfoArray;
|
|
1875
|
-
}
|
|
1876
|
-
|
|
1877
|
-
// src/appium/page.ts
|
|
1878
|
-
function buttonToNumber(button) {
|
|
1879
|
-
return button === "left" ? 0 : button === "middle" ? 1 : 2;
|
|
1880
|
-
}
|
|
1881
|
-
var Page = class {
|
|
1882
|
-
constructor(browser) {
|
|
1883
|
-
this.pageType = "appium";
|
|
1884
|
-
this.browser = browser;
|
|
1885
|
-
}
|
|
1886
|
-
async getElementInfos() {
|
|
1887
|
-
const pageSource = await this.browser.getPageSource();
|
|
1888
|
-
const { width, height } = await this.browser.getWindowSize();
|
|
1889
|
-
const parser = new DOMParser();
|
|
1890
|
-
const doc = parser.parseFromString(pageSource, "text/xml");
|
|
1891
|
-
const infos = extractTextWithPosition2(doc).filter(
|
|
1892
|
-
(element) => element.rect.height !== height && element.rect.width !== width && element.rect.left !== 0 && element.rect.top !== 0 && element.attributes.visible === "true"
|
|
1893
|
-
);
|
|
1894
|
-
return infos;
|
|
1895
|
-
}
|
|
1896
|
-
async screenshot() {
|
|
1897
|
-
const { width, height } = await this.browser.getWindowSize();
|
|
1898
|
-
const path2 = getTmpFile("png");
|
|
1899
|
-
const screenshotBuffer = await this.browser.saveScreenshot(path2);
|
|
1900
|
-
const resizedScreenshotBuffer = await resizeImg(screenshotBuffer, {
|
|
1901
|
-
width,
|
|
1902
|
-
height
|
|
1903
|
-
});
|
|
1904
|
-
fs.writeFileSync(path2, resizedScreenshotBuffer);
|
|
1905
|
-
return path2;
|
|
1906
|
-
}
|
|
1907
|
-
get mouse() {
|
|
1908
|
-
return {
|
|
1909
|
-
click: (x, y, options) => this.mouseClick(x, y, (options == null ? void 0 : options.button) || "left"),
|
|
1910
|
-
wheel: (deltaX, deltaY) => this.mouseWheel(deltaX, deltaY),
|
|
1911
|
-
move: (x, y) => this.mouseMove(x, y)
|
|
1912
|
-
};
|
|
1913
|
-
}
|
|
1914
|
-
// Object that includes keyboard and mouse operations
|
|
1915
|
-
get keyboard() {
|
|
1916
|
-
return {
|
|
1917
|
-
type: (text) => this.keyboardType(text),
|
|
1918
|
-
press: (key) => this.keyboardPress(key)
|
|
1919
2294
|
};
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
if (!element) {
|
|
1923
|
-
return;
|
|
1924
|
-
}
|
|
1925
|
-
const ele = await this.browser.$(element.locator);
|
|
1926
|
-
const blank = " ";
|
|
1927
|
-
await this.keyboardType(blank);
|
|
1928
|
-
await ele.clearValue();
|
|
1929
|
-
}
|
|
1930
|
-
url() {
|
|
1931
|
-
var _a;
|
|
1932
|
-
const platformName = (_a = this.browser.capabilities.platformName) == null ? void 0 : _a.toLowerCase();
|
|
1933
|
-
if (platformName === "ios") {
|
|
1934
|
-
const bundleId = this.browser.capabilities.bundleId;
|
|
1935
|
-
return bundleId;
|
|
1936
|
-
}
|
|
1937
|
-
if (platformName === "android") {
|
|
1938
|
-
const appActivity = this.browser.capabilities.appActivity;
|
|
1939
|
-
return appActivity;
|
|
1940
|
-
}
|
|
1941
|
-
return "";
|
|
1942
|
-
}
|
|
1943
|
-
// Scroll to top element
|
|
1944
|
-
async scrollUntilTop() {
|
|
1945
|
-
const { height } = await this.browser.getWindowSize();
|
|
1946
|
-
await this.mouseWheel(0, height, 100);
|
|
1947
|
-
}
|
|
1948
|
-
// Scroll to bottom element
|
|
1949
|
-
async scrollUntilBottom() {
|
|
1950
|
-
const { height } = await this.browser.getWindowSize();
|
|
1951
|
-
await this.mouseWheel(0, -height, 100);
|
|
1952
|
-
}
|
|
1953
|
-
// Scroll up one screen
|
|
1954
|
-
async scrollUpOneScreen() {
|
|
1955
|
-
const { height } = await this.browser.getWindowSize();
|
|
1956
|
-
await this.mouseWheel(0, height, 1e3);
|
|
1957
|
-
}
|
|
1958
|
-
// Scroll down one screen
|
|
1959
|
-
async scrollDownOneScreen() {
|
|
1960
|
-
const { height } = await this.browser.getWindowSize();
|
|
1961
|
-
await this.mouseWheel(0, -height, 1e3);
|
|
1962
|
-
}
|
|
1963
|
-
async keyboardType(text) {
|
|
1964
|
-
const actions = [];
|
|
1965
|
-
for (const char of text) {
|
|
1966
|
-
actions.push({ type: "keyDown", value: char });
|
|
1967
|
-
actions.push({ type: "keyUp", value: char });
|
|
1968
|
-
}
|
|
1969
|
-
if (!actions.length) {
|
|
1970
|
-
return;
|
|
1971
|
-
}
|
|
1972
|
-
await this.browser.performActions([
|
|
1973
|
-
{
|
|
1974
|
-
type: "key",
|
|
1975
|
-
id: "keyboard",
|
|
1976
|
-
actions
|
|
1977
|
-
}
|
|
1978
|
-
]);
|
|
1979
|
-
}
|
|
1980
|
-
async keyboardPress(key) {
|
|
1981
|
-
await this.browser.performActions([
|
|
1982
|
-
{
|
|
1983
|
-
type: "key",
|
|
1984
|
-
id: "keyboard",
|
|
1985
|
-
actions: [
|
|
1986
|
-
{ type: "keyDown", value: key },
|
|
1987
|
-
{ type: "keyUp", value: key }
|
|
1988
|
-
]
|
|
1989
|
-
}
|
|
1990
|
-
]);
|
|
1991
|
-
}
|
|
1992
|
-
async mouseClick(x, y, button = "left") {
|
|
1993
|
-
await this.mouseMove(x, y);
|
|
1994
|
-
await this.browser.performActions([
|
|
1995
|
-
{
|
|
1996
|
-
type: "pointer",
|
|
1997
|
-
id: "mouse",
|
|
1998
|
-
parameters: { pointerType: "mouse" },
|
|
1999
|
-
actions: [
|
|
2000
|
-
{ type: "pointerMove", duration: 0, x, y },
|
|
2001
|
-
{ type: "pointerDown", button: buttonToNumber(button) },
|
|
2002
|
-
{ type: "pause", duration: 100 },
|
|
2003
|
-
{ type: "pointerUp", button: buttonToNumber(button) }
|
|
2004
|
-
]
|
|
2005
|
-
}
|
|
2006
|
-
]);
|
|
2007
|
-
}
|
|
2008
|
-
async mouseMove(x, y) {
|
|
2009
|
-
await this.browser.performActions([
|
|
2010
|
-
{
|
|
2011
|
-
type: "pointer",
|
|
2012
|
-
id: "mouse",
|
|
2013
|
-
parameters: { pointerType: "mouse" },
|
|
2014
|
-
actions: [{ type: "pointerMove", duration: 0, x, y }]
|
|
2015
|
-
}
|
|
2016
|
-
]);
|
|
2017
|
-
}
|
|
2018
|
-
async mouseWheel(deltaX, deltaY, duration = 1e3) {
|
|
2019
|
-
const n = 4;
|
|
2020
|
-
const windowSize = await this.browser.getWindowSize();
|
|
2021
|
-
const startX = deltaX < 0 ? (n - 1) * (windowSize.width / n) : windowSize.width / n;
|
|
2022
|
-
const startY = deltaY < 0 ? (n - 1) * (windowSize.height / n) : windowSize.height / n;
|
|
2023
|
-
const maxNegativeDeltaX = startX;
|
|
2024
|
-
const maxPositiveDeltaX = (n - 1) * (windowSize.width / n);
|
|
2025
|
-
const maxNegativeDeltaY = startY;
|
|
2026
|
-
const maxPositiveDeltaY = (n - 1) * (windowSize.height / n);
|
|
2027
|
-
deltaX = Math.max(-maxNegativeDeltaX, Math.min(deltaX, maxPositiveDeltaX));
|
|
2028
|
-
deltaY = Math.max(-maxNegativeDeltaY, Math.min(deltaY, maxPositiveDeltaY));
|
|
2029
|
-
await this.browser.performActions([
|
|
2030
|
-
{
|
|
2031
|
-
type: "pointer",
|
|
2032
|
-
id: "finger1",
|
|
2033
|
-
parameters: { pointerType: "touch" },
|
|
2034
|
-
actions: [
|
|
2035
|
-
{ type: "pointerMove", duration: 0, x: startX, y: startY },
|
|
2036
|
-
{ type: "pointerDown", button: 0 },
|
|
2037
|
-
{ type: "pause", duration },
|
|
2038
|
-
{
|
|
2039
|
-
type: "pointerMove",
|
|
2040
|
-
duration,
|
|
2041
|
-
origin: "pointer",
|
|
2042
|
-
// Use 'pointer' as the starting point
|
|
2043
|
-
x: deltaX,
|
|
2044
|
-
// X offset relative to the starting point
|
|
2045
|
-
y: deltaY
|
|
2046
|
-
// Y offset relative to the starting point
|
|
2047
|
-
},
|
|
2048
|
-
{ type: "pointerUp", button: 0 }
|
|
2049
|
-
]
|
|
2050
|
-
}
|
|
2051
|
-
]);
|
|
2052
|
-
}
|
|
2053
|
-
};
|
|
2054
|
-
export {
|
|
2055
|
-
PageAgent as AppiumAgent,
|
|
2056
|
-
Page as AppiumPage
|
|
2057
|
-
};
|
|
2058
|
-
/*! Bundled license information:
|
|
2295
|
+
});
|
|
2296
|
+
/*! Bundled license information:
|
|
2059
2297
|
|
|
2060
2298
|
js-sha256/src/sha256.js:
|
|
2061
2299
|
(**
|
|
@@ -2066,4 +2304,4 @@ js-sha256/src/sha256.js:
|
|
|
2066
2304
|
* @copyright Chen, Yi-Cyuan 2014-2024
|
|
2067
2305
|
* @license MIT
|
|
2068
2306
|
*)
|
|
2069
|
-
*/
|
|
2307
|
+
*/
|