@midscene/recorder 0.24.1-beta-20250729081015.0 → 0.24.1-beta-20250730043959.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,
@@ -652,9 +651,6 @@ ${indentStr}${after}`;
652
651
  function isAElement(node) {
653
652
  return node instanceof HTMLElement && "a" === node.tagName.toLowerCase();
654
653
  }
655
- function isSvgElement(node) {
656
- return node instanceof SVGElement;
657
- }
658
654
  function isImgElement(node) {
659
655
  if (!includeBaseElement(node) && node instanceof Element) {
660
656
  const computedStyle = window.getComputedStyle(node);
@@ -1239,7 +1235,7 @@ ${indentStr}${after}`;
1239
1235
  height: maxBottom - minTop
1240
1236
  };
1241
1237
  }
1242
- var getElementXpathIndex = (element)=>{
1238
+ var getElementIndex = (element)=>{
1243
1239
  let index = 1;
1244
1240
  let prev = element.previousElementSibling;
1245
1241
  while(prev){
@@ -1248,31 +1244,30 @@ ${indentStr}${after}`;
1248
1244
  }
1249
1245
  return index;
1250
1246
  };
1251
- var normalizeXpathText = (text)=>{
1252
- if ("string" != typeof text) return "";
1253
- return text.replace(/\s+/g, " ").trim();
1254
- };
1255
- var buildCurrentElementXpath = (element, isOrderSensitive, isLeafElement)=>{
1256
- const parentPath = element.parentNode ? getElementXpath(element.parentNode, isOrderSensitive) : "";
1257
- const prefix = parentPath ? `${parentPath}/` : "/";
1258
- const tagName = element.nodeName.toLowerCase();
1259
- const textContent = element.textContent?.trim();
1260
- if (isOrderSensitive) {
1261
- const index2 = getElementXpathIndex(element);
1262
- return `${prefix}${tagName}[${index2}]`;
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;
1263
1253
  }
1264
- if (isLeafElement && textContent) return `${prefix}${tagName}[normalize-space()="${normalizeXpathText(textContent)}"]`;
1265
- const index = getElementXpathIndex(element);
1266
- return `${prefix}${tagName}[${index}]`;
1254
+ return index;
1267
1255
  };
1268
- var getElementXpath = (element, isOrderSensitive = false, isLeafElement = false)=>{
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)=>{
1269
1263
  if (element.nodeType === Node.TEXT_NODE) {
1270
1264
  const parentNode = element.parentNode;
1271
1265
  if (parentNode && parentNode.nodeType === Node.ELEMENT_NODE) {
1272
- const parentXPath = getElementXpath(parentNode, isOrderSensitive, true);
1266
+ const parentXPath2 = getElementXPath(parentNode);
1267
+ const textIndex = getTextNodeIndex(element);
1273
1268
  const textContent = element.textContent?.trim();
1274
- if (textContent) return `${parentXPath}/text()[normalize-space()="${normalizeXpathText(textContent)}"]`;
1275
- return `${parentXPath}/text()`;
1269
+ if (textContent) return `${parentXPath2}/text()[${textIndex}]${createNormalizeSpaceCondition(textContent)}`;
1270
+ return `${parentXPath2}/text()[${textIndex}]`;
1276
1271
  }
1277
1272
  return "";
1278
1273
  }
@@ -1280,31 +1275,29 @@ ${indentStr}${after}`;
1280
1275
  const el = element;
1281
1276
  if (el === document.documentElement) return "/html";
1282
1277
  if (el === document.body) return "/html/body";
1283
- if (isSvgElement(el)) {
1284
- let parent = el.parentNode;
1285
- while(parent && parent.nodeType === Node.ELEMENT_NODE){
1286
- if (!isSvgElement(parent)) return getElementXpath(parent, isOrderSensitive, isLeafElement);
1287
- parent = parent.parentNode;
1288
- }
1289
- return getElementXpath(el.parentNode, isOrderSensitive, isLeafElement);
1278
+ const isSVG = "http://www.w3.org/2000/svg" === el.namespaceURI;
1279
+ const tagName = el.nodeName.toLowerCase();
1280
+ if (isSVG && "svg" === tagName) return getElementXPath(el.parentNode);
1281
+ if (!el.parentNode) {
1282
+ const baseXPath2 = `/${tagName}`;
1283
+ return addTextContentToXPath(el, baseXPath2);
1290
1284
  }
1291
- return buildCurrentElementXpath(el, isOrderSensitive, isLeafElement);
1285
+ const parentXPath = getElementXPath(el.parentNode);
1286
+ const index = getElementIndex(el);
1287
+ const baseXPath = `${parentXPath}/${tagName}[${index}]`;
1288
+ return addTextContentToXPath(el, baseXPath);
1292
1289
  };
1293
- function getXpathsById(id) {
1294
- const node = getNodeFromCacheList(id);
1295
- if (!node) return null;
1296
- const fullXPath = getElementXpath(node, false, true);
1290
+ function generateXPaths(node) {
1291
+ if (!node) return [];
1292
+ const fullXPath = getElementXPath(node);
1297
1293
  return [
1298
1294
  fullXPath
1299
1295
  ];
1300
1296
  }
1301
- function getXpathsByPoint(point, isOrderSensitive) {
1302
- const element = document.elementFromPoint(point.left, point.top);
1303
- if (!element) return null;
1304
- const fullXPath = getElementXpath(element, isOrderSensitive, true);
1305
- return [
1306
- fullXPath
1307
- ];
1297
+ function getXpathsById(id) {
1298
+ const node = getNodeFromCacheList(id);
1299
+ if (!node) return null;
1300
+ return generateXPaths(node);
1308
1301
  }
1309
1302
  function getNodeInfoByXpath(xpath) {
1310
1303
  const xpathResult = document.evaluate(xpath, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midscene/recorder",
3
- "version": "0.24.1-beta-20250729081015.0",
3
+ "version": "0.24.1-beta-20250730043959.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-20250729081015.0"
27
+ "@midscene/shared": "0.24.1-beta-20250730043959.0"
28
28
  },
29
29
  "peerDependencies": {
30
30
  "react": "18.3.1",