@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.
- package/dist/browser/extractor-debug.d.ts +2 -0
- package/dist/browser/extractor-debug.js +1254 -0
- package/dist/browser/extractor.d.ts +47 -0
- package/dist/browser/extractor.js +1542 -0
- package/dist/browser/img.d.ts +3 -12
- package/dist/browser/img.js +3 -3
- package/dist/browser/index-305e7a7e.d.ts +32 -0
- package/dist/browser/utils.d.ts +1 -3
- package/dist/browser/utils.js +11 -14
- package/dist/es/extractor-debug.d.ts +2 -0
- package/dist/es/extractor-debug.js +1252 -0
- package/dist/es/extractor.d.ts +47 -0
- package/dist/es/extractor.js +1531 -0
- package/dist/es/img.d.ts +3 -12
- package/dist/es/img.js +3 -3
- package/dist/es/index-305e7a7e.d.ts +32 -0
- package/dist/es/utils.d.ts +1 -3
- package/dist/es/utils.js +11 -14
- package/dist/lib/extractor-debug.d.ts +2 -0
- package/dist/lib/extractor-debug.js +1246 -0
- package/dist/lib/extractor.d.ts +47 -0
- package/dist/lib/extractor.js +1544 -0
- package/dist/lib/img.d.ts +3 -12
- package/dist/lib/img.js +3 -3
- package/dist/lib/index-305e7a7e.d.ts +32 -0
- package/dist/lib/utils.d.ts +1 -3
- package/dist/lib/utils.js +11 -16
- package/dist/script/htmlElement.js +1544 -0
- package/dist/script/htmlElementDebug.js +1256 -0
- package/package.json +20 -2
- package/src/extractor/client-extractor.ts +212 -0
- package/src/extractor/constants.ts +5 -0
- package/src/extractor/debug.ts +10 -0
- package/src/extractor/dom-util.ts +100 -0
- package/src/extractor/index.ts +31 -0
- package/src/extractor/tree.ts +173 -0
- package/src/extractor/util.ts +491 -0
- package/src/extractor/web-extractor.ts +406 -0
- package/src/img/box-select.ts +2 -2
- package/src/img/draw-box.ts +2 -3
- package/src/img/transform.ts +1 -1
- package/src/types/index.ts +31 -2
- package/src/utils.ts +18 -15
|
@@ -0,0 +1,1254 @@
|
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
29
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
30
|
+
for (let key of __getOwnPropNames(from))
|
|
31
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
32
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
33
|
+
}
|
|
34
|
+
return to;
|
|
35
|
+
};
|
|
36
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
37
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
38
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
39
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
40
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
41
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
42
|
+
mod
|
|
43
|
+
));
|
|
44
|
+
|
|
45
|
+
// resolve-false:/empty-stub
|
|
46
|
+
var require_empty_stub = __commonJS({
|
|
47
|
+
"resolve-false:/empty-stub"(exports, module2) {
|
|
48
|
+
"use strict";
|
|
49
|
+
module2.exports = {};
|
|
50
|
+
}
|
|
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, module2) {
|
|
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 module2 === "object" && module2.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_empty_stub();
|
|
180
|
+
var Buffer2 = require_empty_stub().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
|
+
module2.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/constants/index.ts
|
|
573
|
+
var CONTAINER_MINI_HEIGHT = 3;
|
|
574
|
+
var CONTAINER_MINI_WIDTH = 3;
|
|
575
|
+
|
|
576
|
+
// src/extractor/dom-util.ts
|
|
577
|
+
function isFormElement(node) {
|
|
578
|
+
return node instanceof HTMLElement && (node.tagName.toLowerCase() === "input" || node.tagName.toLowerCase() === "textarea" || node.tagName.toLowerCase() === "select" || node.tagName.toLowerCase() === "option");
|
|
579
|
+
}
|
|
580
|
+
function isButtonElement(node) {
|
|
581
|
+
return node instanceof HTMLElement && node.tagName.toLowerCase() === "button";
|
|
582
|
+
}
|
|
583
|
+
function isImgElement(node) {
|
|
584
|
+
if (!includeBaseElement(node) && node instanceof Element) {
|
|
585
|
+
const computedStyle = window.getComputedStyle(node);
|
|
586
|
+
const backgroundImage = computedStyle.getPropertyValue("background-image");
|
|
587
|
+
if (backgroundImage !== "none") {
|
|
588
|
+
return true;
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
if (isIconfont(node)) {
|
|
592
|
+
return true;
|
|
593
|
+
}
|
|
594
|
+
return node instanceof HTMLElement && node.tagName.toLowerCase() === "img" || node instanceof SVGElement && node.tagName.toLowerCase() === "svg";
|
|
595
|
+
}
|
|
596
|
+
function isIconfont(node) {
|
|
597
|
+
if (node instanceof Element) {
|
|
598
|
+
const computedStyle = window.getComputedStyle(node);
|
|
599
|
+
const fontFamilyValue = computedStyle.fontFamily || "";
|
|
600
|
+
return fontFamilyValue.toLowerCase().indexOf("iconfont") >= 0;
|
|
601
|
+
}
|
|
602
|
+
return false;
|
|
603
|
+
}
|
|
604
|
+
function isTextElement(node) {
|
|
605
|
+
return node.nodeName.toLowerCase() === "#text" && !isIconfont(node);
|
|
606
|
+
}
|
|
607
|
+
function isContainerElement(node) {
|
|
608
|
+
if (!(node instanceof HTMLElement))
|
|
609
|
+
return false;
|
|
610
|
+
if (includeBaseElement(node)) {
|
|
611
|
+
return false;
|
|
612
|
+
}
|
|
613
|
+
const computedStyle = window.getComputedStyle(node);
|
|
614
|
+
const backgroundColor = computedStyle.getPropertyValue("background-color");
|
|
615
|
+
if (backgroundColor) {
|
|
616
|
+
return true;
|
|
617
|
+
}
|
|
618
|
+
return false;
|
|
619
|
+
}
|
|
620
|
+
function includeBaseElement(node) {
|
|
621
|
+
if (!(node instanceof HTMLElement))
|
|
622
|
+
return false;
|
|
623
|
+
if (node.innerText) {
|
|
624
|
+
return true;
|
|
625
|
+
}
|
|
626
|
+
const includeList = [
|
|
627
|
+
"svg",
|
|
628
|
+
"button",
|
|
629
|
+
"input",
|
|
630
|
+
"textarea",
|
|
631
|
+
"select",
|
|
632
|
+
"option",
|
|
633
|
+
"img"
|
|
634
|
+
];
|
|
635
|
+
for (const tagName of includeList) {
|
|
636
|
+
const element = node.querySelectorAll(tagName);
|
|
637
|
+
if (element.length > 0) {
|
|
638
|
+
return true;
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
return false;
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
// src/utils.ts
|
|
645
|
+
var import_js_sha256 = __toESM(require_sha256());
|
|
646
|
+
var hashMap = {};
|
|
647
|
+
function generateHashId(rect, content = "") {
|
|
648
|
+
const combined = JSON.stringify({
|
|
649
|
+
content,
|
|
650
|
+
rect
|
|
651
|
+
});
|
|
652
|
+
let sliceLength = 5;
|
|
653
|
+
let slicedHash = "";
|
|
654
|
+
const hashHex = import_js_sha256.sha256.create().update(combined).hex();
|
|
655
|
+
const toLetters = (hex) => {
|
|
656
|
+
return hex.split("").map((char) => {
|
|
657
|
+
const code = Number.parseInt(char, 16);
|
|
658
|
+
return String.fromCharCode(97 + code % 26);
|
|
659
|
+
}).join("");
|
|
660
|
+
};
|
|
661
|
+
const hashLetters = toLetters(hashHex);
|
|
662
|
+
while (sliceLength < hashLetters.length - 1) {
|
|
663
|
+
slicedHash = hashLetters.slice(0, sliceLength);
|
|
664
|
+
if (hashMap[slicedHash] && hashMap[slicedHash] !== combined) {
|
|
665
|
+
sliceLength++;
|
|
666
|
+
continue;
|
|
667
|
+
}
|
|
668
|
+
hashMap[slicedHash] = combined;
|
|
669
|
+
break;
|
|
670
|
+
}
|
|
671
|
+
return slicedHash;
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
// src/extractor/util.ts
|
|
675
|
+
var MAX_VALUE_LENGTH = 300;
|
|
676
|
+
var debugMode = false;
|
|
677
|
+
function setDebugMode(mode) {
|
|
678
|
+
debugMode = mode;
|
|
679
|
+
}
|
|
680
|
+
function getDebugMode() {
|
|
681
|
+
return debugMode;
|
|
682
|
+
}
|
|
683
|
+
function logger(..._msg) {
|
|
684
|
+
if (!debugMode) {
|
|
685
|
+
return;
|
|
686
|
+
}
|
|
687
|
+
console.log(..._msg);
|
|
688
|
+
}
|
|
689
|
+
var taskIdKey = "_midscene_retrieve_task_id";
|
|
690
|
+
function selectorForValue(val) {
|
|
691
|
+
return `[${taskIdKey}='${val}']`;
|
|
692
|
+
}
|
|
693
|
+
function setDataForNode(node, nodeHash, setToParentNode, currentWindow) {
|
|
694
|
+
const taskId = taskIdKey;
|
|
695
|
+
if (!(node instanceof currentWindow.HTMLElement)) {
|
|
696
|
+
return "";
|
|
697
|
+
}
|
|
698
|
+
if (!taskId) {
|
|
699
|
+
console.error("No task id found");
|
|
700
|
+
return "";
|
|
701
|
+
}
|
|
702
|
+
const selector = selectorForValue(nodeHash);
|
|
703
|
+
if (getDebugMode()) {
|
|
704
|
+
if (setToParentNode) {
|
|
705
|
+
if (node.parentNode instanceof currentWindow.HTMLElement) {
|
|
706
|
+
node.parentNode.setAttribute(taskIdKey, nodeHash.toString());
|
|
707
|
+
}
|
|
708
|
+
} else {
|
|
709
|
+
node.setAttribute(taskIdKey, nodeHash.toString());
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
return selector;
|
|
713
|
+
}
|
|
714
|
+
function isElementPartiallyInViewport(rect, currentWindow, currentDocument) {
|
|
715
|
+
const elementHeight = rect.height;
|
|
716
|
+
const elementWidth = rect.width;
|
|
717
|
+
const viewportRect = {
|
|
718
|
+
left: 0,
|
|
719
|
+
top: 0,
|
|
720
|
+
width: currentWindow.innerWidth || currentDocument.documentElement.clientWidth,
|
|
721
|
+
height: currentWindow.innerHeight || currentDocument.documentElement.clientHeight,
|
|
722
|
+
right: currentWindow.innerWidth || currentDocument.documentElement.clientWidth,
|
|
723
|
+
bottom: currentWindow.innerHeight || currentDocument.documentElement.clientHeight,
|
|
724
|
+
x: 0,
|
|
725
|
+
y: 0,
|
|
726
|
+
zoom: 1
|
|
727
|
+
};
|
|
728
|
+
const overlapRect = overlappedRect(rect, viewportRect);
|
|
729
|
+
if (!overlapRect) {
|
|
730
|
+
return false;
|
|
731
|
+
}
|
|
732
|
+
const visibleArea = overlapRect.width * overlapRect.height;
|
|
733
|
+
const totalArea = elementHeight * elementWidth;
|
|
734
|
+
return visibleArea / totalArea >= 2 / 3;
|
|
735
|
+
}
|
|
736
|
+
function getPseudoElementContent(element, currentWindow) {
|
|
737
|
+
if (!(element instanceof currentWindow.HTMLElement)) {
|
|
738
|
+
return { before: "", after: "" };
|
|
739
|
+
}
|
|
740
|
+
const beforeContent = currentWindow.getComputedStyle(element, "::before").getPropertyValue("content");
|
|
741
|
+
const afterContent = currentWindow.getComputedStyle(element, "::after").getPropertyValue("content");
|
|
742
|
+
return {
|
|
743
|
+
before: beforeContent === "none" ? "" : beforeContent.replace(/"/g, ""),
|
|
744
|
+
after: afterContent === "none" ? "" : afterContent.replace(/"/g, "")
|
|
745
|
+
};
|
|
746
|
+
}
|
|
747
|
+
function overlappedRect(rect1, rect2) {
|
|
748
|
+
const left = Math.max(rect1.left, rect2.left);
|
|
749
|
+
const top = Math.max(rect1.top, rect2.top);
|
|
750
|
+
const right = Math.min(rect1.right, rect2.right);
|
|
751
|
+
const bottom = Math.min(rect1.bottom, rect2.bottom);
|
|
752
|
+
if (left < right && top < bottom) {
|
|
753
|
+
return {
|
|
754
|
+
left,
|
|
755
|
+
top,
|
|
756
|
+
right,
|
|
757
|
+
bottom,
|
|
758
|
+
width: right - left,
|
|
759
|
+
height: bottom - top,
|
|
760
|
+
x: left,
|
|
761
|
+
y: top,
|
|
762
|
+
zoom: 1
|
|
763
|
+
};
|
|
764
|
+
}
|
|
765
|
+
return null;
|
|
766
|
+
}
|
|
767
|
+
function getRect(el, baseZoom, currentWindow) {
|
|
768
|
+
let originalRect;
|
|
769
|
+
let newZoom = 1;
|
|
770
|
+
if (!(el instanceof currentWindow.HTMLElement)) {
|
|
771
|
+
const range = currentWindow.document.createRange();
|
|
772
|
+
range.selectNodeContents(el);
|
|
773
|
+
originalRect = range.getBoundingClientRect();
|
|
774
|
+
} else {
|
|
775
|
+
originalRect = el.getBoundingClientRect();
|
|
776
|
+
if (!("currentCSSZoom" in el)) {
|
|
777
|
+
newZoom = Number.parseFloat(currentWindow.getComputedStyle(el).zoom) || 1;
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
const zoom = newZoom * baseZoom;
|
|
781
|
+
return {
|
|
782
|
+
width: originalRect.width * zoom,
|
|
783
|
+
height: originalRect.height * zoom,
|
|
784
|
+
left: originalRect.left * zoom,
|
|
785
|
+
top: originalRect.top * zoom,
|
|
786
|
+
right: originalRect.right * zoom,
|
|
787
|
+
bottom: originalRect.bottom * zoom,
|
|
788
|
+
x: originalRect.x * zoom,
|
|
789
|
+
y: originalRect.y * zoom,
|
|
790
|
+
zoom
|
|
791
|
+
};
|
|
792
|
+
}
|
|
793
|
+
var isElementCovered = (el, rect, currentWindow) => {
|
|
794
|
+
const x = rect.left + rect.width / 2;
|
|
795
|
+
const y = rect.top + rect.height / 2;
|
|
796
|
+
const topElement = currentWindow.document.elementFromPoint(x, y);
|
|
797
|
+
if (!topElement) {
|
|
798
|
+
return false;
|
|
799
|
+
}
|
|
800
|
+
if (topElement === el) {
|
|
801
|
+
return false;
|
|
802
|
+
}
|
|
803
|
+
if (el == null ? void 0 : el.contains(topElement)) {
|
|
804
|
+
return false;
|
|
805
|
+
}
|
|
806
|
+
if (topElement == null ? void 0 : topElement.contains(el)) {
|
|
807
|
+
return false;
|
|
808
|
+
}
|
|
809
|
+
const rectOfTopElement = getRect(topElement, 1, currentWindow);
|
|
810
|
+
const overlapRect = overlappedRect(rect, rectOfTopElement);
|
|
811
|
+
if (!overlapRect) {
|
|
812
|
+
return false;
|
|
813
|
+
}
|
|
814
|
+
logger(el, "Element is covered by another element", {
|
|
815
|
+
topElement,
|
|
816
|
+
el,
|
|
817
|
+
rect,
|
|
818
|
+
x,
|
|
819
|
+
y
|
|
820
|
+
});
|
|
821
|
+
return true;
|
|
822
|
+
};
|
|
823
|
+
function visibleRect(el, currentWindow, currentDocument, baseZoom = 1) {
|
|
824
|
+
if (!el) {
|
|
825
|
+
logger(el, "Element is not in the DOM hierarchy");
|
|
826
|
+
return false;
|
|
827
|
+
}
|
|
828
|
+
if (!(el instanceof currentWindow.HTMLElement) && el.nodeType !== Node.TEXT_NODE && el.nodeName.toLowerCase() !== "svg") {
|
|
829
|
+
logger(el, "Element is not in the DOM hierarchy");
|
|
830
|
+
return false;
|
|
831
|
+
}
|
|
832
|
+
if (el instanceof currentWindow.HTMLElement) {
|
|
833
|
+
const style = currentWindow.getComputedStyle(el);
|
|
834
|
+
if (style.display === "none" || style.visibility === "hidden" || style.opacity === "0" && el.tagName !== "INPUT") {
|
|
835
|
+
logger(el, "Element is hidden");
|
|
836
|
+
return false;
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
const rect = getRect(el, baseZoom, currentWindow);
|
|
840
|
+
if (rect.width === 0 && rect.height === 0) {
|
|
841
|
+
logger(el, "Element has no size");
|
|
842
|
+
return false;
|
|
843
|
+
}
|
|
844
|
+
if (baseZoom === 1 && isElementCovered(el, rect, currentWindow)) {
|
|
845
|
+
return false;
|
|
846
|
+
}
|
|
847
|
+
const scrollLeft = currentWindow.pageXOffset || currentDocument.documentElement.scrollLeft;
|
|
848
|
+
const scrollTop = currentWindow.pageYOffset || currentDocument.documentElement.scrollTop;
|
|
849
|
+
const viewportWidth = currentWindow.innerWidth || currentDocument.documentElement.clientWidth;
|
|
850
|
+
const viewportHeight = currentWindow.innerHeight || currentDocument.documentElement.clientHeight;
|
|
851
|
+
const isPartiallyInViewport = isElementPartiallyInViewport(
|
|
852
|
+
rect,
|
|
853
|
+
currentWindow,
|
|
854
|
+
currentDocument
|
|
855
|
+
);
|
|
856
|
+
if (!isPartiallyInViewport) {
|
|
857
|
+
logger(el, "Element is completely outside the viewport", {
|
|
858
|
+
rect,
|
|
859
|
+
viewportHeight,
|
|
860
|
+
viewportWidth,
|
|
861
|
+
scrollTop,
|
|
862
|
+
scrollLeft
|
|
863
|
+
});
|
|
864
|
+
return false;
|
|
865
|
+
}
|
|
866
|
+
let parent = el;
|
|
867
|
+
while (parent && parent !== currentDocument.body) {
|
|
868
|
+
if (!(parent instanceof currentWindow.HTMLElement)) {
|
|
869
|
+
parent = parent.parentElement;
|
|
870
|
+
continue;
|
|
871
|
+
}
|
|
872
|
+
const parentStyle = currentWindow.getComputedStyle(parent);
|
|
873
|
+
if (parentStyle.overflow === "hidden") {
|
|
874
|
+
const parentRect = getRect(parent, 1, currentWindow);
|
|
875
|
+
const tolerance = 10;
|
|
876
|
+
if (rect.right < parentRect.left - tolerance || rect.left > parentRect.right + tolerance || rect.bottom < parentRect.top - tolerance || rect.top > parentRect.bottom + tolerance) {
|
|
877
|
+
logger(el, "element is partially or totally hidden by an ancestor", {
|
|
878
|
+
rect,
|
|
879
|
+
parentRect
|
|
880
|
+
});
|
|
881
|
+
return false;
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
if (parentStyle.position === "fixed") {
|
|
885
|
+
break;
|
|
886
|
+
}
|
|
887
|
+
parent = parent.parentElement;
|
|
888
|
+
}
|
|
889
|
+
return {
|
|
890
|
+
left: Math.round(rect.left),
|
|
891
|
+
top: Math.round(rect.top),
|
|
892
|
+
width: Math.round(rect.width),
|
|
893
|
+
height: Math.round(rect.height),
|
|
894
|
+
zoom: rect.zoom
|
|
895
|
+
};
|
|
896
|
+
}
|
|
897
|
+
function getNodeAttributes(node, currentWindow) {
|
|
898
|
+
if (!node || !(node instanceof currentWindow.HTMLElement) || !node.attributes) {
|
|
899
|
+
return {};
|
|
900
|
+
}
|
|
901
|
+
const attributesList = Array.from(node.attributes).map((attr) => {
|
|
902
|
+
if (attr.name === "class") {
|
|
903
|
+
return [attr.name, `.${attr.value.split(" ").join(".")}`];
|
|
904
|
+
}
|
|
905
|
+
if (!attr.value) {
|
|
906
|
+
return [];
|
|
907
|
+
}
|
|
908
|
+
let value = attr.value;
|
|
909
|
+
if (value.startsWith("data:image")) {
|
|
910
|
+
value = "image";
|
|
911
|
+
}
|
|
912
|
+
if (value.length > MAX_VALUE_LENGTH) {
|
|
913
|
+
value = `${value.slice(0, MAX_VALUE_LENGTH)}...`;
|
|
914
|
+
}
|
|
915
|
+
return [attr.name, value];
|
|
916
|
+
});
|
|
917
|
+
return Object.fromEntries(attributesList);
|
|
918
|
+
}
|
|
919
|
+
var nodeHashCacheList = [];
|
|
920
|
+
if (typeof window !== "undefined") {
|
|
921
|
+
window.midsceneNodeHashCacheList = window.midsceneNodeHashCacheList || [];
|
|
922
|
+
nodeHashCacheList = window.midsceneNodeHashCacheList;
|
|
923
|
+
}
|
|
924
|
+
function resetNodeHashCacheList() {
|
|
925
|
+
if (typeof window !== "undefined") {
|
|
926
|
+
nodeHashCacheList = window.midsceneNodeHashCacheList || [];
|
|
927
|
+
window.midsceneNodeHashCacheList = [];
|
|
928
|
+
} else {
|
|
929
|
+
nodeHashCacheList = [];
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
function midsceneGenerateHash(node, content, rect) {
|
|
933
|
+
var _a;
|
|
934
|
+
if (node && nodeHashCacheList.find((item) => item.node === node)) {
|
|
935
|
+
return ((_a = nodeHashCacheList.find((item) => item.node === node)) == null ? void 0 : _a.id) || "";
|
|
936
|
+
}
|
|
937
|
+
const slicedHash = generateHashId(rect, content);
|
|
938
|
+
if (node && typeof window !== "undefined") {
|
|
939
|
+
window.midsceneNodeHashCacheList.push({ node, id: slicedHash });
|
|
940
|
+
}
|
|
941
|
+
return slicedHash;
|
|
942
|
+
}
|
|
943
|
+
function setMidsceneVisibleRectOnWindow() {
|
|
944
|
+
if (typeof window !== "undefined") {
|
|
945
|
+
window.midsceneVisibleRect = visibleRect;
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
function setExtractTextWithPositionOnWindow() {
|
|
949
|
+
if (typeof window !== "undefined") {
|
|
950
|
+
window.extractTextWithPosition = extractTextWithPosition;
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
function getTopDocument() {
|
|
954
|
+
const container = document.body || document;
|
|
955
|
+
return container;
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
// src/extractor/web-extractor.ts
|
|
959
|
+
var indexId = 0;
|
|
960
|
+
function tagNameOfNode(node) {
|
|
961
|
+
let tagName = "";
|
|
962
|
+
if (node instanceof HTMLElement) {
|
|
963
|
+
tagName = node.tagName.toLowerCase();
|
|
964
|
+
}
|
|
965
|
+
const parentElement = node.parentElement;
|
|
966
|
+
if (parentElement && parentElement instanceof HTMLElement) {
|
|
967
|
+
tagName = parentElement.tagName.toLowerCase();
|
|
968
|
+
}
|
|
969
|
+
return tagName ? `<${tagName}>` : "";
|
|
970
|
+
}
|
|
971
|
+
function collectElementInfo(node, currentWindow, currentDocument, baseZoom = 1, basePoint = { left: 0, top: 0 }) {
|
|
972
|
+
var _a;
|
|
973
|
+
const rect = visibleRect(node, currentWindow, currentDocument, baseZoom);
|
|
974
|
+
if (!rect || rect.width < CONTAINER_MINI_WIDTH || rect.height < CONTAINER_MINI_HEIGHT) {
|
|
975
|
+
return null;
|
|
976
|
+
}
|
|
977
|
+
if (basePoint.left !== 0 || basePoint.top !== 0) {
|
|
978
|
+
rect.left += basePoint.left;
|
|
979
|
+
rect.top += basePoint.top;
|
|
980
|
+
}
|
|
981
|
+
if (rect.height >= window.innerHeight && rect.width >= window.innerWidth) {
|
|
982
|
+
return null;
|
|
983
|
+
}
|
|
984
|
+
if (isFormElement(node)) {
|
|
985
|
+
const attributes = getNodeAttributes(node, currentWindow);
|
|
986
|
+
let valueContent = attributes.value || attributes.placeholder || node.textContent || "";
|
|
987
|
+
const nodeHashId = midsceneGenerateHash(node, valueContent, rect);
|
|
988
|
+
const selector = setDataForNode(node, nodeHashId, false, currentWindow);
|
|
989
|
+
const tagName = node.tagName.toLowerCase();
|
|
990
|
+
if (node.tagName.toLowerCase() === "select") {
|
|
991
|
+
const selectedOption = node.options[node.selectedIndex];
|
|
992
|
+
valueContent = selectedOption.textContent || "";
|
|
993
|
+
}
|
|
994
|
+
if ((node.tagName.toLowerCase() === "input" || node.tagName.toLowerCase() === "textarea") && node.value) {
|
|
995
|
+
valueContent = node.value;
|
|
996
|
+
}
|
|
997
|
+
const elementInfo = {
|
|
998
|
+
id: nodeHashId,
|
|
999
|
+
nodeHashId,
|
|
1000
|
+
locator: selector,
|
|
1001
|
+
nodeType: "FORM_ITEM Node" /* FORM_ITEM */,
|
|
1002
|
+
indexId: indexId++,
|
|
1003
|
+
attributes: __spreadProps(__spreadValues({}, attributes), {
|
|
1004
|
+
htmlTagName: `<${tagName}>`,
|
|
1005
|
+
nodeType: "FORM_ITEM Node" /* FORM_ITEM */
|
|
1006
|
+
}),
|
|
1007
|
+
content: valueContent.trim(),
|
|
1008
|
+
rect,
|
|
1009
|
+
center: [
|
|
1010
|
+
Math.round(rect.left + rect.width / 2),
|
|
1011
|
+
Math.round(rect.top + rect.height / 2)
|
|
1012
|
+
],
|
|
1013
|
+
zoom: rect.zoom,
|
|
1014
|
+
screenWidth: currentWindow.innerWidth,
|
|
1015
|
+
screenHeight: currentWindow.innerHeight
|
|
1016
|
+
};
|
|
1017
|
+
return elementInfo;
|
|
1018
|
+
}
|
|
1019
|
+
if (isButtonElement(node)) {
|
|
1020
|
+
const attributes = getNodeAttributes(node, currentWindow);
|
|
1021
|
+
const pseudo = getPseudoElementContent(node, currentWindow);
|
|
1022
|
+
const content = node.innerText || pseudo.before || pseudo.after || "";
|
|
1023
|
+
const nodeHashId = midsceneGenerateHash(node, content, rect);
|
|
1024
|
+
const selector = setDataForNode(node, nodeHashId, false, currentWindow);
|
|
1025
|
+
const elementInfo = {
|
|
1026
|
+
id: nodeHashId,
|
|
1027
|
+
indexId: indexId++,
|
|
1028
|
+
nodeHashId,
|
|
1029
|
+
nodeType: "BUTTON Node" /* BUTTON */,
|
|
1030
|
+
locator: selector,
|
|
1031
|
+
attributes: __spreadProps(__spreadValues({}, attributes), {
|
|
1032
|
+
htmlTagName: tagNameOfNode(node),
|
|
1033
|
+
nodeType: "BUTTON Node" /* BUTTON */
|
|
1034
|
+
}),
|
|
1035
|
+
content,
|
|
1036
|
+
rect,
|
|
1037
|
+
center: [
|
|
1038
|
+
Math.round(rect.left + rect.width / 2),
|
|
1039
|
+
Math.round(rect.top + rect.height / 2)
|
|
1040
|
+
],
|
|
1041
|
+
zoom: rect.zoom,
|
|
1042
|
+
screenWidth: currentWindow.innerWidth,
|
|
1043
|
+
screenHeight: currentWindow.innerHeight
|
|
1044
|
+
};
|
|
1045
|
+
return elementInfo;
|
|
1046
|
+
}
|
|
1047
|
+
if (isImgElement(node)) {
|
|
1048
|
+
const attributes = getNodeAttributes(node, currentWindow);
|
|
1049
|
+
const nodeHashId = midsceneGenerateHash(node, "", rect);
|
|
1050
|
+
const selector = setDataForNode(node, nodeHashId, false, currentWindow);
|
|
1051
|
+
const elementInfo = {
|
|
1052
|
+
id: nodeHashId,
|
|
1053
|
+
indexId: indexId++,
|
|
1054
|
+
nodeHashId,
|
|
1055
|
+
locator: selector,
|
|
1056
|
+
attributes: __spreadProps(__spreadValues(__spreadValues({}, attributes), node.nodeName.toLowerCase() === "svg" ? {
|
|
1057
|
+
svgContent: "true"
|
|
1058
|
+
} : {}), {
|
|
1059
|
+
nodeType: "IMG Node" /* IMG */,
|
|
1060
|
+
htmlTagName: tagNameOfNode(node)
|
|
1061
|
+
}),
|
|
1062
|
+
nodeType: "IMG Node" /* IMG */,
|
|
1063
|
+
content: "",
|
|
1064
|
+
rect,
|
|
1065
|
+
center: [
|
|
1066
|
+
Math.round(rect.left + rect.width / 2),
|
|
1067
|
+
Math.round(rect.top + rect.height / 2)
|
|
1068
|
+
],
|
|
1069
|
+
zoom: rect.zoom,
|
|
1070
|
+
screenWidth: currentWindow.innerWidth,
|
|
1071
|
+
screenHeight: currentWindow.innerHeight
|
|
1072
|
+
};
|
|
1073
|
+
return elementInfo;
|
|
1074
|
+
}
|
|
1075
|
+
if (isTextElement(node)) {
|
|
1076
|
+
const text = (_a = node.textContent) == null ? void 0 : _a.trim().replace(/\n+/g, " ");
|
|
1077
|
+
if (!text) {
|
|
1078
|
+
return null;
|
|
1079
|
+
}
|
|
1080
|
+
const attributes = getNodeAttributes(node, currentWindow);
|
|
1081
|
+
const attributeKeys = Object.keys(attributes);
|
|
1082
|
+
if (!text.trim() && attributeKeys.length === 0) {
|
|
1083
|
+
return null;
|
|
1084
|
+
}
|
|
1085
|
+
const nodeHashId = midsceneGenerateHash(node, text, rect);
|
|
1086
|
+
const selector = setDataForNode(node, nodeHashId, true, currentWindow);
|
|
1087
|
+
const elementInfo = {
|
|
1088
|
+
id: nodeHashId,
|
|
1089
|
+
indexId: indexId++,
|
|
1090
|
+
nodeHashId,
|
|
1091
|
+
nodeType: "TEXT Node" /* TEXT */,
|
|
1092
|
+
locator: selector,
|
|
1093
|
+
attributes: __spreadProps(__spreadValues({}, attributes), {
|
|
1094
|
+
nodeType: "TEXT Node" /* TEXT */,
|
|
1095
|
+
htmlTagName: tagNameOfNode(node)
|
|
1096
|
+
}),
|
|
1097
|
+
center: [
|
|
1098
|
+
Math.round(rect.left + rect.width / 2),
|
|
1099
|
+
Math.round(rect.top + rect.height / 2)
|
|
1100
|
+
],
|
|
1101
|
+
// attributes,
|
|
1102
|
+
content: text,
|
|
1103
|
+
rect,
|
|
1104
|
+
zoom: rect.zoom,
|
|
1105
|
+
screenWidth: currentWindow.innerWidth,
|
|
1106
|
+
screenHeight: currentWindow.innerHeight
|
|
1107
|
+
};
|
|
1108
|
+
return elementInfo;
|
|
1109
|
+
}
|
|
1110
|
+
if (isContainerElement(node)) {
|
|
1111
|
+
const attributes = getNodeAttributes(node, currentWindow);
|
|
1112
|
+
const nodeHashId = midsceneGenerateHash(node, "", rect);
|
|
1113
|
+
const selector = setDataForNode(node, nodeHashId, false, currentWindow);
|
|
1114
|
+
const elementInfo = {
|
|
1115
|
+
id: nodeHashId,
|
|
1116
|
+
nodeHashId,
|
|
1117
|
+
indexId: indexId++,
|
|
1118
|
+
nodeType: "CONTAINER Node" /* CONTAINER */,
|
|
1119
|
+
locator: selector,
|
|
1120
|
+
attributes: __spreadProps(__spreadValues({}, attributes), {
|
|
1121
|
+
nodeType: "CONTAINER Node" /* CONTAINER */,
|
|
1122
|
+
htmlTagName: tagNameOfNode(node)
|
|
1123
|
+
}),
|
|
1124
|
+
content: "",
|
|
1125
|
+
rect,
|
|
1126
|
+
center: [
|
|
1127
|
+
Math.round(rect.left + rect.width / 2),
|
|
1128
|
+
Math.round(rect.top + rect.height / 2)
|
|
1129
|
+
],
|
|
1130
|
+
zoom: rect.zoom,
|
|
1131
|
+
screenWidth: currentWindow.innerWidth,
|
|
1132
|
+
screenHeight: currentWindow.innerHeight
|
|
1133
|
+
};
|
|
1134
|
+
return elementInfo;
|
|
1135
|
+
}
|
|
1136
|
+
return null;
|
|
1137
|
+
}
|
|
1138
|
+
function extractTextWithPosition(initNode, debugMode2 = false) {
|
|
1139
|
+
const elementNode = extractTreeNode(initNode, debugMode2);
|
|
1140
|
+
const elementInfoArray = [];
|
|
1141
|
+
function dfsTopChildren(node) {
|
|
1142
|
+
if (node.node) {
|
|
1143
|
+
elementInfoArray.push(node.node);
|
|
1144
|
+
}
|
|
1145
|
+
for (let i = 0; i < node.children.length; i++) {
|
|
1146
|
+
dfsTopChildren(node.children[i]);
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1149
|
+
dfsTopChildren({ children: elementNode.children, node: elementNode.node });
|
|
1150
|
+
return elementInfoArray;
|
|
1151
|
+
}
|
|
1152
|
+
function extractTreeNode(initNode, debugMode2 = false) {
|
|
1153
|
+
setDebugMode(debugMode2);
|
|
1154
|
+
resetNodeHashCacheList();
|
|
1155
|
+
indexId = 0;
|
|
1156
|
+
const topDocument = getTopDocument();
|
|
1157
|
+
const startNode = initNode || topDocument;
|
|
1158
|
+
const topChildren = [];
|
|
1159
|
+
function dfs(node, currentWindow, currentDocument, baseZoom = 1, basePoint = { left: 0, top: 0 }) {
|
|
1160
|
+
if (!node) {
|
|
1161
|
+
return null;
|
|
1162
|
+
}
|
|
1163
|
+
if (node.nodeType && node.nodeType === 10) {
|
|
1164
|
+
return null;
|
|
1165
|
+
}
|
|
1166
|
+
const elementInfo = collectElementInfo(
|
|
1167
|
+
node,
|
|
1168
|
+
currentWindow,
|
|
1169
|
+
currentDocument,
|
|
1170
|
+
baseZoom,
|
|
1171
|
+
basePoint
|
|
1172
|
+
);
|
|
1173
|
+
if (node instanceof currentWindow.HTMLIFrameElement) {
|
|
1174
|
+
if (node.contentWindow && node.contentWindow) {
|
|
1175
|
+
return null;
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
const nodeInfo = {
|
|
1179
|
+
node: elementInfo,
|
|
1180
|
+
children: []
|
|
1181
|
+
};
|
|
1182
|
+
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 */) {
|
|
1183
|
+
return nodeInfo;
|
|
1184
|
+
}
|
|
1185
|
+
const rect = getRect(node, baseZoom, currentWindow);
|
|
1186
|
+
for (let i = 0; i < node.childNodes.length; i++) {
|
|
1187
|
+
logger("will dfs", node.childNodes[i]);
|
|
1188
|
+
const childNodeInfo = dfs(
|
|
1189
|
+
node.childNodes[i],
|
|
1190
|
+
currentWindow,
|
|
1191
|
+
currentDocument,
|
|
1192
|
+
rect.zoom,
|
|
1193
|
+
basePoint
|
|
1194
|
+
);
|
|
1195
|
+
if (childNodeInfo) {
|
|
1196
|
+
nodeInfo.children.push(childNodeInfo);
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
return nodeInfo;
|
|
1200
|
+
}
|
|
1201
|
+
const rootNodeInfo = dfs(startNode, window, document, 1, {
|
|
1202
|
+
left: 0,
|
|
1203
|
+
top: 0
|
|
1204
|
+
});
|
|
1205
|
+
if (rootNodeInfo) {
|
|
1206
|
+
topChildren.push(rootNodeInfo);
|
|
1207
|
+
}
|
|
1208
|
+
if (startNode === topDocument) {
|
|
1209
|
+
const iframes = document.querySelectorAll("iframe");
|
|
1210
|
+
for (let i = 0; i < iframes.length; i++) {
|
|
1211
|
+
const iframe = iframes[i];
|
|
1212
|
+
if (iframe.contentDocument && iframe.contentWindow) {
|
|
1213
|
+
const iframeInfo = collectElementInfo(iframe, window, document, 1);
|
|
1214
|
+
if (iframeInfo) {
|
|
1215
|
+
const iframeChildren = dfs(
|
|
1216
|
+
iframe.contentDocument.body,
|
|
1217
|
+
iframe.contentWindow,
|
|
1218
|
+
iframe.contentDocument,
|
|
1219
|
+
1,
|
|
1220
|
+
{
|
|
1221
|
+
left: iframeInfo.rect.left,
|
|
1222
|
+
top: iframeInfo.rect.top
|
|
1223
|
+
}
|
|
1224
|
+
);
|
|
1225
|
+
if (iframeChildren) {
|
|
1226
|
+
topChildren.push(iframeChildren);
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
}
|
|
1232
|
+
return {
|
|
1233
|
+
node: null,
|
|
1234
|
+
children: topChildren
|
|
1235
|
+
};
|
|
1236
|
+
}
|
|
1237
|
+
|
|
1238
|
+
// src/extractor/debug.ts
|
|
1239
|
+
console.log(extractTextWithPosition(document.body, true));
|
|
1240
|
+
console.log(JSON.stringify(extractTextWithPosition(document.body, true)));
|
|
1241
|
+
setExtractTextWithPositionOnWindow();
|
|
1242
|
+
setMidsceneVisibleRectOnWindow();
|
|
1243
|
+
/*! Bundled license information:
|
|
1244
|
+
|
|
1245
|
+
js-sha256/src/sha256.js:
|
|
1246
|
+
(**
|
|
1247
|
+
* [js-sha256]{@link https://github.com/emn178/js-sha256}
|
|
1248
|
+
*
|
|
1249
|
+
* @version 0.11.0
|
|
1250
|
+
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
|
1251
|
+
* @copyright Chen, Yi-Cyuan 2014-2024
|
|
1252
|
+
* @license MIT
|
|
1253
|
+
*)
|
|
1254
|
+
*/
|