@midscene/web 0.3.0 → 0.3.1

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,871 @@
1
+ "use strict";
2
+ var midscene_element_inspector = (() => {
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __defProps = Object.defineProperties;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
8
+ var __getOwnPropNames = Object.getOwnPropertyNames;
9
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
10
+ var __getProtoOf = Object.getPrototypeOf;
11
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
12
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
13
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
14
+ var __spreadValues = (a, b) => {
15
+ for (var prop in b || (b = {}))
16
+ if (__hasOwnProp.call(b, prop))
17
+ __defNormalProp(a, prop, b[prop]);
18
+ if (__getOwnPropSymbols)
19
+ for (var prop of __getOwnPropSymbols(b)) {
20
+ if (__propIsEnum.call(b, prop))
21
+ __defNormalProp(a, prop, b[prop]);
22
+ }
23
+ return a;
24
+ };
25
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
26
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
27
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
28
+ }) : x)(function(x) {
29
+ if (typeof require !== "undefined")
30
+ return require.apply(this, arguments);
31
+ throw Error('Dynamic require of "' + x + '" is not supported');
32
+ });
33
+ var __commonJS = (cb, mod) => function __require2() {
34
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
35
+ };
36
+ var __copyProps = (to, from, except, desc) => {
37
+ if (from && typeof from === "object" || typeof from === "function") {
38
+ for (let key of __getOwnPropNames(from))
39
+ if (!__hasOwnProp.call(to, key) && key !== except)
40
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
41
+ }
42
+ return to;
43
+ };
44
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
45
+ // If the importer is in node compatibility mode or this is not an ESM
46
+ // file that has been converted to a CommonJS file using a Babel-
47
+ // compatible transform (i.e. "__esModule" has not been set), then set
48
+ // "default" to the CommonJS "module.exports" for node compatibility.
49
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
50
+ mod
51
+ ));
52
+
53
+ // ../../node_modules/.pnpm/js-sha256@0.11.0/node_modules/js-sha256/src/sha256.js
54
+ var require_sha256 = __commonJS({
55
+ "../../node_modules/.pnpm/js-sha256@0.11.0/node_modules/js-sha256/src/sha256.js"(exports, module) {
56
+ "use strict";
57
+ (function() {
58
+ "use strict";
59
+ var ERROR = "input is invalid type";
60
+ var WINDOW = typeof window === "object";
61
+ var root = WINDOW ? window : {};
62
+ if (root.JS_SHA256_NO_WINDOW) {
63
+ WINDOW = false;
64
+ }
65
+ var WEB_WORKER = !WINDOW && typeof self === "object";
66
+ var NODE_JS = !root.JS_SHA256_NO_NODE_JS && typeof process === "object" && process.versions && process.versions.node;
67
+ if (NODE_JS) {
68
+ root = global;
69
+ } else if (WEB_WORKER) {
70
+ root = self;
71
+ }
72
+ var COMMON_JS = !root.JS_SHA256_NO_COMMON_JS && typeof module === "object" && module.exports;
73
+ var AMD = typeof define === "function" && define.amd;
74
+ var ARRAY_BUFFER = !root.JS_SHA256_NO_ARRAY_BUFFER && typeof ArrayBuffer !== "undefined";
75
+ var HEX_CHARS = "0123456789abcdef".split("");
76
+ var EXTRA = [-2147483648, 8388608, 32768, 128];
77
+ var SHIFT = [24, 16, 8, 0];
78
+ var K = [
79
+ 1116352408,
80
+ 1899447441,
81
+ 3049323471,
82
+ 3921009573,
83
+ 961987163,
84
+ 1508970993,
85
+ 2453635748,
86
+ 2870763221,
87
+ 3624381080,
88
+ 310598401,
89
+ 607225278,
90
+ 1426881987,
91
+ 1925078388,
92
+ 2162078206,
93
+ 2614888103,
94
+ 3248222580,
95
+ 3835390401,
96
+ 4022224774,
97
+ 264347078,
98
+ 604807628,
99
+ 770255983,
100
+ 1249150122,
101
+ 1555081692,
102
+ 1996064986,
103
+ 2554220882,
104
+ 2821834349,
105
+ 2952996808,
106
+ 3210313671,
107
+ 3336571891,
108
+ 3584528711,
109
+ 113926993,
110
+ 338241895,
111
+ 666307205,
112
+ 773529912,
113
+ 1294757372,
114
+ 1396182291,
115
+ 1695183700,
116
+ 1986661051,
117
+ 2177026350,
118
+ 2456956037,
119
+ 2730485921,
120
+ 2820302411,
121
+ 3259730800,
122
+ 3345764771,
123
+ 3516065817,
124
+ 3600352804,
125
+ 4094571909,
126
+ 275423344,
127
+ 430227734,
128
+ 506948616,
129
+ 659060556,
130
+ 883997877,
131
+ 958139571,
132
+ 1322822218,
133
+ 1537002063,
134
+ 1747873779,
135
+ 1955562222,
136
+ 2024104815,
137
+ 2227730452,
138
+ 2361852424,
139
+ 2428436474,
140
+ 2756734187,
141
+ 3204031479,
142
+ 3329325298
143
+ ];
144
+ var OUTPUT_TYPES = ["hex", "array", "digest", "arrayBuffer"];
145
+ var blocks = [];
146
+ if (root.JS_SHA256_NO_NODE_JS || !Array.isArray) {
147
+ Array.isArray = function(obj) {
148
+ return Object.prototype.toString.call(obj) === "[object Array]";
149
+ };
150
+ }
151
+ if (ARRAY_BUFFER && (root.JS_SHA256_NO_ARRAY_BUFFER_IS_VIEW || !ArrayBuffer.isView)) {
152
+ ArrayBuffer.isView = function(obj) {
153
+ return typeof obj === "object" && obj.buffer && obj.buffer.constructor === ArrayBuffer;
154
+ };
155
+ }
156
+ var createOutputMethod = function(outputType, is224) {
157
+ return function(message) {
158
+ return new Sha256(is224, true).update(message)[outputType]();
159
+ };
160
+ };
161
+ var createMethod = function(is224) {
162
+ var method = createOutputMethod("hex", is224);
163
+ if (NODE_JS) {
164
+ method = nodeWrap(method, is224);
165
+ }
166
+ method.create = function() {
167
+ return new Sha256(is224);
168
+ };
169
+ method.update = function(message) {
170
+ return method.create().update(message);
171
+ };
172
+ for (var i = 0; i < OUTPUT_TYPES.length; ++i) {
173
+ var type = OUTPUT_TYPES[i];
174
+ method[type] = createOutputMethod(type, is224);
175
+ }
176
+ return method;
177
+ };
178
+ var nodeWrap = function(method, is224) {
179
+ var crypto = __require("crypto");
180
+ var Buffer2 = __require("buffer").Buffer;
181
+ var algorithm = is224 ? "sha224" : "sha256";
182
+ var bufferFrom;
183
+ if (Buffer2.from && !root.JS_SHA256_NO_BUFFER_FROM) {
184
+ bufferFrom = Buffer2.from;
185
+ } else {
186
+ bufferFrom = function(message) {
187
+ return new Buffer2(message);
188
+ };
189
+ }
190
+ var nodeMethod = function(message) {
191
+ if (typeof message === "string") {
192
+ return crypto.createHash(algorithm).update(message, "utf8").digest("hex");
193
+ } else {
194
+ if (message === null || message === void 0) {
195
+ throw new Error(ERROR);
196
+ } else if (message.constructor === ArrayBuffer) {
197
+ message = new Uint8Array(message);
198
+ }
199
+ }
200
+ if (Array.isArray(message) || ArrayBuffer.isView(message) || message.constructor === Buffer2) {
201
+ return crypto.createHash(algorithm).update(bufferFrom(message)).digest("hex");
202
+ } else {
203
+ return method(message);
204
+ }
205
+ };
206
+ return nodeMethod;
207
+ };
208
+ var createHmacOutputMethod = function(outputType, is224) {
209
+ return function(key, message) {
210
+ return new HmacSha256(key, is224, true).update(message)[outputType]();
211
+ };
212
+ };
213
+ var createHmacMethod = function(is224) {
214
+ var method = createHmacOutputMethod("hex", is224);
215
+ method.create = function(key) {
216
+ return new HmacSha256(key, is224);
217
+ };
218
+ method.update = function(key, message) {
219
+ return method.create(key).update(message);
220
+ };
221
+ for (var i = 0; i < OUTPUT_TYPES.length; ++i) {
222
+ var type = OUTPUT_TYPES[i];
223
+ method[type] = createHmacOutputMethod(type, is224);
224
+ }
225
+ return method;
226
+ };
227
+ function Sha256(is224, sharedMemory) {
228
+ if (sharedMemory) {
229
+ 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;
230
+ this.blocks = blocks;
231
+ } else {
232
+ this.blocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
233
+ }
234
+ if (is224) {
235
+ this.h0 = 3238371032;
236
+ this.h1 = 914150663;
237
+ this.h2 = 812702999;
238
+ this.h3 = 4144912697;
239
+ this.h4 = 4290775857;
240
+ this.h5 = 1750603025;
241
+ this.h6 = 1694076839;
242
+ this.h7 = 3204075428;
243
+ } else {
244
+ this.h0 = 1779033703;
245
+ this.h1 = 3144134277;
246
+ this.h2 = 1013904242;
247
+ this.h3 = 2773480762;
248
+ this.h4 = 1359893119;
249
+ this.h5 = 2600822924;
250
+ this.h6 = 528734635;
251
+ this.h7 = 1541459225;
252
+ }
253
+ this.block = this.start = this.bytes = this.hBytes = 0;
254
+ this.finalized = this.hashed = false;
255
+ this.first = true;
256
+ this.is224 = is224;
257
+ }
258
+ Sha256.prototype.update = function(message) {
259
+ if (this.finalized) {
260
+ return;
261
+ }
262
+ var notString, type = typeof message;
263
+ if (type !== "string") {
264
+ if (type === "object") {
265
+ if (message === null) {
266
+ throw new Error(ERROR);
267
+ } else if (ARRAY_BUFFER && message.constructor === ArrayBuffer) {
268
+ message = new Uint8Array(message);
269
+ } else if (!Array.isArray(message)) {
270
+ if (!ARRAY_BUFFER || !ArrayBuffer.isView(message)) {
271
+ throw new Error(ERROR);
272
+ }
273
+ }
274
+ } else {
275
+ throw new Error(ERROR);
276
+ }
277
+ notString = true;
278
+ }
279
+ var code, index = 0, i, length = message.length, blocks2 = this.blocks;
280
+ while (index < length) {
281
+ if (this.hashed) {
282
+ this.hashed = false;
283
+ blocks2[0] = this.block;
284
+ 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;
285
+ }
286
+ if (notString) {
287
+ for (i = this.start; index < length && i < 64; ++index) {
288
+ blocks2[i >>> 2] |= message[index] << SHIFT[i++ & 3];
289
+ }
290
+ } else {
291
+ for (i = this.start; index < length && i < 64; ++index) {
292
+ code = message.charCodeAt(index);
293
+ if (code < 128) {
294
+ blocks2[i >>> 2] |= code << SHIFT[i++ & 3];
295
+ } else if (code < 2048) {
296
+ blocks2[i >>> 2] |= (192 | code >>> 6) << SHIFT[i++ & 3];
297
+ blocks2[i >>> 2] |= (128 | code & 63) << SHIFT[i++ & 3];
298
+ } else if (code < 55296 || code >= 57344) {
299
+ blocks2[i >>> 2] |= (224 | code >>> 12) << SHIFT[i++ & 3];
300
+ blocks2[i >>> 2] |= (128 | code >>> 6 & 63) << SHIFT[i++ & 3];
301
+ blocks2[i >>> 2] |= (128 | code & 63) << SHIFT[i++ & 3];
302
+ } else {
303
+ code = 65536 + ((code & 1023) << 10 | message.charCodeAt(++index) & 1023);
304
+ blocks2[i >>> 2] |= (240 | code >>> 18) << SHIFT[i++ & 3];
305
+ blocks2[i >>> 2] |= (128 | code >>> 12 & 63) << SHIFT[i++ & 3];
306
+ blocks2[i >>> 2] |= (128 | code >>> 6 & 63) << SHIFT[i++ & 3];
307
+ blocks2[i >>> 2] |= (128 | code & 63) << SHIFT[i++ & 3];
308
+ }
309
+ }
310
+ }
311
+ this.lastByteIndex = i;
312
+ this.bytes += i - this.start;
313
+ if (i >= 64) {
314
+ this.block = blocks2[16];
315
+ this.start = i - 64;
316
+ this.hash();
317
+ this.hashed = true;
318
+ } else {
319
+ this.start = i;
320
+ }
321
+ }
322
+ if (this.bytes > 4294967295) {
323
+ this.hBytes += this.bytes / 4294967296 << 0;
324
+ this.bytes = this.bytes % 4294967296;
325
+ }
326
+ return this;
327
+ };
328
+ Sha256.prototype.finalize = function() {
329
+ if (this.finalized) {
330
+ return;
331
+ }
332
+ this.finalized = true;
333
+ var blocks2 = this.blocks, i = this.lastByteIndex;
334
+ blocks2[16] = this.block;
335
+ blocks2[i >>> 2] |= EXTRA[i & 3];
336
+ this.block = blocks2[16];
337
+ if (i >= 56) {
338
+ if (!this.hashed) {
339
+ this.hash();
340
+ }
341
+ blocks2[0] = this.block;
342
+ 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;
343
+ }
344
+ blocks2[14] = this.hBytes << 3 | this.bytes >>> 29;
345
+ blocks2[15] = this.bytes << 3;
346
+ this.hash();
347
+ };
348
+ Sha256.prototype.hash = function() {
349
+ 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;
350
+ for (j = 16; j < 64; ++j) {
351
+ t1 = blocks2[j - 15];
352
+ s0 = (t1 >>> 7 | t1 << 25) ^ (t1 >>> 18 | t1 << 14) ^ t1 >>> 3;
353
+ t1 = blocks2[j - 2];
354
+ s1 = (t1 >>> 17 | t1 << 15) ^ (t1 >>> 19 | t1 << 13) ^ t1 >>> 10;
355
+ blocks2[j] = blocks2[j - 16] + s0 + blocks2[j - 7] + s1 << 0;
356
+ }
357
+ bc = b & c;
358
+ for (j = 0; j < 64; j += 4) {
359
+ if (this.first) {
360
+ if (this.is224) {
361
+ ab = 300032;
362
+ t1 = blocks2[0] - 1413257819;
363
+ h = t1 - 150054599 << 0;
364
+ d = t1 + 24177077 << 0;
365
+ } else {
366
+ ab = 704751109;
367
+ t1 = blocks2[0] - 210244248;
368
+ h = t1 - 1521486534 << 0;
369
+ d = t1 + 143694565 << 0;
370
+ }
371
+ this.first = false;
372
+ } else {
373
+ s0 = (a >>> 2 | a << 30) ^ (a >>> 13 | a << 19) ^ (a >>> 22 | a << 10);
374
+ s1 = (e >>> 6 | e << 26) ^ (e >>> 11 | e << 21) ^ (e >>> 25 | e << 7);
375
+ ab = a & b;
376
+ maj = ab ^ a & c ^ bc;
377
+ ch = e & f ^ ~e & g;
378
+ t1 = h + s1 + ch + K[j] + blocks2[j];
379
+ t2 = s0 + maj;
380
+ h = d + t1 << 0;
381
+ d = t1 + t2 << 0;
382
+ }
383
+ s0 = (d >>> 2 | d << 30) ^ (d >>> 13 | d << 19) ^ (d >>> 22 | d << 10);
384
+ s1 = (h >>> 6 | h << 26) ^ (h >>> 11 | h << 21) ^ (h >>> 25 | h << 7);
385
+ da = d & a;
386
+ maj = da ^ d & b ^ ab;
387
+ ch = h & e ^ ~h & f;
388
+ t1 = g + s1 + ch + K[j + 1] + blocks2[j + 1];
389
+ t2 = s0 + maj;
390
+ g = c + t1 << 0;
391
+ c = t1 + t2 << 0;
392
+ s0 = (c >>> 2 | c << 30) ^ (c >>> 13 | c << 19) ^ (c >>> 22 | c << 10);
393
+ s1 = (g >>> 6 | g << 26) ^ (g >>> 11 | g << 21) ^ (g >>> 25 | g << 7);
394
+ cd = c & d;
395
+ maj = cd ^ c & a ^ da;
396
+ ch = g & h ^ ~g & e;
397
+ t1 = f + s1 + ch + K[j + 2] + blocks2[j + 2];
398
+ t2 = s0 + maj;
399
+ f = b + t1 << 0;
400
+ b = t1 + t2 << 0;
401
+ s0 = (b >>> 2 | b << 30) ^ (b >>> 13 | b << 19) ^ (b >>> 22 | b << 10);
402
+ s1 = (f >>> 6 | f << 26) ^ (f >>> 11 | f << 21) ^ (f >>> 25 | f << 7);
403
+ bc = b & c;
404
+ maj = bc ^ b & d ^ cd;
405
+ ch = f & g ^ ~f & h;
406
+ t1 = e + s1 + ch + K[j + 3] + blocks2[j + 3];
407
+ t2 = s0 + maj;
408
+ e = a + t1 << 0;
409
+ a = t1 + t2 << 0;
410
+ this.chromeBugWorkAround = true;
411
+ }
412
+ this.h0 = this.h0 + a << 0;
413
+ this.h1 = this.h1 + b << 0;
414
+ this.h2 = this.h2 + c << 0;
415
+ this.h3 = this.h3 + d << 0;
416
+ this.h4 = this.h4 + e << 0;
417
+ this.h5 = this.h5 + f << 0;
418
+ this.h6 = this.h6 + g << 0;
419
+ this.h7 = this.h7 + h << 0;
420
+ };
421
+ Sha256.prototype.hex = function() {
422
+ this.finalize();
423
+ 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;
424
+ 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];
425
+ if (!this.is224) {
426
+ 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];
427
+ }
428
+ return hex;
429
+ };
430
+ Sha256.prototype.toString = Sha256.prototype.hex;
431
+ Sha256.prototype.digest = function() {
432
+ this.finalize();
433
+ 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;
434
+ var arr = [
435
+ h0 >>> 24 & 255,
436
+ h0 >>> 16 & 255,
437
+ h0 >>> 8 & 255,
438
+ h0 & 255,
439
+ h1 >>> 24 & 255,
440
+ h1 >>> 16 & 255,
441
+ h1 >>> 8 & 255,
442
+ h1 & 255,
443
+ h2 >>> 24 & 255,
444
+ h2 >>> 16 & 255,
445
+ h2 >>> 8 & 255,
446
+ h2 & 255,
447
+ h3 >>> 24 & 255,
448
+ h3 >>> 16 & 255,
449
+ h3 >>> 8 & 255,
450
+ h3 & 255,
451
+ h4 >>> 24 & 255,
452
+ h4 >>> 16 & 255,
453
+ h4 >>> 8 & 255,
454
+ h4 & 255,
455
+ h5 >>> 24 & 255,
456
+ h5 >>> 16 & 255,
457
+ h5 >>> 8 & 255,
458
+ h5 & 255,
459
+ h6 >>> 24 & 255,
460
+ h6 >>> 16 & 255,
461
+ h6 >>> 8 & 255,
462
+ h6 & 255
463
+ ];
464
+ if (!this.is224) {
465
+ arr.push(h7 >>> 24 & 255, h7 >>> 16 & 255, h7 >>> 8 & 255, h7 & 255);
466
+ }
467
+ return arr;
468
+ };
469
+ Sha256.prototype.array = Sha256.prototype.digest;
470
+ Sha256.prototype.arrayBuffer = function() {
471
+ this.finalize();
472
+ var buffer = new ArrayBuffer(this.is224 ? 28 : 32);
473
+ var dataView = new DataView(buffer);
474
+ dataView.setUint32(0, this.h0);
475
+ dataView.setUint32(4, this.h1);
476
+ dataView.setUint32(8, this.h2);
477
+ dataView.setUint32(12, this.h3);
478
+ dataView.setUint32(16, this.h4);
479
+ dataView.setUint32(20, this.h5);
480
+ dataView.setUint32(24, this.h6);
481
+ if (!this.is224) {
482
+ dataView.setUint32(28, this.h7);
483
+ }
484
+ return buffer;
485
+ };
486
+ function HmacSha256(key, is224, sharedMemory) {
487
+ var i, type = typeof key;
488
+ if (type === "string") {
489
+ var bytes = [], length = key.length, index = 0, code;
490
+ for (i = 0; i < length; ++i) {
491
+ code = key.charCodeAt(i);
492
+ if (code < 128) {
493
+ bytes[index++] = code;
494
+ } else if (code < 2048) {
495
+ bytes[index++] = 192 | code >>> 6;
496
+ bytes[index++] = 128 | code & 63;
497
+ } else if (code < 55296 || code >= 57344) {
498
+ bytes[index++] = 224 | code >>> 12;
499
+ bytes[index++] = 128 | code >>> 6 & 63;
500
+ bytes[index++] = 128 | code & 63;
501
+ } else {
502
+ code = 65536 + ((code & 1023) << 10 | key.charCodeAt(++i) & 1023);
503
+ bytes[index++] = 240 | code >>> 18;
504
+ bytes[index++] = 128 | code >>> 12 & 63;
505
+ bytes[index++] = 128 | code >>> 6 & 63;
506
+ bytes[index++] = 128 | code & 63;
507
+ }
508
+ }
509
+ key = bytes;
510
+ } else {
511
+ if (type === "object") {
512
+ if (key === null) {
513
+ throw new Error(ERROR);
514
+ } else if (ARRAY_BUFFER && key.constructor === ArrayBuffer) {
515
+ key = new Uint8Array(key);
516
+ } else if (!Array.isArray(key)) {
517
+ if (!ARRAY_BUFFER || !ArrayBuffer.isView(key)) {
518
+ throw new Error(ERROR);
519
+ }
520
+ }
521
+ } else {
522
+ throw new Error(ERROR);
523
+ }
524
+ }
525
+ if (key.length > 64) {
526
+ key = new Sha256(is224, true).update(key).array();
527
+ }
528
+ var oKeyPad = [], iKeyPad = [];
529
+ for (i = 0; i < 64; ++i) {
530
+ var b = key[i] || 0;
531
+ oKeyPad[i] = 92 ^ b;
532
+ iKeyPad[i] = 54 ^ b;
533
+ }
534
+ Sha256.call(this, is224, sharedMemory);
535
+ this.update(iKeyPad);
536
+ this.oKeyPad = oKeyPad;
537
+ this.inner = true;
538
+ this.sharedMemory = sharedMemory;
539
+ }
540
+ HmacSha256.prototype = new Sha256();
541
+ HmacSha256.prototype.finalize = function() {
542
+ Sha256.prototype.finalize.call(this);
543
+ if (this.inner) {
544
+ this.inner = false;
545
+ var innerHash = this.array();
546
+ Sha256.call(this, this.is224, this.sharedMemory);
547
+ this.update(this.oKeyPad);
548
+ this.update(innerHash);
549
+ Sha256.prototype.finalize.call(this);
550
+ }
551
+ };
552
+ var exports2 = createMethod();
553
+ exports2.sha256 = exports2;
554
+ exports2.sha224 = createMethod(true);
555
+ exports2.sha256.hmac = createHmacMethod();
556
+ exports2.sha224.hmac = createHmacMethod(true);
557
+ if (COMMON_JS) {
558
+ module.exports = exports2;
559
+ } else {
560
+ root.sha256 = exports2.sha256;
561
+ root.sha224 = exports2.sha224;
562
+ if (AMD) {
563
+ define(function() {
564
+ return exports2;
565
+ });
566
+ }
567
+ }
568
+ })();
569
+ }
570
+ });
571
+
572
+ // src/extractor/dom-util.ts
573
+ function isInputElement(node) {
574
+ return node instanceof HTMLElement && (node.tagName.toLowerCase() === "input" || node.tagName.toLowerCase() === "textarea");
575
+ }
576
+ function isButtonElement(node) {
577
+ return node instanceof HTMLElement && node.tagName.toLowerCase() === "button";
578
+ }
579
+ function isImgElement(node) {
580
+ return node instanceof HTMLElement && node.tagName.toLowerCase() === "img";
581
+ }
582
+ function isTextElement(node) {
583
+ return node.nodeName.toLowerCase() === "#text";
584
+ }
585
+
586
+ // src/extractor/util.ts
587
+ var import_js_sha256 = __toESM(require_sha256());
588
+ var debugMode = false;
589
+ function setDebugMode(mode) {
590
+ debugMode = mode;
591
+ }
592
+ function logger(..._msg) {
593
+ if (!debugMode) {
594
+ return;
595
+ }
596
+ console.log(..._msg);
597
+ }
598
+ var taskIdKey = "_midscene_retrieve_task_id";
599
+ function selectorForValue(val) {
600
+ return `[${taskIdKey}='${val}']`;
601
+ }
602
+ function setDataForNode(node, nodeHash) {
603
+ const taskId = taskIdKey;
604
+ if (!(node instanceof HTMLElement)) {
605
+ return "";
606
+ }
607
+ if (!taskId) {
608
+ console.error("No task id found");
609
+ return "";
610
+ }
611
+ const selector = selectorForValue(nodeHash);
612
+ node.setAttribute(taskIdKey, nodeHash.toString());
613
+ return selector;
614
+ }
615
+ function getPseudoElementContent(element) {
616
+ if (!(element instanceof HTMLElement)) {
617
+ return { before: "", after: "" };
618
+ }
619
+ const beforeContent = window.getComputedStyle(element, "::before").getPropertyValue("content");
620
+ const afterContent = window.getComputedStyle(element, "::after").getPropertyValue("content");
621
+ return {
622
+ before: beforeContent === "none" ? "" : beforeContent.replace(/"/g, ""),
623
+ after: afterContent === "none" ? "" : afterContent.replace(/"/g, "")
624
+ };
625
+ }
626
+ function getRect(el) {
627
+ if (!(el instanceof HTMLElement)) {
628
+ const range = document.createRange();
629
+ range.selectNodeContents(el);
630
+ return range.getBoundingClientRect();
631
+ }
632
+ return el.getBoundingClientRect();
633
+ }
634
+ function visibleRect(el) {
635
+ if (!el) {
636
+ logger(el, "Element is not in the DOM hierarchy");
637
+ return false;
638
+ }
639
+ if (!(el instanceof HTMLElement) && el.nodeType !== Node.TEXT_NODE) {
640
+ logger(el, "Element is not in the DOM hierarchy");
641
+ return false;
642
+ }
643
+ if (el instanceof HTMLElement) {
644
+ const style = window.getComputedStyle(el);
645
+ if (style.display === "none" || style.visibility === "hidden" || style.opacity === "0" && el.tagName !== "INPUT") {
646
+ logger(el, "Element is hidden");
647
+ return false;
648
+ }
649
+ }
650
+ const rect = getRect(el);
651
+ if (rect.width === 0 && rect.height === 0) {
652
+ logger(el, "Element has no size");
653
+ return false;
654
+ }
655
+ const scrollLeft = window.pageXOffset || document.documentElement.scrollLeft;
656
+ const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
657
+ const viewportWidth = window.innerWidth || document.documentElement.clientWidth;
658
+ const viewportHeight = window.innerHeight || document.documentElement.clientHeight;
659
+ const isPartiallyInViewport = rect.right > 0 && rect.bottom > 0 && rect.left < viewportWidth && rect.top < viewportHeight;
660
+ if (!isPartiallyInViewport) {
661
+ logger(el, "Element is completely outside the viewport", {
662
+ rect,
663
+ viewportHeight,
664
+ viewportWidth,
665
+ scrollTop,
666
+ scrollLeft
667
+ });
668
+ return false;
669
+ }
670
+ let parent = el;
671
+ while (parent && parent !== document.body) {
672
+ if (!(parent instanceof HTMLElement)) {
673
+ parent = parent.parentElement;
674
+ continue;
675
+ }
676
+ const parentStyle = window.getComputedStyle(parent);
677
+ if (parentStyle.overflow === "hidden") {
678
+ const parentRect = parent.getBoundingClientRect();
679
+ const tolerance = 10;
680
+ if (rect.top < parentRect.top - tolerance && rect.left < parentRect.left - tolerance && rect.bottom > parentRect.bottom + tolerance && rect.right > parentRect.right + tolerance) {
681
+ logger("Element is clipped by an ancestor", parent, rect, parentRect);
682
+ return false;
683
+ }
684
+ }
685
+ parent = parent.parentElement;
686
+ }
687
+ return {
688
+ left: Math.round(rect.left - scrollLeft),
689
+ top: Math.round(rect.top - scrollTop),
690
+ width: Math.round(rect.width),
691
+ height: Math.round(rect.height)
692
+ };
693
+ }
694
+ function getNodeAttributes(node) {
695
+ if (!node || !(node instanceof HTMLElement) || !node.attributes) {
696
+ return {};
697
+ }
698
+ const attributesList = Array.from(node.attributes).map((attr) => {
699
+ if (attr.name === "class") {
700
+ return [attr.name, `.${attr.value.split(" ").join(".")}`];
701
+ }
702
+ if (!attr.value) {
703
+ return [];
704
+ }
705
+ return [attr.name, attr.value];
706
+ });
707
+ return Object.fromEntries(attributesList);
708
+ }
709
+ function generateHash(content, rect) {
710
+ const combined = JSON.stringify({ content, rect });
711
+ const hashHex = (0, import_js_sha256.default)(combined);
712
+ return hashHex.slice(0, 10);
713
+ }
714
+ window.generateHash = generateHash;
715
+
716
+ // src/extractor/extractor.ts
717
+ var container = document.body;
718
+ function generateId(numberId) {
719
+ return `${numberId}`;
720
+ }
721
+ function extractTextWithPosition(initNode = container, debugMode2 = false) {
722
+ setDebugMode(debugMode2);
723
+ const elementInfoArray = [];
724
+ const nodeMapTree = { node: initNode, children: [] };
725
+ let nodeIndex = 1;
726
+ function dfs(node, parentNode = null) {
727
+ if (!node) {
728
+ return;
729
+ }
730
+ const currentNodeDes = { node, children: [] };
731
+ if (parentNode == null ? void 0 : parentNode.children) {
732
+ parentNode.children.push(currentNodeDes);
733
+ }
734
+ const shouldContinue = collectElementInfo(node);
735
+ if (!shouldContinue) {
736
+ return;
737
+ }
738
+ for (let i = 0; i < node.childNodes.length; i++) {
739
+ logger("will dfs", node.childNodes[i]);
740
+ dfs(node.childNodes[i], currentNodeDes);
741
+ }
742
+ }
743
+ function collectElementInfo(node) {
744
+ var _a;
745
+ const rect = visibleRect(node);
746
+ logger("collectElementInfo", node, node.nodeName, rect);
747
+ if (!rect) {
748
+ logger("Element is not visible", node);
749
+ return true;
750
+ }
751
+ if (isInputElement(node)) {
752
+ const attributes = getNodeAttributes(node);
753
+ const nodeHashId = generateHash(attributes.placeholder, rect);
754
+ const selector = setDataForNode(node, nodeHashId);
755
+ elementInfoArray.push({
756
+ id: nodeHashId,
757
+ indexId: generateId(nodeIndex++),
758
+ nodeHashId,
759
+ locator: selector,
760
+ nodeType: "INPUT Node" /* INPUT */,
761
+ attributes: __spreadProps(__spreadValues({}, attributes), {
762
+ nodeType: "INPUT Node" /* INPUT */
763
+ }),
764
+ content: attributes.placeholder || "",
765
+ rect,
766
+ center: [
767
+ Math.round(rect.left + rect.width / 2),
768
+ Math.round(rect.top + rect.height / 2)
769
+ ],
770
+ htmlNode: debugMode2 ? node : null
771
+ });
772
+ return;
773
+ }
774
+ if (isButtonElement(node)) {
775
+ const attributes = getNodeAttributes(node);
776
+ const pseudo = getPseudoElementContent(node);
777
+ const content = node.innerText || pseudo.before || pseudo.after || "";
778
+ const nodeHashId = generateHash(content, rect);
779
+ const selector = setDataForNode(node, nodeHashId);
780
+ elementInfoArray.push({
781
+ id: nodeHashId,
782
+ indexId: generateId(nodeIndex++),
783
+ nodeHashId,
784
+ nodeType: "BUTTON Node" /* BUTTON */,
785
+ locator: selector,
786
+ attributes: __spreadProps(__spreadValues({}, attributes), {
787
+ nodeType: "BUTTON Node" /* BUTTON */
788
+ }),
789
+ content,
790
+ rect,
791
+ center: [
792
+ Math.round(rect.left + rect.width / 2),
793
+ Math.round(rect.top + rect.height / 2)
794
+ ],
795
+ htmlNode: debugMode2 ? node : null
796
+ });
797
+ return;
798
+ }
799
+ if (isImgElement(node)) {
800
+ const attributes = getNodeAttributes(node);
801
+ const nodeHashId = generateHash("", rect);
802
+ const selector = setDataForNode(node, nodeHashId);
803
+ elementInfoArray.push({
804
+ id: nodeHashId,
805
+ indexId: generateId(nodeIndex++),
806
+ nodeHashId,
807
+ locator: selector,
808
+ attributes: __spreadProps(__spreadValues({}, attributes), {
809
+ nodeType: "IMG Node" /* IMG */
810
+ }),
811
+ nodeType: "IMG Node" /* IMG */,
812
+ content: "",
813
+ rect,
814
+ center: [
815
+ Math.round(rect.left + rect.width / 2),
816
+ Math.round(rect.top + rect.height / 2)
817
+ ],
818
+ htmlNode: debugMode2 ? node : null
819
+ });
820
+ return;
821
+ }
822
+ if (isTextElement(node)) {
823
+ const text = (_a = node.textContent) == null ? void 0 : _a.trim().replace(/\n+/g, " ");
824
+ if (!text) {
825
+ return;
826
+ }
827
+ const attributes = getNodeAttributes(node);
828
+ const nodeHashId = generateHash(text, rect);
829
+ const selector = setDataForNode(node, nodeHashId);
830
+ elementInfoArray.push({
831
+ id: nodeHashId,
832
+ indexId: generateId(nodeIndex++),
833
+ nodeHashId,
834
+ nodeType: "TEXT Node" /* TEXT */,
835
+ locator: selector,
836
+ attributes: __spreadProps(__spreadValues({}, attributes), {
837
+ nodeType: "TEXT Node" /* TEXT */
838
+ }),
839
+ center: [
840
+ Math.round(rect.left + rect.width / 2),
841
+ Math.round(rect.top + rect.height / 2)
842
+ ],
843
+ // attributes,
844
+ content: text,
845
+ rect,
846
+ htmlNode: debugMode2 ? node : null
847
+ });
848
+ return;
849
+ }
850
+ return true;
851
+ }
852
+ dfs(initNode, nodeMapTree);
853
+ return elementInfoArray;
854
+ }
855
+
856
+ // src/extractor/debug.ts
857
+ console.log(extractTextWithPosition(document.body, true));
858
+ console.log(JSON.stringify(extractTextWithPosition(document.body, false)));
859
+ })();
860
+ /*! Bundled license information:
861
+
862
+ js-sha256/src/sha256.js:
863
+ (**
864
+ * [js-sha256]{@link https://github.com/emn178/js-sha256}
865
+ *
866
+ * @version 0.11.0
867
+ * @author Chen, Yi-Cyuan [emn178@gmail.com]
868
+ * @copyright Chen, Yi-Cyuan 2014-2024
869
+ * @license MIT
870
+ *)
871
+ */