@midscene/shared 0.10.4 → 0.10.6-beta-20250207060931.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/dist/browser/extractor-debug.d.ts +2 -0
  2. package/dist/browser/extractor-debug.js +1254 -0
  3. package/dist/browser/extractor.d.ts +47 -0
  4. package/dist/browser/extractor.js +1542 -0
  5. package/dist/browser/img.d.ts +3 -12
  6. package/dist/browser/img.js +3 -3
  7. package/dist/browser/index-305e7a7e.d.ts +32 -0
  8. package/dist/browser/utils.d.ts +1 -3
  9. package/dist/browser/utils.js +11 -14
  10. package/dist/es/extractor-debug.d.ts +2 -0
  11. package/dist/es/extractor-debug.js +1252 -0
  12. package/dist/es/extractor.d.ts +47 -0
  13. package/dist/es/extractor.js +1531 -0
  14. package/dist/es/img.d.ts +3 -12
  15. package/dist/es/img.js +3 -3
  16. package/dist/es/index-305e7a7e.d.ts +32 -0
  17. package/dist/es/utils.d.ts +1 -3
  18. package/dist/es/utils.js +11 -14
  19. package/dist/lib/extractor-debug.d.ts +2 -0
  20. package/dist/lib/extractor-debug.js +1246 -0
  21. package/dist/lib/extractor.d.ts +47 -0
  22. package/dist/lib/extractor.js +1544 -0
  23. package/dist/lib/img.d.ts +3 -12
  24. package/dist/lib/img.js +3 -3
  25. package/dist/lib/index-305e7a7e.d.ts +32 -0
  26. package/dist/lib/utils.d.ts +1 -3
  27. package/dist/lib/utils.js +11 -16
  28. package/dist/script/htmlElement.js +1544 -0
  29. package/dist/script/htmlElementDebug.js +1256 -0
  30. package/package.json +20 -2
  31. package/src/extractor/client-extractor.ts +212 -0
  32. package/src/extractor/constants.ts +5 -0
  33. package/src/extractor/debug.ts +10 -0
  34. package/src/extractor/dom-util.ts +100 -0
  35. package/src/extractor/index.ts +31 -0
  36. package/src/extractor/tree.ts +173 -0
  37. package/src/extractor/util.ts +491 -0
  38. package/src/extractor/web-extractor.ts +406 -0
  39. package/src/img/box-select.ts +2 -2
  40. package/src/img/draw-box.ts +2 -3
  41. package/src/img/transform.ts +1 -1
  42. package/src/types/index.ts +31 -2
  43. package/src/utils.ts +18 -15
@@ -0,0 +1,1542 @@
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
+ // resolve-false:/empty-stub
51
+ var require_empty_stub = __commonJS({
52
+ "resolve-false:/empty-stub"(exports, module2) {
53
+ "use strict";
54
+ module2.exports = {};
55
+ }
56
+ });
57
+
58
+ // ../../node_modules/.pnpm/js-sha256@0.11.0/node_modules/js-sha256/src/sha256.js
59
+ var require_sha256 = __commonJS({
60
+ "../../node_modules/.pnpm/js-sha256@0.11.0/node_modules/js-sha256/src/sha256.js"(exports, module2) {
61
+ "use strict";
62
+ (function() {
63
+ "use strict";
64
+ var ERROR = "input is invalid type";
65
+ var WINDOW = typeof window === "object";
66
+ var root = WINDOW ? window : {};
67
+ if (root.JS_SHA256_NO_WINDOW) {
68
+ WINDOW = false;
69
+ }
70
+ var WEB_WORKER = !WINDOW && typeof self === "object";
71
+ var NODE_JS = !root.JS_SHA256_NO_NODE_JS && typeof process === "object" && process.versions && process.versions.node;
72
+ if (NODE_JS) {
73
+ root = global;
74
+ } else if (WEB_WORKER) {
75
+ root = self;
76
+ }
77
+ var COMMON_JS = !root.JS_SHA256_NO_COMMON_JS && typeof module2 === "object" && module2.exports;
78
+ var AMD = typeof define === "function" && define.amd;
79
+ var ARRAY_BUFFER = !root.JS_SHA256_NO_ARRAY_BUFFER && typeof ArrayBuffer !== "undefined";
80
+ var HEX_CHARS = "0123456789abcdef".split("");
81
+ var EXTRA = [-2147483648, 8388608, 32768, 128];
82
+ var SHIFT = [24, 16, 8, 0];
83
+ var K = [
84
+ 1116352408,
85
+ 1899447441,
86
+ 3049323471,
87
+ 3921009573,
88
+ 961987163,
89
+ 1508970993,
90
+ 2453635748,
91
+ 2870763221,
92
+ 3624381080,
93
+ 310598401,
94
+ 607225278,
95
+ 1426881987,
96
+ 1925078388,
97
+ 2162078206,
98
+ 2614888103,
99
+ 3248222580,
100
+ 3835390401,
101
+ 4022224774,
102
+ 264347078,
103
+ 604807628,
104
+ 770255983,
105
+ 1249150122,
106
+ 1555081692,
107
+ 1996064986,
108
+ 2554220882,
109
+ 2821834349,
110
+ 2952996808,
111
+ 3210313671,
112
+ 3336571891,
113
+ 3584528711,
114
+ 113926993,
115
+ 338241895,
116
+ 666307205,
117
+ 773529912,
118
+ 1294757372,
119
+ 1396182291,
120
+ 1695183700,
121
+ 1986661051,
122
+ 2177026350,
123
+ 2456956037,
124
+ 2730485921,
125
+ 2820302411,
126
+ 3259730800,
127
+ 3345764771,
128
+ 3516065817,
129
+ 3600352804,
130
+ 4094571909,
131
+ 275423344,
132
+ 430227734,
133
+ 506948616,
134
+ 659060556,
135
+ 883997877,
136
+ 958139571,
137
+ 1322822218,
138
+ 1537002063,
139
+ 1747873779,
140
+ 1955562222,
141
+ 2024104815,
142
+ 2227730452,
143
+ 2361852424,
144
+ 2428436474,
145
+ 2756734187,
146
+ 3204031479,
147
+ 3329325298
148
+ ];
149
+ var OUTPUT_TYPES = ["hex", "array", "digest", "arrayBuffer"];
150
+ var blocks = [];
151
+ if (root.JS_SHA256_NO_NODE_JS || !Array.isArray) {
152
+ Array.isArray = function(obj) {
153
+ return Object.prototype.toString.call(obj) === "[object Array]";
154
+ };
155
+ }
156
+ if (ARRAY_BUFFER && (root.JS_SHA256_NO_ARRAY_BUFFER_IS_VIEW || !ArrayBuffer.isView)) {
157
+ ArrayBuffer.isView = function(obj) {
158
+ return typeof obj === "object" && obj.buffer && obj.buffer.constructor === ArrayBuffer;
159
+ };
160
+ }
161
+ var createOutputMethod = function(outputType, is224) {
162
+ return function(message) {
163
+ return new Sha256(is224, true).update(message)[outputType]();
164
+ };
165
+ };
166
+ var createMethod = function(is224) {
167
+ var method = createOutputMethod("hex", is224);
168
+ if (NODE_JS) {
169
+ method = nodeWrap(method, is224);
170
+ }
171
+ method.create = function() {
172
+ return new Sha256(is224);
173
+ };
174
+ method.update = function(message) {
175
+ return method.create().update(message);
176
+ };
177
+ for (var i = 0; i < OUTPUT_TYPES.length; ++i) {
178
+ var type = OUTPUT_TYPES[i];
179
+ method[type] = createOutputMethod(type, is224);
180
+ }
181
+ return method;
182
+ };
183
+ var nodeWrap = function(method, is224) {
184
+ var crypto = require_empty_stub();
185
+ var Buffer2 = require_empty_stub().Buffer;
186
+ var algorithm = is224 ? "sha224" : "sha256";
187
+ var bufferFrom;
188
+ if (Buffer2.from && !root.JS_SHA256_NO_BUFFER_FROM) {
189
+ bufferFrom = Buffer2.from;
190
+ } else {
191
+ bufferFrom = function(message) {
192
+ return new Buffer2(message);
193
+ };
194
+ }
195
+ var nodeMethod = function(message) {
196
+ if (typeof message === "string") {
197
+ return crypto.createHash(algorithm).update(message, "utf8").digest("hex");
198
+ } else {
199
+ if (message === null || message === void 0) {
200
+ throw new Error(ERROR);
201
+ } else if (message.constructor === ArrayBuffer) {
202
+ message = new Uint8Array(message);
203
+ }
204
+ }
205
+ if (Array.isArray(message) || ArrayBuffer.isView(message) || message.constructor === Buffer2) {
206
+ return crypto.createHash(algorithm).update(bufferFrom(message)).digest("hex");
207
+ } else {
208
+ return method(message);
209
+ }
210
+ };
211
+ return nodeMethod;
212
+ };
213
+ var createHmacOutputMethod = function(outputType, is224) {
214
+ return function(key, message) {
215
+ return new HmacSha256(key, is224, true).update(message)[outputType]();
216
+ };
217
+ };
218
+ var createHmacMethod = function(is224) {
219
+ var method = createHmacOutputMethod("hex", is224);
220
+ method.create = function(key) {
221
+ return new HmacSha256(key, is224);
222
+ };
223
+ method.update = function(key, message) {
224
+ return method.create(key).update(message);
225
+ };
226
+ for (var i = 0; i < OUTPUT_TYPES.length; ++i) {
227
+ var type = OUTPUT_TYPES[i];
228
+ method[type] = createHmacOutputMethod(type, is224);
229
+ }
230
+ return method;
231
+ };
232
+ function Sha256(is224, sharedMemory) {
233
+ if (sharedMemory) {
234
+ 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;
235
+ this.blocks = blocks;
236
+ } else {
237
+ this.blocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
238
+ }
239
+ if (is224) {
240
+ this.h0 = 3238371032;
241
+ this.h1 = 914150663;
242
+ this.h2 = 812702999;
243
+ this.h3 = 4144912697;
244
+ this.h4 = 4290775857;
245
+ this.h5 = 1750603025;
246
+ this.h6 = 1694076839;
247
+ this.h7 = 3204075428;
248
+ } else {
249
+ this.h0 = 1779033703;
250
+ this.h1 = 3144134277;
251
+ this.h2 = 1013904242;
252
+ this.h3 = 2773480762;
253
+ this.h4 = 1359893119;
254
+ this.h5 = 2600822924;
255
+ this.h6 = 528734635;
256
+ this.h7 = 1541459225;
257
+ }
258
+ this.block = this.start = this.bytes = this.hBytes = 0;
259
+ this.finalized = this.hashed = false;
260
+ this.first = true;
261
+ this.is224 = is224;
262
+ }
263
+ Sha256.prototype.update = function(message) {
264
+ if (this.finalized) {
265
+ return;
266
+ }
267
+ var notString, type = typeof message;
268
+ if (type !== "string") {
269
+ if (type === "object") {
270
+ if (message === null) {
271
+ throw new Error(ERROR);
272
+ } else if (ARRAY_BUFFER && message.constructor === ArrayBuffer) {
273
+ message = new Uint8Array(message);
274
+ } else if (!Array.isArray(message)) {
275
+ if (!ARRAY_BUFFER || !ArrayBuffer.isView(message)) {
276
+ throw new Error(ERROR);
277
+ }
278
+ }
279
+ } else {
280
+ throw new Error(ERROR);
281
+ }
282
+ notString = true;
283
+ }
284
+ var code, index = 0, i, length = message.length, blocks2 = this.blocks;
285
+ while (index < length) {
286
+ if (this.hashed) {
287
+ this.hashed = false;
288
+ blocks2[0] = this.block;
289
+ 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;
290
+ }
291
+ if (notString) {
292
+ for (i = this.start; index < length && i < 64; ++index) {
293
+ blocks2[i >>> 2] |= message[index] << SHIFT[i++ & 3];
294
+ }
295
+ } else {
296
+ for (i = this.start; index < length && i < 64; ++index) {
297
+ code = message.charCodeAt(index);
298
+ if (code < 128) {
299
+ blocks2[i >>> 2] |= code << SHIFT[i++ & 3];
300
+ } else if (code < 2048) {
301
+ blocks2[i >>> 2] |= (192 | code >>> 6) << SHIFT[i++ & 3];
302
+ blocks2[i >>> 2] |= (128 | code & 63) << SHIFT[i++ & 3];
303
+ } else if (code < 55296 || code >= 57344) {
304
+ blocks2[i >>> 2] |= (224 | code >>> 12) << SHIFT[i++ & 3];
305
+ blocks2[i >>> 2] |= (128 | code >>> 6 & 63) << SHIFT[i++ & 3];
306
+ blocks2[i >>> 2] |= (128 | code & 63) << SHIFT[i++ & 3];
307
+ } else {
308
+ code = 65536 + ((code & 1023) << 10 | message.charCodeAt(++index) & 1023);
309
+ blocks2[i >>> 2] |= (240 | code >>> 18) << SHIFT[i++ & 3];
310
+ blocks2[i >>> 2] |= (128 | code >>> 12 & 63) << SHIFT[i++ & 3];
311
+ blocks2[i >>> 2] |= (128 | code >>> 6 & 63) << SHIFT[i++ & 3];
312
+ blocks2[i >>> 2] |= (128 | code & 63) << SHIFT[i++ & 3];
313
+ }
314
+ }
315
+ }
316
+ this.lastByteIndex = i;
317
+ this.bytes += i - this.start;
318
+ if (i >= 64) {
319
+ this.block = blocks2[16];
320
+ this.start = i - 64;
321
+ this.hash();
322
+ this.hashed = true;
323
+ } else {
324
+ this.start = i;
325
+ }
326
+ }
327
+ if (this.bytes > 4294967295) {
328
+ this.hBytes += this.bytes / 4294967296 << 0;
329
+ this.bytes = this.bytes % 4294967296;
330
+ }
331
+ return this;
332
+ };
333
+ Sha256.prototype.finalize = function() {
334
+ if (this.finalized) {
335
+ return;
336
+ }
337
+ this.finalized = true;
338
+ var blocks2 = this.blocks, i = this.lastByteIndex;
339
+ blocks2[16] = this.block;
340
+ blocks2[i >>> 2] |= EXTRA[i & 3];
341
+ this.block = blocks2[16];
342
+ if (i >= 56) {
343
+ if (!this.hashed) {
344
+ this.hash();
345
+ }
346
+ blocks2[0] = this.block;
347
+ 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;
348
+ }
349
+ blocks2[14] = this.hBytes << 3 | this.bytes >>> 29;
350
+ blocks2[15] = this.bytes << 3;
351
+ this.hash();
352
+ };
353
+ Sha256.prototype.hash = function() {
354
+ 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;
355
+ for (j = 16; j < 64; ++j) {
356
+ t1 = blocks2[j - 15];
357
+ s0 = (t1 >>> 7 | t1 << 25) ^ (t1 >>> 18 | t1 << 14) ^ t1 >>> 3;
358
+ t1 = blocks2[j - 2];
359
+ s1 = (t1 >>> 17 | t1 << 15) ^ (t1 >>> 19 | t1 << 13) ^ t1 >>> 10;
360
+ blocks2[j] = blocks2[j - 16] + s0 + blocks2[j - 7] + s1 << 0;
361
+ }
362
+ bc = b & c;
363
+ for (j = 0; j < 64; j += 4) {
364
+ if (this.first) {
365
+ if (this.is224) {
366
+ ab = 300032;
367
+ t1 = blocks2[0] - 1413257819;
368
+ h = t1 - 150054599 << 0;
369
+ d = t1 + 24177077 << 0;
370
+ } else {
371
+ ab = 704751109;
372
+ t1 = blocks2[0] - 210244248;
373
+ h = t1 - 1521486534 << 0;
374
+ d = t1 + 143694565 << 0;
375
+ }
376
+ this.first = false;
377
+ } else {
378
+ s0 = (a >>> 2 | a << 30) ^ (a >>> 13 | a << 19) ^ (a >>> 22 | a << 10);
379
+ s1 = (e >>> 6 | e << 26) ^ (e >>> 11 | e << 21) ^ (e >>> 25 | e << 7);
380
+ ab = a & b;
381
+ maj = ab ^ a & c ^ bc;
382
+ ch = e & f ^ ~e & g;
383
+ t1 = h + s1 + ch + K[j] + blocks2[j];
384
+ t2 = s0 + maj;
385
+ h = d + t1 << 0;
386
+ d = t1 + t2 << 0;
387
+ }
388
+ s0 = (d >>> 2 | d << 30) ^ (d >>> 13 | d << 19) ^ (d >>> 22 | d << 10);
389
+ s1 = (h >>> 6 | h << 26) ^ (h >>> 11 | h << 21) ^ (h >>> 25 | h << 7);
390
+ da = d & a;
391
+ maj = da ^ d & b ^ ab;
392
+ ch = h & e ^ ~h & f;
393
+ t1 = g + s1 + ch + K[j + 1] + blocks2[j + 1];
394
+ t2 = s0 + maj;
395
+ g = c + t1 << 0;
396
+ c = t1 + t2 << 0;
397
+ s0 = (c >>> 2 | c << 30) ^ (c >>> 13 | c << 19) ^ (c >>> 22 | c << 10);
398
+ s1 = (g >>> 6 | g << 26) ^ (g >>> 11 | g << 21) ^ (g >>> 25 | g << 7);
399
+ cd = c & d;
400
+ maj = cd ^ c & a ^ da;
401
+ ch = g & h ^ ~g & e;
402
+ t1 = f + s1 + ch + K[j + 2] + blocks2[j + 2];
403
+ t2 = s0 + maj;
404
+ f = b + t1 << 0;
405
+ b = t1 + t2 << 0;
406
+ s0 = (b >>> 2 | b << 30) ^ (b >>> 13 | b << 19) ^ (b >>> 22 | b << 10);
407
+ s1 = (f >>> 6 | f << 26) ^ (f >>> 11 | f << 21) ^ (f >>> 25 | f << 7);
408
+ bc = b & c;
409
+ maj = bc ^ b & d ^ cd;
410
+ ch = f & g ^ ~f & h;
411
+ t1 = e + s1 + ch + K[j + 3] + blocks2[j + 3];
412
+ t2 = s0 + maj;
413
+ e = a + t1 << 0;
414
+ a = t1 + t2 << 0;
415
+ this.chromeBugWorkAround = true;
416
+ }
417
+ this.h0 = this.h0 + a << 0;
418
+ this.h1 = this.h1 + b << 0;
419
+ this.h2 = this.h2 + c << 0;
420
+ this.h3 = this.h3 + d << 0;
421
+ this.h4 = this.h4 + e << 0;
422
+ this.h5 = this.h5 + f << 0;
423
+ this.h6 = this.h6 + g << 0;
424
+ this.h7 = this.h7 + h << 0;
425
+ };
426
+ Sha256.prototype.hex = function() {
427
+ this.finalize();
428
+ 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;
429
+ 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];
430
+ if (!this.is224) {
431
+ 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];
432
+ }
433
+ return hex;
434
+ };
435
+ Sha256.prototype.toString = Sha256.prototype.hex;
436
+ Sha256.prototype.digest = function() {
437
+ this.finalize();
438
+ 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;
439
+ var arr = [
440
+ h0 >>> 24 & 255,
441
+ h0 >>> 16 & 255,
442
+ h0 >>> 8 & 255,
443
+ h0 & 255,
444
+ h1 >>> 24 & 255,
445
+ h1 >>> 16 & 255,
446
+ h1 >>> 8 & 255,
447
+ h1 & 255,
448
+ h2 >>> 24 & 255,
449
+ h2 >>> 16 & 255,
450
+ h2 >>> 8 & 255,
451
+ h2 & 255,
452
+ h3 >>> 24 & 255,
453
+ h3 >>> 16 & 255,
454
+ h3 >>> 8 & 255,
455
+ h3 & 255,
456
+ h4 >>> 24 & 255,
457
+ h4 >>> 16 & 255,
458
+ h4 >>> 8 & 255,
459
+ h4 & 255,
460
+ h5 >>> 24 & 255,
461
+ h5 >>> 16 & 255,
462
+ h5 >>> 8 & 255,
463
+ h5 & 255,
464
+ h6 >>> 24 & 255,
465
+ h6 >>> 16 & 255,
466
+ h6 >>> 8 & 255,
467
+ h6 & 255
468
+ ];
469
+ if (!this.is224) {
470
+ arr.push(h7 >>> 24 & 255, h7 >>> 16 & 255, h7 >>> 8 & 255, h7 & 255);
471
+ }
472
+ return arr;
473
+ };
474
+ Sha256.prototype.array = Sha256.prototype.digest;
475
+ Sha256.prototype.arrayBuffer = function() {
476
+ this.finalize();
477
+ var buffer = new ArrayBuffer(this.is224 ? 28 : 32);
478
+ var dataView = new DataView(buffer);
479
+ dataView.setUint32(0, this.h0);
480
+ dataView.setUint32(4, this.h1);
481
+ dataView.setUint32(8, this.h2);
482
+ dataView.setUint32(12, this.h3);
483
+ dataView.setUint32(16, this.h4);
484
+ dataView.setUint32(20, this.h5);
485
+ dataView.setUint32(24, this.h6);
486
+ if (!this.is224) {
487
+ dataView.setUint32(28, this.h7);
488
+ }
489
+ return buffer;
490
+ };
491
+ function HmacSha256(key, is224, sharedMemory) {
492
+ var i, type = typeof key;
493
+ if (type === "string") {
494
+ var bytes = [], length = key.length, index = 0, code;
495
+ for (i = 0; i < length; ++i) {
496
+ code = key.charCodeAt(i);
497
+ if (code < 128) {
498
+ bytes[index++] = code;
499
+ } else if (code < 2048) {
500
+ bytes[index++] = 192 | code >>> 6;
501
+ bytes[index++] = 128 | code & 63;
502
+ } else if (code < 55296 || code >= 57344) {
503
+ bytes[index++] = 224 | code >>> 12;
504
+ bytes[index++] = 128 | code >>> 6 & 63;
505
+ bytes[index++] = 128 | code & 63;
506
+ } else {
507
+ code = 65536 + ((code & 1023) << 10 | key.charCodeAt(++i) & 1023);
508
+ bytes[index++] = 240 | code >>> 18;
509
+ bytes[index++] = 128 | code >>> 12 & 63;
510
+ bytes[index++] = 128 | code >>> 6 & 63;
511
+ bytes[index++] = 128 | code & 63;
512
+ }
513
+ }
514
+ key = bytes;
515
+ } else {
516
+ if (type === "object") {
517
+ if (key === null) {
518
+ throw new Error(ERROR);
519
+ } else if (ARRAY_BUFFER && key.constructor === ArrayBuffer) {
520
+ key = new Uint8Array(key);
521
+ } else if (!Array.isArray(key)) {
522
+ if (!ARRAY_BUFFER || !ArrayBuffer.isView(key)) {
523
+ throw new Error(ERROR);
524
+ }
525
+ }
526
+ } else {
527
+ throw new Error(ERROR);
528
+ }
529
+ }
530
+ if (key.length > 64) {
531
+ key = new Sha256(is224, true).update(key).array();
532
+ }
533
+ var oKeyPad = [], iKeyPad = [];
534
+ for (i = 0; i < 64; ++i) {
535
+ var b = key[i] || 0;
536
+ oKeyPad[i] = 92 ^ b;
537
+ iKeyPad[i] = 54 ^ b;
538
+ }
539
+ Sha256.call(this, is224, sharedMemory);
540
+ this.update(iKeyPad);
541
+ this.oKeyPad = oKeyPad;
542
+ this.inner = true;
543
+ this.sharedMemory = sharedMemory;
544
+ }
545
+ HmacSha256.prototype = new Sha256();
546
+ HmacSha256.prototype.finalize = function() {
547
+ Sha256.prototype.finalize.call(this);
548
+ if (this.inner) {
549
+ this.inner = false;
550
+ var innerHash = this.array();
551
+ Sha256.call(this, this.is224, this.sharedMemory);
552
+ this.update(this.oKeyPad);
553
+ this.update(innerHash);
554
+ Sha256.prototype.finalize.call(this);
555
+ }
556
+ };
557
+ var exports2 = createMethod();
558
+ exports2.sha256 = exports2;
559
+ exports2.sha224 = createMethod(true);
560
+ exports2.sha256.hmac = createHmacMethod();
561
+ exports2.sha224.hmac = createHmacMethod(true);
562
+ if (COMMON_JS) {
563
+ module2.exports = exports2;
564
+ } else {
565
+ root.sha256 = exports2.sha256;
566
+ root.sha224 = exports2.sha224;
567
+ if (AMD) {
568
+ define(function() {
569
+ return exports2;
570
+ });
571
+ }
572
+ }
573
+ })();
574
+ }
575
+ });
576
+
577
+ // src/extractor/index.ts
578
+ var extractor_exports = {};
579
+ __export(extractor_exports, {
580
+ clientExtractTextWithPosition: () => extractTextWithPosition2,
581
+ descriptionOfTree: () => descriptionOfTree,
582
+ traverseTree: () => traverseTree,
583
+ treeToList: () => treeToList,
584
+ webExtractNodeTree: () => extractTreeNode,
585
+ webExtractNodeTreeAsString: () => extractTreeNodeAsString,
586
+ webExtractTextWithPosition: () => extractTextWithPosition
587
+ });
588
+ module.exports = __toCommonJS(extractor_exports);
589
+
590
+ // src/extractor/tree.ts
591
+ function truncateText(text, maxLength = 150) {
592
+ if (typeof text === "undefined") {
593
+ return "";
594
+ }
595
+ if (typeof text === "object") {
596
+ text = JSON.stringify(text);
597
+ }
598
+ if (typeof text === "number") {
599
+ return text.toString();
600
+ }
601
+ if (typeof text === "string" && text.length > maxLength) {
602
+ return `${text.slice(0, maxLength)}...`;
603
+ }
604
+ if (typeof text === "string") {
605
+ return text.trim();
606
+ }
607
+ return "";
608
+ }
609
+ function trimAttributes(attributes, truncateTextLength) {
610
+ const tailorAttributes = Object.keys(attributes).reduce(
611
+ (res, currentKey) => {
612
+ const attributeVal = attributes[currentKey];
613
+ if (currentKey === "style" || currentKey === "src" || currentKey === "htmlTagName" || currentKey === "nodeType") {
614
+ return res;
615
+ }
616
+ res[currentKey] = truncateText(attributeVal, truncateTextLength);
617
+ return res;
618
+ },
619
+ {}
620
+ );
621
+ return tailorAttributes;
622
+ }
623
+ var nodeSizeThreshold = 4;
624
+ function descriptionOfTree(tree, truncateTextLength, filterNonTextContent = false) {
625
+ const attributesString = (kv) => {
626
+ return Object.entries(kv).map(
627
+ ([key, value]) => `${key}="${truncateText(value, truncateTextLength)}"`
628
+ ).join(" ");
629
+ };
630
+ function buildContentTree(node, indent = 0) {
631
+ var _a;
632
+ let before = "";
633
+ let contentWithIndent = "";
634
+ let after = "";
635
+ let emptyNode = true;
636
+ const indentStr = " ".repeat(indent);
637
+ let children = "";
638
+ for (let i = 0; i < (node.children || []).length; i++) {
639
+ const childContent = buildContentTree(node.children[i], indent + 1);
640
+ if (childContent) {
641
+ children += `
642
+ ${childContent}`;
643
+ }
644
+ }
645
+ if (node.node && node.node.rect.width > nodeSizeThreshold && node.node.rect.height > nodeSizeThreshold && (!filterNonTextContent || filterNonTextContent && node.node.content)) {
646
+ emptyNode = false;
647
+ let nodeTypeString;
648
+ if ((_a = node.node.attributes) == null ? void 0 : _a.htmlTagName) {
649
+ nodeTypeString = node.node.attributes.htmlTagName.replace(/[<>]/g, "");
650
+ } else {
651
+ nodeTypeString = node.node.attributes.nodeType.replace(/\sNode$/, "").toLowerCase();
652
+ }
653
+ const markerId = node.node.indexId;
654
+ const markerIdString = markerId ? `markerId="${markerId}"` : "";
655
+ const rectAttribute = node.node.rect ? {
656
+ left: node.node.rect.left,
657
+ top: node.node.rect.top,
658
+ width: node.node.rect.width,
659
+ height: node.node.rect.height
660
+ } : {};
661
+ before = `<${nodeTypeString} id="${node.node.id}" ${markerIdString} ${attributesString(trimAttributes(node.node.attributes || {}, truncateTextLength))} ${attributesString(rectAttribute)}>`;
662
+ const content = truncateText(node.node.content, truncateTextLength);
663
+ contentWithIndent = content ? `
664
+ ${indentStr} ${content}` : "";
665
+ after = `</${nodeTypeString}>`;
666
+ } else if (!filterNonTextContent) {
667
+ if (!children.trim().startsWith("<>")) {
668
+ before = "<>";
669
+ contentWithIndent = "";
670
+ after = "</>";
671
+ }
672
+ }
673
+ if (emptyNode && !children.trim()) {
674
+ return "";
675
+ }
676
+ const result2 = `${indentStr}${before}${contentWithIndent}${children}
677
+ ${indentStr}${after}`;
678
+ if (result2.trim()) {
679
+ return result2;
680
+ }
681
+ return "";
682
+ }
683
+ const result = buildContentTree(tree);
684
+ return result.replace(/^\s*\n/gm, "");
685
+ }
686
+ function treeToList(tree) {
687
+ const result = [];
688
+ function dfs(node) {
689
+ if (node.node) {
690
+ result.push(node.node);
691
+ }
692
+ for (const child of node.children) {
693
+ dfs(child);
694
+ }
695
+ }
696
+ dfs(tree);
697
+ return result;
698
+ }
699
+ function traverseTree(tree, onNode) {
700
+ function dfs(node) {
701
+ if (node.node) {
702
+ node.node = onNode(node.node);
703
+ }
704
+ for (const child of node.children) {
705
+ dfs(child);
706
+ }
707
+ }
708
+ dfs(tree);
709
+ return tree;
710
+ }
711
+
712
+ // src/constants/index.ts
713
+ var CONTAINER_MINI_HEIGHT = 3;
714
+ var CONTAINER_MINI_WIDTH = 3;
715
+
716
+ // src/extractor/dom-util.ts
717
+ function isFormElement(node) {
718
+ return node instanceof HTMLElement && (node.tagName.toLowerCase() === "input" || node.tagName.toLowerCase() === "textarea" || node.tagName.toLowerCase() === "select" || node.tagName.toLowerCase() === "option");
719
+ }
720
+ function isButtonElement(node) {
721
+ return node instanceof HTMLElement && node.tagName.toLowerCase() === "button";
722
+ }
723
+ function isImgElement(node) {
724
+ if (!includeBaseElement(node) && node instanceof Element) {
725
+ const computedStyle = window.getComputedStyle(node);
726
+ const backgroundImage = computedStyle.getPropertyValue("background-image");
727
+ if (backgroundImage !== "none") {
728
+ return true;
729
+ }
730
+ }
731
+ if (isIconfont(node)) {
732
+ return true;
733
+ }
734
+ return node instanceof HTMLElement && node.tagName.toLowerCase() === "img" || node instanceof SVGElement && node.tagName.toLowerCase() === "svg";
735
+ }
736
+ function isIconfont(node) {
737
+ if (node instanceof Element) {
738
+ const computedStyle = window.getComputedStyle(node);
739
+ const fontFamilyValue = computedStyle.fontFamily || "";
740
+ return fontFamilyValue.toLowerCase().indexOf("iconfont") >= 0;
741
+ }
742
+ return false;
743
+ }
744
+ function isTextElement(node) {
745
+ return node.nodeName.toLowerCase() === "#text" && !isIconfont(node);
746
+ }
747
+ function isContainerElement(node) {
748
+ if (!(node instanceof HTMLElement))
749
+ return false;
750
+ if (includeBaseElement(node)) {
751
+ return false;
752
+ }
753
+ const computedStyle = window.getComputedStyle(node);
754
+ const backgroundColor = computedStyle.getPropertyValue("background-color");
755
+ if (backgroundColor) {
756
+ return true;
757
+ }
758
+ return false;
759
+ }
760
+ function includeBaseElement(node) {
761
+ if (!(node instanceof HTMLElement))
762
+ return false;
763
+ if (node.innerText) {
764
+ return true;
765
+ }
766
+ const includeList = [
767
+ "svg",
768
+ "button",
769
+ "input",
770
+ "textarea",
771
+ "select",
772
+ "option",
773
+ "img"
774
+ ];
775
+ for (const tagName of includeList) {
776
+ const element = node.querySelectorAll(tagName);
777
+ if (element.length > 0) {
778
+ return true;
779
+ }
780
+ }
781
+ return false;
782
+ }
783
+
784
+ // src/utils.ts
785
+ var import_js_sha256 = __toESM(require_sha256());
786
+ var hashMap = {};
787
+ function generateHashId(rect, content = "") {
788
+ const combined = JSON.stringify({
789
+ content,
790
+ rect
791
+ });
792
+ let sliceLength = 5;
793
+ let slicedHash = "";
794
+ const hashHex = import_js_sha256.sha256.create().update(combined).hex();
795
+ const toLetters = (hex) => {
796
+ return hex.split("").map((char) => {
797
+ const code = Number.parseInt(char, 16);
798
+ return String.fromCharCode(97 + code % 26);
799
+ }).join("");
800
+ };
801
+ const hashLetters = toLetters(hashHex);
802
+ while (sliceLength < hashLetters.length - 1) {
803
+ slicedHash = hashLetters.slice(0, sliceLength);
804
+ if (hashMap[slicedHash] && hashMap[slicedHash] !== combined) {
805
+ sliceLength++;
806
+ continue;
807
+ }
808
+ hashMap[slicedHash] = combined;
809
+ break;
810
+ }
811
+ return slicedHash;
812
+ }
813
+
814
+ // src/extractor/util.ts
815
+ var MAX_VALUE_LENGTH = 300;
816
+ var debugMode = false;
817
+ function setDebugMode(mode) {
818
+ debugMode = mode;
819
+ }
820
+ function getDebugMode() {
821
+ return debugMode;
822
+ }
823
+ function logger(..._msg) {
824
+ if (!debugMode) {
825
+ return;
826
+ }
827
+ console.log(..._msg);
828
+ }
829
+ var taskIdKey = "_midscene_retrieve_task_id";
830
+ function selectorForValue(val) {
831
+ return `[${taskIdKey}='${val}']`;
832
+ }
833
+ function setDataForNode(node, nodeHash, setToParentNode, currentWindow) {
834
+ const taskId = taskIdKey;
835
+ if (!(node instanceof currentWindow.HTMLElement)) {
836
+ return "";
837
+ }
838
+ if (!taskId) {
839
+ console.error("No task id found");
840
+ return "";
841
+ }
842
+ const selector = selectorForValue(nodeHash);
843
+ if (getDebugMode()) {
844
+ if (setToParentNode) {
845
+ if (node.parentNode instanceof currentWindow.HTMLElement) {
846
+ node.parentNode.setAttribute(taskIdKey, nodeHash.toString());
847
+ }
848
+ } else {
849
+ node.setAttribute(taskIdKey, nodeHash.toString());
850
+ }
851
+ }
852
+ return selector;
853
+ }
854
+ function isElementPartiallyInViewport(rect, currentWindow, currentDocument) {
855
+ const elementHeight = rect.height;
856
+ const elementWidth = rect.width;
857
+ const viewportRect = {
858
+ left: 0,
859
+ top: 0,
860
+ width: currentWindow.innerWidth || currentDocument.documentElement.clientWidth,
861
+ height: currentWindow.innerHeight || currentDocument.documentElement.clientHeight,
862
+ right: currentWindow.innerWidth || currentDocument.documentElement.clientWidth,
863
+ bottom: currentWindow.innerHeight || currentDocument.documentElement.clientHeight,
864
+ x: 0,
865
+ y: 0,
866
+ zoom: 1
867
+ };
868
+ const overlapRect = overlappedRect(rect, viewportRect);
869
+ if (!overlapRect) {
870
+ return false;
871
+ }
872
+ const visibleArea = overlapRect.width * overlapRect.height;
873
+ const totalArea = elementHeight * elementWidth;
874
+ return visibleArea / totalArea >= 2 / 3;
875
+ }
876
+ function getPseudoElementContent(element, currentWindow) {
877
+ if (!(element instanceof currentWindow.HTMLElement)) {
878
+ return { before: "", after: "" };
879
+ }
880
+ const beforeContent = currentWindow.getComputedStyle(element, "::before").getPropertyValue("content");
881
+ const afterContent = currentWindow.getComputedStyle(element, "::after").getPropertyValue("content");
882
+ return {
883
+ before: beforeContent === "none" ? "" : beforeContent.replace(/"/g, ""),
884
+ after: afterContent === "none" ? "" : afterContent.replace(/"/g, "")
885
+ };
886
+ }
887
+ function overlappedRect(rect1, rect2) {
888
+ const left = Math.max(rect1.left, rect2.left);
889
+ const top = Math.max(rect1.top, rect2.top);
890
+ const right = Math.min(rect1.right, rect2.right);
891
+ const bottom = Math.min(rect1.bottom, rect2.bottom);
892
+ if (left < right && top < bottom) {
893
+ return {
894
+ left,
895
+ top,
896
+ right,
897
+ bottom,
898
+ width: right - left,
899
+ height: bottom - top,
900
+ x: left,
901
+ y: top,
902
+ zoom: 1
903
+ };
904
+ }
905
+ return null;
906
+ }
907
+ function getRect(el, baseZoom, currentWindow) {
908
+ let originalRect;
909
+ let newZoom = 1;
910
+ if (!(el instanceof currentWindow.HTMLElement)) {
911
+ const range = currentWindow.document.createRange();
912
+ range.selectNodeContents(el);
913
+ originalRect = range.getBoundingClientRect();
914
+ } else {
915
+ originalRect = el.getBoundingClientRect();
916
+ if (!("currentCSSZoom" in el)) {
917
+ newZoom = Number.parseFloat(currentWindow.getComputedStyle(el).zoom) || 1;
918
+ }
919
+ }
920
+ const zoom = newZoom * baseZoom;
921
+ return {
922
+ width: originalRect.width * zoom,
923
+ height: originalRect.height * zoom,
924
+ left: originalRect.left * zoom,
925
+ top: originalRect.top * zoom,
926
+ right: originalRect.right * zoom,
927
+ bottom: originalRect.bottom * zoom,
928
+ x: originalRect.x * zoom,
929
+ y: originalRect.y * zoom,
930
+ zoom
931
+ };
932
+ }
933
+ var isElementCovered = (el, rect, currentWindow) => {
934
+ const x = rect.left + rect.width / 2;
935
+ const y = rect.top + rect.height / 2;
936
+ const topElement = currentWindow.document.elementFromPoint(x, y);
937
+ if (!topElement) {
938
+ return false;
939
+ }
940
+ if (topElement === el) {
941
+ return false;
942
+ }
943
+ if (el == null ? void 0 : el.contains(topElement)) {
944
+ return false;
945
+ }
946
+ if (topElement == null ? void 0 : topElement.contains(el)) {
947
+ return false;
948
+ }
949
+ const rectOfTopElement = getRect(topElement, 1, currentWindow);
950
+ const overlapRect = overlappedRect(rect, rectOfTopElement);
951
+ if (!overlapRect) {
952
+ return false;
953
+ }
954
+ logger(el, "Element is covered by another element", {
955
+ topElement,
956
+ el,
957
+ rect,
958
+ x,
959
+ y
960
+ });
961
+ return true;
962
+ };
963
+ function visibleRect(el, currentWindow, currentDocument, baseZoom = 1) {
964
+ if (!el) {
965
+ logger(el, "Element is not in the DOM hierarchy");
966
+ return false;
967
+ }
968
+ if (!(el instanceof currentWindow.HTMLElement) && el.nodeType !== Node.TEXT_NODE && el.nodeName.toLowerCase() !== "svg") {
969
+ logger(el, "Element is not in the DOM hierarchy");
970
+ return false;
971
+ }
972
+ if (el instanceof currentWindow.HTMLElement) {
973
+ const style = currentWindow.getComputedStyle(el);
974
+ if (style.display === "none" || style.visibility === "hidden" || style.opacity === "0" && el.tagName !== "INPUT") {
975
+ logger(el, "Element is hidden");
976
+ return false;
977
+ }
978
+ }
979
+ const rect = getRect(el, baseZoom, currentWindow);
980
+ if (rect.width === 0 && rect.height === 0) {
981
+ logger(el, "Element has no size");
982
+ return false;
983
+ }
984
+ if (baseZoom === 1 && isElementCovered(el, rect, currentWindow)) {
985
+ return false;
986
+ }
987
+ const scrollLeft = currentWindow.pageXOffset || currentDocument.documentElement.scrollLeft;
988
+ const scrollTop = currentWindow.pageYOffset || currentDocument.documentElement.scrollTop;
989
+ const viewportWidth = currentWindow.innerWidth || currentDocument.documentElement.clientWidth;
990
+ const viewportHeight = currentWindow.innerHeight || currentDocument.documentElement.clientHeight;
991
+ const isPartiallyInViewport = isElementPartiallyInViewport(
992
+ rect,
993
+ currentWindow,
994
+ currentDocument
995
+ );
996
+ if (!isPartiallyInViewport) {
997
+ logger(el, "Element is completely outside the viewport", {
998
+ rect,
999
+ viewportHeight,
1000
+ viewportWidth,
1001
+ scrollTop,
1002
+ scrollLeft
1003
+ });
1004
+ return false;
1005
+ }
1006
+ let parent = el;
1007
+ while (parent && parent !== currentDocument.body) {
1008
+ if (!(parent instanceof currentWindow.HTMLElement)) {
1009
+ parent = parent.parentElement;
1010
+ continue;
1011
+ }
1012
+ const parentStyle = currentWindow.getComputedStyle(parent);
1013
+ if (parentStyle.overflow === "hidden") {
1014
+ const parentRect = getRect(parent, 1, currentWindow);
1015
+ const tolerance = 10;
1016
+ if (rect.right < parentRect.left - tolerance || rect.left > parentRect.right + tolerance || rect.bottom < parentRect.top - tolerance || rect.top > parentRect.bottom + tolerance) {
1017
+ logger(el, "element is partially or totally hidden by an ancestor", {
1018
+ rect,
1019
+ parentRect
1020
+ });
1021
+ return false;
1022
+ }
1023
+ }
1024
+ if (parentStyle.position === "fixed") {
1025
+ break;
1026
+ }
1027
+ parent = parent.parentElement;
1028
+ }
1029
+ return {
1030
+ left: Math.round(rect.left),
1031
+ top: Math.round(rect.top),
1032
+ width: Math.round(rect.width),
1033
+ height: Math.round(rect.height),
1034
+ zoom: rect.zoom
1035
+ };
1036
+ }
1037
+ function getNodeAttributes(node, currentWindow) {
1038
+ if (!node || !(node instanceof currentWindow.HTMLElement) || !node.attributes) {
1039
+ return {};
1040
+ }
1041
+ const attributesList = Array.from(node.attributes).map((attr) => {
1042
+ if (attr.name === "class") {
1043
+ return [attr.name, `.${attr.value.split(" ").join(".")}`];
1044
+ }
1045
+ if (!attr.value) {
1046
+ return [];
1047
+ }
1048
+ let value = attr.value;
1049
+ if (value.startsWith("data:image")) {
1050
+ value = "image";
1051
+ }
1052
+ if (value.length > MAX_VALUE_LENGTH) {
1053
+ value = `${value.slice(0, MAX_VALUE_LENGTH)}...`;
1054
+ }
1055
+ return [attr.name, value];
1056
+ });
1057
+ return Object.fromEntries(attributesList);
1058
+ }
1059
+ var nodeHashCacheList = [];
1060
+ if (typeof window !== "undefined") {
1061
+ window.midsceneNodeHashCacheList = window.midsceneNodeHashCacheList || [];
1062
+ nodeHashCacheList = window.midsceneNodeHashCacheList;
1063
+ }
1064
+ function resetNodeHashCacheList() {
1065
+ if (typeof window !== "undefined") {
1066
+ nodeHashCacheList = window.midsceneNodeHashCacheList || [];
1067
+ window.midsceneNodeHashCacheList = [];
1068
+ } else {
1069
+ nodeHashCacheList = [];
1070
+ }
1071
+ }
1072
+ function midsceneGenerateHash(node, content, rect) {
1073
+ var _a;
1074
+ if (node && nodeHashCacheList.find((item) => item.node === node)) {
1075
+ return ((_a = nodeHashCacheList.find((item) => item.node === node)) == null ? void 0 : _a.id) || "";
1076
+ }
1077
+ const slicedHash = generateHashId(rect, content);
1078
+ if (node && typeof window !== "undefined") {
1079
+ window.midsceneNodeHashCacheList.push({ node, id: slicedHash });
1080
+ }
1081
+ return slicedHash;
1082
+ }
1083
+ function getTopDocument() {
1084
+ const container = document.body || document;
1085
+ return container;
1086
+ }
1087
+
1088
+ // src/extractor/web-extractor.ts
1089
+ var indexId = 0;
1090
+ function tagNameOfNode(node) {
1091
+ let tagName = "";
1092
+ if (node instanceof HTMLElement) {
1093
+ tagName = node.tagName.toLowerCase();
1094
+ }
1095
+ const parentElement = node.parentElement;
1096
+ if (parentElement && parentElement instanceof HTMLElement) {
1097
+ tagName = parentElement.tagName.toLowerCase();
1098
+ }
1099
+ return tagName ? `<${tagName}>` : "";
1100
+ }
1101
+ function collectElementInfo(node, currentWindow, currentDocument, baseZoom = 1, basePoint = { left: 0, top: 0 }) {
1102
+ var _a;
1103
+ const rect = visibleRect(node, currentWindow, currentDocument, baseZoom);
1104
+ if (!rect || rect.width < CONTAINER_MINI_WIDTH || rect.height < CONTAINER_MINI_HEIGHT) {
1105
+ return null;
1106
+ }
1107
+ if (basePoint.left !== 0 || basePoint.top !== 0) {
1108
+ rect.left += basePoint.left;
1109
+ rect.top += basePoint.top;
1110
+ }
1111
+ if (rect.height >= window.innerHeight && rect.width >= window.innerWidth) {
1112
+ return null;
1113
+ }
1114
+ if (isFormElement(node)) {
1115
+ const attributes = getNodeAttributes(node, currentWindow);
1116
+ let valueContent = attributes.value || attributes.placeholder || node.textContent || "";
1117
+ const nodeHashId = midsceneGenerateHash(node, valueContent, rect);
1118
+ const selector = setDataForNode(node, nodeHashId, false, currentWindow);
1119
+ const tagName = node.tagName.toLowerCase();
1120
+ if (node.tagName.toLowerCase() === "select") {
1121
+ const selectedOption = node.options[node.selectedIndex];
1122
+ valueContent = selectedOption.textContent || "";
1123
+ }
1124
+ if ((node.tagName.toLowerCase() === "input" || node.tagName.toLowerCase() === "textarea") && node.value) {
1125
+ valueContent = node.value;
1126
+ }
1127
+ const elementInfo = {
1128
+ id: nodeHashId,
1129
+ nodeHashId,
1130
+ locator: selector,
1131
+ nodeType: "FORM_ITEM Node" /* FORM_ITEM */,
1132
+ indexId: indexId++,
1133
+ attributes: __spreadProps(__spreadValues({}, attributes), {
1134
+ htmlTagName: `<${tagName}>`,
1135
+ nodeType: "FORM_ITEM Node" /* FORM_ITEM */
1136
+ }),
1137
+ content: valueContent.trim(),
1138
+ rect,
1139
+ center: [
1140
+ Math.round(rect.left + rect.width / 2),
1141
+ Math.round(rect.top + rect.height / 2)
1142
+ ],
1143
+ zoom: rect.zoom,
1144
+ screenWidth: currentWindow.innerWidth,
1145
+ screenHeight: currentWindow.innerHeight
1146
+ };
1147
+ return elementInfo;
1148
+ }
1149
+ if (isButtonElement(node)) {
1150
+ const attributes = getNodeAttributes(node, currentWindow);
1151
+ const pseudo = getPseudoElementContent(node, currentWindow);
1152
+ const content = node.innerText || pseudo.before || pseudo.after || "";
1153
+ const nodeHashId = midsceneGenerateHash(node, content, rect);
1154
+ const selector = setDataForNode(node, nodeHashId, false, currentWindow);
1155
+ const elementInfo = {
1156
+ id: nodeHashId,
1157
+ indexId: indexId++,
1158
+ nodeHashId,
1159
+ nodeType: "BUTTON Node" /* BUTTON */,
1160
+ locator: selector,
1161
+ attributes: __spreadProps(__spreadValues({}, attributes), {
1162
+ htmlTagName: tagNameOfNode(node),
1163
+ nodeType: "BUTTON Node" /* BUTTON */
1164
+ }),
1165
+ content,
1166
+ rect,
1167
+ center: [
1168
+ Math.round(rect.left + rect.width / 2),
1169
+ Math.round(rect.top + rect.height / 2)
1170
+ ],
1171
+ zoom: rect.zoom,
1172
+ screenWidth: currentWindow.innerWidth,
1173
+ screenHeight: currentWindow.innerHeight
1174
+ };
1175
+ return elementInfo;
1176
+ }
1177
+ if (isImgElement(node)) {
1178
+ const attributes = getNodeAttributes(node, currentWindow);
1179
+ const nodeHashId = midsceneGenerateHash(node, "", rect);
1180
+ const selector = setDataForNode(node, nodeHashId, false, currentWindow);
1181
+ const elementInfo = {
1182
+ id: nodeHashId,
1183
+ indexId: indexId++,
1184
+ nodeHashId,
1185
+ locator: selector,
1186
+ attributes: __spreadProps(__spreadValues(__spreadValues({}, attributes), node.nodeName.toLowerCase() === "svg" ? {
1187
+ svgContent: "true"
1188
+ } : {}), {
1189
+ nodeType: "IMG Node" /* IMG */,
1190
+ htmlTagName: tagNameOfNode(node)
1191
+ }),
1192
+ nodeType: "IMG Node" /* IMG */,
1193
+ content: "",
1194
+ rect,
1195
+ center: [
1196
+ Math.round(rect.left + rect.width / 2),
1197
+ Math.round(rect.top + rect.height / 2)
1198
+ ],
1199
+ zoom: rect.zoom,
1200
+ screenWidth: currentWindow.innerWidth,
1201
+ screenHeight: currentWindow.innerHeight
1202
+ };
1203
+ return elementInfo;
1204
+ }
1205
+ if (isTextElement(node)) {
1206
+ const text = (_a = node.textContent) == null ? void 0 : _a.trim().replace(/\n+/g, " ");
1207
+ if (!text) {
1208
+ return null;
1209
+ }
1210
+ const attributes = getNodeAttributes(node, currentWindow);
1211
+ const attributeKeys = Object.keys(attributes);
1212
+ if (!text.trim() && attributeKeys.length === 0) {
1213
+ return null;
1214
+ }
1215
+ const nodeHashId = midsceneGenerateHash(node, text, rect);
1216
+ const selector = setDataForNode(node, nodeHashId, true, currentWindow);
1217
+ const elementInfo = {
1218
+ id: nodeHashId,
1219
+ indexId: indexId++,
1220
+ nodeHashId,
1221
+ nodeType: "TEXT Node" /* TEXT */,
1222
+ locator: selector,
1223
+ attributes: __spreadProps(__spreadValues({}, attributes), {
1224
+ nodeType: "TEXT Node" /* TEXT */,
1225
+ htmlTagName: tagNameOfNode(node)
1226
+ }),
1227
+ center: [
1228
+ Math.round(rect.left + rect.width / 2),
1229
+ Math.round(rect.top + rect.height / 2)
1230
+ ],
1231
+ // attributes,
1232
+ content: text,
1233
+ rect,
1234
+ zoom: rect.zoom,
1235
+ screenWidth: currentWindow.innerWidth,
1236
+ screenHeight: currentWindow.innerHeight
1237
+ };
1238
+ return elementInfo;
1239
+ }
1240
+ if (isContainerElement(node)) {
1241
+ const attributes = getNodeAttributes(node, currentWindow);
1242
+ const nodeHashId = midsceneGenerateHash(node, "", rect);
1243
+ const selector = setDataForNode(node, nodeHashId, false, currentWindow);
1244
+ const elementInfo = {
1245
+ id: nodeHashId,
1246
+ nodeHashId,
1247
+ indexId: indexId++,
1248
+ nodeType: "CONTAINER Node" /* CONTAINER */,
1249
+ locator: selector,
1250
+ attributes: __spreadProps(__spreadValues({}, attributes), {
1251
+ nodeType: "CONTAINER Node" /* CONTAINER */,
1252
+ htmlTagName: tagNameOfNode(node)
1253
+ }),
1254
+ content: "",
1255
+ rect,
1256
+ center: [
1257
+ Math.round(rect.left + rect.width / 2),
1258
+ Math.round(rect.top + rect.height / 2)
1259
+ ],
1260
+ zoom: rect.zoom,
1261
+ screenWidth: currentWindow.innerWidth,
1262
+ screenHeight: currentWindow.innerHeight
1263
+ };
1264
+ return elementInfo;
1265
+ }
1266
+ return null;
1267
+ }
1268
+ function extractTextWithPosition(initNode, debugMode2 = false) {
1269
+ const elementNode = extractTreeNode(initNode, debugMode2);
1270
+ const elementInfoArray = [];
1271
+ function dfsTopChildren(node) {
1272
+ if (node.node) {
1273
+ elementInfoArray.push(node.node);
1274
+ }
1275
+ for (let i = 0; i < node.children.length; i++) {
1276
+ dfsTopChildren(node.children[i]);
1277
+ }
1278
+ }
1279
+ dfsTopChildren({ children: elementNode.children, node: elementNode.node });
1280
+ return elementInfoArray;
1281
+ }
1282
+ function extractTreeNodeAsString(initNode, debugMode2 = false) {
1283
+ const elementNode = extractTreeNode(initNode, debugMode2);
1284
+ return descriptionOfTree(elementNode);
1285
+ }
1286
+ function extractTreeNode(initNode, debugMode2 = false) {
1287
+ setDebugMode(debugMode2);
1288
+ resetNodeHashCacheList();
1289
+ indexId = 0;
1290
+ const topDocument = getTopDocument();
1291
+ const startNode = initNode || topDocument;
1292
+ const topChildren = [];
1293
+ function dfs(node, currentWindow, currentDocument, baseZoom = 1, basePoint = { left: 0, top: 0 }) {
1294
+ if (!node) {
1295
+ return null;
1296
+ }
1297
+ if (node.nodeType && node.nodeType === 10) {
1298
+ return null;
1299
+ }
1300
+ const elementInfo = collectElementInfo(
1301
+ node,
1302
+ currentWindow,
1303
+ currentDocument,
1304
+ baseZoom,
1305
+ basePoint
1306
+ );
1307
+ if (node instanceof currentWindow.HTMLIFrameElement) {
1308
+ if (node.contentWindow && node.contentWindow) {
1309
+ return null;
1310
+ }
1311
+ }
1312
+ const nodeInfo = {
1313
+ node: elementInfo,
1314
+ children: []
1315
+ };
1316
+ if ((elementInfo == null ? void 0 : elementInfo.nodeType) === "BUTTON Node" /* BUTTON */ || (elementInfo == null ? void 0 : elementInfo.nodeType) === "IMG Node" /* IMG */ || (elementInfo == null ? void 0 : elementInfo.nodeType) === "TEXT Node" /* TEXT */ || (elementInfo == null ? void 0 : elementInfo.nodeType) === "FORM_ITEM Node" /* FORM_ITEM */ || (elementInfo == null ? void 0 : elementInfo.nodeType) === "CONTAINER Node" /* CONTAINER */) {
1317
+ return nodeInfo;
1318
+ }
1319
+ const rect = getRect(node, baseZoom, currentWindow);
1320
+ for (let i = 0; i < node.childNodes.length; i++) {
1321
+ logger("will dfs", node.childNodes[i]);
1322
+ const childNodeInfo = dfs(
1323
+ node.childNodes[i],
1324
+ currentWindow,
1325
+ currentDocument,
1326
+ rect.zoom,
1327
+ basePoint
1328
+ );
1329
+ if (childNodeInfo) {
1330
+ nodeInfo.children.push(childNodeInfo);
1331
+ }
1332
+ }
1333
+ return nodeInfo;
1334
+ }
1335
+ const rootNodeInfo = dfs(startNode, window, document, 1, {
1336
+ left: 0,
1337
+ top: 0
1338
+ });
1339
+ if (rootNodeInfo) {
1340
+ topChildren.push(rootNodeInfo);
1341
+ }
1342
+ if (startNode === topDocument) {
1343
+ const iframes = document.querySelectorAll("iframe");
1344
+ for (let i = 0; i < iframes.length; i++) {
1345
+ const iframe = iframes[i];
1346
+ if (iframe.contentDocument && iframe.contentWindow) {
1347
+ const iframeInfo = collectElementInfo(iframe, window, document, 1);
1348
+ if (iframeInfo) {
1349
+ const iframeChildren = dfs(
1350
+ iframe.contentDocument.body,
1351
+ iframe.contentWindow,
1352
+ iframe.contentDocument,
1353
+ 1,
1354
+ {
1355
+ left: iframeInfo.rect.left,
1356
+ top: iframeInfo.rect.top
1357
+ }
1358
+ );
1359
+ if (iframeChildren) {
1360
+ topChildren.push(iframeChildren);
1361
+ }
1362
+ }
1363
+ }
1364
+ }
1365
+ }
1366
+ return {
1367
+ node: null,
1368
+ children: topChildren
1369
+ };
1370
+ }
1371
+
1372
+ // src/extractor/client-extractor.ts
1373
+ function getNodeAttributes2(node) {
1374
+ var _a;
1375
+ const attrs = {};
1376
+ if (node && node.nodeType === 1) {
1377
+ const element = node;
1378
+ for (let i = 0; i < element.attributes.length; i++) {
1379
+ const attr = element.attributes[i];
1380
+ attrs[attr.nodeName] = (_a = attr.nodeValue) != null ? _a : "";
1381
+ }
1382
+ }
1383
+ return attrs;
1384
+ }
1385
+ function getRect2(attributes) {
1386
+ var _a, _b, _c, _d;
1387
+ const x = Math.round(Number.parseFloat((_a = attributes.x) != null ? _a : "0"));
1388
+ const y = Math.round(Number.parseFloat((_b = attributes.y) != null ? _b : "0"));
1389
+ const width = Math.round(Number.parseFloat((_c = attributes.width) != null ? _c : "0"));
1390
+ const height = Math.round(Number.parseFloat((_d = attributes.height) != null ? _d : "0"));
1391
+ return {
1392
+ left: Math.max(0, Math.floor(x)),
1393
+ top: Math.max(0, Math.floor(y)),
1394
+ width: Math.max(0, width),
1395
+ height: Math.max(0, height)
1396
+ };
1397
+ }
1398
+ function validTextNodeContent(node) {
1399
+ var _a;
1400
+ if (node.nodeType === 3) {
1401
+ return ((_a = node.nodeValue) == null ? void 0 : _a.trim()) || "";
1402
+ }
1403
+ return "";
1404
+ }
1405
+ function getXPathForElement(element) {
1406
+ if (element.nodeType !== 1) {
1407
+ return "";
1408
+ }
1409
+ const getIndex = (sib, name) => {
1410
+ let count = 1;
1411
+ for (let cur = sib.previousSibling; cur; cur = cur.previousSibling) {
1412
+ if (cur.nodeType === 1 && cur.nodeName === name) {
1413
+ count++;
1414
+ }
1415
+ }
1416
+ return count;
1417
+ };
1418
+ const buildAttributePart = (elem) => {
1419
+ const attributes = ["id", "resource-id", "content-desc", "class"];
1420
+ for (const attr of attributes) {
1421
+ if (elem.hasAttribute(attr)) {
1422
+ const value = elem.getAttribute(attr);
1423
+ if (value && value.trim() !== "") {
1424
+ return `[@${attr}="${value}"]`;
1425
+ }
1426
+ }
1427
+ }
1428
+ return "";
1429
+ };
1430
+ const getPath = (node, path = "") => {
1431
+ if (node.parentNode) {
1432
+ path = getPath(node.parentNode, path);
1433
+ }
1434
+ if (node.nodeType === 1) {
1435
+ const elem = node;
1436
+ const tagName = elem.nodeName.toLowerCase();
1437
+ let part = `/${tagName}`;
1438
+ const attributePart = buildAttributePart(elem);
1439
+ if (attributePart) {
1440
+ part += attributePart;
1441
+ } else {
1442
+ const index = getIndex(node, node.nodeName);
1443
+ if (index > 1) {
1444
+ part += `[${index}]`;
1445
+ }
1446
+ }
1447
+ path += part;
1448
+ }
1449
+ return path;
1450
+ };
1451
+ return getPath(element);
1452
+ }
1453
+ function extractTextWithPosition2(initNode) {
1454
+ const elementInfoArray = [];
1455
+ let nodeIndex = 1;
1456
+ function dfs(node, parentNode = null) {
1457
+ if (!node) {
1458
+ return;
1459
+ }
1460
+ const currentNodeDes = { node, children: [] };
1461
+ if (parentNode) {
1462
+ parentNode.children.push(currentNodeDes);
1463
+ }
1464
+ collectElementInfo2(node);
1465
+ if (node.childNodes && node.childNodes.length > 0) {
1466
+ for (let i = 0; i < node.childNodes.length; i++) {
1467
+ dfs(node.childNodes[i], currentNodeDes);
1468
+ }
1469
+ }
1470
+ }
1471
+ function collectElementInfo2(node) {
1472
+ const attributes = getNodeAttributes2(node);
1473
+ const rect = getRect2(attributes);
1474
+ const nodeHashId = midsceneGenerateHash(null, attributes.placeholder, rect);
1475
+ const text = validTextNodeContent(node);
1476
+ let nodeType;
1477
+ switch (node.nodeName.toUpperCase()) {
1478
+ case "TEXT":
1479
+ nodeType = "TEXT Node" /* TEXT */;
1480
+ break;
1481
+ case "IMAGE":
1482
+ nodeType = "IMG Node" /* IMG */;
1483
+ break;
1484
+ case "BUTTON":
1485
+ nodeType = "BUTTON Node" /* BUTTON */;
1486
+ break;
1487
+ case "SEARCHINPUT":
1488
+ case "TEXTINPUT":
1489
+ case "INPUT":
1490
+ nodeType = "FORM_ITEM Node" /* FORM_ITEM */;
1491
+ break;
1492
+ case "NAV":
1493
+ case "LIST":
1494
+ case "CELL":
1495
+ nodeType = "CONTAINER Node" /* CONTAINER */;
1496
+ break;
1497
+ default:
1498
+ if (attributes.id === "android:id/input" || attributes.id === "android:id/inputArea") {
1499
+ nodeType = "FORM_ITEM Node" /* FORM_ITEM */;
1500
+ } else {
1501
+ nodeType = "CONTAINER Node" /* CONTAINER */;
1502
+ }
1503
+ break;
1504
+ }
1505
+ const xpath = getXPathForElement(node);
1506
+ const elementInfo = {
1507
+ id: nodeHashId,
1508
+ indexId: nodeIndex++,
1509
+ nodeHashId,
1510
+ locator: xpath,
1511
+ attributes: __spreadValues({
1512
+ nodeType
1513
+ }, attributes),
1514
+ content: text,
1515
+ rect,
1516
+ center: [
1517
+ Math.round(rect.left + rect.width / 2),
1518
+ Math.round(rect.top + rect.height / 2)
1519
+ ],
1520
+ nodeType
1521
+ };
1522
+ if (elementInfo.nodeType !== "CONTAINER Node" /* CONTAINER */) {
1523
+ elementInfoArray.push(elementInfo);
1524
+ }
1525
+ }
1526
+ const rootNode = initNode;
1527
+ const rootDescriptor = { node: rootNode, children: [] };
1528
+ dfs(rootNode, rootDescriptor);
1529
+ return elementInfoArray;
1530
+ }
1531
+ /*! Bundled license information:
1532
+
1533
+ js-sha256/src/sha256.js:
1534
+ (**
1535
+ * [js-sha256]{@link https://github.com/emn178/js-sha256}
1536
+ *
1537
+ * @version 0.11.0
1538
+ * @author Chen, Yi-Cyuan [emn178@gmail.com]
1539
+ * @copyright Chen, Yi-Cyuan 2014-2024
1540
+ * @license MIT
1541
+ *)
1542
+ */