@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.
- package/dist/es/extractor/dom-util.mjs +7 -9
- package/dist/es/extractor/index.mjs +1 -2
- package/dist/es/extractor/tree.mjs +1 -3
- package/dist/es/extractor/util.mjs +1 -25
- package/dist/es/node/fs.mjs +2 -2
- package/dist/lib/extractor/dom-util.js +7 -9
- package/dist/lib/extractor/index.js +7 -14
- package/dist/lib/extractor/tree.js +1 -3
- package/dist/lib/extractor/util.js +0 -33
- package/dist/lib/node/fs.js +2 -2
- package/dist/types/env/types.d.ts +3 -18
- package/dist/types/extractor/dom-util.d.ts +2 -15
- package/dist/types/extractor/index.d.ts +0 -1
- package/dist/types/extractor/tree.d.ts +1 -4
- package/dist/types/extractor/util.d.ts +0 -3
- package/dist/types/types/index.d.ts +6 -2
- package/package.json +1 -1
- package/src/env/types.ts +6 -18
- package/src/extractor/dom-util.ts +12 -8
- package/src/extractor/index.ts +0 -2
- package/src/extractor/locator.ts +0 -1
- package/src/extractor/tree.ts +4 -4
- package/src/extractor/util.ts +0 -32
- package/src/node/fs.ts +1 -1
- package/src/types/index.ts +9 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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: {
|
|
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 -
|
|
138
|
-
top: Math.max(position.y -
|
|
139
|
-
width:
|
|
140
|
-
height:
|
|
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;
|
package/src/extractor/index.ts
CHANGED
|
@@ -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,
|
package/src/extractor/locator.ts
CHANGED
|
@@ -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
|
|
package/src/extractor/tree.ts
CHANGED
|
@@ -45,7 +45,7 @@ export function trimAttributes(
|
|
|
45
45
|
res[currentKey] = truncateText(attributeVal, truncateTextLength);
|
|
46
46
|
return res;
|
|
47
47
|
},
|
|
48
|
-
{} as
|
|
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}" ${
|
|
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}>`;
|
package/src/extractor/util.ts
CHANGED
|
@@ -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()}
|
|
78
|
+
const elementInfosScriptContent = `${getElementInfosScriptContent()};`;
|
|
79
79
|
|
|
80
80
|
if (tree) {
|
|
81
81
|
return `${elementInfosScriptContent}midscene_element_inspector.webExtractNodeTree()`;
|
package/src/types/index.ts
CHANGED
|
@@ -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
|
+
};
|