@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
|
@@ -587,6 +587,8 @@ var midscene_element_inspector = (() => {
|
|
|
587
587
|
setNodeHashCacheListOnWindow: () => setNodeHashCacheListOnWindow,
|
|
588
588
|
traverseTree: () => traverseTree,
|
|
589
589
|
treeToList: () => treeToList,
|
|
590
|
+
trimAttributes: () => trimAttributes,
|
|
591
|
+
truncateText: () => truncateText,
|
|
590
592
|
webExtractNodeTree: () => extractTreeNode,
|
|
591
593
|
webExtractNodeTreeAsString: () => extractTreeNodeAsString,
|
|
592
594
|
webExtractTextWithPosition: () => extractTextWithPosition
|
|
@@ -615,7 +617,7 @@ var midscene_element_inspector = (() => {
|
|
|
615
617
|
const tailorAttributes = Object.keys(attributes).reduce(
|
|
616
618
|
(res, currentKey) => {
|
|
617
619
|
const attributeVal = attributes[currentKey];
|
|
618
|
-
if (currentKey === "style" || currentKey === "
|
|
620
|
+
if (currentKey === "style" || currentKey === "htmlTagName" || currentKey === "nodeType") {
|
|
619
621
|
return res;
|
|
620
622
|
}
|
|
621
623
|
res[currentKey] = truncateText(attributeVal, truncateTextLength);
|
|
@@ -626,13 +628,13 @@ var midscene_element_inspector = (() => {
|
|
|
626
628
|
return tailorAttributes;
|
|
627
629
|
}
|
|
628
630
|
var nodeSizeThreshold = 4;
|
|
629
|
-
function descriptionOfTree(tree, truncateTextLength, filterNonTextContent = false) {
|
|
631
|
+
function descriptionOfTree(tree, truncateTextLength, filterNonTextContent = false, visibleOnly = true) {
|
|
630
632
|
const attributesString = (kv) => {
|
|
631
633
|
return Object.entries(kv).map(
|
|
632
634
|
([key, value]) => `${key}="${truncateText(value, truncateTextLength)}"`
|
|
633
635
|
).join(" ");
|
|
634
636
|
};
|
|
635
|
-
function buildContentTree(node, indent = 0) {
|
|
637
|
+
function buildContentTree(node, indent = 0, visibleOnly2 = true) {
|
|
636
638
|
var _a;
|
|
637
639
|
let before = "";
|
|
638
640
|
let contentWithIndent = "";
|
|
@@ -641,13 +643,17 @@ var midscene_element_inspector = (() => {
|
|
|
641
643
|
const indentStr = " ".repeat(indent);
|
|
642
644
|
let children = "";
|
|
643
645
|
for (let i = 0; i < (node.children || []).length; i++) {
|
|
644
|
-
const childContent = buildContentTree(
|
|
646
|
+
const childContent = buildContentTree(
|
|
647
|
+
node.children[i],
|
|
648
|
+
indent + 1,
|
|
649
|
+
visibleOnly2
|
|
650
|
+
);
|
|
645
651
|
if (childContent) {
|
|
646
652
|
children += `
|
|
647
653
|
${childContent}`;
|
|
648
654
|
}
|
|
649
655
|
}
|
|
650
|
-
if (node.node && node.node.rect.width > nodeSizeThreshold && node.node.rect.height > nodeSizeThreshold && (!filterNonTextContent || filterNonTextContent && node.node.content)) {
|
|
656
|
+
if (node.node && node.node.rect.width > nodeSizeThreshold && node.node.rect.height > nodeSizeThreshold && (!filterNonTextContent || filterNonTextContent && node.node.content) && (!visibleOnly2 || visibleOnly2 && node.node.isVisible)) {
|
|
651
657
|
emptyNode = false;
|
|
652
658
|
let nodeTypeString;
|
|
653
659
|
if ((_a = node.node.attributes) == null ? void 0 : _a.htmlTagName) {
|
|
@@ -685,7 +691,7 @@ ${indentStr}${after}`;
|
|
|
685
691
|
}
|
|
686
692
|
return "";
|
|
687
693
|
}
|
|
688
|
-
const result = buildContentTree(tree);
|
|
694
|
+
const result = buildContentTree(tree, 0, visibleOnly);
|
|
689
695
|
return result.replace(/^\s*\n/gm, "");
|
|
690
696
|
}
|
|
691
697
|
function treeToList(tree) {
|
|
@@ -986,7 +992,7 @@ ${indentStr}${after}`;
|
|
|
986
992
|
});
|
|
987
993
|
return true;
|
|
988
994
|
};
|
|
989
|
-
function elementRect(el, currentWindow, currentDocument, baseZoom = 1
|
|
995
|
+
function elementRect(el, currentWindow, currentDocument, baseZoom = 1) {
|
|
990
996
|
if (!el) {
|
|
991
997
|
logger(el, "Element is not in the DOM hierarchy");
|
|
992
998
|
return false;
|
|
@@ -1010,21 +1016,11 @@ ${indentStr}${after}`;
|
|
|
1010
1016
|
if (baseZoom === 1 && isElementCovered(el, rect, currentWindow)) {
|
|
1011
1017
|
return false;
|
|
1012
1018
|
}
|
|
1013
|
-
const
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
if (!isPartiallyInViewport) {
|
|
1019
|
-
logger(el, "Element is completely outside the viewport", {
|
|
1020
|
-
rect,
|
|
1021
|
-
viewportHeight,
|
|
1022
|
-
viewportWidth,
|
|
1023
|
-
scrollTop,
|
|
1024
|
-
scrollLeft
|
|
1025
|
-
});
|
|
1026
|
-
return false;
|
|
1027
|
-
}
|
|
1019
|
+
const isVisible = isElementPartiallyInViewport(
|
|
1020
|
+
rect,
|
|
1021
|
+
currentWindow,
|
|
1022
|
+
currentDocument
|
|
1023
|
+
);
|
|
1028
1024
|
let parent = el;
|
|
1029
1025
|
const parentUntilNonStatic = (currentNode) => {
|
|
1030
1026
|
let parent2 = currentNode == null ? void 0 : currentNode.parentElement;
|
|
@@ -1068,7 +1064,8 @@ ${indentStr}${after}`;
|
|
|
1068
1064
|
top: Math.round(rect.top),
|
|
1069
1065
|
width: Math.round(rect.width),
|
|
1070
1066
|
height: Math.round(rect.height),
|
|
1071
|
-
zoom: rect.zoom
|
|
1067
|
+
zoom: rect.zoom,
|
|
1068
|
+
isVisible
|
|
1072
1069
|
};
|
|
1073
1070
|
}
|
|
1074
1071
|
function getNodeAttributes(node, currentWindow) {
|
|
@@ -1137,26 +1134,21 @@ ${indentStr}${after}`;
|
|
|
1137
1134
|
let tagName = "";
|
|
1138
1135
|
if (node instanceof HTMLElement) {
|
|
1139
1136
|
tagName = node.tagName.toLowerCase();
|
|
1140
|
-
}
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1137
|
+
} else {
|
|
1138
|
+
const parentElement = node.parentElement;
|
|
1139
|
+
if (parentElement && parentElement instanceof HTMLElement) {
|
|
1140
|
+
tagName = parentElement.tagName.toLowerCase();
|
|
1141
|
+
}
|
|
1144
1142
|
}
|
|
1145
1143
|
return tagName ? `<${tagName}>` : "";
|
|
1146
1144
|
}
|
|
1147
|
-
function collectElementInfo(node, currentWindow, currentDocument, baseZoom = 1, basePoint = { left: 0, top: 0 }
|
|
1145
|
+
function collectElementInfo(node, currentWindow, currentDocument, baseZoom = 1, basePoint = { left: 0, top: 0 }) {
|
|
1148
1146
|
var _a;
|
|
1149
|
-
const rect = elementRect(
|
|
1150
|
-
node,
|
|
1151
|
-
currentWindow,
|
|
1152
|
-
currentDocument,
|
|
1153
|
-
baseZoom,
|
|
1154
|
-
visibleOnly
|
|
1155
|
-
);
|
|
1147
|
+
const rect = elementRect(node, currentWindow, currentDocument, baseZoom);
|
|
1156
1148
|
if (!rect) {
|
|
1157
1149
|
return null;
|
|
1158
1150
|
}
|
|
1159
|
-
if (
|
|
1151
|
+
if (rect.width < CONTAINER_MINI_WIDTH || rect.height < CONTAINER_MINI_HEIGHT) {
|
|
1160
1152
|
return null;
|
|
1161
1153
|
}
|
|
1162
1154
|
if (basePoint.left !== 0 || basePoint.top !== 0) {
|
|
@@ -1195,7 +1187,8 @@ ${indentStr}${after}`;
|
|
|
1195
1187
|
Math.round(rect.left + rect.width / 2),
|
|
1196
1188
|
Math.round(rect.top + rect.height / 2)
|
|
1197
1189
|
],
|
|
1198
|
-
zoom: rect.zoom
|
|
1190
|
+
zoom: rect.zoom,
|
|
1191
|
+
isVisible: rect.isVisible
|
|
1199
1192
|
};
|
|
1200
1193
|
return elementInfo;
|
|
1201
1194
|
}
|
|
@@ -1204,8 +1197,7 @@ ${indentStr}${after}`;
|
|
|
1204
1197
|
node,
|
|
1205
1198
|
currentWindow,
|
|
1206
1199
|
currentDocument,
|
|
1207
|
-
baseZoom
|
|
1208
|
-
visibleOnly
|
|
1200
|
+
baseZoom
|
|
1209
1201
|
);
|
|
1210
1202
|
if (!rect2) {
|
|
1211
1203
|
return null;
|
|
@@ -1231,7 +1223,8 @@ ${indentStr}${after}`;
|
|
|
1231
1223
|
Math.round(rect2.left + rect2.width / 2),
|
|
1232
1224
|
Math.round(rect2.top + rect2.height / 2)
|
|
1233
1225
|
],
|
|
1234
|
-
zoom: rect2.zoom
|
|
1226
|
+
zoom: rect2.zoom,
|
|
1227
|
+
isVisible: rect2.isVisible
|
|
1235
1228
|
};
|
|
1236
1229
|
return elementInfo;
|
|
1237
1230
|
}
|
|
@@ -1257,7 +1250,8 @@ ${indentStr}${after}`;
|
|
|
1257
1250
|
Math.round(rect.left + rect.width / 2),
|
|
1258
1251
|
Math.round(rect.top + rect.height / 2)
|
|
1259
1252
|
],
|
|
1260
|
-
zoom: rect.zoom
|
|
1253
|
+
zoom: rect.zoom,
|
|
1254
|
+
isVisible: rect.isVisible
|
|
1261
1255
|
};
|
|
1262
1256
|
return elementInfo;
|
|
1263
1257
|
}
|
|
@@ -1289,7 +1283,8 @@ ${indentStr}${after}`;
|
|
|
1289
1283
|
],
|
|
1290
1284
|
content: text,
|
|
1291
1285
|
rect,
|
|
1292
|
-
zoom: rect.zoom
|
|
1286
|
+
zoom: rect.zoom,
|
|
1287
|
+
isVisible: rect.isVisible
|
|
1293
1288
|
};
|
|
1294
1289
|
return elementInfo;
|
|
1295
1290
|
}
|
|
@@ -1315,7 +1310,8 @@ ${indentStr}${after}`;
|
|
|
1315
1310
|
Math.round(rect.left + rect.width / 2),
|
|
1316
1311
|
Math.round(rect.top + rect.height / 2)
|
|
1317
1312
|
],
|
|
1318
|
-
zoom: rect.zoom
|
|
1313
|
+
zoom: rect.zoom,
|
|
1314
|
+
isVisible: rect.isVisible
|
|
1319
1315
|
};
|
|
1320
1316
|
return elementInfo;
|
|
1321
1317
|
}
|
|
@@ -1339,7 +1335,8 @@ ${indentStr}${after}`;
|
|
|
1339
1335
|
Math.round(rect.left + rect.width / 2),
|
|
1340
1336
|
Math.round(rect.top + rect.height / 2)
|
|
1341
1337
|
],
|
|
1342
|
-
zoom: rect.zoom
|
|
1338
|
+
zoom: rect.zoom,
|
|
1339
|
+
isVisible: rect.isVisible
|
|
1343
1340
|
};
|
|
1344
1341
|
return elementInfo;
|
|
1345
1342
|
}
|
|
@@ -1359,9 +1356,9 @@ ${indentStr}${after}`;
|
|
|
1359
1356
|
dfsTopChildren({ children: elementNode.children, node: elementNode.node });
|
|
1360
1357
|
return elementInfoArray;
|
|
1361
1358
|
}
|
|
1362
|
-
function extractTreeNodeAsString(initNode, debugMode2 = false) {
|
|
1359
|
+
function extractTreeNodeAsString(initNode, visibleOnly = false, debugMode2 = false) {
|
|
1363
1360
|
const elementNode = extractTreeNode(initNode, debugMode2);
|
|
1364
|
-
return descriptionOfTree(elementNode);
|
|
1361
|
+
return descriptionOfTree(elementNode, void 0, false, visibleOnly);
|
|
1365
1362
|
}
|
|
1366
1363
|
function extractTreeNode(initNode, debugMode2 = false) {
|
|
1367
1364
|
setDebugMode(debugMode2);
|
|
@@ -1392,7 +1389,7 @@ ${indentStr}${after}`;
|
|
|
1392
1389
|
node: elementInfo,
|
|
1393
1390
|
children: []
|
|
1394
1391
|
};
|
|
1395
|
-
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) === "
|
|
1392
|
+
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 */) {
|
|
1396
1393
|
return nodeInfo;
|
|
1397
1394
|
}
|
|
1398
1395
|
const rect = getRect(node, baseZoom, currentWindow);
|
|
@@ -1447,14 +1444,8 @@ ${indentStr}${after}`;
|
|
|
1447
1444
|
children: topChildren
|
|
1448
1445
|
};
|
|
1449
1446
|
}
|
|
1450
|
-
function mergeElementAndChildrenRects(node, currentWindow, currentDocument, baseZoom = 1
|
|
1451
|
-
const selfRect = elementRect(
|
|
1452
|
-
node,
|
|
1453
|
-
currentWindow,
|
|
1454
|
-
currentDocument,
|
|
1455
|
-
baseZoom,
|
|
1456
|
-
visibleOnly
|
|
1457
|
-
);
|
|
1447
|
+
function mergeElementAndChildrenRects(node, currentWindow, currentDocument, baseZoom = 1) {
|
|
1448
|
+
const selfRect = elementRect(node, currentWindow, currentDocument, baseZoom);
|
|
1458
1449
|
if (!selfRect)
|
|
1459
1450
|
return null;
|
|
1460
1451
|
let minLeft = selfRect.left;
|
|
@@ -1465,13 +1456,7 @@ ${indentStr}${after}`;
|
|
|
1465
1456
|
for (let i = 0; i < child.childNodes.length; i++) {
|
|
1466
1457
|
const sub = child.childNodes[i];
|
|
1467
1458
|
if (sub.nodeType === 1) {
|
|
1468
|
-
const rect = elementRect(
|
|
1469
|
-
sub,
|
|
1470
|
-
currentWindow,
|
|
1471
|
-
currentDocument,
|
|
1472
|
-
baseZoom,
|
|
1473
|
-
visibleOnly
|
|
1474
|
-
);
|
|
1459
|
+
const rect = elementRect(sub, currentWindow, currentDocument, baseZoom);
|
|
1475
1460
|
if (rect) {
|
|
1476
1461
|
minLeft = Math.min(minLeft, rect.left);
|
|
1477
1462
|
minTop = Math.min(minTop, rect.top);
|
|
@@ -1588,17 +1573,10 @@ ${indentStr}${after}`;
|
|
|
1588
1573
|
node.scrollIntoView({ behavior: "instant", block: "center" });
|
|
1589
1574
|
}
|
|
1590
1575
|
}
|
|
1591
|
-
return collectElementInfo(
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
1,
|
|
1596
|
-
{
|
|
1597
|
-
left: 0,
|
|
1598
|
-
top: 0
|
|
1599
|
-
},
|
|
1600
|
-
false
|
|
1601
|
-
);
|
|
1576
|
+
return collectElementInfo(node, window, document, 1, {
|
|
1577
|
+
left: 0,
|
|
1578
|
+
top: 0
|
|
1579
|
+
});
|
|
1602
1580
|
}
|
|
1603
1581
|
return __toCommonJS(extractor_exports);
|
|
1604
1582
|
})();
|
|
@@ -825,7 +825,7 @@ var midscene_element_inspector = (() => {
|
|
|
825
825
|
});
|
|
826
826
|
return true;
|
|
827
827
|
};
|
|
828
|
-
function elementRect(el, currentWindow, currentDocument, baseZoom = 1
|
|
828
|
+
function elementRect(el, currentWindow, currentDocument, baseZoom = 1) {
|
|
829
829
|
if (!el) {
|
|
830
830
|
logger(el, "Element is not in the DOM hierarchy");
|
|
831
831
|
return false;
|
|
@@ -849,21 +849,11 @@ var midscene_element_inspector = (() => {
|
|
|
849
849
|
if (baseZoom === 1 && isElementCovered(el, rect, currentWindow)) {
|
|
850
850
|
return false;
|
|
851
851
|
}
|
|
852
|
-
const
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
if (!isPartiallyInViewport) {
|
|
858
|
-
logger(el, "Element is completely outside the viewport", {
|
|
859
|
-
rect,
|
|
860
|
-
viewportHeight,
|
|
861
|
-
viewportWidth,
|
|
862
|
-
scrollTop,
|
|
863
|
-
scrollLeft
|
|
864
|
-
});
|
|
865
|
-
return false;
|
|
866
|
-
}
|
|
852
|
+
const isVisible = isElementPartiallyInViewport(
|
|
853
|
+
rect,
|
|
854
|
+
currentWindow,
|
|
855
|
+
currentDocument
|
|
856
|
+
);
|
|
867
857
|
let parent = el;
|
|
868
858
|
const parentUntilNonStatic = (currentNode) => {
|
|
869
859
|
let parent2 = currentNode == null ? void 0 : currentNode.parentElement;
|
|
@@ -907,7 +897,8 @@ var midscene_element_inspector = (() => {
|
|
|
907
897
|
top: Math.round(rect.top),
|
|
908
898
|
width: Math.round(rect.width),
|
|
909
899
|
height: Math.round(rect.height),
|
|
910
|
-
zoom: rect.zoom
|
|
900
|
+
zoom: rect.zoom,
|
|
901
|
+
isVisible
|
|
911
902
|
};
|
|
912
903
|
}
|
|
913
904
|
function getNodeAttributes(node, currentWindow) {
|
|
@@ -986,26 +977,21 @@ var midscene_element_inspector = (() => {
|
|
|
986
977
|
let tagName = "";
|
|
987
978
|
if (node instanceof HTMLElement) {
|
|
988
979
|
tagName = node.tagName.toLowerCase();
|
|
989
|
-
}
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
980
|
+
} else {
|
|
981
|
+
const parentElement = node.parentElement;
|
|
982
|
+
if (parentElement && parentElement instanceof HTMLElement) {
|
|
983
|
+
tagName = parentElement.tagName.toLowerCase();
|
|
984
|
+
}
|
|
993
985
|
}
|
|
994
986
|
return tagName ? `<${tagName}>` : "";
|
|
995
987
|
}
|
|
996
|
-
function collectElementInfo(node, currentWindow, currentDocument, baseZoom = 1, basePoint = { left: 0, top: 0 }
|
|
988
|
+
function collectElementInfo(node, currentWindow, currentDocument, baseZoom = 1, basePoint = { left: 0, top: 0 }) {
|
|
997
989
|
var _a;
|
|
998
|
-
const rect = elementRect(
|
|
999
|
-
node,
|
|
1000
|
-
currentWindow,
|
|
1001
|
-
currentDocument,
|
|
1002
|
-
baseZoom,
|
|
1003
|
-
visibleOnly
|
|
1004
|
-
);
|
|
990
|
+
const rect = elementRect(node, currentWindow, currentDocument, baseZoom);
|
|
1005
991
|
if (!rect) {
|
|
1006
992
|
return null;
|
|
1007
993
|
}
|
|
1008
|
-
if (
|
|
994
|
+
if (rect.width < CONTAINER_MINI_WIDTH || rect.height < CONTAINER_MINI_HEIGHT) {
|
|
1009
995
|
return null;
|
|
1010
996
|
}
|
|
1011
997
|
if (basePoint.left !== 0 || basePoint.top !== 0) {
|
|
@@ -1044,7 +1030,8 @@ var midscene_element_inspector = (() => {
|
|
|
1044
1030
|
Math.round(rect.left + rect.width / 2),
|
|
1045
1031
|
Math.round(rect.top + rect.height / 2)
|
|
1046
1032
|
],
|
|
1047
|
-
zoom: rect.zoom
|
|
1033
|
+
zoom: rect.zoom,
|
|
1034
|
+
isVisible: rect.isVisible
|
|
1048
1035
|
};
|
|
1049
1036
|
return elementInfo;
|
|
1050
1037
|
}
|
|
@@ -1053,8 +1040,7 @@ var midscene_element_inspector = (() => {
|
|
|
1053
1040
|
node,
|
|
1054
1041
|
currentWindow,
|
|
1055
1042
|
currentDocument,
|
|
1056
|
-
baseZoom
|
|
1057
|
-
visibleOnly
|
|
1043
|
+
baseZoom
|
|
1058
1044
|
);
|
|
1059
1045
|
if (!rect2) {
|
|
1060
1046
|
return null;
|
|
@@ -1080,7 +1066,8 @@ var midscene_element_inspector = (() => {
|
|
|
1080
1066
|
Math.round(rect2.left + rect2.width / 2),
|
|
1081
1067
|
Math.round(rect2.top + rect2.height / 2)
|
|
1082
1068
|
],
|
|
1083
|
-
zoom: rect2.zoom
|
|
1069
|
+
zoom: rect2.zoom,
|
|
1070
|
+
isVisible: rect2.isVisible
|
|
1084
1071
|
};
|
|
1085
1072
|
return elementInfo;
|
|
1086
1073
|
}
|
|
@@ -1106,7 +1093,8 @@ var midscene_element_inspector = (() => {
|
|
|
1106
1093
|
Math.round(rect.left + rect.width / 2),
|
|
1107
1094
|
Math.round(rect.top + rect.height / 2)
|
|
1108
1095
|
],
|
|
1109
|
-
zoom: rect.zoom
|
|
1096
|
+
zoom: rect.zoom,
|
|
1097
|
+
isVisible: rect.isVisible
|
|
1110
1098
|
};
|
|
1111
1099
|
return elementInfo;
|
|
1112
1100
|
}
|
|
@@ -1138,7 +1126,8 @@ var midscene_element_inspector = (() => {
|
|
|
1138
1126
|
],
|
|
1139
1127
|
content: text,
|
|
1140
1128
|
rect,
|
|
1141
|
-
zoom: rect.zoom
|
|
1129
|
+
zoom: rect.zoom,
|
|
1130
|
+
isVisible: rect.isVisible
|
|
1142
1131
|
};
|
|
1143
1132
|
return elementInfo;
|
|
1144
1133
|
}
|
|
@@ -1164,7 +1153,8 @@ var midscene_element_inspector = (() => {
|
|
|
1164
1153
|
Math.round(rect.left + rect.width / 2),
|
|
1165
1154
|
Math.round(rect.top + rect.height / 2)
|
|
1166
1155
|
],
|
|
1167
|
-
zoom: rect.zoom
|
|
1156
|
+
zoom: rect.zoom,
|
|
1157
|
+
isVisible: rect.isVisible
|
|
1168
1158
|
};
|
|
1169
1159
|
return elementInfo;
|
|
1170
1160
|
}
|
|
@@ -1188,7 +1178,8 @@ var midscene_element_inspector = (() => {
|
|
|
1188
1178
|
Math.round(rect.left + rect.width / 2),
|
|
1189
1179
|
Math.round(rect.top + rect.height / 2)
|
|
1190
1180
|
],
|
|
1191
|
-
zoom: rect.zoom
|
|
1181
|
+
zoom: rect.zoom,
|
|
1182
|
+
isVisible: rect.isVisible
|
|
1192
1183
|
};
|
|
1193
1184
|
return elementInfo;
|
|
1194
1185
|
}
|
|
@@ -1237,7 +1228,7 @@ var midscene_element_inspector = (() => {
|
|
|
1237
1228
|
node: elementInfo,
|
|
1238
1229
|
children: []
|
|
1239
1230
|
};
|
|
1240
|
-
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) === "
|
|
1231
|
+
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 */) {
|
|
1241
1232
|
return nodeInfo;
|
|
1242
1233
|
}
|
|
1243
1234
|
const rect = getRect(node, baseZoom, currentWindow);
|
|
@@ -1292,14 +1283,8 @@ var midscene_element_inspector = (() => {
|
|
|
1292
1283
|
children: topChildren
|
|
1293
1284
|
};
|
|
1294
1285
|
}
|
|
1295
|
-
function mergeElementAndChildrenRects(node, currentWindow, currentDocument, baseZoom = 1
|
|
1296
|
-
const selfRect = elementRect(
|
|
1297
|
-
node,
|
|
1298
|
-
currentWindow,
|
|
1299
|
-
currentDocument,
|
|
1300
|
-
baseZoom,
|
|
1301
|
-
visibleOnly
|
|
1302
|
-
);
|
|
1286
|
+
function mergeElementAndChildrenRects(node, currentWindow, currentDocument, baseZoom = 1) {
|
|
1287
|
+
const selfRect = elementRect(node, currentWindow, currentDocument, baseZoom);
|
|
1303
1288
|
if (!selfRect)
|
|
1304
1289
|
return null;
|
|
1305
1290
|
let minLeft = selfRect.left;
|
|
@@ -1310,13 +1295,7 @@ var midscene_element_inspector = (() => {
|
|
|
1310
1295
|
for (let i = 0; i < child.childNodes.length; i++) {
|
|
1311
1296
|
const sub = child.childNodes[i];
|
|
1312
1297
|
if (sub.nodeType === 1) {
|
|
1313
|
-
const rect = elementRect(
|
|
1314
|
-
sub,
|
|
1315
|
-
currentWindow,
|
|
1316
|
-
currentDocument,
|
|
1317
|
-
baseZoom,
|
|
1318
|
-
visibleOnly
|
|
1319
|
-
);
|
|
1298
|
+
const rect = elementRect(sub, currentWindow, currentDocument, baseZoom);
|
|
1320
1299
|
if (rect) {
|
|
1321
1300
|
minLeft = Math.min(minLeft, rect.left);
|
|
1322
1301
|
minTop = Math.min(minTop, rect.top);
|
|
@@ -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/types/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/types/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';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midscene/shared",
|
|
3
|
-
"version": "0.17.4
|
|
3
|
+
"version": "0.17.4",
|
|
4
4
|
"repository": "https://github.com/web-infra-dev/midscene",
|
|
5
5
|
"homepage": "https://midscenejs.com/",
|
|
6
6
|
"types": "./dist/types/index.d.ts",
|
|
@@ -101,7 +101,6 @@
|
|
|
101
101
|
"new": "modern new",
|
|
102
102
|
"upgrade": "modern upgrade",
|
|
103
103
|
"test": "vitest --run",
|
|
104
|
-
"test:u": "vitest --run -u"
|
|
105
|
-
"test:ai": "AITEST=true npm run test"
|
|
104
|
+
"test:u": "vitest --run -u"
|
|
106
105
|
}
|
|
107
106
|
}
|
package/src/extractor/index.ts
CHANGED
|
@@ -14,6 +14,7 @@ export interface ElementInfo {
|
|
|
14
14
|
content: string;
|
|
15
15
|
rect: { left: number; top: number; width: number; height: number };
|
|
16
16
|
center: [number, number];
|
|
17
|
+
isVisible: boolean;
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
export interface ElementNode {
|
|
@@ -21,7 +22,13 @@ export interface ElementNode {
|
|
|
21
22
|
children: ElementNode[];
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
export {
|
|
25
|
+
export {
|
|
26
|
+
descriptionOfTree,
|
|
27
|
+
traverseTree,
|
|
28
|
+
treeToList,
|
|
29
|
+
truncateText,
|
|
30
|
+
trimAttributes,
|
|
31
|
+
} from './tree';
|
|
25
32
|
|
|
26
33
|
export { extractTextWithPosition as webExtractTextWithPosition } from './web-extractor';
|
|
27
34
|
|
package/src/extractor/locator.ts
CHANGED
|
@@ -133,15 +133,8 @@ export function getElementInfoByXpath(xpath: string): ElementInfo | null {
|
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
-
return collectElementInfo(
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
1,
|
|
141
|
-
{
|
|
142
|
-
left: 0,
|
|
143
|
-
top: 0,
|
|
144
|
-
},
|
|
145
|
-
false,
|
|
146
|
-
);
|
|
136
|
+
return collectElementInfo(node, window, document, 1, {
|
|
137
|
+
left: 0,
|
|
138
|
+
top: 0,
|
|
139
|
+
});
|
|
147
140
|
}
|
package/src/extractor/tree.ts
CHANGED
|
@@ -36,7 +36,6 @@ export function trimAttributes(
|
|
|
36
36
|
const attributeVal = (attributes as any)[currentKey];
|
|
37
37
|
if (
|
|
38
38
|
currentKey === 'style' ||
|
|
39
|
-
currentKey === 'src' ||
|
|
40
39
|
currentKey === 'htmlTagName' ||
|
|
41
40
|
currentKey === 'nodeType'
|
|
42
41
|
) {
|
|
@@ -58,6 +57,7 @@ export function descriptionOfTree<
|
|
|
58
57
|
tree: ElementTreeNode<ElementType>,
|
|
59
58
|
truncateTextLength?: number,
|
|
60
59
|
filterNonTextContent = false,
|
|
60
|
+
visibleOnly = true,
|
|
61
61
|
) {
|
|
62
62
|
const attributesString = (kv: Record<string, any>) => {
|
|
63
63
|
return Object.entries(kv)
|
|
@@ -70,6 +70,7 @@ export function descriptionOfTree<
|
|
|
70
70
|
function buildContentTree(
|
|
71
71
|
node: ElementTreeNode<ElementType>,
|
|
72
72
|
indent = 0,
|
|
73
|
+
visibleOnly = true,
|
|
73
74
|
): string {
|
|
74
75
|
let before = '';
|
|
75
76
|
let contentWithIndent = '';
|
|
@@ -79,7 +80,11 @@ export function descriptionOfTree<
|
|
|
79
80
|
|
|
80
81
|
let children = '';
|
|
81
82
|
for (let i = 0; i < (node.children || []).length; i++) {
|
|
82
|
-
const childContent = buildContentTree(
|
|
83
|
+
const childContent = buildContentTree(
|
|
84
|
+
node.children[i],
|
|
85
|
+
indent + 1,
|
|
86
|
+
visibleOnly,
|
|
87
|
+
);
|
|
83
88
|
if (childContent) {
|
|
84
89
|
children += `\n${childContent}`;
|
|
85
90
|
}
|
|
@@ -89,7 +94,8 @@ export function descriptionOfTree<
|
|
|
89
94
|
node.node &&
|
|
90
95
|
node.node.rect.width > nodeSizeThreshold &&
|
|
91
96
|
node.node.rect.height > nodeSizeThreshold &&
|
|
92
|
-
(!filterNonTextContent || (filterNonTextContent && node.node.content))
|
|
97
|
+
(!filterNonTextContent || (filterNonTextContent && node.node.content)) &&
|
|
98
|
+
(!visibleOnly || (visibleOnly && node.node.isVisible))
|
|
93
99
|
) {
|
|
94
100
|
emptyNode = false;
|
|
95
101
|
let nodeTypeString: string;
|
|
@@ -133,7 +139,7 @@ export function descriptionOfTree<
|
|
|
133
139
|
return '';
|
|
134
140
|
}
|
|
135
141
|
|
|
136
|
-
const result = buildContentTree(tree);
|
|
142
|
+
const result = buildContentTree(tree, 0, visibleOnly);
|
|
137
143
|
return result.replace(/^\s*\n/gm, '');
|
|
138
144
|
}
|
|
139
145
|
|