@rpascene/shared 0.30.12 → 0.30.14
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/constants/index.mjs +73 -27
- package/dist/es/extractor/web-extractor.mjs +4 -39
- package/dist/es/node/fs.mjs +1 -1
- package/dist/lib/constants/index.js +79 -27
- package/dist/lib/extractor/web-extractor.js +4 -39
- package/dist/lib/node/fs.js +1 -1
- package/dist/types/constants/index.d.ts +34 -0
- package/dist/types/extractor/web-extractor.d.ts +1 -1
- package/package.json +1 -1
- package/src/constants/index.ts +77 -26
- package/src/extractor/web-extractor.ts +15 -48
|
@@ -21,54 +21,100 @@ const DEFAULT_WAIT_FOR_NAVIGATION_TIMEOUT = 5000;
|
|
|
21
21
|
const DEFAULT_WAIT_FOR_NETWORK_IDLE_TIMEOUT = 2000;
|
|
22
22
|
const DEFAULT_WAIT_FOR_NETWORK_IDLE_TIME = 300;
|
|
23
23
|
const DEFAULT_WAIT_FOR_NETWORK_IDLE_CONCURRENCY = 2;
|
|
24
|
+
const rpasceneCommand = {
|
|
25
|
+
Tap: "Tap",
|
|
26
|
+
RightClick: "RightClick",
|
|
27
|
+
DoubleClick: "DoubleClick",
|
|
28
|
+
Hover: "Hover",
|
|
29
|
+
Input: "Input",
|
|
30
|
+
KeyboardPress: "KeyboardPress",
|
|
31
|
+
Scroll: "Scroll",
|
|
32
|
+
DragAndDrop: "DragAndDrop",
|
|
33
|
+
ClearInput: "ClearInput",
|
|
34
|
+
Sleep: "Sleep",
|
|
35
|
+
LongPress: "LongPress",
|
|
36
|
+
Swipe: "Swipe",
|
|
37
|
+
Reload: "Reload",
|
|
38
|
+
GoBack: "GoBack",
|
|
39
|
+
Navigate: 'Navigate'
|
|
40
|
+
};
|
|
41
|
+
const rpastudioCommand = {
|
|
42
|
+
SeleniumClickCommand: "SeleniumClickCommand",
|
|
43
|
+
SeleniumRightClickCommand: "SeleniumRightClickCommand",
|
|
44
|
+
SeleniumDoubleClickCommand: "SeleniumDoubleClickCommand",
|
|
45
|
+
SeleniumMouseHoverCommand: "SeleniumMouseHoverCommand",
|
|
46
|
+
SeleniumSetValueCommand: "SeleniumSetValueCommand",
|
|
47
|
+
SeleniumElementSendKeysCommand: "SeleniumElementSendKeysCommand",
|
|
48
|
+
SeleniumSendKeysCommand: "SeleniumSendKeysCommand",
|
|
49
|
+
SeleniumElementScrollCommand: 'SeleniumElementScrollCommand',
|
|
50
|
+
SeleniumWindowScrollCommand: 'SeleniumWindowScrollCommand',
|
|
51
|
+
SeleniumDragAndDropCommand: 'SeleniumDragAndDropCommand',
|
|
52
|
+
SeleniumClearValueCommand: "SeleniumClearValueCommand",
|
|
53
|
+
PauseCommand: "PauseCommand",
|
|
54
|
+
SeleniumBrowserRefreshCommand: "SeleniumBrowserRefreshCommand",
|
|
55
|
+
SeleniumBrowserNavigateBackCommand: 'SeleniumBrowserNavigateBackCommand',
|
|
56
|
+
SeleniumBrowserNavigateCommand: 'SeleniumBrowserNavigateCommand'
|
|
57
|
+
};
|
|
24
58
|
const commandMap = {
|
|
25
|
-
Tap: {
|
|
26
|
-
CommandName:
|
|
59
|
+
[rpasceneCommand.Tap]: {
|
|
60
|
+
CommandName: rpastudioCommand.SeleniumClickCommand,
|
|
27
61
|
DisplayName: "\u5143\u7D20\u70B9\u51FB"
|
|
28
62
|
},
|
|
29
|
-
RightClick: {
|
|
30
|
-
CommandName:
|
|
63
|
+
[rpasceneCommand.RightClick]: {
|
|
64
|
+
CommandName: rpastudioCommand.SeleniumRightClickCommand,
|
|
31
65
|
DisplayName: "\u5143\u7D20\u53F3\u952E\u70B9\u51FB"
|
|
32
66
|
},
|
|
33
|
-
DoubleClick: {
|
|
34
|
-
CommandName:
|
|
67
|
+
[rpasceneCommand.DoubleClick]: {
|
|
68
|
+
CommandName: rpastudioCommand.SeleniumDoubleClickCommand,
|
|
35
69
|
DisplayName: "\u5143\u7D20\u53CC\u51FB"
|
|
36
70
|
},
|
|
37
|
-
Hover: {
|
|
38
|
-
CommandName:
|
|
71
|
+
[rpasceneCommand.Hover]: {
|
|
72
|
+
CommandName: rpastudioCommand.SeleniumMouseHoverCommand,
|
|
39
73
|
DisplayName: "\u9F20\u6807\u60AC\u505C"
|
|
40
74
|
},
|
|
41
|
-
Input: {
|
|
42
|
-
CommandName:
|
|
75
|
+
[rpasceneCommand.Input]: {
|
|
76
|
+
CommandName: rpastudioCommand.SeleniumSetValueCommand,
|
|
43
77
|
DisplayName: "\u8BBE\u7F6E\u6587\u672C"
|
|
44
78
|
},
|
|
45
|
-
KeyboardPress: {
|
|
46
|
-
CommandName:
|
|
79
|
+
[rpasceneCommand.KeyboardPress]: {
|
|
80
|
+
CommandName: rpastudioCommand.SeleniumElementSendKeysCommand,
|
|
47
81
|
DisplayName: "\u6A21\u62DF\u6309\u952E"
|
|
48
82
|
},
|
|
49
|
-
Scroll: {
|
|
50
|
-
CommandName:
|
|
83
|
+
[rpasceneCommand.Scroll]: {
|
|
84
|
+
CommandName: rpastudioCommand.SeleniumElementScrollCommand,
|
|
51
85
|
DisplayName: "\u5143\u7D20\u6EDA\u52A8"
|
|
52
86
|
},
|
|
53
|
-
DragAndDrop: {
|
|
54
|
-
CommandName:
|
|
87
|
+
[rpasceneCommand.DragAndDrop]: {
|
|
88
|
+
CommandName: rpastudioCommand.SeleniumDragAndDropCommand,
|
|
55
89
|
DisplayName: "\u5143\u7D20\u62D6\u62FD\uFF08\u81F3\u6307\u5B9A\u5143\u7D20\uFF09"
|
|
56
90
|
},
|
|
57
|
-
ClearInput: {
|
|
58
|
-
CommandName:
|
|
91
|
+
[rpasceneCommand.ClearInput]: {
|
|
92
|
+
CommandName: rpastudioCommand.SeleniumClearValueCommand,
|
|
59
93
|
DisplayName: "\u6E05\u7A7A\u6587\u672C"
|
|
60
94
|
},
|
|
61
|
-
Sleep: {
|
|
62
|
-
CommandName:
|
|
95
|
+
[rpasceneCommand.Sleep]: {
|
|
96
|
+
CommandName: rpastudioCommand.PauseCommand,
|
|
63
97
|
DisplayName: "\u6682\u505C\u811A\u672C"
|
|
64
98
|
},
|
|
65
|
-
LongPress: {
|
|
66
|
-
CommandName: "
|
|
67
|
-
DisplayName: "
|
|
99
|
+
[rpasceneCommand.LongPress]: {
|
|
100
|
+
CommandName: "",
|
|
101
|
+
DisplayName: ""
|
|
68
102
|
},
|
|
69
|
-
Swipe: {
|
|
70
|
-
CommandName: "
|
|
71
|
-
DisplayName: "
|
|
103
|
+
[rpasceneCommand.Swipe]: {
|
|
104
|
+
CommandName: "",
|
|
105
|
+
DisplayName: ""
|
|
106
|
+
},
|
|
107
|
+
[rpasceneCommand.Reload]: {
|
|
108
|
+
CommandName: rpastudioCommand.SeleniumBrowserRefreshCommand,
|
|
109
|
+
DisplayName: "\u5237\u65B0"
|
|
110
|
+
},
|
|
111
|
+
[rpasceneCommand.GoBack]: {
|
|
112
|
+
CommandName: rpastudioCommand.SeleniumBrowserNavigateBackCommand,
|
|
113
|
+
DisplayName: "\u540E\u9000"
|
|
114
|
+
},
|
|
115
|
+
[rpasceneCommand.Navigate]: {
|
|
116
|
+
CommandName: rpastudioCommand.SeleniumBrowserNavigateCommand,
|
|
117
|
+
DisplayName: "\u6253\u5F00\u9875\u9762"
|
|
72
118
|
}
|
|
73
119
|
};
|
|
74
|
-
export { CONTAINER_MINI_HEIGHT, CONTAINER_MINI_WIDTH, DEFAULT_WAIT_FOR_NAVIGATION_TIMEOUT, DEFAULT_WAIT_FOR_NETWORK_IDLE_CONCURRENCY, DEFAULT_WAIT_FOR_NETWORK_IDLE_TIME, DEFAULT_WAIT_FOR_NETWORK_IDLE_TIMEOUT, DEFAULT_WDA_PORT, constants_NodeType as NodeType, PLAYGROUND_SERVER_PORT, PLAYWRIGHT_EXAMPLE_CODE, SCRCPY_SERVER_PORT, TEXT_MAX_SIZE, TEXT_SIZE_THRESHOLD, WEBDRIVER_ELEMENT_ID_KEY, YAML_EXAMPLE_CODE, commandMap };
|
|
120
|
+
export { CONTAINER_MINI_HEIGHT, CONTAINER_MINI_WIDTH, DEFAULT_WAIT_FOR_NAVIGATION_TIMEOUT, DEFAULT_WAIT_FOR_NETWORK_IDLE_CONCURRENCY, DEFAULT_WAIT_FOR_NETWORK_IDLE_TIME, DEFAULT_WAIT_FOR_NETWORK_IDLE_TIMEOUT, DEFAULT_WDA_PORT, constants_NodeType as NodeType, PLAYGROUND_SERVER_PORT, PLAYWRIGHT_EXAMPLE_CODE, SCRCPY_SERVER_PORT, TEXT_MAX_SIZE, TEXT_SIZE_THRESHOLD, WEBDRIVER_ELEMENT_ID_KEY, YAML_EXAMPLE_CODE, commandMap, rpasceneCommand, rpastudioCommand };
|
|
@@ -220,12 +220,9 @@ async function extractTreeNodeAsString(initNode, visibleOnly = false, debugMode
|
|
|
220
220
|
async function extractTreeNode(initNode, debugMode = false, basePoint = {
|
|
221
221
|
left: 0,
|
|
222
222
|
top: 0
|
|
223
|
-
}, baseZoom = 1
|
|
223
|
+
}, baseZoom = 1) {
|
|
224
224
|
setDebugMode(debugMode);
|
|
225
225
|
indexId = 0;
|
|
226
|
-
let containerPathClone = [
|
|
227
|
-
...containerPaths
|
|
228
|
-
];
|
|
229
226
|
const topDocument = getTopDocument();
|
|
230
227
|
const startNode = initNode || topDocument;
|
|
231
228
|
const topChildren = [];
|
|
@@ -236,11 +233,6 @@ async function extractTreeNode(initNode, debugMode = false, basePoint = {
|
|
|
236
233
|
if (!node) return null;
|
|
237
234
|
if (node.nodeType && 10 === node.nodeType) return null;
|
|
238
235
|
const elementInfo = collectElementInfo(node, currentWindow, currentDocument, baseZoom, basePoint, false);
|
|
239
|
-
if (elementInfo) {
|
|
240
|
-
const allPaths = getLocators(node);
|
|
241
|
-
elementInfo.allPaths = allPaths;
|
|
242
|
-
elementInfo.containerPaths = containerPathClone;
|
|
243
|
-
}
|
|
244
236
|
if (node instanceof currentWindow.HTMLIFrameElement) {
|
|
245
237
|
if (node.contentWindow && node.contentWindow) return null;
|
|
246
238
|
}
|
|
@@ -262,20 +254,6 @@ async function extractTreeNode(initNode, debugMode = false, basePoint = {
|
|
|
262
254
|
}
|
|
263
255
|
return nodeInfo;
|
|
264
256
|
}
|
|
265
|
-
function getCssScale(ele) {
|
|
266
|
-
try {
|
|
267
|
-
const { width, height } = ele.getBoundingClientRect();
|
|
268
|
-
return {
|
|
269
|
-
cssScaleX: Number((width / ele.offsetWidth).toFixed(1)),
|
|
270
|
-
cssScaleY: Number((height / ele.offsetHeight).toFixed(1))
|
|
271
|
-
};
|
|
272
|
-
} catch (error) {
|
|
273
|
-
return {
|
|
274
|
-
cssScaleX: 1,
|
|
275
|
-
cssScaleY: 1
|
|
276
|
-
};
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
257
|
const rootNodeInfo = dfs(startNode, window, document, baseZoom, basePoint);
|
|
280
258
|
if (Array.isArray(rootNodeInfo)) topChildren.push(...rootNodeInfo);
|
|
281
259
|
else if (rootNodeInfo) topChildren.push(rootNodeInfo);
|
|
@@ -284,19 +262,7 @@ async function extractTreeNode(initNode, debugMode = false, basePoint = {
|
|
|
284
262
|
for(let i = 0; i < iframes.length; i++){
|
|
285
263
|
const iframe = iframes[i];
|
|
286
264
|
const iframeInfo = collectElementInfo(iframe, window, document, 1);
|
|
287
|
-
|
|
288
|
-
const containerPath = getContainerPath(iframe);
|
|
289
|
-
containerPathClone = containerPathClone.concat(containerPath);
|
|
290
|
-
if (iframeInfo) if (iframe.contentDocument && iframe.contentWindow) {
|
|
291
|
-
console.log("iframe\u540C\u57DF");
|
|
292
|
-
const iframeChildren = dfs(iframe.contentDocument.body, iframe.contentWindow, iframe.contentDocument, baseZoom, {
|
|
293
|
-
left: iframeInfo.rect.left,
|
|
294
|
-
top: iframeInfo.rect.top
|
|
295
|
-
});
|
|
296
|
-
if (Array.isArray(iframeChildren)) topChildren.push(...iframeChildren);
|
|
297
|
-
else if (iframeChildren) topChildren.push(iframeChildren);
|
|
298
|
-
} else {
|
|
299
|
-
console.log(iframeInfo, "iframe\u8DE8\u57DF\u4E86");
|
|
265
|
+
if (iframeInfo) {
|
|
300
266
|
const iframeChildren = await postWindowMessage(iframe.contentWindow, window, {
|
|
301
267
|
action: 'extractTreeNode',
|
|
302
268
|
data: {
|
|
@@ -304,8 +270,7 @@ async function extractTreeNode(initNode, debugMode = false, basePoint = {
|
|
|
304
270
|
left: iframeInfo.rect.left,
|
|
305
271
|
top: iframeInfo.rect.top
|
|
306
272
|
},
|
|
307
|
-
baseZoom
|
|
308
|
-
containerPaths: containerPathClone
|
|
273
|
+
baseZoom
|
|
309
274
|
}
|
|
310
275
|
});
|
|
311
276
|
if (Array.isArray(iframeChildren)) topChildren.push(...iframeChildren);
|
|
@@ -351,7 +316,7 @@ function mergeElementAndChildrenRects(node, currentWindow, currentDocument, base
|
|
|
351
316
|
}
|
|
352
317
|
if ('undefined' != typeof window) onWindowMessage(window, async ({ action, data }, { source })=>{
|
|
353
318
|
if ('extractTreeNode' === action) try {
|
|
354
|
-
return await extractTreeNode(document.body, false, data.basePoint, data.baseZoom
|
|
319
|
+
return await extractTreeNode(document.body, false, data.basePoint, data.baseZoom);
|
|
355
320
|
} catch (error) {
|
|
356
321
|
return {
|
|
357
322
|
error: 'error message'
|