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