@sqaitech/shared 0.5.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/README.md +9 -0
- package/dist/es/baseDB.mjs +109 -0
- package/dist/es/build/copy-static.mjs +29 -0
- package/dist/es/common.mjs +37 -0
- package/dist/es/constants/example-code.mjs +202 -0
- package/dist/es/constants/index.mjs +24 -0
- package/dist/es/env/basic.mjs +6 -0
- package/dist/es/env/constants.mjs +97 -0
- package/dist/es/env/decide-model-config.mjs +172 -0
- package/dist/es/env/global-config-manager.mjs +91 -0
- package/dist/es/env/helper.mjs +48 -0
- package/dist/es/env/index.mjs +5 -0
- package/dist/es/env/init-debug.mjs +18 -0
- package/dist/es/env/model-config-manager.mjs +99 -0
- package/dist/es/env/parse.mjs +69 -0
- package/dist/es/env/types.mjs +253 -0
- package/dist/es/env/utils.mjs +18 -0
- package/dist/es/extractor/constants.mjs +2 -0
- package/dist/es/extractor/debug.mjs +6 -0
- package/dist/es/extractor/dom-util.mjs +92 -0
- package/dist/es/extractor/index.mjs +6 -0
- package/dist/es/extractor/locator.mjs +95 -0
- package/dist/es/extractor/tree.mjs +81 -0
- package/dist/es/extractor/util.mjs +244 -0
- package/dist/es/extractor/web-extractor.mjs +310 -0
- package/dist/es/img/box-select.mjs +184 -0
- package/dist/es/img/draw-box.mjs +42 -0
- package/dist/es/img/get-jimp.mjs +10 -0
- package/dist/es/img/get-photon.mjs +19 -0
- package/dist/es/img/get-sharp.mjs +11 -0
- package/dist/es/img/index.mjs +5 -0
- package/dist/es/img/info.mjs +32 -0
- package/dist/es/img/transform.mjs +192 -0
- package/dist/es/index.mjs +3 -0
- package/dist/es/logger.mjs +61 -0
- package/dist/es/node/fs.mjs +44 -0
- package/dist/es/node/index.mjs +1 -0
- package/dist/es/polyfills/async-hooks.mjs +2 -0
- package/dist/es/polyfills/index.mjs +1 -0
- package/dist/es/types/index.mjs +3 -0
- package/dist/es/us-keyboard-layout.mjs +1414 -0
- package/dist/es/us-keyboard-layout.mjs.LICENSE.txt +5 -0
- package/dist/es/utils.mjs +66 -0
- package/dist/lib/baseDB.js +149 -0
- package/dist/lib/build/copy-static.js +77 -0
- package/dist/lib/common.js +93 -0
- package/dist/lib/constants/example-code.js +239 -0
- package/dist/lib/constants/index.js +100 -0
- package/dist/lib/env/basic.js +40 -0
- package/dist/lib/env/constants.js +143 -0
- package/dist/lib/env/decide-model-config.js +212 -0
- package/dist/lib/env/global-config-manager.js +125 -0
- package/dist/lib/env/helper.js +89 -0
- package/dist/lib/env/index.js +94 -0
- package/dist/lib/env/init-debug.js +52 -0
- package/dist/lib/env/model-config-manager.js +133 -0
- package/dist/lib/env/parse.js +106 -0
- package/dist/lib/env/types.js +635 -0
- package/dist/lib/env/utils.js +61 -0
- package/dist/lib/extractor/constants.js +42 -0
- package/dist/lib/extractor/debug.js +12 -0
- package/dist/lib/extractor/dom-util.js +150 -0
- package/dist/lib/extractor/index.js +88 -0
- package/dist/lib/extractor/locator.js +141 -0
- package/dist/lib/extractor/tree.js +127 -0
- package/dist/lib/extractor/util.js +335 -0
- package/dist/lib/extractor/web-extractor.js +356 -0
- package/dist/lib/img/box-select.js +232 -0
- package/dist/lib/img/draw-box.js +89 -0
- package/dist/lib/img/get-jimp.js +72 -0
- package/dist/lib/img/get-photon.js +76 -0
- package/dist/lib/img/get-sharp.js +63 -0
- package/dist/lib/img/index.js +102 -0
- package/dist/lib/img/info.js +86 -0
- package/dist/lib/img/transform.js +279 -0
- package/dist/lib/index.js +43 -0
- package/dist/lib/logger.js +114 -0
- package/dist/lib/node/fs.js +97 -0
- package/dist/lib/node/index.js +60 -0
- package/dist/lib/polyfills/async-hooks.js +36 -0
- package/dist/lib/polyfills/index.js +60 -0
- package/dist/lib/types/index.js +37 -0
- package/dist/lib/us-keyboard-layout.js +1457 -0
- package/dist/lib/us-keyboard-layout.js.LICENSE.txt +5 -0
- package/dist/lib/utils.js +136 -0
- package/dist/types/baseDB.d.ts +25 -0
- package/dist/types/build/copy-static.d.ts +31 -0
- package/dist/types/common.d.ts +12 -0
- package/dist/types/constants/example-code.d.ts +2 -0
- package/dist/types/constants/index.d.ts +22 -0
- package/dist/types/env/basic.d.ts +6 -0
- package/dist/types/env/constants.d.ts +40 -0
- package/dist/types/env/decide-model-config.d.ts +14 -0
- package/dist/types/env/global-config-manager.d.ts +32 -0
- package/dist/types/env/helper.d.ts +6 -0
- package/dist/types/env/index.d.ts +4 -0
- package/dist/types/env/init-debug.d.ts +1 -0
- package/dist/types/env/model-config-manager.d.ts +24 -0
- package/dist/types/env/parse.d.ts +12 -0
- package/dist/types/env/types.d.ts +294 -0
- package/dist/types/env/utils.d.ts +7 -0
- package/dist/types/extractor/constants.d.ts +1 -0
- package/dist/types/extractor/debug.d.ts +1 -0
- package/dist/types/extractor/dom-util.d.ts +26 -0
- package/dist/types/extractor/index.d.ts +33 -0
- package/dist/types/extractor/locator.d.ts +7 -0
- package/dist/types/extractor/tree.d.ts +9 -0
- package/dist/types/extractor/util.d.ts +43 -0
- package/dist/types/extractor/web-extractor.d.ts +19 -0
- package/dist/types/img/box-select.d.ts +25 -0
- package/dist/types/img/draw-box.d.ts +15 -0
- package/dist/types/img/get-jimp.d.ts +2 -0
- package/dist/types/img/get-photon.d.ts +8 -0
- package/dist/types/img/get-sharp.d.ts +3 -0
- package/dist/types/img/index.d.ts +4 -0
- package/dist/types/img/info.d.ts +29 -0
- package/dist/types/img/transform.d.ts +88 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/logger.d.ts +4 -0
- package/dist/types/node/fs.d.ts +15 -0
- package/dist/types/node/index.d.ts +1 -0
- package/dist/types/polyfills/async-hooks.d.ts +6 -0
- package/dist/types/polyfills/index.d.ts +4 -0
- package/dist/types/types/index.d.ts +34 -0
- package/dist/types/us-keyboard-layout.d.ts +32 -0
- package/dist/types/utils.d.ts +22 -0
- package/package.json +106 -0
- package/src/baseDB.ts +158 -0
- package/src/build/copy-static.ts +62 -0
- package/src/common.ts +67 -0
- package/src/constants/example-code.ts +202 -0
- package/src/constants/index.ts +30 -0
- package/src/env/basic.ts +12 -0
- package/src/env/constants.ts +291 -0
- package/src/env/decide-model-config.ts +319 -0
- package/src/env/global-config-manager.ts +174 -0
- package/src/env/helper.ts +79 -0
- package/src/env/index.ts +4 -0
- package/src/env/init-debug.ts +29 -0
- package/src/env/model-config-manager.ts +145 -0
- package/src/env/parse.ts +131 -0
- package/src/env/types.ts +560 -0
- package/src/env/utils.ts +39 -0
- package/src/extractor/constants.ts +5 -0
- package/src/extractor/debug.ts +10 -0
- package/src/extractor/dom-util.ts +152 -0
- package/src/extractor/index.ts +50 -0
- package/src/extractor/locator.ts +179 -0
- package/src/extractor/tree.ts +179 -0
- package/src/extractor/util.ts +468 -0
- package/src/extractor/web-extractor.ts +481 -0
- package/src/img/box-select.ts +346 -0
- package/src/img/draw-box.ts +60 -0
- package/src/img/get-jimp.ts +12 -0
- package/src/img/get-photon.ts +48 -0
- package/src/img/get-sharp.ts +18 -0
- package/src/img/index.ts +24 -0
- package/src/img/info.ts +79 -0
- package/src/img/jimp.d.ts +4 -0
- package/src/img/transform.ts +396 -0
- package/src/index.ts +6 -0
- package/src/logger.ts +93 -0
- package/src/node/fs.ts +84 -0
- package/src/node/index.ts +1 -0
- package/src/polyfills/async-hooks.ts +6 -0
- package/src/polyfills/index.ts +4 -0
- package/src/types/index.ts +47 -0
- package/src/us-keyboard-layout.ts +723 -0
- package/src/utils.ts +127 -0
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
midsceneGenerateHash: ()=>midsceneGenerateHash,
|
|
28
|
+
validTextNodeContent: ()=>validTextNodeContent,
|
|
29
|
+
setNodeHashCacheListOnWindow: ()=>setNodeHashCacheListOnWindow,
|
|
30
|
+
overlappedRect: ()=>overlappedRect,
|
|
31
|
+
isElementPartiallyInViewport: ()=>isElementPartiallyInViewport,
|
|
32
|
+
elementRect: ()=>elementRect,
|
|
33
|
+
getTopDocument: ()=>getTopDocument,
|
|
34
|
+
setMidsceneVisibleRectOnWindow: ()=>setMidsceneVisibleRectOnWindow,
|
|
35
|
+
getNodeFromCacheList: ()=>getNodeFromCacheList,
|
|
36
|
+
getNodeAttributes: ()=>getNodeAttributes,
|
|
37
|
+
generateId: ()=>generateId,
|
|
38
|
+
setNodeToCacheList: ()=>setNodeToCacheList,
|
|
39
|
+
logger: ()=>logger,
|
|
40
|
+
getPseudoElementContent: ()=>getPseudoElementContent,
|
|
41
|
+
getDebugMode: ()=>getDebugMode,
|
|
42
|
+
hasOverflowY: ()=>hasOverflowY,
|
|
43
|
+
getRect: ()=>getRect,
|
|
44
|
+
setDebugMode: ()=>setDebugMode,
|
|
45
|
+
setExtractTextWithPositionOnWindow: ()=>setExtractTextWithPositionOnWindow,
|
|
46
|
+
setGenerateHashOnWindow: ()=>setGenerateHashOnWindow
|
|
47
|
+
});
|
|
48
|
+
const external_utils_js_namespaceObject = require("../utils.js");
|
|
49
|
+
const external_web_extractor_js_namespaceObject = require("./web-extractor.js");
|
|
50
|
+
const MAX_VALUE_LENGTH = 300;
|
|
51
|
+
let debugMode = false;
|
|
52
|
+
function setDebugMode(mode) {
|
|
53
|
+
debugMode = mode;
|
|
54
|
+
}
|
|
55
|
+
function getDebugMode() {
|
|
56
|
+
return debugMode;
|
|
57
|
+
}
|
|
58
|
+
function logger(..._msg) {
|
|
59
|
+
if (!debugMode) return;
|
|
60
|
+
console.log(..._msg);
|
|
61
|
+
}
|
|
62
|
+
function isElementPartiallyInViewport(rect, currentWindow, currentDocument, visibleAreaRatio = 2 / 3) {
|
|
63
|
+
const elementHeight = rect.height;
|
|
64
|
+
const elementWidth = rect.width;
|
|
65
|
+
const viewportRect = {
|
|
66
|
+
left: 0,
|
|
67
|
+
top: 0,
|
|
68
|
+
width: currentWindow.innerWidth || currentDocument.documentElement.clientWidth,
|
|
69
|
+
height: currentWindow.innerHeight || currentDocument.documentElement.clientHeight,
|
|
70
|
+
right: currentWindow.innerWidth || currentDocument.documentElement.clientWidth,
|
|
71
|
+
bottom: currentWindow.innerHeight || currentDocument.documentElement.clientHeight,
|
|
72
|
+
x: 0,
|
|
73
|
+
y: 0,
|
|
74
|
+
zoom: 1
|
|
75
|
+
};
|
|
76
|
+
const overlapRect = overlappedRect(rect, viewportRect);
|
|
77
|
+
if (!overlapRect) return false;
|
|
78
|
+
const visibleArea = overlapRect.width * overlapRect.height;
|
|
79
|
+
const totalArea = elementHeight * elementWidth;
|
|
80
|
+
return visibleArea / totalArea >= visibleAreaRatio;
|
|
81
|
+
}
|
|
82
|
+
function getPseudoElementContent(element, currentWindow) {
|
|
83
|
+
if (!(element instanceof currentWindow.HTMLElement)) return {
|
|
84
|
+
before: '',
|
|
85
|
+
after: ''
|
|
86
|
+
};
|
|
87
|
+
const beforeContent = currentWindow.getComputedStyle(element, '::before').getPropertyValue('content');
|
|
88
|
+
const afterContent = currentWindow.getComputedStyle(element, '::after').getPropertyValue('content');
|
|
89
|
+
return {
|
|
90
|
+
before: 'none' === beforeContent ? '' : beforeContent.replace(/"/g, ''),
|
|
91
|
+
after: 'none' === afterContent ? '' : afterContent.replace(/"/g, '')
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
function hasOverflowY(element, currentWindow) {
|
|
95
|
+
const style = currentWindow.getComputedStyle(element);
|
|
96
|
+
return 'scroll' === style.overflowY || 'auto' === style.overflowY || 'hidden' === style.overflowY;
|
|
97
|
+
}
|
|
98
|
+
function overlappedRect(rect1, rect2) {
|
|
99
|
+
const left = Math.max(rect1.left, rect2.left);
|
|
100
|
+
const top = Math.max(rect1.top, rect2.top);
|
|
101
|
+
const right = Math.min(rect1.right, rect2.right);
|
|
102
|
+
const bottom = Math.min(rect1.bottom, rect2.bottom);
|
|
103
|
+
if (left < right && top < bottom) return {
|
|
104
|
+
left,
|
|
105
|
+
top,
|
|
106
|
+
right,
|
|
107
|
+
bottom,
|
|
108
|
+
width: right - left,
|
|
109
|
+
height: bottom - top,
|
|
110
|
+
x: left,
|
|
111
|
+
y: top,
|
|
112
|
+
zoom: 1
|
|
113
|
+
};
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
function getRect(el, baseZoom, currentWindow) {
|
|
117
|
+
let originalRect;
|
|
118
|
+
let newZoom = 1;
|
|
119
|
+
if (el instanceof currentWindow.HTMLElement) {
|
|
120
|
+
originalRect = el.getBoundingClientRect();
|
|
121
|
+
if (!('currentCSSZoom' in el)) newZoom = Number.parseFloat(currentWindow.getComputedStyle(el).zoom) || 1;
|
|
122
|
+
} else {
|
|
123
|
+
const range = currentWindow.document.createRange();
|
|
124
|
+
range.selectNodeContents(el);
|
|
125
|
+
originalRect = range.getBoundingClientRect();
|
|
126
|
+
}
|
|
127
|
+
const zoom = newZoom * baseZoom;
|
|
128
|
+
return {
|
|
129
|
+
width: originalRect.width * zoom,
|
|
130
|
+
height: originalRect.height * zoom,
|
|
131
|
+
left: originalRect.left * zoom,
|
|
132
|
+
top: originalRect.top * zoom,
|
|
133
|
+
right: originalRect.right * zoom,
|
|
134
|
+
bottom: originalRect.bottom * zoom,
|
|
135
|
+
x: originalRect.x * zoom,
|
|
136
|
+
y: originalRect.y * zoom,
|
|
137
|
+
zoom
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
const isElementCovered = (el, rect, currentWindow)=>{
|
|
141
|
+
const x = rect.left + rect.width / 2;
|
|
142
|
+
const y = rect.top + rect.height / 2;
|
|
143
|
+
const topElement = currentWindow.document.elementFromPoint(x, y);
|
|
144
|
+
if (!topElement) return false;
|
|
145
|
+
if (topElement === el) return false;
|
|
146
|
+
if (null == el ? void 0 : el.contains(topElement)) return false;
|
|
147
|
+
if (null == topElement ? void 0 : topElement.contains(el)) return false;
|
|
148
|
+
const rectOfTopElement = getRect(topElement, 1, currentWindow);
|
|
149
|
+
const overlapRect = overlappedRect(rect, rectOfTopElement);
|
|
150
|
+
if (!overlapRect) return false;
|
|
151
|
+
logger(el, 'Element is covered by another element', {
|
|
152
|
+
topElement,
|
|
153
|
+
el,
|
|
154
|
+
rect,
|
|
155
|
+
x,
|
|
156
|
+
y
|
|
157
|
+
});
|
|
158
|
+
return true;
|
|
159
|
+
};
|
|
160
|
+
function elementRect(el, currentWindow, currentDocument, baseZoom = 1) {
|
|
161
|
+
if (!el) {
|
|
162
|
+
logger(el, 'Element is not in the DOM hierarchy');
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
if (!(el instanceof currentWindow.HTMLElement) && el.nodeType !== Node.TEXT_NODE && 'svg' !== el.nodeName.toLowerCase()) {
|
|
166
|
+
logger(el, 'Element is not in the DOM hierarchy');
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
if (el instanceof currentWindow.HTMLElement) {
|
|
170
|
+
const style = currentWindow.getComputedStyle(el);
|
|
171
|
+
if ('none' === style.display || 'hidden' === style.visibility || '0' === style.opacity && 'INPUT' !== el.tagName) {
|
|
172
|
+
logger(el, 'Element is hidden');
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
const rect = getRect(el, baseZoom, currentWindow);
|
|
177
|
+
if (0 === rect.width && 0 === rect.height) {
|
|
178
|
+
logger(el, 'Element has no size');
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
if (1 === baseZoom && isElementCovered(el, rect, currentWindow)) return false;
|
|
182
|
+
const isVisible = isElementPartiallyInViewport(rect, currentWindow, currentDocument);
|
|
183
|
+
let parent = el;
|
|
184
|
+
const parentUntilNonStatic = (currentNode)=>{
|
|
185
|
+
let parent = null == currentNode ? void 0 : currentNode.parentElement;
|
|
186
|
+
while(parent){
|
|
187
|
+
const style = currentWindow.getComputedStyle(parent);
|
|
188
|
+
if ('static' !== style.position) return parent;
|
|
189
|
+
parent = parent.parentElement;
|
|
190
|
+
}
|
|
191
|
+
return null;
|
|
192
|
+
};
|
|
193
|
+
while(parent && parent !== currentDocument.body){
|
|
194
|
+
if (!(parent instanceof currentWindow.HTMLElement)) {
|
|
195
|
+
parent = parent.parentElement;
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
const parentStyle = currentWindow.getComputedStyle(parent);
|
|
199
|
+
if ('hidden' === parentStyle.overflow) {
|
|
200
|
+
const parentRect = getRect(parent, 1, currentWindow);
|
|
201
|
+
const tolerance = 10;
|
|
202
|
+
if (rect.right < parentRect.left - tolerance || rect.left > parentRect.right + tolerance || rect.bottom < parentRect.top - tolerance || rect.top > parentRect.bottom + tolerance) {
|
|
203
|
+
logger(el, 'element is partially or totally hidden by an ancestor', {
|
|
204
|
+
rect,
|
|
205
|
+
parentRect
|
|
206
|
+
});
|
|
207
|
+
return false;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
if ('fixed' === parentStyle.position || 'sticky' === parentStyle.position) break;
|
|
211
|
+
parent = 'absolute' === parentStyle.position ? parentUntilNonStatic(parent) : parent.parentElement;
|
|
212
|
+
}
|
|
213
|
+
return {
|
|
214
|
+
left: Math.round(rect.left),
|
|
215
|
+
top: Math.round(rect.top),
|
|
216
|
+
width: Math.round(rect.width),
|
|
217
|
+
height: Math.round(rect.height),
|
|
218
|
+
zoom: rect.zoom,
|
|
219
|
+
isVisible
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
function validTextNodeContent(node) {
|
|
223
|
+
if (!node) return false;
|
|
224
|
+
if (node.nodeType !== Node.ELEMENT_NODE && node.nodeType !== Node.TEXT_NODE && '#text' !== node.nodeName) return false;
|
|
225
|
+
const content = node.textContent || node.innerText;
|
|
226
|
+
if (content && !/^\s*$/.test(content)) return content.trim();
|
|
227
|
+
return false;
|
|
228
|
+
}
|
|
229
|
+
function getNodeAttributes(node, currentWindow) {
|
|
230
|
+
if (!node || !(node instanceof currentWindow.HTMLElement) || !node.attributes) return {};
|
|
231
|
+
const attributesList = Array.from(node.attributes).map((attr)=>{
|
|
232
|
+
if ('class' === attr.name) return [
|
|
233
|
+
attr.name,
|
|
234
|
+
`.${attr.value.split(' ').join('.')}`
|
|
235
|
+
];
|
|
236
|
+
if (!attr.value) return [];
|
|
237
|
+
let value = attr.value;
|
|
238
|
+
if (value.startsWith('data:image')) value = 'image';
|
|
239
|
+
if (value.length > MAX_VALUE_LENGTH) value = `${value.slice(0, MAX_VALUE_LENGTH)}...`;
|
|
240
|
+
return [
|
|
241
|
+
attr.name,
|
|
242
|
+
value
|
|
243
|
+
];
|
|
244
|
+
});
|
|
245
|
+
return Object.fromEntries(attributesList);
|
|
246
|
+
}
|
|
247
|
+
function midsceneGenerateHash(node, content, rect) {
|
|
248
|
+
const slicedHash = (0, external_utils_js_namespaceObject.generateHashId)(rect, content);
|
|
249
|
+
if (node) {
|
|
250
|
+
if (!window.midsceneNodeHashCacheList) setNodeHashCacheListOnWindow();
|
|
251
|
+
setNodeToCacheList(node, slicedHash);
|
|
252
|
+
}
|
|
253
|
+
return slicedHash;
|
|
254
|
+
}
|
|
255
|
+
function setNodeHashCacheListOnWindow() {
|
|
256
|
+
if ('undefined' != typeof window) window.midsceneNodeHashCacheList = [];
|
|
257
|
+
}
|
|
258
|
+
function setNodeToCacheList(node, id) {
|
|
259
|
+
if ('undefined' != typeof window) {
|
|
260
|
+
var _window_midsceneNodeHashCacheList;
|
|
261
|
+
if (getNodeFromCacheList(id)) return;
|
|
262
|
+
null == (_window_midsceneNodeHashCacheList = window.midsceneNodeHashCacheList) || _window_midsceneNodeHashCacheList.push({
|
|
263
|
+
node,
|
|
264
|
+
id
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
function getNodeFromCacheList(id) {
|
|
269
|
+
if ('undefined' != typeof window) {
|
|
270
|
+
var _window_midsceneNodeHashCacheList_find, _window_midsceneNodeHashCacheList;
|
|
271
|
+
return null == (_window_midsceneNodeHashCacheList = window.midsceneNodeHashCacheList) ? void 0 : null == (_window_midsceneNodeHashCacheList_find = _window_midsceneNodeHashCacheList.find((item)=>item.id === id)) ? void 0 : _window_midsceneNodeHashCacheList_find.node;
|
|
272
|
+
}
|
|
273
|
+
return null;
|
|
274
|
+
}
|
|
275
|
+
function generateId(numberId) {
|
|
276
|
+
return `${numberId}`;
|
|
277
|
+
}
|
|
278
|
+
function setGenerateHashOnWindow() {
|
|
279
|
+
if ('undefined' != typeof window) window.midsceneGenerateHash = midsceneGenerateHash;
|
|
280
|
+
}
|
|
281
|
+
function setMidsceneVisibleRectOnWindow() {
|
|
282
|
+
if ('undefined' != typeof window) window.midsceneVisibleRect = elementRect;
|
|
283
|
+
}
|
|
284
|
+
function setExtractTextWithPositionOnWindow() {
|
|
285
|
+
if ('undefined' != typeof window) window.extractTextWithPosition = external_web_extractor_js_namespaceObject.extractTextWithPosition;
|
|
286
|
+
}
|
|
287
|
+
function getTopDocument() {
|
|
288
|
+
const container = document.body || document;
|
|
289
|
+
return container;
|
|
290
|
+
}
|
|
291
|
+
exports.elementRect = __webpack_exports__.elementRect;
|
|
292
|
+
exports.generateId = __webpack_exports__.generateId;
|
|
293
|
+
exports.getDebugMode = __webpack_exports__.getDebugMode;
|
|
294
|
+
exports.getNodeAttributes = __webpack_exports__.getNodeAttributes;
|
|
295
|
+
exports.getNodeFromCacheList = __webpack_exports__.getNodeFromCacheList;
|
|
296
|
+
exports.getPseudoElementContent = __webpack_exports__.getPseudoElementContent;
|
|
297
|
+
exports.getRect = __webpack_exports__.getRect;
|
|
298
|
+
exports.getTopDocument = __webpack_exports__.getTopDocument;
|
|
299
|
+
exports.hasOverflowY = __webpack_exports__.hasOverflowY;
|
|
300
|
+
exports.isElementPartiallyInViewport = __webpack_exports__.isElementPartiallyInViewport;
|
|
301
|
+
exports.logger = __webpack_exports__.logger;
|
|
302
|
+
exports.midsceneGenerateHash = __webpack_exports__.midsceneGenerateHash;
|
|
303
|
+
exports.overlappedRect = __webpack_exports__.overlappedRect;
|
|
304
|
+
exports.setDebugMode = __webpack_exports__.setDebugMode;
|
|
305
|
+
exports.setExtractTextWithPositionOnWindow = __webpack_exports__.setExtractTextWithPositionOnWindow;
|
|
306
|
+
exports.setGenerateHashOnWindow = __webpack_exports__.setGenerateHashOnWindow;
|
|
307
|
+
exports.setMidsceneVisibleRectOnWindow = __webpack_exports__.setMidsceneVisibleRectOnWindow;
|
|
308
|
+
exports.setNodeHashCacheListOnWindow = __webpack_exports__.setNodeHashCacheListOnWindow;
|
|
309
|
+
exports.setNodeToCacheList = __webpack_exports__.setNodeToCacheList;
|
|
310
|
+
exports.validTextNodeContent = __webpack_exports__.validTextNodeContent;
|
|
311
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
312
|
+
"elementRect",
|
|
313
|
+
"generateId",
|
|
314
|
+
"getDebugMode",
|
|
315
|
+
"getNodeAttributes",
|
|
316
|
+
"getNodeFromCacheList",
|
|
317
|
+
"getPseudoElementContent",
|
|
318
|
+
"getRect",
|
|
319
|
+
"getTopDocument",
|
|
320
|
+
"hasOverflowY",
|
|
321
|
+
"isElementPartiallyInViewport",
|
|
322
|
+
"logger",
|
|
323
|
+
"midsceneGenerateHash",
|
|
324
|
+
"overlappedRect",
|
|
325
|
+
"setDebugMode",
|
|
326
|
+
"setExtractTextWithPositionOnWindow",
|
|
327
|
+
"setGenerateHashOnWindow",
|
|
328
|
+
"setMidsceneVisibleRectOnWindow",
|
|
329
|
+
"setNodeHashCacheListOnWindow",
|
|
330
|
+
"setNodeToCacheList",
|
|
331
|
+
"validTextNodeContent"
|
|
332
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
333
|
+
Object.defineProperty(exports, '__esModule', {
|
|
334
|
+
value: true
|
|
335
|
+
});
|
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
collectElementInfo: ()=>collectElementInfo,
|
|
28
|
+
extractTreeNodeAsString: ()=>extractTreeNodeAsString,
|
|
29
|
+
extractTreeNode: ()=>extractTreeNode,
|
|
30
|
+
mergeElementAndChildrenRects: ()=>mergeElementAndChildrenRects,
|
|
31
|
+
extractTextWithPosition: ()=>extractTextWithPosition
|
|
32
|
+
});
|
|
33
|
+
const index_js_namespaceObject = require("../constants/index.js");
|
|
34
|
+
const external_dom_util_js_namespaceObject = require("./dom-util.js");
|
|
35
|
+
const external_tree_js_namespaceObject = require("./tree.js");
|
|
36
|
+
const external_util_js_namespaceObject = require("./util.js");
|
|
37
|
+
let indexId = 0;
|
|
38
|
+
function tagNameOfNode(node) {
|
|
39
|
+
let tagName = '';
|
|
40
|
+
if (node instanceof HTMLElement) {
|
|
41
|
+
var _node_tagName;
|
|
42
|
+
tagName = null == (_node_tagName = node.tagName) ? void 0 : _node_tagName.toLowerCase();
|
|
43
|
+
} else {
|
|
44
|
+
const parentElement = node.parentElement;
|
|
45
|
+
if (parentElement && parentElement instanceof HTMLElement) {
|
|
46
|
+
var _parentElement_tagName;
|
|
47
|
+
tagName = null == (_parentElement_tagName = parentElement.tagName) ? void 0 : _parentElement_tagName.toLowerCase();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return tagName ? `<${tagName}>` : '';
|
|
51
|
+
}
|
|
52
|
+
function collectElementInfo(node, currentWindow, currentDocument, baseZoom = 1, basePoint = {
|
|
53
|
+
left: 0,
|
|
54
|
+
top: 0
|
|
55
|
+
}, isContainer = false) {
|
|
56
|
+
const rect = (0, external_util_js_namespaceObject.elementRect)(node, currentWindow, currentDocument, baseZoom);
|
|
57
|
+
if (!rect) return null;
|
|
58
|
+
if (rect.width < index_js_namespaceObject.CONTAINER_MINI_WIDTH || rect.height < index_js_namespaceObject.CONTAINER_MINI_HEIGHT) return null;
|
|
59
|
+
if (0 !== basePoint.left || 0 !== basePoint.top) {
|
|
60
|
+
rect.left += basePoint.left;
|
|
61
|
+
rect.top += basePoint.top;
|
|
62
|
+
}
|
|
63
|
+
if (rect.height >= window.innerHeight && rect.width >= window.innerWidth) return null;
|
|
64
|
+
if ((0, external_dom_util_js_namespaceObject.isFormElement)(node)) {
|
|
65
|
+
const attributes = (0, external_util_js_namespaceObject.getNodeAttributes)(node, currentWindow);
|
|
66
|
+
let valueContent = attributes.value || attributes.placeholder || node.textContent || '';
|
|
67
|
+
const nodeHashId = (0, external_util_js_namespaceObject.midsceneGenerateHash)(node, valueContent, rect);
|
|
68
|
+
const tagName = node.tagName.toLowerCase();
|
|
69
|
+
if ('select' === node.tagName.toLowerCase()) {
|
|
70
|
+
const selectedOption = node.options[node.selectedIndex];
|
|
71
|
+
valueContent = (null == selectedOption ? void 0 : selectedOption.textContent) || '';
|
|
72
|
+
}
|
|
73
|
+
if (('input' === node.tagName.toLowerCase() || 'textarea' === node.tagName.toLowerCase()) && node.value) valueContent = node.value;
|
|
74
|
+
const elementInfo = {
|
|
75
|
+
id: nodeHashId,
|
|
76
|
+
nodeHashId,
|
|
77
|
+
nodeType: index_js_namespaceObject.NodeType.FORM_ITEM,
|
|
78
|
+
indexId: indexId++,
|
|
79
|
+
attributes: {
|
|
80
|
+
...attributes,
|
|
81
|
+
htmlTagName: `<${tagName}>`,
|
|
82
|
+
nodeType: index_js_namespaceObject.NodeType.FORM_ITEM
|
|
83
|
+
},
|
|
84
|
+
content: valueContent.trim(),
|
|
85
|
+
rect,
|
|
86
|
+
center: [
|
|
87
|
+
Math.round(rect.left + rect.width / 2),
|
|
88
|
+
Math.round(rect.top + rect.height / 2)
|
|
89
|
+
],
|
|
90
|
+
zoom: rect.zoom,
|
|
91
|
+
isVisible: rect.isVisible
|
|
92
|
+
};
|
|
93
|
+
return elementInfo;
|
|
94
|
+
}
|
|
95
|
+
if ((0, external_dom_util_js_namespaceObject.isButtonElement)(node)) {
|
|
96
|
+
const rect = mergeElementAndChildrenRects(node, currentWindow, currentDocument, baseZoom);
|
|
97
|
+
if (!rect) return null;
|
|
98
|
+
const attributes = (0, external_util_js_namespaceObject.getNodeAttributes)(node, currentWindow);
|
|
99
|
+
const pseudo = (0, external_util_js_namespaceObject.getPseudoElementContent)(node, currentWindow);
|
|
100
|
+
const content = node.innerText || pseudo.before || pseudo.after || '';
|
|
101
|
+
const nodeHashId = (0, external_util_js_namespaceObject.midsceneGenerateHash)(node, content, rect);
|
|
102
|
+
const elementInfo = {
|
|
103
|
+
id: nodeHashId,
|
|
104
|
+
indexId: indexId++,
|
|
105
|
+
nodeHashId,
|
|
106
|
+
nodeType: index_js_namespaceObject.NodeType.BUTTON,
|
|
107
|
+
attributes: {
|
|
108
|
+
...attributes,
|
|
109
|
+
htmlTagName: tagNameOfNode(node),
|
|
110
|
+
nodeType: index_js_namespaceObject.NodeType.BUTTON
|
|
111
|
+
},
|
|
112
|
+
content,
|
|
113
|
+
rect,
|
|
114
|
+
center: [
|
|
115
|
+
Math.round(rect.left + rect.width / 2),
|
|
116
|
+
Math.round(rect.top + rect.height / 2)
|
|
117
|
+
],
|
|
118
|
+
zoom: rect.zoom,
|
|
119
|
+
isVisible: rect.isVisible
|
|
120
|
+
};
|
|
121
|
+
return elementInfo;
|
|
122
|
+
}
|
|
123
|
+
if ((0, external_dom_util_js_namespaceObject.isImgElement)(node)) {
|
|
124
|
+
var _node_nodeName;
|
|
125
|
+
const attributes = (0, external_util_js_namespaceObject.getNodeAttributes)(node, currentWindow);
|
|
126
|
+
const nodeHashId = (0, external_util_js_namespaceObject.midsceneGenerateHash)(node, '', rect);
|
|
127
|
+
const elementInfo = {
|
|
128
|
+
id: nodeHashId,
|
|
129
|
+
indexId: indexId++,
|
|
130
|
+
nodeHashId,
|
|
131
|
+
attributes: {
|
|
132
|
+
...attributes,
|
|
133
|
+
...(null == (_node_nodeName = node.nodeName) ? void 0 : _node_nodeName.toLowerCase()) === 'svg' ? {
|
|
134
|
+
svgContent: 'true'
|
|
135
|
+
} : {},
|
|
136
|
+
nodeType: index_js_namespaceObject.NodeType.IMG,
|
|
137
|
+
htmlTagName: tagNameOfNode(node)
|
|
138
|
+
},
|
|
139
|
+
nodeType: index_js_namespaceObject.NodeType.IMG,
|
|
140
|
+
content: '',
|
|
141
|
+
rect,
|
|
142
|
+
center: [
|
|
143
|
+
Math.round(rect.left + rect.width / 2),
|
|
144
|
+
Math.round(rect.top + rect.height / 2)
|
|
145
|
+
],
|
|
146
|
+
zoom: rect.zoom,
|
|
147
|
+
isVisible: rect.isVisible
|
|
148
|
+
};
|
|
149
|
+
return elementInfo;
|
|
150
|
+
}
|
|
151
|
+
if ((0, external_dom_util_js_namespaceObject.isTextElement)(node)) {
|
|
152
|
+
var _node_textContent;
|
|
153
|
+
const text = null == (_node_textContent = node.textContent) ? void 0 : _node_textContent.trim().replace(/\n+/g, ' ');
|
|
154
|
+
if (!text) return null;
|
|
155
|
+
const attributes = (0, external_util_js_namespaceObject.getNodeAttributes)(node, currentWindow);
|
|
156
|
+
const attributeKeys = Object.keys(attributes);
|
|
157
|
+
if (!text.trim() && 0 === attributeKeys.length) return null;
|
|
158
|
+
const nodeHashId = (0, external_util_js_namespaceObject.midsceneGenerateHash)(node, text, rect);
|
|
159
|
+
const elementInfo = {
|
|
160
|
+
id: nodeHashId,
|
|
161
|
+
indexId: indexId++,
|
|
162
|
+
nodeHashId,
|
|
163
|
+
nodeType: index_js_namespaceObject.NodeType.TEXT,
|
|
164
|
+
attributes: {
|
|
165
|
+
...attributes,
|
|
166
|
+
nodeType: index_js_namespaceObject.NodeType.TEXT,
|
|
167
|
+
htmlTagName: tagNameOfNode(node)
|
|
168
|
+
},
|
|
169
|
+
center: [
|
|
170
|
+
Math.round(rect.left + rect.width / 2),
|
|
171
|
+
Math.round(rect.top + rect.height / 2)
|
|
172
|
+
],
|
|
173
|
+
content: text,
|
|
174
|
+
rect,
|
|
175
|
+
zoom: rect.zoom,
|
|
176
|
+
isVisible: rect.isVisible
|
|
177
|
+
};
|
|
178
|
+
return elementInfo;
|
|
179
|
+
}
|
|
180
|
+
if ((0, external_dom_util_js_namespaceObject.isAElement)(node)) {
|
|
181
|
+
const attributes = (0, external_util_js_namespaceObject.getNodeAttributes)(node, currentWindow);
|
|
182
|
+
const pseudo = (0, external_util_js_namespaceObject.getPseudoElementContent)(node, currentWindow);
|
|
183
|
+
const content = node.innerText || pseudo.before || pseudo.after || '';
|
|
184
|
+
const nodeHashId = (0, external_util_js_namespaceObject.midsceneGenerateHash)(node, content, rect);
|
|
185
|
+
const elementInfo = {
|
|
186
|
+
id: nodeHashId,
|
|
187
|
+
indexId: indexId++,
|
|
188
|
+
nodeHashId,
|
|
189
|
+
nodeType: index_js_namespaceObject.NodeType.A,
|
|
190
|
+
attributes: {
|
|
191
|
+
...attributes,
|
|
192
|
+
htmlTagName: tagNameOfNode(node),
|
|
193
|
+
nodeType: index_js_namespaceObject.NodeType.A
|
|
194
|
+
},
|
|
195
|
+
content,
|
|
196
|
+
rect,
|
|
197
|
+
center: [
|
|
198
|
+
Math.round(rect.left + rect.width / 2),
|
|
199
|
+
Math.round(rect.top + rect.height / 2)
|
|
200
|
+
],
|
|
201
|
+
zoom: rect.zoom,
|
|
202
|
+
isVisible: rect.isVisible
|
|
203
|
+
};
|
|
204
|
+
return elementInfo;
|
|
205
|
+
}
|
|
206
|
+
if ((0, external_dom_util_js_namespaceObject.isContainerElement)(node) || isContainer) {
|
|
207
|
+
const attributes = (0, external_util_js_namespaceObject.getNodeAttributes)(node, currentWindow);
|
|
208
|
+
const nodeHashId = (0, external_util_js_namespaceObject.midsceneGenerateHash)(node, '', rect);
|
|
209
|
+
const elementInfo = {
|
|
210
|
+
id: nodeHashId,
|
|
211
|
+
nodeHashId,
|
|
212
|
+
indexId: indexId++,
|
|
213
|
+
nodeType: index_js_namespaceObject.NodeType.CONTAINER,
|
|
214
|
+
attributes: {
|
|
215
|
+
...attributes,
|
|
216
|
+
nodeType: index_js_namespaceObject.NodeType.CONTAINER,
|
|
217
|
+
htmlTagName: tagNameOfNode(node)
|
|
218
|
+
},
|
|
219
|
+
content: '',
|
|
220
|
+
rect,
|
|
221
|
+
center: [
|
|
222
|
+
Math.round(rect.left + rect.width / 2),
|
|
223
|
+
Math.round(rect.top + rect.height / 2)
|
|
224
|
+
],
|
|
225
|
+
zoom: rect.zoom,
|
|
226
|
+
isVisible: rect.isVisible
|
|
227
|
+
};
|
|
228
|
+
return elementInfo;
|
|
229
|
+
}
|
|
230
|
+
return null;
|
|
231
|
+
}
|
|
232
|
+
function extractTextWithPosition(initNode, debugMode = false) {
|
|
233
|
+
const elementNode = extractTreeNode(initNode, debugMode);
|
|
234
|
+
const elementInfoArray = [];
|
|
235
|
+
function dfsTopChildren(node) {
|
|
236
|
+
if (node.node) elementInfoArray.push(node.node);
|
|
237
|
+
for(let i = 0; i < node.children.length; i++)dfsTopChildren(node.children[i]);
|
|
238
|
+
}
|
|
239
|
+
dfsTopChildren({
|
|
240
|
+
children: elementNode.children,
|
|
241
|
+
node: elementNode.node
|
|
242
|
+
});
|
|
243
|
+
return elementInfoArray;
|
|
244
|
+
}
|
|
245
|
+
function extractTreeNodeAsString(initNode, visibleOnly = false, debugMode = false) {
|
|
246
|
+
const elementNode = extractTreeNode(initNode, debugMode);
|
|
247
|
+
return (0, external_tree_js_namespaceObject.descriptionOfTree)(elementNode, void 0, false, visibleOnly);
|
|
248
|
+
}
|
|
249
|
+
function extractTreeNode(initNode, debugMode = false) {
|
|
250
|
+
(0, external_util_js_namespaceObject.setDebugMode)(debugMode);
|
|
251
|
+
indexId = 0;
|
|
252
|
+
const topDocument = (0, external_util_js_namespaceObject.getTopDocument)();
|
|
253
|
+
const startNode = initNode || topDocument;
|
|
254
|
+
const topChildren = [];
|
|
255
|
+
function dfs(node, currentWindow, currentDocument, baseZoom = 1, basePoint = {
|
|
256
|
+
left: 0,
|
|
257
|
+
top: 0
|
|
258
|
+
}) {
|
|
259
|
+
if (!node) return null;
|
|
260
|
+
if (node.nodeType && 10 === node.nodeType) return null;
|
|
261
|
+
const elementInfo = collectElementInfo(node, currentWindow, currentDocument, baseZoom, basePoint);
|
|
262
|
+
if (node instanceof currentWindow.HTMLIFrameElement) {
|
|
263
|
+
if (node.contentWindow && node.contentWindow) return null;
|
|
264
|
+
}
|
|
265
|
+
const nodeInfo = {
|
|
266
|
+
node: elementInfo,
|
|
267
|
+
children: []
|
|
268
|
+
};
|
|
269
|
+
if ((null == elementInfo ? void 0 : elementInfo.nodeType) === index_js_namespaceObject.NodeType.BUTTON || (null == elementInfo ? void 0 : elementInfo.nodeType) === index_js_namespaceObject.NodeType.IMG || (null == elementInfo ? void 0 : elementInfo.nodeType) === index_js_namespaceObject.NodeType.TEXT || (null == elementInfo ? void 0 : elementInfo.nodeType) === index_js_namespaceObject.NodeType.FORM_ITEM || (null == elementInfo ? void 0 : elementInfo.nodeType) === index_js_namespaceObject.NodeType.CONTAINER) return nodeInfo;
|
|
270
|
+
const rect = (0, external_util_js_namespaceObject.getRect)(node, baseZoom, currentWindow);
|
|
271
|
+
for(let i = 0; i < node.childNodes.length; i++){
|
|
272
|
+
(0, external_util_js_namespaceObject.logger)('will dfs', node.childNodes[i]);
|
|
273
|
+
const childNodeInfo = dfs(node.childNodes[i], currentWindow, currentDocument, rect.zoom, basePoint);
|
|
274
|
+
if (Array.isArray(childNodeInfo)) nodeInfo.children.push(...childNodeInfo);
|
|
275
|
+
else if (childNodeInfo) nodeInfo.children.push(childNodeInfo);
|
|
276
|
+
}
|
|
277
|
+
if (null === nodeInfo.node) {
|
|
278
|
+
if (0 === nodeInfo.children.length) return null;
|
|
279
|
+
return nodeInfo.children;
|
|
280
|
+
}
|
|
281
|
+
return nodeInfo;
|
|
282
|
+
}
|
|
283
|
+
const rootNodeInfo = dfs(startNode, window, document, 1, {
|
|
284
|
+
left: 0,
|
|
285
|
+
top: 0
|
|
286
|
+
});
|
|
287
|
+
if (Array.isArray(rootNodeInfo)) topChildren.push(...rootNodeInfo);
|
|
288
|
+
else if (rootNodeInfo) topChildren.push(rootNodeInfo);
|
|
289
|
+
if (startNode === topDocument) {
|
|
290
|
+
const iframes = document.querySelectorAll('iframe');
|
|
291
|
+
for(let i = 0; i < iframes.length; i++){
|
|
292
|
+
const iframe = iframes[i];
|
|
293
|
+
if (iframe.contentDocument && iframe.contentWindow) {
|
|
294
|
+
const iframeInfo = collectElementInfo(iframe, window, document, 1);
|
|
295
|
+
if (iframeInfo) {
|
|
296
|
+
const iframeChildren = dfs(iframe.contentDocument.body, iframe.contentWindow, iframe.contentDocument, 1, {
|
|
297
|
+
left: iframeInfo.rect.left,
|
|
298
|
+
top: iframeInfo.rect.top
|
|
299
|
+
});
|
|
300
|
+
if (Array.isArray(iframeChildren)) topChildren.push(...iframeChildren);
|
|
301
|
+
else if (iframeChildren) topChildren.push(iframeChildren);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
return {
|
|
307
|
+
node: null,
|
|
308
|
+
children: topChildren
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
function mergeElementAndChildrenRects(node, currentWindow, currentDocument, baseZoom = 1) {
|
|
312
|
+
const selfRect = (0, external_util_js_namespaceObject.elementRect)(node, currentWindow, currentDocument, baseZoom);
|
|
313
|
+
if (!selfRect) return null;
|
|
314
|
+
let minLeft = selfRect.left;
|
|
315
|
+
let minTop = selfRect.top;
|
|
316
|
+
let maxRight = selfRect.left + selfRect.width;
|
|
317
|
+
let maxBottom = selfRect.top + selfRect.height;
|
|
318
|
+
function traverse(child) {
|
|
319
|
+
for(let i = 0; i < child.childNodes.length; i++){
|
|
320
|
+
const sub = child.childNodes[i];
|
|
321
|
+
if (1 === sub.nodeType) {
|
|
322
|
+
const rect = (0, external_util_js_namespaceObject.elementRect)(sub, currentWindow, currentDocument, baseZoom);
|
|
323
|
+
if (rect) {
|
|
324
|
+
minLeft = Math.min(minLeft, rect.left);
|
|
325
|
+
minTop = Math.min(minTop, rect.top);
|
|
326
|
+
maxRight = Math.max(maxRight, rect.left + rect.width);
|
|
327
|
+
maxBottom = Math.max(maxBottom, rect.top + rect.height);
|
|
328
|
+
}
|
|
329
|
+
traverse(sub);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
traverse(node);
|
|
334
|
+
return {
|
|
335
|
+
...selfRect,
|
|
336
|
+
left: minLeft,
|
|
337
|
+
top: minTop,
|
|
338
|
+
width: maxRight - minLeft,
|
|
339
|
+
height: maxBottom - minTop
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
exports.collectElementInfo = __webpack_exports__.collectElementInfo;
|
|
343
|
+
exports.extractTextWithPosition = __webpack_exports__.extractTextWithPosition;
|
|
344
|
+
exports.extractTreeNode = __webpack_exports__.extractTreeNode;
|
|
345
|
+
exports.extractTreeNodeAsString = __webpack_exports__.extractTreeNodeAsString;
|
|
346
|
+
exports.mergeElementAndChildrenRects = __webpack_exports__.mergeElementAndChildrenRects;
|
|
347
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
348
|
+
"collectElementInfo",
|
|
349
|
+
"extractTextWithPosition",
|
|
350
|
+
"extractTreeNode",
|
|
351
|
+
"extractTreeNodeAsString",
|
|
352
|
+
"mergeElementAndChildrenRects"
|
|
353
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
354
|
+
Object.defineProperty(exports, '__esModule', {
|
|
355
|
+
value: true
|
|
356
|
+
});
|