@midscene/shared 0.17.4-beta-20250528162713.0 → 0.17.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es/extractor-debug.js +33 -54
- package/dist/es/extractor.d.ts +1 -1
- package/dist/es/extractor.js +51 -73
- package/dist/es/img.d.ts +1 -1
- package/dist/es/{index-113807ee.d.ts → index-a171e36c.d.ts} +11 -3
- package/dist/es/types.d.ts +1 -1
- package/dist/lib/extractor-debug.js +33 -54
- package/dist/lib/extractor.d.ts +1 -1
- package/dist/lib/extractor.js +53 -73
- package/dist/lib/img.d.ts +1 -1
- package/dist/lib/{index-113807ee.d.ts → index-a171e36c.d.ts} +11 -3
- package/dist/lib/types.d.ts +1 -1
- package/dist/script/htmlElement.js +51 -73
- package/dist/script/htmlElementDebug.js +33 -54
- package/dist/types/extractor.d.ts +1 -1
- package/dist/types/img.d.ts +1 -1
- package/dist/types/{index-113807ee.d.ts → index-a171e36c.d.ts} +11 -3
- package/dist/types/types.d.ts +1 -1
- package/package.json +2 -3
- package/src/extractor/index.ts +8 -1
- package/src/extractor/locator.ts +4 -11
- package/src/extractor/tree.ts +10 -4
- package/src/extractor/util.ts +14 -25
- package/src/extractor/web-extractor.ts +20 -35
- package/src/types/index.ts +4 -0
|
@@ -255,7 +255,7 @@ var isElementCovered = (el, rect, currentWindow) => {
|
|
|
255
255
|
});
|
|
256
256
|
return true;
|
|
257
257
|
};
|
|
258
|
-
function elementRect(el, currentWindow, currentDocument, baseZoom = 1
|
|
258
|
+
function elementRect(el, currentWindow, currentDocument, baseZoom = 1) {
|
|
259
259
|
if (!el) {
|
|
260
260
|
logger(el, "Element is not in the DOM hierarchy");
|
|
261
261
|
return false;
|
|
@@ -279,21 +279,11 @@ function elementRect(el, currentWindow, currentDocument, baseZoom = 1, visibleOn
|
|
|
279
279
|
if (baseZoom === 1 && isElementCovered(el, rect, currentWindow)) {
|
|
280
280
|
return false;
|
|
281
281
|
}
|
|
282
|
-
const
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
if (!isPartiallyInViewport) {
|
|
288
|
-
logger(el, "Element is completely outside the viewport", {
|
|
289
|
-
rect,
|
|
290
|
-
viewportHeight,
|
|
291
|
-
viewportWidth,
|
|
292
|
-
scrollTop,
|
|
293
|
-
scrollLeft
|
|
294
|
-
});
|
|
295
|
-
return false;
|
|
296
|
-
}
|
|
282
|
+
const isVisible = isElementPartiallyInViewport(
|
|
283
|
+
rect,
|
|
284
|
+
currentWindow,
|
|
285
|
+
currentDocument
|
|
286
|
+
);
|
|
297
287
|
let parent = el;
|
|
298
288
|
const parentUntilNonStatic = (currentNode) => {
|
|
299
289
|
let parent2 = currentNode?.parentElement;
|
|
@@ -337,7 +327,8 @@ function elementRect(el, currentWindow, currentDocument, baseZoom = 1, visibleOn
|
|
|
337
327
|
top: Math.round(rect.top),
|
|
338
328
|
width: Math.round(rect.width),
|
|
339
329
|
height: Math.round(rect.height),
|
|
340
|
-
zoom: rect.zoom
|
|
330
|
+
zoom: rect.zoom,
|
|
331
|
+
isVisible
|
|
341
332
|
};
|
|
342
333
|
}
|
|
343
334
|
function getNodeAttributes(node, currentWindow) {
|
|
@@ -414,25 +405,20 @@ function tagNameOfNode(node) {
|
|
|
414
405
|
let tagName = "";
|
|
415
406
|
if (node instanceof HTMLElement) {
|
|
416
407
|
tagName = node.tagName.toLowerCase();
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
408
|
+
} else {
|
|
409
|
+
const parentElement = node.parentElement;
|
|
410
|
+
if (parentElement && parentElement instanceof HTMLElement) {
|
|
411
|
+
tagName = parentElement.tagName.toLowerCase();
|
|
412
|
+
}
|
|
421
413
|
}
|
|
422
414
|
return tagName ? `<${tagName}>` : "";
|
|
423
415
|
}
|
|
424
|
-
function collectElementInfo(node, currentWindow, currentDocument, baseZoom = 1, basePoint = { left: 0, top: 0 }
|
|
425
|
-
const rect = elementRect(
|
|
426
|
-
node,
|
|
427
|
-
currentWindow,
|
|
428
|
-
currentDocument,
|
|
429
|
-
baseZoom,
|
|
430
|
-
visibleOnly
|
|
431
|
-
);
|
|
416
|
+
function collectElementInfo(node, currentWindow, currentDocument, baseZoom = 1, basePoint = { left: 0, top: 0 }) {
|
|
417
|
+
const rect = elementRect(node, currentWindow, currentDocument, baseZoom);
|
|
432
418
|
if (!rect) {
|
|
433
419
|
return null;
|
|
434
420
|
}
|
|
435
|
-
if (
|
|
421
|
+
if (rect.width < CONTAINER_MINI_WIDTH || rect.height < CONTAINER_MINI_HEIGHT) {
|
|
436
422
|
return null;
|
|
437
423
|
}
|
|
438
424
|
if (basePoint.left !== 0 || basePoint.top !== 0) {
|
|
@@ -472,7 +458,8 @@ function collectElementInfo(node, currentWindow, currentDocument, baseZoom = 1,
|
|
|
472
458
|
Math.round(rect.left + rect.width / 2),
|
|
473
459
|
Math.round(rect.top + rect.height / 2)
|
|
474
460
|
],
|
|
475
|
-
zoom: rect.zoom
|
|
461
|
+
zoom: rect.zoom,
|
|
462
|
+
isVisible: rect.isVisible
|
|
476
463
|
};
|
|
477
464
|
return elementInfo;
|
|
478
465
|
}
|
|
@@ -481,8 +468,7 @@ function collectElementInfo(node, currentWindow, currentDocument, baseZoom = 1,
|
|
|
481
468
|
node,
|
|
482
469
|
currentWindow,
|
|
483
470
|
currentDocument,
|
|
484
|
-
baseZoom
|
|
485
|
-
visibleOnly
|
|
471
|
+
baseZoom
|
|
486
472
|
);
|
|
487
473
|
if (!rect2) {
|
|
488
474
|
return null;
|
|
@@ -509,7 +495,8 @@ function collectElementInfo(node, currentWindow, currentDocument, baseZoom = 1,
|
|
|
509
495
|
Math.round(rect2.left + rect2.width / 2),
|
|
510
496
|
Math.round(rect2.top + rect2.height / 2)
|
|
511
497
|
],
|
|
512
|
-
zoom: rect2.zoom
|
|
498
|
+
zoom: rect2.zoom,
|
|
499
|
+
isVisible: rect2.isVisible
|
|
513
500
|
};
|
|
514
501
|
return elementInfo;
|
|
515
502
|
}
|
|
@@ -537,7 +524,8 @@ function collectElementInfo(node, currentWindow, currentDocument, baseZoom = 1,
|
|
|
537
524
|
Math.round(rect.left + rect.width / 2),
|
|
538
525
|
Math.round(rect.top + rect.height / 2)
|
|
539
526
|
],
|
|
540
|
-
zoom: rect.zoom
|
|
527
|
+
zoom: rect.zoom,
|
|
528
|
+
isVisible: rect.isVisible
|
|
541
529
|
};
|
|
542
530
|
return elementInfo;
|
|
543
531
|
}
|
|
@@ -570,7 +558,8 @@ function collectElementInfo(node, currentWindow, currentDocument, baseZoom = 1,
|
|
|
570
558
|
],
|
|
571
559
|
content: text,
|
|
572
560
|
rect,
|
|
573
|
-
zoom: rect.zoom
|
|
561
|
+
zoom: rect.zoom,
|
|
562
|
+
isVisible: rect.isVisible
|
|
574
563
|
};
|
|
575
564
|
return elementInfo;
|
|
576
565
|
}
|
|
@@ -597,7 +586,8 @@ function collectElementInfo(node, currentWindow, currentDocument, baseZoom = 1,
|
|
|
597
586
|
Math.round(rect.left + rect.width / 2),
|
|
598
587
|
Math.round(rect.top + rect.height / 2)
|
|
599
588
|
],
|
|
600
|
-
zoom: rect.zoom
|
|
589
|
+
zoom: rect.zoom,
|
|
590
|
+
isVisible: rect.isVisible
|
|
601
591
|
};
|
|
602
592
|
return elementInfo;
|
|
603
593
|
}
|
|
@@ -622,7 +612,8 @@ function collectElementInfo(node, currentWindow, currentDocument, baseZoom = 1,
|
|
|
622
612
|
Math.round(rect.left + rect.width / 2),
|
|
623
613
|
Math.round(rect.top + rect.height / 2)
|
|
624
614
|
],
|
|
625
|
-
zoom: rect.zoom
|
|
615
|
+
zoom: rect.zoom,
|
|
616
|
+
isVisible: rect.isVisible
|
|
626
617
|
};
|
|
627
618
|
return elementInfo;
|
|
628
619
|
}
|
|
@@ -671,7 +662,7 @@ function extractTreeNode(initNode, debugMode2 = false) {
|
|
|
671
662
|
node: elementInfo,
|
|
672
663
|
children: []
|
|
673
664
|
};
|
|
674
|
-
if (elementInfo?.nodeType === "BUTTON Node" /* BUTTON */ || elementInfo?.nodeType === "IMG Node" /* IMG */ || elementInfo?.nodeType === "TEXT Node" /* TEXT */ || elementInfo?.nodeType === "
|
|
665
|
+
if (elementInfo?.nodeType === "BUTTON Node" /* BUTTON */ || elementInfo?.nodeType === "IMG Node" /* IMG */ || elementInfo?.nodeType === "TEXT Node" /* TEXT */ || elementInfo?.nodeType === "FORM_ITEM Node" /* FORM_ITEM */ || elementInfo?.nodeType === "CONTAINER Node" /* CONTAINER */) {
|
|
675
666
|
return nodeInfo;
|
|
676
667
|
}
|
|
677
668
|
const rect = getRect(node, baseZoom, currentWindow);
|
|
@@ -726,14 +717,8 @@ function extractTreeNode(initNode, debugMode2 = false) {
|
|
|
726
717
|
children: topChildren
|
|
727
718
|
};
|
|
728
719
|
}
|
|
729
|
-
function mergeElementAndChildrenRects(node, currentWindow, currentDocument, baseZoom = 1
|
|
730
|
-
const selfRect = elementRect(
|
|
731
|
-
node,
|
|
732
|
-
currentWindow,
|
|
733
|
-
currentDocument,
|
|
734
|
-
baseZoom,
|
|
735
|
-
visibleOnly
|
|
736
|
-
);
|
|
720
|
+
function mergeElementAndChildrenRects(node, currentWindow, currentDocument, baseZoom = 1) {
|
|
721
|
+
const selfRect = elementRect(node, currentWindow, currentDocument, baseZoom);
|
|
737
722
|
if (!selfRect)
|
|
738
723
|
return null;
|
|
739
724
|
let minLeft = selfRect.left;
|
|
@@ -744,13 +729,7 @@ function mergeElementAndChildrenRects(node, currentWindow, currentDocument, base
|
|
|
744
729
|
for (let i = 0; i < child.childNodes.length; i++) {
|
|
745
730
|
const sub = child.childNodes[i];
|
|
746
731
|
if (sub.nodeType === 1) {
|
|
747
|
-
const rect = elementRect(
|
|
748
|
-
sub,
|
|
749
|
-
currentWindow,
|
|
750
|
-
currentDocument,
|
|
751
|
-
baseZoom,
|
|
752
|
-
visibleOnly
|
|
753
|
-
);
|
|
732
|
+
const rect = elementRect(sub, currentWindow, currentDocument, baseZoom);
|
|
754
733
|
if (rect) {
|
|
755
734
|
minLeft = Math.min(minLeft, rect.left);
|
|
756
735
|
minTop = Math.min(minTop, rect.top);
|
package/dist/lib/extractor.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import './constants.js';
|
|
2
|
-
export { E as ElementInfo, a as ElementNode, d as descriptionOfTree,
|
|
2
|
+
export { E as ElementInfo, a as ElementNode, d as descriptionOfTree, m as generateElementByPosition, l as getElementInfoByXpath, i as getNodeFromCacheList, k as getNodeInfoByXpath, j as getXpathsById, s as setNodeHashCacheListOnWindow, t as traverseTree, b as treeToList, e as trimAttributes, c as truncateText, g as webExtractNodeTree, h as webExtractNodeTreeAsString, f as webExtractTextWithPosition } from './index-a171e36c.js';
|
package/dist/lib/extractor.js
CHANGED
|
@@ -29,6 +29,8 @@ __export(extractor_exports, {
|
|
|
29
29
|
setNodeHashCacheListOnWindow: () => setNodeHashCacheListOnWindow,
|
|
30
30
|
traverseTree: () => traverseTree,
|
|
31
31
|
treeToList: () => treeToList,
|
|
32
|
+
trimAttributes: () => trimAttributes,
|
|
33
|
+
truncateText: () => truncateText,
|
|
32
34
|
webExtractNodeTree: () => extractTreeNode,
|
|
33
35
|
webExtractNodeTreeAsString: () => extractTreeNodeAsString,
|
|
34
36
|
webExtractTextWithPosition: () => extractTextWithPosition
|
|
@@ -58,7 +60,7 @@ function trimAttributes(attributes, truncateTextLength) {
|
|
|
58
60
|
const tailorAttributes = Object.keys(attributes).reduce(
|
|
59
61
|
(res, currentKey) => {
|
|
60
62
|
const attributeVal = attributes[currentKey];
|
|
61
|
-
if (currentKey === "style" || currentKey === "
|
|
63
|
+
if (currentKey === "style" || currentKey === "htmlTagName" || currentKey === "nodeType") {
|
|
62
64
|
return res;
|
|
63
65
|
}
|
|
64
66
|
res[currentKey] = truncateText(attributeVal, truncateTextLength);
|
|
@@ -69,13 +71,13 @@ function trimAttributes(attributes, truncateTextLength) {
|
|
|
69
71
|
return tailorAttributes;
|
|
70
72
|
}
|
|
71
73
|
var nodeSizeThreshold = 4;
|
|
72
|
-
function descriptionOfTree(tree, truncateTextLength, filterNonTextContent = false) {
|
|
74
|
+
function descriptionOfTree(tree, truncateTextLength, filterNonTextContent = false, visibleOnly = true) {
|
|
73
75
|
const attributesString = (kv) => {
|
|
74
76
|
return Object.entries(kv).map(
|
|
75
77
|
([key, value]) => `${key}="${truncateText(value, truncateTextLength)}"`
|
|
76
78
|
).join(" ");
|
|
77
79
|
};
|
|
78
|
-
function buildContentTree(node, indent = 0) {
|
|
80
|
+
function buildContentTree(node, indent = 0, visibleOnly2 = true) {
|
|
79
81
|
let before = "";
|
|
80
82
|
let contentWithIndent = "";
|
|
81
83
|
let after = "";
|
|
@@ -83,13 +85,17 @@ function descriptionOfTree(tree, truncateTextLength, filterNonTextContent = fals
|
|
|
83
85
|
const indentStr = " ".repeat(indent);
|
|
84
86
|
let children = "";
|
|
85
87
|
for (let i = 0; i < (node.children || []).length; i++) {
|
|
86
|
-
const childContent = buildContentTree(
|
|
88
|
+
const childContent = buildContentTree(
|
|
89
|
+
node.children[i],
|
|
90
|
+
indent + 1,
|
|
91
|
+
visibleOnly2
|
|
92
|
+
);
|
|
87
93
|
if (childContent) {
|
|
88
94
|
children += `
|
|
89
95
|
${childContent}`;
|
|
90
96
|
}
|
|
91
97
|
}
|
|
92
|
-
if (node.node && node.node.rect.width > nodeSizeThreshold && node.node.rect.height > nodeSizeThreshold && (!filterNonTextContent || filterNonTextContent && node.node.content)) {
|
|
98
|
+
if (node.node && node.node.rect.width > nodeSizeThreshold && node.node.rect.height > nodeSizeThreshold && (!filterNonTextContent || filterNonTextContent && node.node.content) && (!visibleOnly2 || visibleOnly2 && node.node.isVisible)) {
|
|
93
99
|
emptyNode = false;
|
|
94
100
|
let nodeTypeString;
|
|
95
101
|
if (node.node.attributes?.htmlTagName) {
|
|
@@ -127,7 +133,7 @@ ${indentStr}${after}`;
|
|
|
127
133
|
}
|
|
128
134
|
return "";
|
|
129
135
|
}
|
|
130
|
-
const result = buildContentTree(tree);
|
|
136
|
+
const result = buildContentTree(tree, 0, visibleOnly);
|
|
131
137
|
return result.replace(/^\s*\n/gm, "");
|
|
132
138
|
}
|
|
133
139
|
function treeToList(tree) {
|
|
@@ -428,7 +434,7 @@ var isElementCovered = (el, rect, currentWindow) => {
|
|
|
428
434
|
});
|
|
429
435
|
return true;
|
|
430
436
|
};
|
|
431
|
-
function elementRect(el, currentWindow, currentDocument, baseZoom = 1
|
|
437
|
+
function elementRect(el, currentWindow, currentDocument, baseZoom = 1) {
|
|
432
438
|
if (!el) {
|
|
433
439
|
logger(el, "Element is not in the DOM hierarchy");
|
|
434
440
|
return false;
|
|
@@ -452,21 +458,11 @@ function elementRect(el, currentWindow, currentDocument, baseZoom = 1, visibleOn
|
|
|
452
458
|
if (baseZoom === 1 && isElementCovered(el, rect, currentWindow)) {
|
|
453
459
|
return false;
|
|
454
460
|
}
|
|
455
|
-
const
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
if (!isPartiallyInViewport) {
|
|
461
|
-
logger(el, "Element is completely outside the viewport", {
|
|
462
|
-
rect,
|
|
463
|
-
viewportHeight,
|
|
464
|
-
viewportWidth,
|
|
465
|
-
scrollTop,
|
|
466
|
-
scrollLeft
|
|
467
|
-
});
|
|
468
|
-
return false;
|
|
469
|
-
}
|
|
461
|
+
const isVisible = isElementPartiallyInViewport(
|
|
462
|
+
rect,
|
|
463
|
+
currentWindow,
|
|
464
|
+
currentDocument
|
|
465
|
+
);
|
|
470
466
|
let parent = el;
|
|
471
467
|
const parentUntilNonStatic = (currentNode) => {
|
|
472
468
|
let parent2 = currentNode?.parentElement;
|
|
@@ -510,7 +506,8 @@ function elementRect(el, currentWindow, currentDocument, baseZoom = 1, visibleOn
|
|
|
510
506
|
top: Math.round(rect.top),
|
|
511
507
|
width: Math.round(rect.width),
|
|
512
508
|
height: Math.round(rect.height),
|
|
513
|
-
zoom: rect.zoom
|
|
509
|
+
zoom: rect.zoom,
|
|
510
|
+
isVisible
|
|
514
511
|
};
|
|
515
512
|
}
|
|
516
513
|
function getNodeAttributes(node, currentWindow) {
|
|
@@ -577,25 +574,20 @@ function tagNameOfNode(node) {
|
|
|
577
574
|
let tagName = "";
|
|
578
575
|
if (node instanceof HTMLElement) {
|
|
579
576
|
tagName = node.tagName.toLowerCase();
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
577
|
+
} else {
|
|
578
|
+
const parentElement = node.parentElement;
|
|
579
|
+
if (parentElement && parentElement instanceof HTMLElement) {
|
|
580
|
+
tagName = parentElement.tagName.toLowerCase();
|
|
581
|
+
}
|
|
584
582
|
}
|
|
585
583
|
return tagName ? `<${tagName}>` : "";
|
|
586
584
|
}
|
|
587
|
-
function collectElementInfo(node, currentWindow, currentDocument, baseZoom = 1, basePoint = { left: 0, top: 0 }
|
|
588
|
-
const rect = elementRect(
|
|
589
|
-
node,
|
|
590
|
-
currentWindow,
|
|
591
|
-
currentDocument,
|
|
592
|
-
baseZoom,
|
|
593
|
-
visibleOnly
|
|
594
|
-
);
|
|
585
|
+
function collectElementInfo(node, currentWindow, currentDocument, baseZoom = 1, basePoint = { left: 0, top: 0 }) {
|
|
586
|
+
const rect = elementRect(node, currentWindow, currentDocument, baseZoom);
|
|
595
587
|
if (!rect) {
|
|
596
588
|
return null;
|
|
597
589
|
}
|
|
598
|
-
if (
|
|
590
|
+
if (rect.width < CONTAINER_MINI_WIDTH || rect.height < CONTAINER_MINI_HEIGHT) {
|
|
599
591
|
return null;
|
|
600
592
|
}
|
|
601
593
|
if (basePoint.left !== 0 || basePoint.top !== 0) {
|
|
@@ -635,7 +627,8 @@ function collectElementInfo(node, currentWindow, currentDocument, baseZoom = 1,
|
|
|
635
627
|
Math.round(rect.left + rect.width / 2),
|
|
636
628
|
Math.round(rect.top + rect.height / 2)
|
|
637
629
|
],
|
|
638
|
-
zoom: rect.zoom
|
|
630
|
+
zoom: rect.zoom,
|
|
631
|
+
isVisible: rect.isVisible
|
|
639
632
|
};
|
|
640
633
|
return elementInfo;
|
|
641
634
|
}
|
|
@@ -644,8 +637,7 @@ function collectElementInfo(node, currentWindow, currentDocument, baseZoom = 1,
|
|
|
644
637
|
node,
|
|
645
638
|
currentWindow,
|
|
646
639
|
currentDocument,
|
|
647
|
-
baseZoom
|
|
648
|
-
visibleOnly
|
|
640
|
+
baseZoom
|
|
649
641
|
);
|
|
650
642
|
if (!rect2) {
|
|
651
643
|
return null;
|
|
@@ -672,7 +664,8 @@ function collectElementInfo(node, currentWindow, currentDocument, baseZoom = 1,
|
|
|
672
664
|
Math.round(rect2.left + rect2.width / 2),
|
|
673
665
|
Math.round(rect2.top + rect2.height / 2)
|
|
674
666
|
],
|
|
675
|
-
zoom: rect2.zoom
|
|
667
|
+
zoom: rect2.zoom,
|
|
668
|
+
isVisible: rect2.isVisible
|
|
676
669
|
};
|
|
677
670
|
return elementInfo;
|
|
678
671
|
}
|
|
@@ -700,7 +693,8 @@ function collectElementInfo(node, currentWindow, currentDocument, baseZoom = 1,
|
|
|
700
693
|
Math.round(rect.left + rect.width / 2),
|
|
701
694
|
Math.round(rect.top + rect.height / 2)
|
|
702
695
|
],
|
|
703
|
-
zoom: rect.zoom
|
|
696
|
+
zoom: rect.zoom,
|
|
697
|
+
isVisible: rect.isVisible
|
|
704
698
|
};
|
|
705
699
|
return elementInfo;
|
|
706
700
|
}
|
|
@@ -733,7 +727,8 @@ function collectElementInfo(node, currentWindow, currentDocument, baseZoom = 1,
|
|
|
733
727
|
],
|
|
734
728
|
content: text,
|
|
735
729
|
rect,
|
|
736
|
-
zoom: rect.zoom
|
|
730
|
+
zoom: rect.zoom,
|
|
731
|
+
isVisible: rect.isVisible
|
|
737
732
|
};
|
|
738
733
|
return elementInfo;
|
|
739
734
|
}
|
|
@@ -760,7 +755,8 @@ function collectElementInfo(node, currentWindow, currentDocument, baseZoom = 1,
|
|
|
760
755
|
Math.round(rect.left + rect.width / 2),
|
|
761
756
|
Math.round(rect.top + rect.height / 2)
|
|
762
757
|
],
|
|
763
|
-
zoom: rect.zoom
|
|
758
|
+
zoom: rect.zoom,
|
|
759
|
+
isVisible: rect.isVisible
|
|
764
760
|
};
|
|
765
761
|
return elementInfo;
|
|
766
762
|
}
|
|
@@ -785,7 +781,8 @@ function collectElementInfo(node, currentWindow, currentDocument, baseZoom = 1,
|
|
|
785
781
|
Math.round(rect.left + rect.width / 2),
|
|
786
782
|
Math.round(rect.top + rect.height / 2)
|
|
787
783
|
],
|
|
788
|
-
zoom: rect.zoom
|
|
784
|
+
zoom: rect.zoom,
|
|
785
|
+
isVisible: rect.isVisible
|
|
789
786
|
};
|
|
790
787
|
return elementInfo;
|
|
791
788
|
}
|
|
@@ -805,9 +802,9 @@ function extractTextWithPosition(initNode, debugMode2 = false) {
|
|
|
805
802
|
dfsTopChildren({ children: elementNode.children, node: elementNode.node });
|
|
806
803
|
return elementInfoArray;
|
|
807
804
|
}
|
|
808
|
-
function extractTreeNodeAsString(initNode, debugMode2 = false) {
|
|
805
|
+
function extractTreeNodeAsString(initNode, visibleOnly = false, debugMode2 = false) {
|
|
809
806
|
const elementNode = extractTreeNode(initNode, debugMode2);
|
|
810
|
-
return descriptionOfTree(elementNode);
|
|
807
|
+
return descriptionOfTree(elementNode, void 0, false, visibleOnly);
|
|
811
808
|
}
|
|
812
809
|
function extractTreeNode(initNode, debugMode2 = false) {
|
|
813
810
|
setDebugMode(debugMode2);
|
|
@@ -838,7 +835,7 @@ function extractTreeNode(initNode, debugMode2 = false) {
|
|
|
838
835
|
node: elementInfo,
|
|
839
836
|
children: []
|
|
840
837
|
};
|
|
841
|
-
if (elementInfo?.nodeType === "BUTTON Node" /* BUTTON */ || elementInfo?.nodeType === "IMG Node" /* IMG */ || elementInfo?.nodeType === "TEXT Node" /* TEXT */ || elementInfo?.nodeType === "
|
|
838
|
+
if (elementInfo?.nodeType === "BUTTON Node" /* BUTTON */ || elementInfo?.nodeType === "IMG Node" /* IMG */ || elementInfo?.nodeType === "TEXT Node" /* TEXT */ || elementInfo?.nodeType === "FORM_ITEM Node" /* FORM_ITEM */ || elementInfo?.nodeType === "CONTAINER Node" /* CONTAINER */) {
|
|
842
839
|
return nodeInfo;
|
|
843
840
|
}
|
|
844
841
|
const rect = getRect(node, baseZoom, currentWindow);
|
|
@@ -893,14 +890,8 @@ function extractTreeNode(initNode, debugMode2 = false) {
|
|
|
893
890
|
children: topChildren
|
|
894
891
|
};
|
|
895
892
|
}
|
|
896
|
-
function mergeElementAndChildrenRects(node, currentWindow, currentDocument, baseZoom = 1
|
|
897
|
-
const selfRect = elementRect(
|
|
898
|
-
node,
|
|
899
|
-
currentWindow,
|
|
900
|
-
currentDocument,
|
|
901
|
-
baseZoom,
|
|
902
|
-
visibleOnly
|
|
903
|
-
);
|
|
893
|
+
function mergeElementAndChildrenRects(node, currentWindow, currentDocument, baseZoom = 1) {
|
|
894
|
+
const selfRect = elementRect(node, currentWindow, currentDocument, baseZoom);
|
|
904
895
|
if (!selfRect)
|
|
905
896
|
return null;
|
|
906
897
|
let minLeft = selfRect.left;
|
|
@@ -911,13 +902,7 @@ function mergeElementAndChildrenRects(node, currentWindow, currentDocument, base
|
|
|
911
902
|
for (let i = 0; i < child.childNodes.length; i++) {
|
|
912
903
|
const sub = child.childNodes[i];
|
|
913
904
|
if (sub.nodeType === 1) {
|
|
914
|
-
const rect = elementRect(
|
|
915
|
-
sub,
|
|
916
|
-
currentWindow,
|
|
917
|
-
currentDocument,
|
|
918
|
-
baseZoom,
|
|
919
|
-
visibleOnly
|
|
920
|
-
);
|
|
905
|
+
const rect = elementRect(sub, currentWindow, currentDocument, baseZoom);
|
|
921
906
|
if (rect) {
|
|
922
907
|
minLeft = Math.min(minLeft, rect.left);
|
|
923
908
|
minTop = Math.min(minTop, rect.top);
|
|
@@ -1034,17 +1019,10 @@ function getElementInfoByXpath(xpath) {
|
|
|
1034
1019
|
node.scrollIntoView({ behavior: "instant", block: "center" });
|
|
1035
1020
|
}
|
|
1036
1021
|
}
|
|
1037
|
-
return collectElementInfo(
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
1,
|
|
1042
|
-
{
|
|
1043
|
-
left: 0,
|
|
1044
|
-
top: 0
|
|
1045
|
-
},
|
|
1046
|
-
false
|
|
1047
|
-
);
|
|
1022
|
+
return collectElementInfo(node, window, document, 1, {
|
|
1023
|
+
left: 0,
|
|
1024
|
+
top: 0
|
|
1025
|
+
});
|
|
1048
1026
|
}
|
|
1049
1027
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1050
1028
|
0 && (module.exports = {
|
|
@@ -1057,6 +1035,8 @@ function getElementInfoByXpath(xpath) {
|
|
|
1057
1035
|
setNodeHashCacheListOnWindow,
|
|
1058
1036
|
traverseTree,
|
|
1059
1037
|
treeToList,
|
|
1038
|
+
trimAttributes,
|
|
1039
|
+
truncateText,
|
|
1060
1040
|
webExtractNodeTree,
|
|
1061
1041
|
webExtractNodeTreeAsString,
|
|
1062
1042
|
webExtractTextWithPosition
|
package/dist/lib/img.d.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { NodeType } from './constants.js';
|
|
2
2
|
|
|
3
|
-
declare function
|
|
3
|
+
declare function truncateText(text: string | number | object | undefined, maxLength?: number): string;
|
|
4
|
+
declare function trimAttributes(attributes: Record<string, any>, truncateTextLength?: number): {
|
|
5
|
+
[key: string]: string;
|
|
6
|
+
nodeType: NodeType;
|
|
7
|
+
};
|
|
8
|
+
declare function descriptionOfTree<ElementType extends BaseElement = BaseElement>(tree: ElementTreeNode<ElementType>, truncateTextLength?: number, filterNonTextContent?: boolean, visibleOnly?: boolean): string;
|
|
4
9
|
declare function treeToList<T extends BaseElement>(tree: ElementTreeNode<T>): T[];
|
|
5
10
|
declare function traverseTree<T extends BaseElement, ReturnNodeType extends BaseElement>(tree: ElementTreeNode<T>, onNode: (node: T) => ReturnNodeType): ElementTreeNode<ReturnNodeType>;
|
|
6
11
|
|
|
@@ -9,7 +14,7 @@ interface WebElementNode {
|
|
|
9
14
|
children: WebElementNode[];
|
|
10
15
|
}
|
|
11
16
|
declare function extractTextWithPosition(initNode: globalThis.Node, debugMode?: boolean): WebElementInfo[];
|
|
12
|
-
declare function extractTreeNodeAsString(initNode: globalThis.Node, debugMode?: boolean): string;
|
|
17
|
+
declare function extractTreeNodeAsString(initNode: globalThis.Node, visibleOnly?: boolean, debugMode?: boolean): string;
|
|
13
18
|
declare function extractTreeNode(initNode: globalThis.Node, debugMode?: boolean): WebElementNode;
|
|
14
19
|
|
|
15
20
|
declare function setNodeHashCacheListOnWindow(): void;
|
|
@@ -56,6 +61,7 @@ interface ElementInfo {
|
|
|
56
61
|
height: number;
|
|
57
62
|
};
|
|
58
63
|
center: [number, number];
|
|
64
|
+
isVisible: boolean;
|
|
59
65
|
}
|
|
60
66
|
interface ElementNode {
|
|
61
67
|
node: ElementInfo | null;
|
|
@@ -85,6 +91,8 @@ declare abstract class BaseElement {
|
|
|
85
91
|
abstract rect: Rect;
|
|
86
92
|
abstract center: [number, number];
|
|
87
93
|
abstract locator?: string;
|
|
94
|
+
abstract xpaths?: string[];
|
|
95
|
+
abstract isVisible: boolean;
|
|
88
96
|
}
|
|
89
97
|
interface ElementTreeNode<ElementType extends BaseElement = BaseElement> {
|
|
90
98
|
node: ElementType | null;
|
|
@@ -94,4 +102,4 @@ interface WebElementInfo extends ElementInfo {
|
|
|
94
102
|
zoom: number;
|
|
95
103
|
}
|
|
96
104
|
|
|
97
|
-
export { BaseElement as B, type ElementInfo as E, type Point as P, type Rect as R, type Size as S, type WebElementInfo as W, type ElementNode as a, treeToList as b,
|
|
105
|
+
export { BaseElement as B, type ElementInfo as E, type Point as P, type Rect as R, type Size as S, type WebElementInfo as W, type ElementNode as a, treeToList as b, truncateText as c, descriptionOfTree as d, trimAttributes as e, extractTextWithPosition as f, extractTreeNode as g, extractTreeNodeAsString as h, getNodeFromCacheList as i, getXpathsById as j, getNodeInfoByXpath as k, getElementInfoByXpath as l, generateElementByPosition as m, type ElementTreeNode as n, setNodeHashCacheListOnWindow as s, traverseTree as t };
|
package/dist/lib/types.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import './constants.js';
|
|
2
|
-
export { B as BaseElement,
|
|
2
|
+
export { B as BaseElement, n as ElementTreeNode, P as Point, R as Rect, S as Size, W as WebElementInfo } from './index-a171e36c.js';
|