@midscene/shared 0.16.9-beta-20250508125518.0 → 0.16.9
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/common.js +2 -0
- package/dist/es/env.d.ts +3 -1
- package/dist/es/env.js +3 -0
- package/dist/es/extractor-debug.js +16 -21
- package/dist/es/extractor.d.ts +47 -2
- package/dist/es/extractor.js +168 -104
- package/dist/es/fs.d.ts +1 -2
- package/dist/es/fs.js +4 -9
- package/dist/es/img.d.ts +1 -1
- package/dist/es/index-305e7a7e.d.ts +32 -0
- package/dist/es/logger.js +2 -0
- package/dist/lib/common.js +2 -0
- package/dist/lib/env.d.ts +3 -1
- package/dist/lib/env.js +4 -0
- package/dist/lib/extractor-debug.js +16 -21
- package/dist/lib/extractor.d.ts +47 -2
- package/dist/lib/extractor.js +169 -107
- package/dist/lib/fs.d.ts +1 -2
- package/dist/lib/fs.js +4 -10
- package/dist/lib/img.d.ts +1 -1
- package/dist/lib/index-305e7a7e.d.ts +32 -0
- package/dist/lib/logger.js +2 -0
- package/dist/script/htmlElement.js +166 -101
- package/dist/script/htmlElementDebug.js +16 -21
- package/dist/types/env.d.ts +3 -1
- package/dist/types/extractor.d.ts +47 -2
- package/dist/types/fs.d.ts +1 -2
- package/dist/types/img.d.ts +1 -1
- package/dist/types/index-305e7a7e.d.ts +32 -0
- package/package.json +2 -6
- package/src/env.ts +3 -0
- package/src/extractor/client-extractor.ts +211 -0
- package/src/extractor/index.ts +3 -5
- package/src/extractor/util.ts +2 -31
- package/src/extractor/web-extractor.ts +19 -2
- package/src/node/fs.ts +4 -12
- package/src/types/index.ts +0 -5
- package/dist/es/index-df4e781b.d.ts +0 -77
- package/dist/es/types.d.ts +0 -2
- package/dist/es/types.js +0 -6
- package/dist/lib/index-df4e781b.d.ts +0 -77
- package/dist/lib/types.d.ts +0 -2
- package/dist/lib/types.js +0 -31
- package/dist/types/index-df4e781b.d.ts +0 -77
- package/dist/types/types.d.ts +0 -2
- package/src/extractor/locator.ts +0 -117
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import type { ElementInfo } from './';
|
|
2
|
+
import { NodeType } from './constants';
|
|
3
|
+
import { midsceneGenerateHash } from './util';
|
|
4
|
+
|
|
5
|
+
// Definition of NodeDescriptor interface
|
|
6
|
+
interface NodeDescriptor {
|
|
7
|
+
node: globalThis.Node;
|
|
8
|
+
children: NodeDescriptor[];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// Retrieve attributes from a node
|
|
12
|
+
function getNodeAttributes(node: globalThis.Node): { [key: string]: string } {
|
|
13
|
+
const attrs: { [key: string]: string } = {};
|
|
14
|
+
|
|
15
|
+
// Check if node exists and its type is ELEMENT_NODE
|
|
16
|
+
if (node && node.nodeType === 1) {
|
|
17
|
+
const element = node as globalThis.Element;
|
|
18
|
+
|
|
19
|
+
for (let i = 0; i < element.attributes.length; i++) {
|
|
20
|
+
const attr = element.attributes[i];
|
|
21
|
+
attrs[attr.nodeName] = attr.nodeValue ?? '';
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return attrs;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Retrieve rectangle information
|
|
29
|
+
function getRect(attributes: { [key: string]: string }): {
|
|
30
|
+
left: number;
|
|
31
|
+
top: number;
|
|
32
|
+
width: number;
|
|
33
|
+
height: number;
|
|
34
|
+
} {
|
|
35
|
+
const x = Math.round(Number.parseFloat(attributes.x ?? '0'));
|
|
36
|
+
const y = Math.round(Number.parseFloat(attributes.y ?? '0'));
|
|
37
|
+
const width = Math.round(Number.parseFloat(attributes.width ?? '0'));
|
|
38
|
+
const height = Math.round(Number.parseFloat(attributes.height ?? '0'));
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
left: Math.max(0, Math.floor(x)),
|
|
42
|
+
top: Math.max(0, Math.floor(y)),
|
|
43
|
+
width: Math.max(0, width),
|
|
44
|
+
height: Math.max(0, height),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Validate if the node can provide text content
|
|
49
|
+
function validTextNodeContent(node: Node): string {
|
|
50
|
+
if (node.nodeType === 3) {
|
|
51
|
+
return node.nodeValue?.trim() || '';
|
|
52
|
+
}
|
|
53
|
+
return '';
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function getXPathForElement(element: Node): string {
|
|
57
|
+
if (element.nodeType !== 1) {
|
|
58
|
+
return '';
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const getIndex = (sib: Node, name: string) => {
|
|
62
|
+
let count = 1;
|
|
63
|
+
for (let cur = sib.previousSibling; cur; cur = cur.previousSibling) {
|
|
64
|
+
if (cur.nodeType === 1 && cur.nodeName === name) {
|
|
65
|
+
count++;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return count;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const buildAttributePart = (elem: Element): string => {
|
|
72
|
+
const attributes = ['id', 'resource-id', 'content-desc', 'class'];
|
|
73
|
+
for (const attr of attributes) {
|
|
74
|
+
if (elem.hasAttribute(attr)) {
|
|
75
|
+
const value = elem.getAttribute(attr);
|
|
76
|
+
if (value && value.trim() !== '') {
|
|
77
|
+
return `[@${attr}="${value}"]`;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return '';
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const getPath = (node: Node, path = ''): string => {
|
|
85
|
+
if (node.parentNode) {
|
|
86
|
+
path = getPath(node.parentNode, path);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (node.nodeType === 1) {
|
|
90
|
+
const elem = node as Element;
|
|
91
|
+
const tagName = elem.nodeName.toLowerCase();
|
|
92
|
+
let part = `/${tagName}`;
|
|
93
|
+
|
|
94
|
+
const attributePart = buildAttributePart(elem);
|
|
95
|
+
|
|
96
|
+
// 如果找到有意义的属性,则添加属性部分
|
|
97
|
+
if (attributePart) {
|
|
98
|
+
part += attributePart;
|
|
99
|
+
} else {
|
|
100
|
+
// 如果没有有意义的属性,则添加索引
|
|
101
|
+
const index = getIndex(node, node.nodeName);
|
|
102
|
+
if (index > 1) {
|
|
103
|
+
part += `[${index}]`;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
path += part;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return path;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
return getPath(element);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Perform DFS traversal and collect element information
|
|
117
|
+
export function extractTextWithPosition(
|
|
118
|
+
initNode: globalThis.Document,
|
|
119
|
+
): ElementInfo[] {
|
|
120
|
+
const elementInfoArray: ElementInfo[] = [];
|
|
121
|
+
let nodeIndex = 1;
|
|
122
|
+
|
|
123
|
+
function dfs(node: Node, parentNode: NodeDescriptor | null = null): void {
|
|
124
|
+
if (!node) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const currentNodeDes: NodeDescriptor = { node, children: [] };
|
|
129
|
+
if (parentNode) {
|
|
130
|
+
parentNode.children.push(currentNodeDes);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
collectElementInfo(node);
|
|
134
|
+
|
|
135
|
+
if (node.childNodes && node.childNodes.length > 0) {
|
|
136
|
+
for (let i = 0; i < node.childNodes.length; i++) {
|
|
137
|
+
dfs(node.childNodes[i], currentNodeDes);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function collectElementInfo(node: Node) {
|
|
143
|
+
const attributes = getNodeAttributes(node);
|
|
144
|
+
const rect = getRect(attributes);
|
|
145
|
+
const nodeHashId = midsceneGenerateHash(null, attributes.placeholder, rect);
|
|
146
|
+
const text = validTextNodeContent(node);
|
|
147
|
+
|
|
148
|
+
let nodeType;
|
|
149
|
+
|
|
150
|
+
switch (node.nodeName.toUpperCase()) {
|
|
151
|
+
case 'TEXT':
|
|
152
|
+
nodeType = NodeType.TEXT;
|
|
153
|
+
break;
|
|
154
|
+
case 'IMAGE':
|
|
155
|
+
nodeType = NodeType.IMG;
|
|
156
|
+
break;
|
|
157
|
+
case 'BUTTON':
|
|
158
|
+
nodeType = NodeType.BUTTON;
|
|
159
|
+
break;
|
|
160
|
+
case 'SEARCHINPUT':
|
|
161
|
+
case 'TEXTINPUT':
|
|
162
|
+
case 'INPUT':
|
|
163
|
+
nodeType = NodeType.FORM_ITEM;
|
|
164
|
+
break;
|
|
165
|
+
case 'NAV':
|
|
166
|
+
case 'LIST':
|
|
167
|
+
case 'CELL':
|
|
168
|
+
nodeType = NodeType.CONTAINER;
|
|
169
|
+
break;
|
|
170
|
+
default:
|
|
171
|
+
if (
|
|
172
|
+
attributes.id === 'android:id/input' ||
|
|
173
|
+
attributes.id === 'android:id/inputArea'
|
|
174
|
+
) {
|
|
175
|
+
nodeType = NodeType.FORM_ITEM;
|
|
176
|
+
} else {
|
|
177
|
+
nodeType = NodeType.CONTAINER;
|
|
178
|
+
}
|
|
179
|
+
break;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const xpath = getXPathForElement(node);
|
|
183
|
+
const elementInfo: ElementInfo = {
|
|
184
|
+
id: nodeHashId,
|
|
185
|
+
indexId: nodeIndex++,
|
|
186
|
+
nodeHashId,
|
|
187
|
+
locator: xpath,
|
|
188
|
+
attributes: {
|
|
189
|
+
nodeType,
|
|
190
|
+
...attributes,
|
|
191
|
+
},
|
|
192
|
+
content: text,
|
|
193
|
+
rect,
|
|
194
|
+
center: [
|
|
195
|
+
Math.round(rect.left + rect.width / 2),
|
|
196
|
+
Math.round(rect.top + rect.height / 2),
|
|
197
|
+
],
|
|
198
|
+
nodeType,
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
if (elementInfo.nodeType !== NodeType.CONTAINER) {
|
|
202
|
+
elementInfoArray.push(elementInfo);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const rootNode = initNode;
|
|
207
|
+
const rootDescriptor: NodeDescriptor = { node: rootNode, children: [] };
|
|
208
|
+
dfs(rootNode, rootDescriptor);
|
|
209
|
+
|
|
210
|
+
return elementInfoArray;
|
|
211
|
+
}
|
package/src/extractor/index.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { NodeType } from '../constants/index';
|
|
2
|
+
|
|
2
3
|
export interface ElementInfo {
|
|
3
4
|
id: string;
|
|
4
5
|
indexId: number;
|
|
5
6
|
nodeHashId: string;
|
|
6
7
|
locator: string;
|
|
7
|
-
xpaths?: string[];
|
|
8
8
|
attributes: {
|
|
9
9
|
nodeType: NodeType;
|
|
10
10
|
[key: string]: string;
|
|
@@ -24,10 +24,8 @@ export { descriptionOfTree, traverseTree, treeToList } from './tree';
|
|
|
24
24
|
|
|
25
25
|
export { extractTextWithPosition as webExtractTextWithPosition } from './web-extractor';
|
|
26
26
|
|
|
27
|
+
export { extractTextWithPosition as clientExtractTextWithPosition } from './client-extractor';
|
|
28
|
+
|
|
27
29
|
export { extractTreeNode as webExtractNodeTree } from './web-extractor';
|
|
28
30
|
|
|
29
31
|
export { extractTreeNodeAsString as webExtractNodeTreeAsString } from './web-extractor';
|
|
30
|
-
|
|
31
|
-
export { setNodeHashCacheListOnWindow } from './util';
|
|
32
|
-
|
|
33
|
-
export { getXpathsById, getElementInfoByNode } from './locator';
|
package/src/extractor/util.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { Rect } from '../types';
|
|
2
1
|
import { generateHashId } from '../utils';
|
|
3
2
|
import { extractTextWithPosition } from './web-extractor';
|
|
4
3
|
|
|
4
|
+
// import { TEXT_MAX_SIZE } from './constants';
|
|
5
5
|
const MAX_VALUE_LENGTH = 300;
|
|
6
6
|
let debugMode = false;
|
|
7
7
|
|
|
@@ -444,43 +444,14 @@ export function getNodeAttributes(
|
|
|
444
444
|
export function midsceneGenerateHash(
|
|
445
445
|
node: globalThis.Node | null,
|
|
446
446
|
content: string,
|
|
447
|
-
rect:
|
|
447
|
+
rect: any,
|
|
448
448
|
): string {
|
|
449
449
|
const slicedHash = generateHashId(rect, content);
|
|
450
450
|
|
|
451
|
-
if (node) {
|
|
452
|
-
if (!(window as any).midsceneNodeHashCacheList) {
|
|
453
|
-
setNodeHashCacheListOnWindow();
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
setNodeToCacheList(node, slicedHash);
|
|
457
|
-
}
|
|
458
|
-
|
|
459
451
|
// Returns the first 10 characters as a short hash
|
|
460
452
|
return slicedHash;
|
|
461
453
|
}
|
|
462
454
|
|
|
463
|
-
export function setNodeHashCacheListOnWindow() {
|
|
464
|
-
if (typeof window !== 'undefined') {
|
|
465
|
-
(window as any).midsceneNodeHashCacheList = [];
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
export function setNodeToCacheList(node: globalThis.Node, id: string) {
|
|
470
|
-
if (typeof window !== 'undefined') {
|
|
471
|
-
(window as any).midsceneNodeHashCacheList.push({ node, id });
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
export function getNodeFromCacheList(id: string) {
|
|
476
|
-
if (typeof window !== 'undefined') {
|
|
477
|
-
return (window as any).midsceneNodeHashCacheList.find(
|
|
478
|
-
(item: { node: Node; id: string }) => item.id === id,
|
|
479
|
-
)?.node;
|
|
480
|
-
}
|
|
481
|
-
return null;
|
|
482
|
-
}
|
|
483
|
-
|
|
484
455
|
export function generateId(numberId: number) {
|
|
485
456
|
// const letters = 'ABCDEFGHIJKLMNPRSTUVXYZ';
|
|
486
457
|
// const numbers = '0123456789';
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import type { ElementInfo } from '.';
|
|
1
2
|
import {
|
|
2
3
|
CONTAINER_MINI_HEIGHT,
|
|
3
4
|
CONTAINER_MINI_WIDTH,
|
|
4
5
|
NodeType,
|
|
5
6
|
} from '../constants/index';
|
|
6
|
-
import type { WebElementInfo } from '../types';
|
|
7
7
|
import type { Point } from '../types';
|
|
8
8
|
import {
|
|
9
9
|
isButtonElement,
|
|
@@ -25,6 +25,12 @@ import {
|
|
|
25
25
|
visibleRect,
|
|
26
26
|
} from './util';
|
|
27
27
|
|
|
28
|
+
interface WebElementInfo extends ElementInfo {
|
|
29
|
+
zoom: number;
|
|
30
|
+
screenWidth?: number;
|
|
31
|
+
screenHeight?: number;
|
|
32
|
+
}
|
|
33
|
+
|
|
28
34
|
let indexId = 0;
|
|
29
35
|
|
|
30
36
|
function tagNameOfNode(node: globalThis.Node): string {
|
|
@@ -41,7 +47,7 @@ function tagNameOfNode(node: globalThis.Node): string {
|
|
|
41
47
|
return tagName ? `<${tagName}>` : '';
|
|
42
48
|
}
|
|
43
49
|
|
|
44
|
-
|
|
50
|
+
function collectElementInfo(
|
|
45
51
|
node: Node,
|
|
46
52
|
currentWindow: typeof window,
|
|
47
53
|
currentDocument: typeof document,
|
|
@@ -109,6 +115,8 @@ export function collectElementInfo(
|
|
|
109
115
|
Math.round(rect.top + rect.height / 2),
|
|
110
116
|
],
|
|
111
117
|
zoom: rect.zoom,
|
|
118
|
+
screenWidth: currentWindow.innerWidth,
|
|
119
|
+
screenHeight: currentWindow.innerHeight,
|
|
112
120
|
};
|
|
113
121
|
return elementInfo;
|
|
114
122
|
}
|
|
@@ -137,6 +145,8 @@ export function collectElementInfo(
|
|
|
137
145
|
Math.round(rect.top + rect.height / 2),
|
|
138
146
|
],
|
|
139
147
|
zoom: rect.zoom,
|
|
148
|
+
screenWidth: currentWindow.innerWidth,
|
|
149
|
+
screenHeight: currentWindow.innerHeight,
|
|
140
150
|
};
|
|
141
151
|
return elementInfo;
|
|
142
152
|
}
|
|
@@ -168,6 +178,8 @@ export function collectElementInfo(
|
|
|
168
178
|
Math.round(rect.top + rect.height / 2),
|
|
169
179
|
],
|
|
170
180
|
zoom: rect.zoom,
|
|
181
|
+
screenWidth: currentWindow.innerWidth,
|
|
182
|
+
screenHeight: currentWindow.innerHeight,
|
|
171
183
|
};
|
|
172
184
|
return elementInfo;
|
|
173
185
|
}
|
|
@@ -199,9 +211,12 @@ export function collectElementInfo(
|
|
|
199
211
|
Math.round(rect.left + rect.width / 2),
|
|
200
212
|
Math.round(rect.top + rect.height / 2),
|
|
201
213
|
],
|
|
214
|
+
// attributes,
|
|
202
215
|
content: text,
|
|
203
216
|
rect,
|
|
204
217
|
zoom: rect.zoom,
|
|
218
|
+
screenWidth: currentWindow.innerWidth,
|
|
219
|
+
screenHeight: currentWindow.innerHeight,
|
|
205
220
|
};
|
|
206
221
|
return elementInfo;
|
|
207
222
|
}
|
|
@@ -229,6 +244,8 @@ export function collectElementInfo(
|
|
|
229
244
|
Math.round(rect.top + rect.height / 2),
|
|
230
245
|
],
|
|
231
246
|
zoom: rect.zoom,
|
|
247
|
+
screenWidth: currentWindow.innerWidth,
|
|
248
|
+
screenHeight: currentWindow.innerHeight,
|
|
232
249
|
};
|
|
233
250
|
return elementInfo;
|
|
234
251
|
}
|
package/src/node/fs.ts
CHANGED
|
@@ -60,24 +60,16 @@ export function findNearestPackageJson(dir: string): string | null {
|
|
|
60
60
|
return findNearestPackageJson(parentDir);
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
export function
|
|
63
|
+
export async function getExtraReturnLogic(tree = false) {
|
|
64
|
+
if (ifInBrowser) {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
64
67
|
// Get __dirname equivalent in Node.js environment
|
|
65
68
|
const currentFilePath = __filename;
|
|
66
69
|
const pathDir = findNearestPackageJson(dirname(currentFilePath));
|
|
67
70
|
assert(pathDir, `can't find pathDir, with ${dirname}`);
|
|
68
71
|
const scriptPath = path.join(pathDir, './dist/script/htmlElement.js');
|
|
69
72
|
const elementInfosScriptContent = readFileSync(scriptPath, 'utf-8');
|
|
70
|
-
|
|
71
|
-
return elementInfosScriptContent;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export async function getExtraReturnLogic(tree = false) {
|
|
75
|
-
if (ifInBrowser) {
|
|
76
|
-
return null;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const elementInfosScriptContent = `${getElementInfosScriptContent()}midscene_element_inspector.setNodeHashCacheListOnWindow();`;
|
|
80
|
-
|
|
81
73
|
if (tree) {
|
|
82
74
|
return `${elementInfosScriptContent}midscene_element_inspector.webExtractNodeTree()`;
|
|
83
75
|
}
|
package/src/types/index.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { NodeType } from '../constants';
|
|
2
|
-
import type { ElementInfo } from '../extractor';
|
|
3
2
|
|
|
4
3
|
export interface Point {
|
|
5
4
|
left: number;
|
|
@@ -39,7 +38,3 @@ export interface ElementTreeNode<
|
|
|
39
38
|
node: ElementType | null;
|
|
40
39
|
children: ElementTreeNode<ElementType>[];
|
|
41
40
|
}
|
|
42
|
-
|
|
43
|
-
export interface WebElementInfo extends ElementInfo {
|
|
44
|
-
zoom: number;
|
|
45
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { NodeType } from './constants.js';
|
|
2
|
-
|
|
3
|
-
declare function descriptionOfTree<ElementType extends BaseElement = BaseElement>(tree: ElementTreeNode<ElementType>, truncateTextLength?: number, filterNonTextContent?: boolean): string;
|
|
4
|
-
declare function treeToList<T extends BaseElement>(tree: ElementTreeNode<T>): T[];
|
|
5
|
-
declare function traverseTree<T extends BaseElement, ReturnNodeType extends BaseElement>(tree: ElementTreeNode<T>, onNode: (node: T) => ReturnNodeType): ElementTreeNode<ReturnNodeType>;
|
|
6
|
-
|
|
7
|
-
interface WebElementNode {
|
|
8
|
-
node: WebElementInfo | null;
|
|
9
|
-
children: WebElementNode[];
|
|
10
|
-
}
|
|
11
|
-
declare function extractTextWithPosition(initNode: globalThis.Node, debugMode?: boolean): WebElementInfo[];
|
|
12
|
-
declare function extractTreeNodeAsString(initNode: globalThis.Node, debugMode?: boolean): string;
|
|
13
|
-
declare function extractTreeNode(initNode: globalThis.Node, debugMode?: boolean): WebElementNode;
|
|
14
|
-
|
|
15
|
-
declare function setNodeHashCacheListOnWindow(): void;
|
|
16
|
-
|
|
17
|
-
declare function getXpathsById(id: string): string[] | null;
|
|
18
|
-
declare function getElementInfoByNode(node: Node): ElementInfo | null;
|
|
19
|
-
|
|
20
|
-
interface ElementInfo {
|
|
21
|
-
id: string;
|
|
22
|
-
indexId: number;
|
|
23
|
-
nodeHashId: string;
|
|
24
|
-
locator: string;
|
|
25
|
-
xpaths?: string[];
|
|
26
|
-
attributes: {
|
|
27
|
-
nodeType: NodeType;
|
|
28
|
-
[key: string]: string;
|
|
29
|
-
};
|
|
30
|
-
nodeType: NodeType;
|
|
31
|
-
content: string;
|
|
32
|
-
rect: {
|
|
33
|
-
left: number;
|
|
34
|
-
top: number;
|
|
35
|
-
width: number;
|
|
36
|
-
height: number;
|
|
37
|
-
};
|
|
38
|
-
center: [number, number];
|
|
39
|
-
}
|
|
40
|
-
interface ElementNode {
|
|
41
|
-
node: ElementInfo | null;
|
|
42
|
-
children: ElementNode[];
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
interface Point {
|
|
46
|
-
left: number;
|
|
47
|
-
top: number;
|
|
48
|
-
}
|
|
49
|
-
interface Size {
|
|
50
|
-
width: number;
|
|
51
|
-
height: number;
|
|
52
|
-
dpr?: number;
|
|
53
|
-
}
|
|
54
|
-
type Rect = Point & Size & {
|
|
55
|
-
zoom?: number;
|
|
56
|
-
};
|
|
57
|
-
declare abstract class BaseElement {
|
|
58
|
-
abstract id: string;
|
|
59
|
-
abstract indexId?: number;
|
|
60
|
-
abstract attributes: {
|
|
61
|
-
nodeType: NodeType;
|
|
62
|
-
[key: string]: string;
|
|
63
|
-
};
|
|
64
|
-
abstract content: string;
|
|
65
|
-
abstract rect: Rect;
|
|
66
|
-
abstract center: [number, number];
|
|
67
|
-
abstract locator?: string;
|
|
68
|
-
}
|
|
69
|
-
interface ElementTreeNode<ElementType extends BaseElement = BaseElement> {
|
|
70
|
-
node: ElementType | null;
|
|
71
|
-
children: ElementTreeNode<ElementType>[];
|
|
72
|
-
}
|
|
73
|
-
interface WebElementInfo extends ElementInfo {
|
|
74
|
-
zoom: number;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
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, extractTreeNode as c, descriptionOfTree as d, extractTextWithPosition as e, extractTreeNodeAsString as f, getXpathsById as g, getElementInfoByNode as h, type ElementTreeNode as i, setNodeHashCacheListOnWindow as s, traverseTree as t };
|
package/dist/es/types.d.ts
DELETED
package/dist/es/types.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { NodeType } from './constants.js';
|
|
2
|
-
|
|
3
|
-
declare function descriptionOfTree<ElementType extends BaseElement = BaseElement>(tree: ElementTreeNode<ElementType>, truncateTextLength?: number, filterNonTextContent?: boolean): string;
|
|
4
|
-
declare function treeToList<T extends BaseElement>(tree: ElementTreeNode<T>): T[];
|
|
5
|
-
declare function traverseTree<T extends BaseElement, ReturnNodeType extends BaseElement>(tree: ElementTreeNode<T>, onNode: (node: T) => ReturnNodeType): ElementTreeNode<ReturnNodeType>;
|
|
6
|
-
|
|
7
|
-
interface WebElementNode {
|
|
8
|
-
node: WebElementInfo | null;
|
|
9
|
-
children: WebElementNode[];
|
|
10
|
-
}
|
|
11
|
-
declare function extractTextWithPosition(initNode: globalThis.Node, debugMode?: boolean): WebElementInfo[];
|
|
12
|
-
declare function extractTreeNodeAsString(initNode: globalThis.Node, debugMode?: boolean): string;
|
|
13
|
-
declare function extractTreeNode(initNode: globalThis.Node, debugMode?: boolean): WebElementNode;
|
|
14
|
-
|
|
15
|
-
declare function setNodeHashCacheListOnWindow(): void;
|
|
16
|
-
|
|
17
|
-
declare function getXpathsById(id: string): string[] | null;
|
|
18
|
-
declare function getElementInfoByNode(node: Node): ElementInfo | null;
|
|
19
|
-
|
|
20
|
-
interface ElementInfo {
|
|
21
|
-
id: string;
|
|
22
|
-
indexId: number;
|
|
23
|
-
nodeHashId: string;
|
|
24
|
-
locator: string;
|
|
25
|
-
xpaths?: string[];
|
|
26
|
-
attributes: {
|
|
27
|
-
nodeType: NodeType;
|
|
28
|
-
[key: string]: string;
|
|
29
|
-
};
|
|
30
|
-
nodeType: NodeType;
|
|
31
|
-
content: string;
|
|
32
|
-
rect: {
|
|
33
|
-
left: number;
|
|
34
|
-
top: number;
|
|
35
|
-
width: number;
|
|
36
|
-
height: number;
|
|
37
|
-
};
|
|
38
|
-
center: [number, number];
|
|
39
|
-
}
|
|
40
|
-
interface ElementNode {
|
|
41
|
-
node: ElementInfo | null;
|
|
42
|
-
children: ElementNode[];
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
interface Point {
|
|
46
|
-
left: number;
|
|
47
|
-
top: number;
|
|
48
|
-
}
|
|
49
|
-
interface Size {
|
|
50
|
-
width: number;
|
|
51
|
-
height: number;
|
|
52
|
-
dpr?: number;
|
|
53
|
-
}
|
|
54
|
-
type Rect = Point & Size & {
|
|
55
|
-
zoom?: number;
|
|
56
|
-
};
|
|
57
|
-
declare abstract class BaseElement {
|
|
58
|
-
abstract id: string;
|
|
59
|
-
abstract indexId?: number;
|
|
60
|
-
abstract attributes: {
|
|
61
|
-
nodeType: NodeType;
|
|
62
|
-
[key: string]: string;
|
|
63
|
-
};
|
|
64
|
-
abstract content: string;
|
|
65
|
-
abstract rect: Rect;
|
|
66
|
-
abstract center: [number, number];
|
|
67
|
-
abstract locator?: string;
|
|
68
|
-
}
|
|
69
|
-
interface ElementTreeNode<ElementType extends BaseElement = BaseElement> {
|
|
70
|
-
node: ElementType | null;
|
|
71
|
-
children: ElementTreeNode<ElementType>[];
|
|
72
|
-
}
|
|
73
|
-
interface WebElementInfo extends ElementInfo {
|
|
74
|
-
zoom: number;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
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, extractTreeNode as c, descriptionOfTree as d, extractTextWithPosition as e, extractTreeNodeAsString as f, getXpathsById as g, getElementInfoByNode as h, type ElementTreeNode as i, setNodeHashCacheListOnWindow as s, traverseTree as t };
|
package/dist/lib/types.d.ts
DELETED
package/dist/lib/types.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/types/index.ts
|
|
21
|
-
var types_exports = {};
|
|
22
|
-
__export(types_exports, {
|
|
23
|
-
BaseElement: () => BaseElement
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(types_exports);
|
|
26
|
-
var BaseElement = class {
|
|
27
|
-
};
|
|
28
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
29
|
-
0 && (module.exports = {
|
|
30
|
-
BaseElement
|
|
31
|
-
});
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { NodeType } from './constants.js';
|
|
2
|
-
|
|
3
|
-
declare function descriptionOfTree<ElementType extends BaseElement = BaseElement>(tree: ElementTreeNode<ElementType>, truncateTextLength?: number, filterNonTextContent?: boolean): string;
|
|
4
|
-
declare function treeToList<T extends BaseElement>(tree: ElementTreeNode<T>): T[];
|
|
5
|
-
declare function traverseTree<T extends BaseElement, ReturnNodeType extends BaseElement>(tree: ElementTreeNode<T>, onNode: (node: T) => ReturnNodeType): ElementTreeNode<ReturnNodeType>;
|
|
6
|
-
|
|
7
|
-
interface WebElementNode {
|
|
8
|
-
node: WebElementInfo | null;
|
|
9
|
-
children: WebElementNode[];
|
|
10
|
-
}
|
|
11
|
-
declare function extractTextWithPosition(initNode: globalThis.Node, debugMode?: boolean): WebElementInfo[];
|
|
12
|
-
declare function extractTreeNodeAsString(initNode: globalThis.Node, debugMode?: boolean): string;
|
|
13
|
-
declare function extractTreeNode(initNode: globalThis.Node, debugMode?: boolean): WebElementNode;
|
|
14
|
-
|
|
15
|
-
declare function setNodeHashCacheListOnWindow(): void;
|
|
16
|
-
|
|
17
|
-
declare function getXpathsById(id: string): string[] | null;
|
|
18
|
-
declare function getElementInfoByNode(node: Node): ElementInfo | null;
|
|
19
|
-
|
|
20
|
-
interface ElementInfo {
|
|
21
|
-
id: string;
|
|
22
|
-
indexId: number;
|
|
23
|
-
nodeHashId: string;
|
|
24
|
-
locator: string;
|
|
25
|
-
xpaths?: string[];
|
|
26
|
-
attributes: {
|
|
27
|
-
nodeType: NodeType;
|
|
28
|
-
[key: string]: string;
|
|
29
|
-
};
|
|
30
|
-
nodeType: NodeType;
|
|
31
|
-
content: string;
|
|
32
|
-
rect: {
|
|
33
|
-
left: number;
|
|
34
|
-
top: number;
|
|
35
|
-
width: number;
|
|
36
|
-
height: number;
|
|
37
|
-
};
|
|
38
|
-
center: [number, number];
|
|
39
|
-
}
|
|
40
|
-
interface ElementNode {
|
|
41
|
-
node: ElementInfo | null;
|
|
42
|
-
children: ElementNode[];
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
interface Point {
|
|
46
|
-
left: number;
|
|
47
|
-
top: number;
|
|
48
|
-
}
|
|
49
|
-
interface Size {
|
|
50
|
-
width: number;
|
|
51
|
-
height: number;
|
|
52
|
-
dpr?: number;
|
|
53
|
-
}
|
|
54
|
-
type Rect = Point & Size & {
|
|
55
|
-
zoom?: number;
|
|
56
|
-
};
|
|
57
|
-
declare abstract class BaseElement {
|
|
58
|
-
abstract id: string;
|
|
59
|
-
abstract indexId?: number;
|
|
60
|
-
abstract attributes: {
|
|
61
|
-
nodeType: NodeType;
|
|
62
|
-
[key: string]: string;
|
|
63
|
-
};
|
|
64
|
-
abstract content: string;
|
|
65
|
-
abstract rect: Rect;
|
|
66
|
-
abstract center: [number, number];
|
|
67
|
-
abstract locator?: string;
|
|
68
|
-
}
|
|
69
|
-
interface ElementTreeNode<ElementType extends BaseElement = BaseElement> {
|
|
70
|
-
node: ElementType | null;
|
|
71
|
-
children: ElementTreeNode<ElementType>[];
|
|
72
|
-
}
|
|
73
|
-
interface WebElementInfo extends ElementInfo {
|
|
74
|
-
zoom: number;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
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, extractTreeNode as c, descriptionOfTree as d, extractTextWithPosition as e, extractTreeNodeAsString as f, getXpathsById as g, getElementInfoByNode as h, type ElementTreeNode as i, setNodeHashCacheListOnWindow as s, traverseTree as t };
|
package/dist/types/types.d.ts
DELETED