@midscene/shared 0.9.1 → 0.9.2-beta-20250114083542.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/es/utils.js CHANGED
@@ -1,13 +1,605 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
8
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
9
+ }) : x)(function(x) {
10
+ if (typeof require !== "undefined")
11
+ return require.apply(this, arguments);
12
+ throw Error('Dynamic require of "' + x + '" is not supported');
13
+ });
14
+ var __commonJS = (cb, mod) => function __require2() {
15
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
16
+ };
17
+ var __copyProps = (to, from, except, desc) => {
18
+ if (from && typeof from === "object" || typeof from === "function") {
19
+ for (let key of __getOwnPropNames(from))
20
+ if (!__hasOwnProp.call(to, key) && key !== except)
21
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
22
+ }
23
+ return to;
24
+ };
25
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
26
+ // If the importer is in node compatibility mode or this is not an ESM
27
+ // file that has been converted to a CommonJS file using a Babel-
28
+ // compatible transform (i.e. "__esModule" has not been set), then set
29
+ // "default" to the CommonJS "module.exports" for node compatibility.
30
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
31
+ mod
32
+ ));
33
+
34
+ // ../../node_modules/.pnpm/js-sha256@0.11.0/node_modules/js-sha256/src/sha256.js
35
+ var require_sha256 = __commonJS({
36
+ "../../node_modules/.pnpm/js-sha256@0.11.0/node_modules/js-sha256/src/sha256.js"(exports, module) {
37
+ "use strict";
38
+ (function() {
39
+ "use strict";
40
+ var ERROR = "input is invalid type";
41
+ var WINDOW = typeof window === "object";
42
+ var root = WINDOW ? window : {};
43
+ if (root.JS_SHA256_NO_WINDOW) {
44
+ WINDOW = false;
45
+ }
46
+ var WEB_WORKER = !WINDOW && typeof self === "object";
47
+ var NODE_JS = !root.JS_SHA256_NO_NODE_JS && typeof process === "object" && process.versions && process.versions.node;
48
+ if (NODE_JS) {
49
+ root = global;
50
+ } else if (WEB_WORKER) {
51
+ root = self;
52
+ }
53
+ var COMMON_JS = !root.JS_SHA256_NO_COMMON_JS && typeof module === "object" && module.exports;
54
+ var AMD = typeof define === "function" && define.amd;
55
+ var ARRAY_BUFFER = !root.JS_SHA256_NO_ARRAY_BUFFER && typeof ArrayBuffer !== "undefined";
56
+ var HEX_CHARS = "0123456789abcdef".split("");
57
+ var EXTRA = [-2147483648, 8388608, 32768, 128];
58
+ var SHIFT = [24, 16, 8, 0];
59
+ var K = [
60
+ 1116352408,
61
+ 1899447441,
62
+ 3049323471,
63
+ 3921009573,
64
+ 961987163,
65
+ 1508970993,
66
+ 2453635748,
67
+ 2870763221,
68
+ 3624381080,
69
+ 310598401,
70
+ 607225278,
71
+ 1426881987,
72
+ 1925078388,
73
+ 2162078206,
74
+ 2614888103,
75
+ 3248222580,
76
+ 3835390401,
77
+ 4022224774,
78
+ 264347078,
79
+ 604807628,
80
+ 770255983,
81
+ 1249150122,
82
+ 1555081692,
83
+ 1996064986,
84
+ 2554220882,
85
+ 2821834349,
86
+ 2952996808,
87
+ 3210313671,
88
+ 3336571891,
89
+ 3584528711,
90
+ 113926993,
91
+ 338241895,
92
+ 666307205,
93
+ 773529912,
94
+ 1294757372,
95
+ 1396182291,
96
+ 1695183700,
97
+ 1986661051,
98
+ 2177026350,
99
+ 2456956037,
100
+ 2730485921,
101
+ 2820302411,
102
+ 3259730800,
103
+ 3345764771,
104
+ 3516065817,
105
+ 3600352804,
106
+ 4094571909,
107
+ 275423344,
108
+ 430227734,
109
+ 506948616,
110
+ 659060556,
111
+ 883997877,
112
+ 958139571,
113
+ 1322822218,
114
+ 1537002063,
115
+ 1747873779,
116
+ 1955562222,
117
+ 2024104815,
118
+ 2227730452,
119
+ 2361852424,
120
+ 2428436474,
121
+ 2756734187,
122
+ 3204031479,
123
+ 3329325298
124
+ ];
125
+ var OUTPUT_TYPES = ["hex", "array", "digest", "arrayBuffer"];
126
+ var blocks = [];
127
+ if (root.JS_SHA256_NO_NODE_JS || !Array.isArray) {
128
+ Array.isArray = function(obj) {
129
+ return Object.prototype.toString.call(obj) === "[object Array]";
130
+ };
131
+ }
132
+ if (ARRAY_BUFFER && (root.JS_SHA256_NO_ARRAY_BUFFER_IS_VIEW || !ArrayBuffer.isView)) {
133
+ ArrayBuffer.isView = function(obj) {
134
+ return typeof obj === "object" && obj.buffer && obj.buffer.constructor === ArrayBuffer;
135
+ };
136
+ }
137
+ var createOutputMethod = function(outputType, is224) {
138
+ return function(message) {
139
+ return new Sha256(is224, true).update(message)[outputType]();
140
+ };
141
+ };
142
+ var createMethod = function(is224) {
143
+ var method = createOutputMethod("hex", is224);
144
+ if (NODE_JS) {
145
+ method = nodeWrap(method, is224);
146
+ }
147
+ method.create = function() {
148
+ return new Sha256(is224);
149
+ };
150
+ method.update = function(message) {
151
+ return method.create().update(message);
152
+ };
153
+ for (var i = 0; i < OUTPUT_TYPES.length; ++i) {
154
+ var type = OUTPUT_TYPES[i];
155
+ method[type] = createOutputMethod(type, is224);
156
+ }
157
+ return method;
158
+ };
159
+ var nodeWrap = function(method, is224) {
160
+ var crypto = __require("crypto");
161
+ var Buffer2 = __require("buffer").Buffer;
162
+ var algorithm = is224 ? "sha224" : "sha256";
163
+ var bufferFrom;
164
+ if (Buffer2.from && !root.JS_SHA256_NO_BUFFER_FROM) {
165
+ bufferFrom = Buffer2.from;
166
+ } else {
167
+ bufferFrom = function(message) {
168
+ return new Buffer2(message);
169
+ };
170
+ }
171
+ var nodeMethod = function(message) {
172
+ if (typeof message === "string") {
173
+ return crypto.createHash(algorithm).update(message, "utf8").digest("hex");
174
+ } else {
175
+ if (message === null || message === void 0) {
176
+ throw new Error(ERROR);
177
+ } else if (message.constructor === ArrayBuffer) {
178
+ message = new Uint8Array(message);
179
+ }
180
+ }
181
+ if (Array.isArray(message) || ArrayBuffer.isView(message) || message.constructor === Buffer2) {
182
+ return crypto.createHash(algorithm).update(bufferFrom(message)).digest("hex");
183
+ } else {
184
+ return method(message);
185
+ }
186
+ };
187
+ return nodeMethod;
188
+ };
189
+ var createHmacOutputMethod = function(outputType, is224) {
190
+ return function(key, message) {
191
+ return new HmacSha256(key, is224, true).update(message)[outputType]();
192
+ };
193
+ };
194
+ var createHmacMethod = function(is224) {
195
+ var method = createHmacOutputMethod("hex", is224);
196
+ method.create = function(key) {
197
+ return new HmacSha256(key, is224);
198
+ };
199
+ method.update = function(key, message) {
200
+ return method.create(key).update(message);
201
+ };
202
+ for (var i = 0; i < OUTPUT_TYPES.length; ++i) {
203
+ var type = OUTPUT_TYPES[i];
204
+ method[type] = createHmacOutputMethod(type, is224);
205
+ }
206
+ return method;
207
+ };
208
+ function Sha256(is224, sharedMemory) {
209
+ if (sharedMemory) {
210
+ 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;
211
+ this.blocks = blocks;
212
+ } else {
213
+ this.blocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
214
+ }
215
+ if (is224) {
216
+ this.h0 = 3238371032;
217
+ this.h1 = 914150663;
218
+ this.h2 = 812702999;
219
+ this.h3 = 4144912697;
220
+ this.h4 = 4290775857;
221
+ this.h5 = 1750603025;
222
+ this.h6 = 1694076839;
223
+ this.h7 = 3204075428;
224
+ } else {
225
+ this.h0 = 1779033703;
226
+ this.h1 = 3144134277;
227
+ this.h2 = 1013904242;
228
+ this.h3 = 2773480762;
229
+ this.h4 = 1359893119;
230
+ this.h5 = 2600822924;
231
+ this.h6 = 528734635;
232
+ this.h7 = 1541459225;
233
+ }
234
+ this.block = this.start = this.bytes = this.hBytes = 0;
235
+ this.finalized = this.hashed = false;
236
+ this.first = true;
237
+ this.is224 = is224;
238
+ }
239
+ Sha256.prototype.update = function(message) {
240
+ if (this.finalized) {
241
+ return;
242
+ }
243
+ var notString, type = typeof message;
244
+ if (type !== "string") {
245
+ if (type === "object") {
246
+ if (message === null) {
247
+ throw new Error(ERROR);
248
+ } else if (ARRAY_BUFFER && message.constructor === ArrayBuffer) {
249
+ message = new Uint8Array(message);
250
+ } else if (!Array.isArray(message)) {
251
+ if (!ARRAY_BUFFER || !ArrayBuffer.isView(message)) {
252
+ throw new Error(ERROR);
253
+ }
254
+ }
255
+ } else {
256
+ throw new Error(ERROR);
257
+ }
258
+ notString = true;
259
+ }
260
+ var code, index = 0, i, length = message.length, blocks2 = this.blocks;
261
+ while (index < length) {
262
+ if (this.hashed) {
263
+ this.hashed = false;
264
+ blocks2[0] = this.block;
265
+ 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;
266
+ }
267
+ if (notString) {
268
+ for (i = this.start; index < length && i < 64; ++index) {
269
+ blocks2[i >>> 2] |= message[index] << SHIFT[i++ & 3];
270
+ }
271
+ } else {
272
+ for (i = this.start; index < length && i < 64; ++index) {
273
+ code = message.charCodeAt(index);
274
+ if (code < 128) {
275
+ blocks2[i >>> 2] |= code << SHIFT[i++ & 3];
276
+ } else if (code < 2048) {
277
+ blocks2[i >>> 2] |= (192 | code >>> 6) << SHIFT[i++ & 3];
278
+ blocks2[i >>> 2] |= (128 | code & 63) << SHIFT[i++ & 3];
279
+ } else if (code < 55296 || code >= 57344) {
280
+ blocks2[i >>> 2] |= (224 | code >>> 12) << SHIFT[i++ & 3];
281
+ blocks2[i >>> 2] |= (128 | code >>> 6 & 63) << SHIFT[i++ & 3];
282
+ blocks2[i >>> 2] |= (128 | code & 63) << SHIFT[i++ & 3];
283
+ } else {
284
+ code = 65536 + ((code & 1023) << 10 | message.charCodeAt(++index) & 1023);
285
+ blocks2[i >>> 2] |= (240 | code >>> 18) << SHIFT[i++ & 3];
286
+ blocks2[i >>> 2] |= (128 | code >>> 12 & 63) << SHIFT[i++ & 3];
287
+ blocks2[i >>> 2] |= (128 | code >>> 6 & 63) << SHIFT[i++ & 3];
288
+ blocks2[i >>> 2] |= (128 | code & 63) << SHIFT[i++ & 3];
289
+ }
290
+ }
291
+ }
292
+ this.lastByteIndex = i;
293
+ this.bytes += i - this.start;
294
+ if (i >= 64) {
295
+ this.block = blocks2[16];
296
+ this.start = i - 64;
297
+ this.hash();
298
+ this.hashed = true;
299
+ } else {
300
+ this.start = i;
301
+ }
302
+ }
303
+ if (this.bytes > 4294967295) {
304
+ this.hBytes += this.bytes / 4294967296 << 0;
305
+ this.bytes = this.bytes % 4294967296;
306
+ }
307
+ return this;
308
+ };
309
+ Sha256.prototype.finalize = function() {
310
+ if (this.finalized) {
311
+ return;
312
+ }
313
+ this.finalized = true;
314
+ var blocks2 = this.blocks, i = this.lastByteIndex;
315
+ blocks2[16] = this.block;
316
+ blocks2[i >>> 2] |= EXTRA[i & 3];
317
+ this.block = blocks2[16];
318
+ if (i >= 56) {
319
+ if (!this.hashed) {
320
+ this.hash();
321
+ }
322
+ blocks2[0] = this.block;
323
+ 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;
324
+ }
325
+ blocks2[14] = this.hBytes << 3 | this.bytes >>> 29;
326
+ blocks2[15] = this.bytes << 3;
327
+ this.hash();
328
+ };
329
+ Sha256.prototype.hash = function() {
330
+ 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;
331
+ for (j = 16; j < 64; ++j) {
332
+ t1 = blocks2[j - 15];
333
+ s0 = (t1 >>> 7 | t1 << 25) ^ (t1 >>> 18 | t1 << 14) ^ t1 >>> 3;
334
+ t1 = blocks2[j - 2];
335
+ s1 = (t1 >>> 17 | t1 << 15) ^ (t1 >>> 19 | t1 << 13) ^ t1 >>> 10;
336
+ blocks2[j] = blocks2[j - 16] + s0 + blocks2[j - 7] + s1 << 0;
337
+ }
338
+ bc = b & c;
339
+ for (j = 0; j < 64; j += 4) {
340
+ if (this.first) {
341
+ if (this.is224) {
342
+ ab = 300032;
343
+ t1 = blocks2[0] - 1413257819;
344
+ h = t1 - 150054599 << 0;
345
+ d = t1 + 24177077 << 0;
346
+ } else {
347
+ ab = 704751109;
348
+ t1 = blocks2[0] - 210244248;
349
+ h = t1 - 1521486534 << 0;
350
+ d = t1 + 143694565 << 0;
351
+ }
352
+ this.first = false;
353
+ } else {
354
+ s0 = (a >>> 2 | a << 30) ^ (a >>> 13 | a << 19) ^ (a >>> 22 | a << 10);
355
+ s1 = (e >>> 6 | e << 26) ^ (e >>> 11 | e << 21) ^ (e >>> 25 | e << 7);
356
+ ab = a & b;
357
+ maj = ab ^ a & c ^ bc;
358
+ ch = e & f ^ ~e & g;
359
+ t1 = h + s1 + ch + K[j] + blocks2[j];
360
+ t2 = s0 + maj;
361
+ h = d + t1 << 0;
362
+ d = t1 + t2 << 0;
363
+ }
364
+ s0 = (d >>> 2 | d << 30) ^ (d >>> 13 | d << 19) ^ (d >>> 22 | d << 10);
365
+ s1 = (h >>> 6 | h << 26) ^ (h >>> 11 | h << 21) ^ (h >>> 25 | h << 7);
366
+ da = d & a;
367
+ maj = da ^ d & b ^ ab;
368
+ ch = h & e ^ ~h & f;
369
+ t1 = g + s1 + ch + K[j + 1] + blocks2[j + 1];
370
+ t2 = s0 + maj;
371
+ g = c + t1 << 0;
372
+ c = t1 + t2 << 0;
373
+ s0 = (c >>> 2 | c << 30) ^ (c >>> 13 | c << 19) ^ (c >>> 22 | c << 10);
374
+ s1 = (g >>> 6 | g << 26) ^ (g >>> 11 | g << 21) ^ (g >>> 25 | g << 7);
375
+ cd = c & d;
376
+ maj = cd ^ c & a ^ da;
377
+ ch = g & h ^ ~g & e;
378
+ t1 = f + s1 + ch + K[j + 2] + blocks2[j + 2];
379
+ t2 = s0 + maj;
380
+ f = b + t1 << 0;
381
+ b = t1 + t2 << 0;
382
+ s0 = (b >>> 2 | b << 30) ^ (b >>> 13 | b << 19) ^ (b >>> 22 | b << 10);
383
+ s1 = (f >>> 6 | f << 26) ^ (f >>> 11 | f << 21) ^ (f >>> 25 | f << 7);
384
+ bc = b & c;
385
+ maj = bc ^ b & d ^ cd;
386
+ ch = f & g ^ ~f & h;
387
+ t1 = e + s1 + ch + K[j + 3] + blocks2[j + 3];
388
+ t2 = s0 + maj;
389
+ e = a + t1 << 0;
390
+ a = t1 + t2 << 0;
391
+ this.chromeBugWorkAround = true;
392
+ }
393
+ this.h0 = this.h0 + a << 0;
394
+ this.h1 = this.h1 + b << 0;
395
+ this.h2 = this.h2 + c << 0;
396
+ this.h3 = this.h3 + d << 0;
397
+ this.h4 = this.h4 + e << 0;
398
+ this.h5 = this.h5 + f << 0;
399
+ this.h6 = this.h6 + g << 0;
400
+ this.h7 = this.h7 + h << 0;
401
+ };
402
+ Sha256.prototype.hex = function() {
403
+ this.finalize();
404
+ 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;
405
+ 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];
406
+ if (!this.is224) {
407
+ 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];
408
+ }
409
+ return hex;
410
+ };
411
+ Sha256.prototype.toString = Sha256.prototype.hex;
412
+ Sha256.prototype.digest = function() {
413
+ this.finalize();
414
+ 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;
415
+ var arr = [
416
+ h0 >>> 24 & 255,
417
+ h0 >>> 16 & 255,
418
+ h0 >>> 8 & 255,
419
+ h0 & 255,
420
+ h1 >>> 24 & 255,
421
+ h1 >>> 16 & 255,
422
+ h1 >>> 8 & 255,
423
+ h1 & 255,
424
+ h2 >>> 24 & 255,
425
+ h2 >>> 16 & 255,
426
+ h2 >>> 8 & 255,
427
+ h2 & 255,
428
+ h3 >>> 24 & 255,
429
+ h3 >>> 16 & 255,
430
+ h3 >>> 8 & 255,
431
+ h3 & 255,
432
+ h4 >>> 24 & 255,
433
+ h4 >>> 16 & 255,
434
+ h4 >>> 8 & 255,
435
+ h4 & 255,
436
+ h5 >>> 24 & 255,
437
+ h5 >>> 16 & 255,
438
+ h5 >>> 8 & 255,
439
+ h5 & 255,
440
+ h6 >>> 24 & 255,
441
+ h6 >>> 16 & 255,
442
+ h6 >>> 8 & 255,
443
+ h6 & 255
444
+ ];
445
+ if (!this.is224) {
446
+ arr.push(h7 >>> 24 & 255, h7 >>> 16 & 255, h7 >>> 8 & 255, h7 & 255);
447
+ }
448
+ return arr;
449
+ };
450
+ Sha256.prototype.array = Sha256.prototype.digest;
451
+ Sha256.prototype.arrayBuffer = function() {
452
+ this.finalize();
453
+ var buffer = new ArrayBuffer(this.is224 ? 28 : 32);
454
+ var dataView = new DataView(buffer);
455
+ dataView.setUint32(0, this.h0);
456
+ dataView.setUint32(4, this.h1);
457
+ dataView.setUint32(8, this.h2);
458
+ dataView.setUint32(12, this.h3);
459
+ dataView.setUint32(16, this.h4);
460
+ dataView.setUint32(20, this.h5);
461
+ dataView.setUint32(24, this.h6);
462
+ if (!this.is224) {
463
+ dataView.setUint32(28, this.h7);
464
+ }
465
+ return buffer;
466
+ };
467
+ function HmacSha256(key, is224, sharedMemory) {
468
+ var i, type = typeof key;
469
+ if (type === "string") {
470
+ var bytes = [], length = key.length, index = 0, code;
471
+ for (i = 0; i < length; ++i) {
472
+ code = key.charCodeAt(i);
473
+ if (code < 128) {
474
+ bytes[index++] = code;
475
+ } else if (code < 2048) {
476
+ bytes[index++] = 192 | code >>> 6;
477
+ bytes[index++] = 128 | code & 63;
478
+ } else if (code < 55296 || code >= 57344) {
479
+ bytes[index++] = 224 | code >>> 12;
480
+ bytes[index++] = 128 | code >>> 6 & 63;
481
+ bytes[index++] = 128 | code & 63;
482
+ } else {
483
+ code = 65536 + ((code & 1023) << 10 | key.charCodeAt(++i) & 1023);
484
+ bytes[index++] = 240 | code >>> 18;
485
+ bytes[index++] = 128 | code >>> 12 & 63;
486
+ bytes[index++] = 128 | code >>> 6 & 63;
487
+ bytes[index++] = 128 | code & 63;
488
+ }
489
+ }
490
+ key = bytes;
491
+ } else {
492
+ if (type === "object") {
493
+ if (key === null) {
494
+ throw new Error(ERROR);
495
+ } else if (ARRAY_BUFFER && key.constructor === ArrayBuffer) {
496
+ key = new Uint8Array(key);
497
+ } else if (!Array.isArray(key)) {
498
+ if (!ARRAY_BUFFER || !ArrayBuffer.isView(key)) {
499
+ throw new Error(ERROR);
500
+ }
501
+ }
502
+ } else {
503
+ throw new Error(ERROR);
504
+ }
505
+ }
506
+ if (key.length > 64) {
507
+ key = new Sha256(is224, true).update(key).array();
508
+ }
509
+ var oKeyPad = [], iKeyPad = [];
510
+ for (i = 0; i < 64; ++i) {
511
+ var b = key[i] || 0;
512
+ oKeyPad[i] = 92 ^ b;
513
+ iKeyPad[i] = 54 ^ b;
514
+ }
515
+ Sha256.call(this, is224, sharedMemory);
516
+ this.update(iKeyPad);
517
+ this.oKeyPad = oKeyPad;
518
+ this.inner = true;
519
+ this.sharedMemory = sharedMemory;
520
+ }
521
+ HmacSha256.prototype = new Sha256();
522
+ HmacSha256.prototype.finalize = function() {
523
+ Sha256.prototype.finalize.call(this);
524
+ if (this.inner) {
525
+ this.inner = false;
526
+ var innerHash = this.array();
527
+ Sha256.call(this, this.is224, this.sharedMemory);
528
+ this.update(this.oKeyPad);
529
+ this.update(innerHash);
530
+ Sha256.prototype.finalize.call(this);
531
+ }
532
+ };
533
+ var exports2 = createMethod();
534
+ exports2.sha256 = exports2;
535
+ exports2.sha224 = createMethod(true);
536
+ exports2.sha256.hmac = createHmacMethod();
537
+ exports2.sha224.hmac = createHmacMethod(true);
538
+ if (COMMON_JS) {
539
+ module.exports = exports2;
540
+ } else {
541
+ root.sha256 = exports2.sha256;
542
+ root.sha224 = exports2.sha224;
543
+ if (AMD) {
544
+ define(function() {
545
+ return exports2;
546
+ });
547
+ }
548
+ }
549
+ })();
550
+ }
551
+ });
552
+
1
553
  // src/utils.ts
2
- import { randomUUID } from "crypto";
554
+ var import_js_sha256 = __toESM(require_sha256());
3
555
  var ifInBrowser = typeof window !== "undefined";
4
556
  function uuid() {
5
- if (ifInBrowser) {
6
- return Math.random().toString(36).substring(2, 15);
557
+ return Math.random().toString(36).substring(2, 15);
558
+ }
559
+ var hashMap = {};
560
+ var frameId = 0;
561
+ function getFrameId() {
562
+ return frameId;
563
+ }
564
+ function setFrameId(id) {
565
+ frameId = id;
566
+ }
567
+ function generateHashId(rect, content = "") {
568
+ const combined = JSON.stringify({
569
+ content,
570
+ rect,
571
+ _midscene_frame_id: getFrameId()
572
+ });
573
+ let sliceLength = 8;
574
+ let slicedHash = "";
575
+ const hashHex = import_js_sha256.sha256.create().update(combined).hex();
576
+ while (sliceLength < hashHex.length - 1) {
577
+ slicedHash = hashHex.slice(0, sliceLength);
578
+ if (hashMap[slicedHash] && hashMap[slicedHash] !== combined) {
579
+ sliceLength++;
580
+ continue;
581
+ }
582
+ hashMap[slicedHash] = combined;
583
+ break;
7
584
  }
8
- return randomUUID();
585
+ return slicedHash;
9
586
  }
10
587
  export {
588
+ generateHashId,
589
+ getFrameId,
11
590
  ifInBrowser,
591
+ setFrameId,
12
592
  uuid
13
593
  };
594
+ /*! Bundled license information:
595
+
596
+ js-sha256/src/sha256.js:
597
+ (**
598
+ * [js-sha256]{@link https://github.com/emn178/js-sha256}
599
+ *
600
+ * @version 0.11.0
601
+ * @author Chen, Yi-Cyuan [emn178@gmail.com]
602
+ * @copyright Chen, Yi-Cyuan 2014-2024
603
+ * @license MIT
604
+ *)
605
+ */
@@ -7,7 +7,8 @@ declare enum NodeType {
7
7
  FORM_ITEM = "FORM_ITEM Node",
8
8
  BUTTON = "BUTTON Node",
9
9
  IMG = "IMG Node",
10
- TEXT = "TEXT Node"
10
+ TEXT = "TEXT Node",
11
+ POSITION = "POSITION Node"
11
12
  }
12
13
 
13
14
  export { CONTAINER_MINI_HEIGHT, CONTAINER_MINI_WIDTH, NodeType, TEXT_MAX_SIZE, TEXT_SIZE_THRESHOLD };
@@ -37,6 +37,7 @@ var NodeType = /* @__PURE__ */ ((NodeType2) => {
37
37
  NodeType2["BUTTON"] = "BUTTON Node";
38
38
  NodeType2["IMG"] = "IMG Node";
39
39
  NodeType2["TEXT"] = "TEXT Node";
40
+ NodeType2["POSITION"] = "POSITION Node";
40
41
  return NodeType2;
41
42
  })(NodeType || {});
42
43
  // Annotate the CommonJS export names for ESM import in node:
@@ -1,4 +1,7 @@
1
1
  declare const ifInBrowser: boolean;
2
2
  declare function uuid(): string;
3
+ declare function getFrameId(): number;
4
+ declare function setFrameId(id: number): void;
5
+ declare function generateHashId(rect: any, content?: string): string;
3
6
 
4
- export { ifInBrowser, uuid };
7
+ export { generateHashId, getFrameId, ifInBrowser, setFrameId, uuid };