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