@midscene/shared 0.18.0 → 0.18.1-beta-20250611082446.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.
@@ -673,17 +673,27 @@ function extractTreeNode(initNode, debugMode2 = false) {
673
673
  rect.zoom,
674
674
  basePoint
675
675
  );
676
- if (childNodeInfo) {
676
+ if (Array.isArray(childNodeInfo)) {
677
+ nodeInfo.children.push(...childNodeInfo);
678
+ } else if (childNodeInfo) {
677
679
  nodeInfo.children.push(childNodeInfo);
678
680
  }
679
681
  }
682
+ if (nodeInfo.node === null) {
683
+ if (nodeInfo.children.length === 0) {
684
+ return null;
685
+ }
686
+ return nodeInfo.children;
687
+ }
680
688
  return nodeInfo;
681
689
  }
682
690
  const rootNodeInfo = dfs(startNode, window, document, 1, {
683
691
  left: 0,
684
692
  top: 0
685
693
  });
686
- if (rootNodeInfo) {
694
+ if (Array.isArray(rootNodeInfo)) {
695
+ topChildren.push(...rootNodeInfo);
696
+ } else if (rootNodeInfo) {
687
697
  topChildren.push(rootNodeInfo);
688
698
  }
689
699
  if (startNode === topDocument) {
@@ -703,7 +713,9 @@ function extractTreeNode(initNode, debugMode2 = false) {
703
713
  top: iframeInfo.rect.top
704
714
  }
705
715
  );
706
- if (iframeChildren) {
716
+ if (Array.isArray(iframeChildren)) {
717
+ topChildren.push(...iframeChildren);
718
+ } else if (iframeChildren) {
707
719
  topChildren.push(iframeChildren);
708
720
  }
709
721
  }
@@ -809,17 +809,27 @@ function extractTreeNode(initNode, debugMode2 = false) {
809
809
  rect.zoom,
810
810
  basePoint
811
811
  );
812
- if (childNodeInfo) {
812
+ if (Array.isArray(childNodeInfo)) {
813
+ nodeInfo.children.push(...childNodeInfo);
814
+ } else if (childNodeInfo) {
813
815
  nodeInfo.children.push(childNodeInfo);
814
816
  }
815
817
  }
818
+ if (nodeInfo.node === null) {
819
+ if (nodeInfo.children.length === 0) {
820
+ return null;
821
+ }
822
+ return nodeInfo.children;
823
+ }
816
824
  return nodeInfo;
817
825
  }
818
826
  const rootNodeInfo = dfs(startNode, window, document, 1, {
819
827
  left: 0,
820
828
  top: 0
821
829
  });
822
- if (rootNodeInfo) {
830
+ if (Array.isArray(rootNodeInfo)) {
831
+ topChildren.push(...rootNodeInfo);
832
+ } else if (rootNodeInfo) {
823
833
  topChildren.push(rootNodeInfo);
824
834
  }
825
835
  if (startNode === topDocument) {
@@ -839,7 +849,9 @@ function extractTreeNode(initNode, debugMode2 = false) {
839
849
  top: iframeInfo.rect.top
840
850
  }
841
851
  );
842
- if (iframeChildren) {
852
+ if (Array.isArray(iframeChildren)) {
853
+ topChildren.push(...iframeChildren);
854
+ } else if (iframeChildren) {
843
855
  topChildren.push(iframeChildren);
844
856
  }
845
857
  }
@@ -675,17 +675,27 @@ function extractTreeNode(initNode, debugMode2 = false) {
675
675
  rect.zoom,
676
676
  basePoint
677
677
  );
678
- if (childNodeInfo) {
678
+ if (Array.isArray(childNodeInfo)) {
679
+ nodeInfo.children.push(...childNodeInfo);
680
+ } else if (childNodeInfo) {
679
681
  nodeInfo.children.push(childNodeInfo);
680
682
  }
681
683
  }
684
+ if (nodeInfo.node === null) {
685
+ if (nodeInfo.children.length === 0) {
686
+ return null;
687
+ }
688
+ return nodeInfo.children;
689
+ }
682
690
  return nodeInfo;
683
691
  }
684
692
  const rootNodeInfo = dfs(startNode, window, document, 1, {
685
693
  left: 0,
686
694
  top: 0
687
695
  });
688
- if (rootNodeInfo) {
696
+ if (Array.isArray(rootNodeInfo)) {
697
+ topChildren.push(...rootNodeInfo);
698
+ } else if (rootNodeInfo) {
689
699
  topChildren.push(rootNodeInfo);
690
700
  }
691
701
  if (startNode === topDocument) {
@@ -705,7 +715,9 @@ function extractTreeNode(initNode, debugMode2 = false) {
705
715
  top: iframeInfo.rect.top
706
716
  }
707
717
  );
708
- if (iframeChildren) {
718
+ if (Array.isArray(iframeChildren)) {
719
+ topChildren.push(...iframeChildren);
720
+ } else if (iframeChildren) {
709
721
  topChildren.push(iframeChildren);
710
722
  }
711
723
  }
@@ -848,17 +848,27 @@ function extractTreeNode(initNode, debugMode2 = false) {
848
848
  rect.zoom,
849
849
  basePoint
850
850
  );
851
- if (childNodeInfo) {
851
+ if (Array.isArray(childNodeInfo)) {
852
+ nodeInfo.children.push(...childNodeInfo);
853
+ } else if (childNodeInfo) {
852
854
  nodeInfo.children.push(childNodeInfo);
853
855
  }
854
856
  }
857
+ if (nodeInfo.node === null) {
858
+ if (nodeInfo.children.length === 0) {
859
+ return null;
860
+ }
861
+ return nodeInfo.children;
862
+ }
855
863
  return nodeInfo;
856
864
  }
857
865
  const rootNodeInfo = dfs(startNode, window, document, 1, {
858
866
  left: 0,
859
867
  top: 0
860
868
  });
861
- if (rootNodeInfo) {
869
+ if (Array.isArray(rootNodeInfo)) {
870
+ topChildren.push(...rootNodeInfo);
871
+ } else if (rootNodeInfo) {
862
872
  topChildren.push(rootNodeInfo);
863
873
  }
864
874
  if (startNode === topDocument) {
@@ -878,7 +888,9 @@ function extractTreeNode(initNode, debugMode2 = false) {
878
888
  top: iframeInfo.rect.top
879
889
  }
880
890
  );
881
- if (iframeChildren) {
891
+ if (Array.isArray(iframeChildren)) {
892
+ topChildren.push(...iframeChildren);
893
+ } else if (iframeChildren) {
882
894
  topChildren.push(iframeChildren);
883
895
  }
884
896
  }
@@ -1402,17 +1402,27 @@ ${indentStr}${after}`;
1402
1402
  rect.zoom,
1403
1403
  basePoint
1404
1404
  );
1405
- if (childNodeInfo) {
1405
+ if (Array.isArray(childNodeInfo)) {
1406
+ nodeInfo.children.push(...childNodeInfo);
1407
+ } else if (childNodeInfo) {
1406
1408
  nodeInfo.children.push(childNodeInfo);
1407
1409
  }
1408
1410
  }
1411
+ if (nodeInfo.node === null) {
1412
+ if (nodeInfo.children.length === 0) {
1413
+ return null;
1414
+ }
1415
+ return nodeInfo.children;
1416
+ }
1409
1417
  return nodeInfo;
1410
1418
  }
1411
1419
  const rootNodeInfo = dfs(startNode, window, document, 1, {
1412
1420
  left: 0,
1413
1421
  top: 0
1414
1422
  });
1415
- if (rootNodeInfo) {
1423
+ if (Array.isArray(rootNodeInfo)) {
1424
+ topChildren.push(...rootNodeInfo);
1425
+ } else if (rootNodeInfo) {
1416
1426
  topChildren.push(rootNodeInfo);
1417
1427
  }
1418
1428
  if (startNode === topDocument) {
@@ -1432,7 +1442,9 @@ ${indentStr}${after}`;
1432
1442
  top: iframeInfo.rect.top
1433
1443
  }
1434
1444
  );
1435
- if (iframeChildren) {
1445
+ if (Array.isArray(iframeChildren)) {
1446
+ topChildren.push(...iframeChildren);
1447
+ } else if (iframeChildren) {
1436
1448
  topChildren.push(iframeChildren);
1437
1449
  }
1438
1450
  }
@@ -1241,17 +1241,27 @@ var midscene_element_inspector = (() => {
1241
1241
  rect.zoom,
1242
1242
  basePoint
1243
1243
  );
1244
- if (childNodeInfo) {
1244
+ if (Array.isArray(childNodeInfo)) {
1245
+ nodeInfo.children.push(...childNodeInfo);
1246
+ } else if (childNodeInfo) {
1245
1247
  nodeInfo.children.push(childNodeInfo);
1246
1248
  }
1247
1249
  }
1250
+ if (nodeInfo.node === null) {
1251
+ if (nodeInfo.children.length === 0) {
1252
+ return null;
1253
+ }
1254
+ return nodeInfo.children;
1255
+ }
1248
1256
  return nodeInfo;
1249
1257
  }
1250
1258
  const rootNodeInfo = dfs(startNode, window, document, 1, {
1251
1259
  left: 0,
1252
1260
  top: 0
1253
1261
  });
1254
- if (rootNodeInfo) {
1262
+ if (Array.isArray(rootNodeInfo)) {
1263
+ topChildren.push(...rootNodeInfo);
1264
+ } else if (rootNodeInfo) {
1255
1265
  topChildren.push(rootNodeInfo);
1256
1266
  }
1257
1267
  if (startNode === topDocument) {
@@ -1271,7 +1281,9 @@ var midscene_element_inspector = (() => {
1271
1281
  top: iframeInfo.rect.top
1272
1282
  }
1273
1283
  );
1274
- if (iframeChildren) {
1284
+ if (Array.isArray(iframeChildren)) {
1285
+ topChildren.push(...iframeChildren);
1286
+ } else if (iframeChildren) {
1275
1287
  topChildren.push(iframeChildren);
1276
1288
  }
1277
1289
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midscene/shared",
3
- "version": "0.18.0",
3
+ "version": "0.18.1-beta-20250611082446.0",
4
4
  "repository": "https://github.com/web-infra-dev/midscene",
5
5
  "homepage": "https://midscenejs.com/",
6
6
  "types": "./dist/types/index.d.ts",
@@ -336,7 +336,7 @@ export function extractTreeNode(
336
336
  currentDocument: typeof globalThis.document,
337
337
  baseZoom = 1,
338
338
  basePoint: Point = { left: 0, top: 0 },
339
- ): WebElementNode | null {
339
+ ): WebElementNode | WebElementNode[] | null {
340
340
  if (!node) {
341
341
  return null;
342
342
  }
@@ -388,11 +388,23 @@ export function extractTreeNode(
388
388
  rect.zoom,
389
389
  basePoint,
390
390
  );
391
- if (childNodeInfo) {
391
+ if (Array.isArray(childNodeInfo)) {
392
+ // if the recursive return is an array, expand and merge it into children
393
+ nodeInfo.children.push(...childNodeInfo);
394
+ } else if (childNodeInfo) {
392
395
  nodeInfo.children.push(childNodeInfo);
393
396
  }
394
397
  }
395
398
 
399
+ // if nodeInfo.node is null
400
+ if (nodeInfo.node === null) {
401
+ if (nodeInfo.children.length === 0) {
402
+ return null;
403
+ }
404
+ // promote children to the upper layer
405
+ return nodeInfo.children;
406
+ }
407
+
396
408
  return nodeInfo;
397
409
  }
398
410
 
@@ -400,7 +412,9 @@ export function extractTreeNode(
400
412
  left: 0,
401
413
  top: 0,
402
414
  });
403
- if (rootNodeInfo) {
415
+ if (Array.isArray(rootNodeInfo)) {
416
+ topChildren.push(...rootNodeInfo);
417
+ } else if (rootNodeInfo) {
404
418
  topChildren.push(rootNodeInfo);
405
419
  }
406
420
  if (startNode === topDocument) {
@@ -422,7 +436,9 @@ export function extractTreeNode(
422
436
  top: iframeInfo.rect.top,
423
437
  },
424
438
  );
425
- if (iframeChildren) {
439
+ if (Array.isArray(iframeChildren)) {
440
+ topChildren.push(...iframeChildren);
441
+ } else if (iframeChildren) {
426
442
  topChildren.push(iframeChildren);
427
443
  }
428
444
  }