@midscene/web 0.3.2 → 0.3.3

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.
@@ -0,0 +1,563 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __commonJS = (cb, mod) => function __require() {
9
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
+ };
11
+ var __export = (target, all) => {
12
+ for (var name in all)
13
+ __defProp(target, name, { get: all[name], enumerable: true });
14
+ };
15
+ var __copyProps = (to, from, except, desc) => {
16
+ if (from && typeof from === "object" || typeof from === "function") {
17
+ for (let key of __getOwnPropNames(from))
18
+ if (!__hasOwnProp.call(to, key) && key !== except)
19
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
20
+ }
21
+ return to;
22
+ };
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
24
+ // If the importer is in node compatibility mode or this is not an ESM
25
+ // file that has been converted to a CommonJS file using a Babel-
26
+ // compatible transform (i.e. "__esModule" has not been set), then set
27
+ // "default" to the CommonJS "module.exports" for node compatibility.
28
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
29
+ mod
30
+ ));
31
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
+
33
+ // ../../node_modules/.pnpm/dayjs@1.11.11/node_modules/dayjs/dayjs.min.js
34
+ var require_dayjs_min = __commonJS({
35
+ "../../node_modules/.pnpm/dayjs@1.11.11/node_modules/dayjs/dayjs.min.js"(exports, module2) {
36
+ "use strict";
37
+ !function(t, e) {
38
+ "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();
39
+ }(exports, function() {
40
+ "use strict";
41
+ 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) {
42
+ var e2 = ["th", "st", "nd", "rd"], n2 = t2 % 100;
43
+ return "[" + t2 + (e2[(n2 - 20) % 10] || e2[n2] || e2[0]) + "]";
44
+ } }, m = function(t2, e2, n2) {
45
+ var r2 = String(t2);
46
+ return !r2 || r2.length >= e2 ? t2 : "" + Array(e2 + 1 - r2.length).join(n2) + t2;
47
+ }, v = { s: m, z: function(t2) {
48
+ var e2 = -t2.utcOffset(), n2 = Math.abs(e2), r2 = Math.floor(n2 / 60), i2 = n2 % 60;
49
+ return (e2 <= 0 ? "+" : "-") + m(r2, 2, "0") + ":" + m(i2, 2, "0");
50
+ }, m: function t2(e2, n2) {
51
+ if (e2.date() < n2.date())
52
+ return -t2(n2, e2);
53
+ 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);
54
+ return +(-(r2 + (n2 - i2) / (s2 ? i2 - u2 : u2 - i2)) || 0);
55
+ }, a: function(t2) {
56
+ return t2 < 0 ? Math.ceil(t2) || 0 : Math.floor(t2);
57
+ }, p: function(t2) {
58
+ 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$/, "");
59
+ }, u: function(t2) {
60
+ return void 0 === t2;
61
+ } }, g = "en", D = {};
62
+ D[g] = M;
63
+ var p = "$isDayjsObject", S = function(t2) {
64
+ return t2 instanceof _ || !(!t2 || !t2[p]);
65
+ }, w = function t2(e2, n2, r2) {
66
+ var i2;
67
+ if (!e2)
68
+ return g;
69
+ if ("string" == typeof e2) {
70
+ var s2 = e2.toLowerCase();
71
+ D[s2] && (i2 = s2), n2 && (D[s2] = n2, i2 = s2);
72
+ var u2 = e2.split("-");
73
+ if (!i2 && u2.length > 1)
74
+ return t2(u2[0]);
75
+ } else {
76
+ var a2 = e2.name;
77
+ D[a2] = e2, i2 = a2;
78
+ }
79
+ return !r2 && i2 && (g = i2), i2 || !r2 && g;
80
+ }, O = function(t2, e2) {
81
+ if (S(t2))
82
+ return t2.clone();
83
+ var n2 = "object" == typeof e2 ? e2 : {};
84
+ return n2.date = t2, n2.args = arguments, new _(n2);
85
+ }, b = v;
86
+ b.l = w, b.i = S, b.w = function(t2, e2) {
87
+ return O(t2, { locale: e2.$L, utc: e2.$u, x: e2.$x, $offset: e2.$offset });
88
+ };
89
+ var _ = function() {
90
+ function M2(t2) {
91
+ this.$L = w(t2.locale, null, true), this.parse(t2), this.$x = this.$x || t2.x || {}, this[p] = true;
92
+ }
93
+ var m2 = M2.prototype;
94
+ return m2.parse = function(t2) {
95
+ this.$d = function(t3) {
96
+ var e2 = t3.date, n2 = t3.utc;
97
+ if (null === e2)
98
+ return /* @__PURE__ */ new Date(NaN);
99
+ if (b.u(e2))
100
+ return /* @__PURE__ */ new Date();
101
+ if (e2 instanceof Date)
102
+ return new Date(e2);
103
+ if ("string" == typeof e2 && !/Z$/i.test(e2)) {
104
+ var r2 = e2.match($);
105
+ if (r2) {
106
+ var i2 = r2[2] - 1 || 0, s2 = (r2[7] || "0").substring(0, 3);
107
+ 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);
108
+ }
109
+ }
110
+ return new Date(e2);
111
+ }(t2), this.init();
112
+ }, m2.init = function() {
113
+ var t2 = this.$d;
114
+ 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();
115
+ }, m2.$utils = function() {
116
+ return b;
117
+ }, m2.isValid = function() {
118
+ return !(this.$d.toString() === l);
119
+ }, m2.isSame = function(t2, e2) {
120
+ var n2 = O(t2);
121
+ return this.startOf(e2) <= n2 && n2 <= this.endOf(e2);
122
+ }, m2.isAfter = function(t2, e2) {
123
+ return O(t2) < this.startOf(e2);
124
+ }, m2.isBefore = function(t2, e2) {
125
+ return this.endOf(e2) < O(t2);
126
+ }, m2.$g = function(t2, e2, n2) {
127
+ return b.u(t2) ? this[e2] : this.set(n2, t2);
128
+ }, m2.unix = function() {
129
+ return Math.floor(this.valueOf() / 1e3);
130
+ }, m2.valueOf = function() {
131
+ return this.$d.getTime();
132
+ }, m2.startOf = function(t2, e2) {
133
+ var n2 = this, r2 = !!b.u(e2) || e2, f2 = b.p(t2), l2 = function(t3, e3) {
134
+ var i2 = b.w(n2.$u ? Date.UTC(n2.$y, e3, t3) : new Date(n2.$y, e3, t3), n2);
135
+ return r2 ? i2 : i2.endOf(a);
136
+ }, $2 = function(t3, e3) {
137
+ return b.w(n2.toDate()[t3].apply(n2.toDate("s"), (r2 ? [0, 0, 0, 0] : [23, 59, 59, 999]).slice(e3)), n2);
138
+ }, y2 = this.$W, M3 = this.$M, m3 = this.$D, v2 = "set" + (this.$u ? "UTC" : "");
139
+ switch (f2) {
140
+ case h:
141
+ return r2 ? l2(1, 0) : l2(31, 11);
142
+ case c:
143
+ return r2 ? l2(1, M3) : l2(0, M3 + 1);
144
+ case o:
145
+ var g2 = this.$locale().weekStart || 0, D2 = (y2 < g2 ? y2 + 7 : y2) - g2;
146
+ return l2(r2 ? m3 - D2 : m3 + (6 - D2), M3);
147
+ case a:
148
+ case d:
149
+ return $2(v2 + "Hours", 0);
150
+ case u:
151
+ return $2(v2 + "Minutes", 1);
152
+ case s:
153
+ return $2(v2 + "Seconds", 2);
154
+ case i:
155
+ return $2(v2 + "Milliseconds", 3);
156
+ default:
157
+ return this.clone();
158
+ }
159
+ }, m2.endOf = function(t2) {
160
+ return this.startOf(t2, false);
161
+ }, m2.$set = function(t2, e2) {
162
+ 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;
163
+ if (o2 === c || o2 === h) {
164
+ var y2 = this.clone().set(d, 1);
165
+ y2.$d[l2]($2), y2.init(), this.$d = y2.set(d, Math.min(this.$D, y2.daysInMonth())).$d;
166
+ } else
167
+ l2 && this.$d[l2]($2);
168
+ return this.init(), this;
169
+ }, m2.set = function(t2, e2) {
170
+ return this.clone().$set(t2, e2);
171
+ }, m2.get = function(t2) {
172
+ return this[b.p(t2)]();
173
+ }, m2.add = function(r2, f2) {
174
+ var d2, l2 = this;
175
+ r2 = Number(r2);
176
+ var $2 = b.p(f2), y2 = function(t2) {
177
+ var e2 = O(l2);
178
+ return b.w(e2.date(e2.date() + Math.round(t2 * r2)), l2);
179
+ };
180
+ if ($2 === c)
181
+ return this.set(c, this.$M + r2);
182
+ if ($2 === h)
183
+ return this.set(h, this.$y + r2);
184
+ if ($2 === a)
185
+ return y2(1);
186
+ if ($2 === o)
187
+ return y2(7);
188
+ var M3 = (d2 = {}, d2[s] = e, d2[u] = n, d2[i] = t, d2)[$2] || 1, m3 = this.$d.getTime() + r2 * M3;
189
+ return b.w(m3, this);
190
+ }, m2.subtract = function(t2, e2) {
191
+ return this.add(-1 * t2, e2);
192
+ }, m2.format = function(t2) {
193
+ var e2 = this, n2 = this.$locale();
194
+ if (!this.isValid())
195
+ return n2.invalidDate || l;
196
+ 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) {
197
+ return t3 && (t3[n3] || t3(e2, r2)) || i3[n3].slice(0, s3);
198
+ }, d2 = function(t3) {
199
+ return b.s(s2 % 12 || 12, t3, "0");
200
+ }, $2 = f2 || function(t3, e3, n3) {
201
+ var r3 = t3 < 12 ? "AM" : "PM";
202
+ return n3 ? r3.toLowerCase() : r3;
203
+ };
204
+ return r2.replace(y, function(t3, r3) {
205
+ return r3 || function(t4) {
206
+ switch (t4) {
207
+ case "YY":
208
+ return String(e2.$y).slice(-2);
209
+ case "YYYY":
210
+ return b.s(e2.$y, 4, "0");
211
+ case "M":
212
+ return a2 + 1;
213
+ case "MM":
214
+ return b.s(a2 + 1, 2, "0");
215
+ case "MMM":
216
+ return h2(n2.monthsShort, a2, c2, 3);
217
+ case "MMMM":
218
+ return h2(c2, a2);
219
+ case "D":
220
+ return e2.$D;
221
+ case "DD":
222
+ return b.s(e2.$D, 2, "0");
223
+ case "d":
224
+ return String(e2.$W);
225
+ case "dd":
226
+ return h2(n2.weekdaysMin, e2.$W, o2, 2);
227
+ case "ddd":
228
+ return h2(n2.weekdaysShort, e2.$W, o2, 3);
229
+ case "dddd":
230
+ return o2[e2.$W];
231
+ case "H":
232
+ return String(s2);
233
+ case "HH":
234
+ return b.s(s2, 2, "0");
235
+ case "h":
236
+ return d2(1);
237
+ case "hh":
238
+ return d2(2);
239
+ case "a":
240
+ return $2(s2, u2, true);
241
+ case "A":
242
+ return $2(s2, u2, false);
243
+ case "m":
244
+ return String(u2);
245
+ case "mm":
246
+ return b.s(u2, 2, "0");
247
+ case "s":
248
+ return String(e2.$s);
249
+ case "ss":
250
+ return b.s(e2.$s, 2, "0");
251
+ case "SSS":
252
+ return b.s(e2.$ms, 3, "0");
253
+ case "Z":
254
+ return i2;
255
+ }
256
+ return null;
257
+ }(t3) || i2.replace(":", "");
258
+ });
259
+ }, m2.utcOffset = function() {
260
+ return 15 * -Math.round(this.$d.getTimezoneOffset() / 15);
261
+ }, m2.diff = function(r2, d2, l2) {
262
+ var $2, y2 = this, M3 = b.p(d2), m3 = O(r2), v2 = (m3.utcOffset() - this.utcOffset()) * e, g2 = this - m3, D2 = function() {
263
+ return b.m(y2, m3);
264
+ };
265
+ switch (M3) {
266
+ case h:
267
+ $2 = D2() / 12;
268
+ break;
269
+ case c:
270
+ $2 = D2();
271
+ break;
272
+ case f:
273
+ $2 = D2() / 3;
274
+ break;
275
+ case o:
276
+ $2 = (g2 - v2) / 6048e5;
277
+ break;
278
+ case a:
279
+ $2 = (g2 - v2) / 864e5;
280
+ break;
281
+ case u:
282
+ $2 = g2 / n;
283
+ break;
284
+ case s:
285
+ $2 = g2 / e;
286
+ break;
287
+ case i:
288
+ $2 = g2 / t;
289
+ break;
290
+ default:
291
+ $2 = g2;
292
+ }
293
+ return l2 ? $2 : b.a($2);
294
+ }, m2.daysInMonth = function() {
295
+ return this.endOf(c).$D;
296
+ }, m2.$locale = function() {
297
+ return D[this.$L];
298
+ }, m2.locale = function(t2, e2) {
299
+ if (!t2)
300
+ return this.$L;
301
+ var n2 = this.clone(), r2 = w(t2, e2, true);
302
+ return r2 && (n2.$L = r2), n2;
303
+ }, m2.clone = function() {
304
+ return b.w(this.$d, this);
305
+ }, m2.toDate = function() {
306
+ return new Date(this.valueOf());
307
+ }, m2.toJSON = function() {
308
+ return this.isValid() ? this.toISOString() : null;
309
+ }, m2.toISOString = function() {
310
+ return this.$d.toISOString();
311
+ }, m2.toString = function() {
312
+ return this.$d.toUTCString();
313
+ }, M2;
314
+ }(), k = _.prototype;
315
+ return O.prototype = k, [["$ms", r], ["$s", i], ["$m", s], ["$H", u], ["$W", a], ["$M", c], ["$y", h], ["$D", d]].forEach(function(t2) {
316
+ k[t2[1]] = function(e2) {
317
+ return this.$g(e2, t2[0], t2[1]);
318
+ };
319
+ }), O.extend = function(t2, e2) {
320
+ return t2.$i || (t2(e2, _, O), t2.$i = true), O;
321
+ }, O.locale = w, O.isDayjs = S, O.unix = function(t2) {
322
+ return O(1e3 * t2);
323
+ }, O.en = D[g], O.Ls = D, O.p = {}, O;
324
+ });
325
+ }
326
+ });
327
+
328
+ // src/debug/index.ts
329
+ var debug_exports = {};
330
+ __export(debug_exports, {
331
+ generateExtractData: () => generateExtractData,
332
+ generateTestDataPath: () => generateTestDataPath,
333
+ writeFileSyncWithDir: () => writeFileSyncWithDir
334
+ });
335
+ module.exports = __toCommonJS(debug_exports);
336
+ var import_node_fs2 = require("fs");
337
+ var import_node_path2 = __toESM(require("path"));
338
+
339
+ // src/img/img.ts
340
+ var import_node_assert = __toESM(require("assert"));
341
+ var import_node_buffer = require("buffer");
342
+ var import_sharp = __toESM(require("sharp"));
343
+ var createSvgOverlay = (elements, imageWidth, imageHeight) => {
344
+ let svgContent = `<svg width="${imageWidth}" height="${imageHeight}" xmlns="http://www.w3.org/2000/svg">`;
345
+ const colors = [
346
+ { rect: "blue", text: "white" },
347
+ { rect: "green", text: "white" }
348
+ ];
349
+ svgContent += "<defs>";
350
+ elements.forEach((element, index) => {
351
+ svgContent += `
352
+ <clipPath id="clip${index}">
353
+ <rect x="${element.x}" y="${element.y}" width="${element.width}" height="${element.height}" />
354
+ </clipPath>
355
+ `;
356
+ });
357
+ svgContent += "</defs>";
358
+ elements.forEach((element, index) => {
359
+ const textWidth = element.label.length * 8;
360
+ const textHeight = 12;
361
+ const rectWidth = textWidth + 5;
362
+ const rectHeight = textHeight + 4;
363
+ let rectX = element.x - rectWidth;
364
+ let rectY = element.y + element.height / 2 - textHeight / 2 - 2;
365
+ let textX = rectX + rectWidth / 2;
366
+ let textY = rectY + rectHeight / 2 + 6;
367
+ if (rectX < 0) {
368
+ rectX = element.x;
369
+ rectY = element.y - rectHeight;
370
+ textX = rectX + rectWidth / 2;
371
+ textY = rectY + rectHeight / 2 + 6;
372
+ }
373
+ const color = colors[index % colors.length];
374
+ svgContent += `
375
+ <rect x="${element.x}" y="${element.y}" width="${element.width}" height="${element.height}"
376
+ style="fill:none;stroke:${color.rect};stroke-width:4" clip-path="url(#clip${index})" />
377
+ <rect x="${rectX}" y="${rectY}" width="${rectWidth}" height="${rectHeight}" style="fill:${color.rect};" />
378
+ <text x="${textX}" y="${textY}"
379
+ text-anchor="middle" dominant-baseline="middle" style="fill:${color.text};font-size:12px;font-weight:bold;">
380
+ ${element.label}
381
+ </text>
382
+ `;
383
+ });
384
+ svgContent += "</svg>";
385
+ return import_node_buffer.Buffer.from(svgContent);
386
+ };
387
+ var processImageElementInfo = async (options) => {
388
+ const base64Image = options.inputImgBase64.split(";base64,").pop();
389
+ (0, import_node_assert.default)(base64Image, "base64Image is undefined");
390
+ const imageBuffer = import_node_buffer.Buffer.from(base64Image, "base64");
391
+ const metadata = await (0, import_sharp.default)(imageBuffer).metadata();
392
+ const { width, height } = metadata;
393
+ if (width && height) {
394
+ const svgOverlay = createSvgOverlay(
395
+ options.elementsPositionInfo,
396
+ width,
397
+ height
398
+ );
399
+ const svgOverlayWithoutText = createSvgOverlay(
400
+ options.elementsPositionInfoWithoutText,
401
+ width,
402
+ height
403
+ );
404
+ const compositeElementInfoImgBase64 = await (0, import_sharp.default)(imageBuffer).composite([{ input: svgOverlay, blend: "over" }]).toBuffer().then((data) => {
405
+ return data.toString("base64");
406
+ }).catch((err) => {
407
+ throw err;
408
+ });
409
+ const compositeElementInfoImgWithoutTextBase64 = await (0, import_sharp.default)(imageBuffer).composite([{ input: svgOverlayWithoutText, blend: "over" }]).toBuffer().then((data) => {
410
+ return data.toString("base64");
411
+ }).catch((err) => {
412
+ throw err;
413
+ });
414
+ return {
415
+ compositeElementInfoImgBase64,
416
+ compositeElementInfoImgWithoutTextBase64
417
+ };
418
+ }
419
+ throw Error("Image processing failed because width or height is undefined");
420
+ };
421
+
422
+ // src/common/utils.ts
423
+ var import_node_assert2 = __toESM(require("assert"));
424
+ var import_node_fs = __toESM(require("fs"));
425
+ var import_node_path = __toESM(require("path"));
426
+ var import_image = require("@midscene/core/image");
427
+ var import_utils = require("@midscene/core/utils");
428
+ var import_dayjs = __toESM(require_dayjs_min());
429
+ async function getElementInfosFromPage(page) {
430
+ const pathDir = findNearestPackageJson(__dirname);
431
+ (0, import_node_assert2.default)(pathDir, `can't find pathDir, with ${__dirname}`);
432
+ const scriptPath = import_node_path.default.join(pathDir, "./dist/script/htmlElement.js");
433
+ const elementInfosScriptContent = (0, import_node_fs.readFileSync)(scriptPath, "utf-8");
434
+ const extraReturnLogic = `${elementInfosScriptContent}midscene_element_inspector.extractTextWithPosition()`;
435
+ const captureElementSnapshot = await page.evaluate(extraReturnLogic);
436
+ return captureElementSnapshot;
437
+ }
438
+ function findNearestPackageJson(dir) {
439
+ const packageJsonPath = import_node_path.default.join(dir, "package.json");
440
+ if (import_node_fs.default.existsSync(packageJsonPath)) {
441
+ return dir;
442
+ }
443
+ const parentDir = import_node_path.default.dirname(dir);
444
+ if (parentDir === dir) {
445
+ return null;
446
+ }
447
+ return findNearestPackageJson(parentDir);
448
+ }
449
+
450
+ // src/img/util.ts
451
+ async function getElementInfos(page) {
452
+ const captureElementSnapshot = await getElementInfosFromPage(page);
453
+ const elementsPositionInfo = captureElementSnapshot.map((elementInfo) => {
454
+ return {
455
+ label: elementInfo.indexId.toString(),
456
+ x: elementInfo.rect.left,
457
+ y: elementInfo.rect.top,
458
+ width: elementInfo.rect.width,
459
+ height: elementInfo.rect.height,
460
+ attributes: elementInfo.attributes
461
+ };
462
+ });
463
+ const elementsPositionInfoWithoutText = elementsPositionInfo.filter(
464
+ (elementInfo) => {
465
+ if (elementInfo.attributes.nodeType === "TEXT Node" /* TEXT */) {
466
+ return false;
467
+ }
468
+ return true;
469
+ }
470
+ );
471
+ return {
472
+ elementsPositionInfo,
473
+ captureElementSnapshot,
474
+ elementsPositionInfoWithoutText
475
+ };
476
+ }
477
+
478
+ // src/debug/index.ts
479
+ var import_image2 = require("@midscene/core/image");
480
+ async function generateExtractData(page, targetDir, saveImgType) {
481
+ const buffer = await page.screenshot({
482
+ encoding: "base64"
483
+ });
484
+ const inputImgBase64 = buffer.toString("base64");
485
+ const {
486
+ elementsPositionInfo,
487
+ captureElementSnapshot,
488
+ elementsPositionInfoWithoutText
489
+ } = await getElementInfos(page);
490
+ const inputImagePath = import_node_path2.default.join(targetDir, "input.png");
491
+ const outputImagePath = import_node_path2.default.join(targetDir, "output.png");
492
+ const outputWithoutTextImgPath = import_node_path2.default.join(
493
+ targetDir,
494
+ "output_without_text.png"
495
+ );
496
+ const resizeOutputImgPath = import_node_path2.default.join(targetDir, "resize-output.png");
497
+ const snapshotJsonPath = import_node_path2.default.join(targetDir, "element-snapshot.json");
498
+ const {
499
+ compositeElementInfoImgBase64,
500
+ compositeElementInfoImgWithoutTextBase64
501
+ } = await processImageElementInfo({
502
+ elementsPositionInfo,
503
+ elementsPositionInfoWithoutText,
504
+ inputImgBase64
505
+ });
506
+ const resizeImgBase64 = await (0, import_image2.resizeImg)(inputImgBase64);
507
+ if (!(saveImgType == null ? void 0 : saveImgType.disableSnapshot)) {
508
+ writeFileSyncWithDir(
509
+ snapshotJsonPath,
510
+ JSON.stringify(captureElementSnapshot, null, 2)
511
+ );
512
+ }
513
+ if (!(saveImgType == null ? void 0 : saveImgType.disableInputImage)) {
514
+ await (0, import_image2.saveBase64Image)({
515
+ base64Data: inputImgBase64,
516
+ outputPath: inputImagePath
517
+ });
518
+ }
519
+ if (!(saveImgType == null ? void 0 : saveImgType.disableOutputImage)) {
520
+ await (0, import_image2.saveBase64Image)({
521
+ base64Data: compositeElementInfoImgBase64,
522
+ outputPath: outputImagePath
523
+ });
524
+ }
525
+ if (!(saveImgType == null ? void 0 : saveImgType.disableOutputWithoutTextImg)) {
526
+ await (0, import_image2.saveBase64Image)({
527
+ base64Data: compositeElementInfoImgWithoutTextBase64,
528
+ outputPath: outputWithoutTextImgPath
529
+ });
530
+ }
531
+ if (!(saveImgType == null ? void 0 : saveImgType.disableResizeOutputImg)) {
532
+ await (0, import_image2.saveBase64Image)({
533
+ base64Data: resizeImgBase64,
534
+ outputPath: resizeOutputImgPath
535
+ });
536
+ }
537
+ }
538
+ function generateTestDataPath(testDataName) {
539
+ const modulePath = require.resolve("@midscene/core").replace("dist/lib/index.js", "");
540
+ const midsceneTestDataPath = import_node_path2.default.join(
541
+ modulePath,
542
+ `tests/ai/inspector/test-data/${testDataName}`
543
+ );
544
+ return midsceneTestDataPath;
545
+ }
546
+ function ensureDirectoryExistence(filePath) {
547
+ const dirname = import_node_path2.default.dirname(filePath);
548
+ if ((0, import_node_fs2.existsSync)(dirname)) {
549
+ return;
550
+ }
551
+ ensureDirectoryExistence(dirname);
552
+ (0, import_node_fs2.mkdirSync)(dirname);
553
+ }
554
+ function writeFileSyncWithDir(filePath, content, options = {}) {
555
+ ensureDirectoryExistence(filePath);
556
+ (0, import_node_fs2.writeFileSync)(filePath, content, options);
557
+ }
558
+ // Annotate the CommonJS export names for ESM import in node:
559
+ 0 && (module.exports = {
560
+ generateExtractData,
561
+ generateTestDataPath,
562
+ writeFileSyncWithDir
563
+ });
package/dist/lib/index.js CHANGED
@@ -351,7 +351,7 @@ __export(src_exports, {
351
351
  });
352
352
  module.exports = __toCommonJS(src_exports);
353
353
 
354
- // src/playwright/index.ts
354
+ // src/playwright/ai-fixture.ts
355
355
  var import_node_crypto = require("crypto");
356
356
 
357
357
  // src/common/agent.ts
@@ -1053,7 +1053,7 @@ ${errorTask == null ? void 0 : errorTask.errorStack}`);
1053
1053
  }
1054
1054
  };
1055
1055
 
1056
- // src/playwright/index.ts
1056
+ // src/playwright/ai-fixture.ts
1057
1057
  var import_test = require("@playwright/test");
1058
1058
 
1059
1059
  // src/playwright/cache.ts
@@ -1115,7 +1115,7 @@ function getPkgInfo() {
1115
1115
  };
1116
1116
  }
1117
1117
 
1118
- // src/playwright/index.ts
1118
+ // src/playwright/ai-fixture.ts
1119
1119
  var groupAndCaseForTest = (testInfo) => {
1120
1120
  let taskFile;
1121
1121
  let taskTitle;