@midscene/shared 1.0.1-beta-20251024063839.0 → 1.0.1-beta-20251027033034.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.
@@ -1,4 +1,4 @@
1
- import { NodeType } from '../constants';
1
+ import type { LocateResultElement, Rect } from '../types';
2
2
  import { generateHashId } from '../utils';
3
3
 
4
4
  export function isFormElement(node: globalThis.Node) {
@@ -132,20 +132,24 @@ function includeBaseElement(node: globalThis.Node) {
132
132
  return false;
133
133
  }
134
134
 
135
- export function generateElementByPosition(position: { x: number; y: number }) {
135
+ export function generateElementByPosition(position: {
136
+ x: number;
137
+ y: number;
138
+ }): LocateResultElement {
139
+ const edgeSize = 8;
136
140
  const rect = {
137
- left: Math.max(position.x - 4, 0),
138
- top: Math.max(position.y - 4, 0),
139
- width: 8,
140
- height: 8,
141
+ left: Math.round(Math.max(position.x - edgeSize / 2, 0)),
142
+ top: Math.round(Math.max(position.y - edgeSize / 2, 0)),
143
+ width: edgeSize,
144
+ height: edgeSize,
141
145
  };
142
146
  const id = generateHashId(rect);
143
147
  const element = {
144
148
  id,
145
- attributes: { nodeType: NodeType.POSITION },
146
149
  rect,
147
150
  content: '',
148
- center: [position.x, position.y],
151
+ center: [position.x, position.y] as [number, number],
152
+ isOrderSensitive: false, // actually it's 'unknown'
149
153
  };
150
154
 
151
155
  return element;
@@ -35,8 +35,6 @@ export { extractTreeNode as webExtractNodeTree } from './web-extractor';
35
35
 
36
36
  export { extractTreeNodeAsString as webExtractNodeTreeAsString } from './web-extractor';
37
37
 
38
- export { setNodeHashCacheListOnWindow, getNodeFromCacheList } from './util';
39
-
40
38
  export {
41
39
  getXpathsByPoint,
42
40
  getNodeInfoByXpath,
@@ -1,7 +1,6 @@
1
1
  import type { ElementInfo } from '.';
2
2
  import type { Point } from '../types';
3
3
  import { isSvgElement } from './dom-util';
4
- import { getNodeFromCacheList } from './util';
5
4
  import { getRect, isElementPartiallyInViewport } from './util';
6
5
  import { collectElementInfo } from './web-extractor';
7
6
 
@@ -45,7 +45,7 @@ export function trimAttributes(
45
45
  res[currentKey] = truncateText(attributeVal, truncateTextLength);
46
46
  return res;
47
47
  },
48
- {} as BaseElement['attributes'],
48
+ {} as Record<string, string>,
49
49
  );
50
50
  return tailorAttributes;
51
51
  }
@@ -106,8 +106,8 @@ export function descriptionOfTree<
106
106
  .replace(/\sNode$/, '')
107
107
  .toLowerCase();
108
108
  }
109
- const markerId = node.node.indexId;
110
- const markerIdString = markerId ? `markerId="${markerId}"` : '';
109
+ // const markerId = node.node.indexId;
110
+ // const markerIdString = markerId ? `markerId="${markerId}"` : '';
111
111
  const rectAttribute = node.node.rect
112
112
  ? {
113
113
  left: node.node.rect.left,
@@ -116,7 +116,7 @@ export function descriptionOfTree<
116
116
  height: node.node.rect.height,
117
117
  }
118
118
  : {};
119
- before = `<${nodeTypeString} id="${node.node.id}" ${markerIdString} ${attributesString(trimAttributes(node.node.attributes || {}, truncateTextLength))} ${attributesString(rectAttribute)}>`;
119
+ before = `<${nodeTypeString} id="${node.node.id}" ${attributesString(trimAttributes(node.node.attributes || {}, truncateTextLength))} ${attributesString(rectAttribute)}>`;
120
120
  const content = truncateText(node.node.content, truncateTextLength);
121
121
  contentWithIndent = content ? `\n${indentStr} ${content}` : '';
122
122
  after = `</${nodeTypeString}>`;
@@ -399,42 +399,10 @@ export function midsceneGenerateHash(
399
399
  ): string {
400
400
  const slicedHash = generateHashId(rect, content);
401
401
 
402
- if (node) {
403
- if (!(window as any).midsceneNodeHashCacheList) {
404
- setNodeHashCacheListOnWindow();
405
- }
406
-
407
- setNodeToCacheList(node, slicedHash);
408
- }
409
-
410
402
  // Returns the first 10 characters as a short hash
411
403
  return slicedHash;
412
404
  }
413
405
 
414
- export function setNodeHashCacheListOnWindow() {
415
- if (typeof window !== 'undefined') {
416
- (window as any).midsceneNodeHashCacheList = [];
417
- }
418
- }
419
-
420
- export function setNodeToCacheList(node: globalThis.Node, id: string) {
421
- if (typeof window !== 'undefined') {
422
- if (getNodeFromCacheList(id)) {
423
- return;
424
- }
425
- (window as any).midsceneNodeHashCacheList?.push({ node, id });
426
- }
427
- }
428
-
429
- export function getNodeFromCacheList(id: string) {
430
- if (typeof window !== 'undefined') {
431
- return (window as any).midsceneNodeHashCacheList?.find(
432
- (item: { node: Node; id: string }) => item.id === id,
433
- )?.node;
434
- }
435
- return null;
436
- }
437
-
438
406
  export function generateId(numberId: number) {
439
407
  // const letters = 'ABCDEFGHIJKLMNPRSTUVXYZ';
440
408
  // const numbers = '0123456789';
package/src/node/fs.ts CHANGED
@@ -75,7 +75,7 @@ export async function getExtraReturnLogic(tree = false) {
75
75
  return null;
76
76
  }
77
77
 
78
- const elementInfosScriptContent = `${getElementInfosScriptContent()}midscene_element_inspector.setNodeHashCacheListOnWindow();`;
78
+ const elementInfosScriptContent = `${getElementInfosScriptContent()};`;
79
79
 
80
80
  if (tree) {
81
81
  return `${elementInfosScriptContent}midscene_element_inspector.webExtractNodeTree()`;
@@ -17,7 +17,7 @@ export type Rect = Point & Size & { zoom?: number };
17
17
  export abstract class BaseElement {
18
18
  abstract id: string;
19
19
 
20
- abstract indexId?: number; // markerId for web
20
+ // abstract indexId?: number; // markerId for web
21
21
 
22
22
  abstract attributes: {
23
23
  nodeType: NodeType;
@@ -30,7 +30,7 @@ export abstract class BaseElement {
30
30
 
31
31
  abstract center: [number, number];
32
32
 
33
- abstract xpaths?: string[];
33
+ // abstract xpaths?: string[];
34
34
 
35
35
  abstract isVisible: boolean;
36
36
  }
@@ -45,3 +45,10 @@ export interface ElementTreeNode<
45
45
  export interface WebElementInfo extends ElementInfo {
46
46
  zoom: number;
47
47
  }
48
+
49
+ export type LocateResultElement = {
50
+ center: [number, number];
51
+ rect: Rect;
52
+ id: string;
53
+ isOrderSensitive?: boolean;
54
+ };