@midscene/recorder 0.24.1-beta-20250728094050.0 → 0.24.1-beta-20250728154033.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.
@@ -521,7 +521,6 @@
521
521
  getNodeFromCacheList: ()=>getNodeFromCacheList,
522
522
  getNodeInfoByXpath: ()=>getNodeInfoByXpath,
523
523
  getXpathsById: ()=>getXpathsById,
524
- getXpathsByPoint: ()=>getXpathsByPoint,
525
524
  isNotContainerElement: ()=>isNotContainerElement,
526
525
  setNodeHashCacheListOnWindow: ()=>setNodeHashCacheListOnWindow,
527
526
  traverseTree: ()=>traverseTree,
@@ -1245,18 +1244,30 @@ ${indentStr}${after}`;
1245
1244
  }
1246
1245
  return index;
1247
1246
  };
1248
- function normalizeText(text) {
1249
- if ("string" != typeof text) return "";
1250
- return text.replace(/\s+/g, " ").trim();
1251
- }
1252
- var getElementXPath = (element, isOrderSensitive, isLeafElement)=>{
1247
+ var getTextNodeIndex = (textNode)=>{
1248
+ let index = 1;
1249
+ let current = textNode.previousSibling;
1250
+ while(current){
1251
+ if (current.nodeType === Node.TEXT_NODE) index++;
1252
+ current = current.previousSibling;
1253
+ }
1254
+ return index;
1255
+ };
1256
+ var createNormalizeSpaceCondition = (textContent)=>`[normalize-space()="${textContent}"]`;
1257
+ var addTextContentToXPath = (el, baseXPath)=>{
1258
+ const textContent = el.textContent?.trim();
1259
+ if (textContent && (isButtonElement(el) || isFormElement(el))) return `${baseXPath}${createNormalizeSpaceCondition(textContent)}`;
1260
+ return baseXPath;
1261
+ };
1262
+ var getElementXPath = (element)=>{
1253
1263
  if (element.nodeType === Node.TEXT_NODE) {
1254
1264
  const parentNode = element.parentNode;
1255
1265
  if (parentNode && parentNode.nodeType === Node.ELEMENT_NODE) {
1256
- const parentXPath = getElementXPath(parentNode, true);
1257
- const textContent2 = element.textContent?.trim();
1258
- if (textContent2) return `${parentXPath}/text()[normalize-space()="${normalizeText(textContent2)}"]`;
1259
- return `${parentXPath}/text()`;
1266
+ const parentXPath2 = getElementXPath(parentNode);
1267
+ const textIndex = getTextNodeIndex(element);
1268
+ const textContent = element.textContent?.trim();
1269
+ if (textContent) return `${parentXPath2}/text()[${textIndex}]${createNormalizeSpaceCondition(textContent)}`;
1270
+ return `${parentXPath2}/text()[${textIndex}]`;
1260
1271
  }
1261
1272
  return "";
1262
1273
  }
@@ -1266,37 +1277,19 @@ ${indentStr}${after}`;
1266
1277
  if (el === document.body) return "/html/body";
1267
1278
  const isSVG = "http://www.w3.org/2000/svg" === el.namespaceURI;
1268
1279
  const tagName = el.nodeName.toLowerCase();
1269
- if (isSVG) {
1270
- let parent = el.parentNode;
1271
- while(parent && parent.nodeType === Node.ELEMENT_NODE){
1272
- const parentEl = parent;
1273
- if ("http://www.w3.org/2000/svg" !== parentEl.namespaceURI) return getElementXPath(parent, isOrderSensitive, isLeafElement);
1274
- parent = parent.parentNode;
1275
- }
1276
- return getElementXPath(el.parentNode, isOrderSensitive, isLeafElement);
1280
+ if (isSVG && "svg" === tagName) return getElementXPath(el.parentNode);
1281
+ if (!el.parentNode) {
1282
+ const baseXPath2 = `/${tagName}`;
1283
+ return addTextContentToXPath(el, baseXPath2);
1277
1284
  }
1278
- const textContent = el.textContent?.trim();
1279
- const buildParentPath = ()=>{
1280
- if (!el.parentNode) return "";
1281
- return getElementXPath(el.parentNode, true);
1282
- };
1283
- const buildCurrentElement = (useIndex, useText)=>{
1284
- const parentPath = buildParentPath();
1285
- const prefix = parentPath ? `${parentPath}/` : "/";
1286
- if (useText && textContent) return `${prefix}${tagName}[normalize-space()="${normalizeText(textContent)}"]`;
1287
- if (useIndex) {
1288
- const index = getElementIndex(el);
1289
- return `${prefix}${tagName}[${index}]`;
1290
- }
1291
- return `${prefix}${tagName}`;
1292
- };
1293
- if (isOrderSensitive) return buildCurrentElement(true);
1294
- if (isLeafElement) return buildCurrentElement(false, true);
1295
- return buildCurrentElement(true);
1285
+ const parentXPath = getElementXPath(el.parentNode);
1286
+ const index = getElementIndex(el);
1287
+ const baseXPath = `${parentXPath}/${tagName}[${index}]`;
1288
+ return addTextContentToXPath(el, baseXPath);
1296
1289
  };
1297
- function generateXPaths(node, isOrderSensitive) {
1290
+ function generateXPaths(node) {
1298
1291
  if (!node) return [];
1299
- const fullXPath = getElementXPath(node, isOrderSensitive, true);
1292
+ const fullXPath = getElementXPath(node);
1300
1293
  return [
1301
1294
  fullXPath
1302
1295
  ];
@@ -1306,11 +1299,6 @@ ${indentStr}${after}`;
1306
1299
  if (!node) return null;
1307
1300
  return generateXPaths(node);
1308
1301
  }
1309
- function getXpathsByPoint(point, isOrderSensitive) {
1310
- const element = document.elementFromPoint(point.left, point.top);
1311
- if (!element) return null;
1312
- return generateXPaths(element, isOrderSensitive);
1313
- }
1314
1302
  function getNodeInfoByXpath(xpath) {
1315
1303
  const xpathResult = document.evaluate(xpath, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
1316
1304
  if (1 !== xpathResult.snapshotLength) return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midscene/recorder",
3
- "version": "0.24.1-beta-20250728094050.0",
3
+ "version": "0.24.1-beta-20250728154033.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -24,7 +24,7 @@
24
24
  "antd": "^5.21.6",
25
25
  "dayjs": "^1.11.11",
26
26
  "react-dom": "18.3.1",
27
- "@midscene/shared": "0.24.1-beta-20250728094050.0"
27
+ "@midscene/shared": "0.24.1-beta-20250728154033.0"
28
28
  },
29
29
  "peerDependencies": {
30
30
  "react": "18.3.1",