@midscene/web 0.7.1 → 0.7.2-beta-20241024094141.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/lib/debug.js CHANGED
@@ -26,6 +26,26 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  mod
27
27
  ));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var __async = (__this, __arguments, generator) => {
30
+ return new Promise((resolve, reject) => {
31
+ var fulfilled = (value) => {
32
+ try {
33
+ step(generator.next(value));
34
+ } catch (e) {
35
+ reject(e);
36
+ }
37
+ };
38
+ var rejected = (value) => {
39
+ try {
40
+ step(generator.throw(value));
41
+ } catch (e) {
42
+ reject(e);
43
+ }
44
+ };
45
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
46
+ step((generator = generator.apply(__this, __arguments)).next());
47
+ });
48
+ };
29
49
 
30
50
  // src/debug/index.ts
31
51
  var debug_exports = {};
@@ -44,67 +64,67 @@ var import_constants = require("@midscene/shared/constants");
44
64
 
45
65
  // src/debug/index.ts
46
66
  var import_img = require("@midscene/shared/img");
47
- async function generateExtractData(page, targetDir, saveImgType) {
48
- const file = await page.screenshot();
49
- const screenshotBuffer = (0, import_node_fs.readFileSync)(file);
50
- const inputImgBase64 = screenshotBuffer.toString("base64");
51
- const {
52
- elementsPositionInfo,
53
- captureElementSnapshot,
54
- elementsPositionInfoWithoutText
55
- } = await getElementInfos(page);
56
- const inputImagePath = import_node_path.default.join(targetDir, "input.png");
57
- const outputImagePath = import_node_path.default.join(targetDir, "output.png");
58
- const outputWithoutTextImgPath = import_node_path.default.join(
59
- targetDir,
60
- "output_without_text.png"
61
- );
62
- const resizeOutputImgPath = import_node_path.default.join(targetDir, "resize-output.png");
63
- const snapshotJsonPath = import_node_path.default.join(targetDir, "element-snapshot.json");
64
- const {
65
- compositeElementInfoImgBase64,
66
- compositeElementInfoImgWithoutTextBase64
67
- } = await (0, import_img.processImageElementInfo)({
68
- elementsPositionInfo,
69
- elementsPositionInfoWithoutText,
70
- inputImgBase64
71
- });
72
- const resizeImgBase64 = await (0, import_img.resizeImg)(inputImgBase64);
73
- const existingSnapshot = (0, import_node_fs.existsSync)(snapshotJsonPath) ? JSON.parse((0, import_node_fs.readFileSync)(snapshotJsonPath, "utf-8")) : null;
74
- if (existingSnapshot && JSON.stringify(existingSnapshot) === JSON.stringify(captureElementSnapshot)) {
75
- console.log("skip save snapshot for ", targetDir);
76
- return;
77
- }
78
- if (!(saveImgType == null ? void 0 : saveImgType.disableSnapshot)) {
79
- writeFileSyncWithDir(
80
- snapshotJsonPath,
81
- JSON.stringify(captureElementSnapshot, null, 2)
67
+ function generateExtractData(page, targetDir, saveImgType) {
68
+ return __async(this, null, function* () {
69
+ const inputImgBase64 = yield page.screenshotBase64();
70
+ const {
71
+ elementsPositionInfo,
72
+ captureElementSnapshot,
73
+ elementsPositionInfoWithoutText
74
+ } = yield getElementInfos(page);
75
+ const inputImagePath = import_node_path.default.join(targetDir, "input.png");
76
+ const outputImagePath = import_node_path.default.join(targetDir, "output.png");
77
+ const outputWithoutTextImgPath = import_node_path.default.join(
78
+ targetDir,
79
+ "output_without_text.png"
82
80
  );
83
- }
84
- if (!(saveImgType == null ? void 0 : saveImgType.disableInputImage)) {
85
- await (0, import_img.saveBase64Image)({
86
- base64Data: inputImgBase64,
87
- outputPath: inputImagePath
88
- });
89
- }
90
- if (!(saveImgType == null ? void 0 : saveImgType.disableOutputImage)) {
91
- await (0, import_img.saveBase64Image)({
92
- base64Data: compositeElementInfoImgBase64,
93
- outputPath: outputImagePath
81
+ const resizeOutputImgPath = import_node_path.default.join(targetDir, "resize-output.png");
82
+ const snapshotJsonPath = import_node_path.default.join(targetDir, "element-snapshot.json");
83
+ const {
84
+ compositeElementInfoImgBase64,
85
+ compositeElementInfoImgWithoutTextBase64
86
+ } = yield (0, import_img.processImageElementInfo)({
87
+ elementsPositionInfo,
88
+ elementsPositionInfoWithoutText,
89
+ inputImgBase64
94
90
  });
95
- }
96
- if (!(saveImgType == null ? void 0 : saveImgType.disableOutputWithoutTextImg)) {
97
- await (0, import_img.saveBase64Image)({
98
- base64Data: compositeElementInfoImgWithoutTextBase64,
99
- outputPath: outputWithoutTextImgPath
100
- });
101
- }
102
- if (!(saveImgType == null ? void 0 : saveImgType.disableResizeOutputImg)) {
103
- await (0, import_img.saveBase64Image)({
104
- base64Data: resizeImgBase64,
105
- outputPath: resizeOutputImgPath
106
- });
107
- }
91
+ const resizeImgBase64 = yield (0, import_img.resizeImg)(inputImgBase64);
92
+ const existingSnapshot = (0, import_node_fs.existsSync)(snapshotJsonPath) ? JSON.parse((0, import_node_fs.readFileSync)(snapshotJsonPath, "utf-8")) : null;
93
+ if (existingSnapshot && JSON.stringify(existingSnapshot) === JSON.stringify(captureElementSnapshot)) {
94
+ console.log("skip save snapshot for ", targetDir);
95
+ return;
96
+ }
97
+ if (!(saveImgType == null ? void 0 : saveImgType.disableSnapshot)) {
98
+ writeFileSyncWithDir(
99
+ snapshotJsonPath,
100
+ JSON.stringify(captureElementSnapshot, null, 2)
101
+ );
102
+ }
103
+ if (!(saveImgType == null ? void 0 : saveImgType.disableInputImage)) {
104
+ yield (0, import_img.saveBase64Image)({
105
+ base64Data: inputImgBase64,
106
+ outputPath: inputImagePath
107
+ });
108
+ }
109
+ if (!(saveImgType == null ? void 0 : saveImgType.disableOutputImage)) {
110
+ yield (0, import_img.saveBase64Image)({
111
+ base64Data: compositeElementInfoImgBase64,
112
+ outputPath: outputImagePath
113
+ });
114
+ }
115
+ if (!(saveImgType == null ? void 0 : saveImgType.disableOutputWithoutTextImg)) {
116
+ yield (0, import_img.saveBase64Image)({
117
+ base64Data: compositeElementInfoImgWithoutTextBase64,
118
+ outputPath: outputWithoutTextImgPath
119
+ });
120
+ }
121
+ if (!(saveImgType == null ? void 0 : saveImgType.disableResizeOutputImg)) {
122
+ yield (0, import_img.saveBase64Image)({
123
+ base64Data: resizeImgBase64,
124
+ outputPath: resizeOutputImgPath
125
+ });
126
+ }
127
+ });
108
128
  }
109
129
  function generateTestDataPath(testDataName) {
110
130
  const modulePath = require.resolve("@midscene/core").replace("dist/lib/index.js", "");
@@ -126,21 +146,23 @@ function writeFileSyncWithDir(filePath, content, options = {}) {
126
146
  ensureDirectoryExistence(filePath);
127
147
  (0, import_node_fs.writeFileSync)(filePath, content, options);
128
148
  }
129
- async function getElementInfos(page) {
130
- const captureElementSnapshot = await page.getElementInfos();
131
- const elementsPositionInfoWithoutText = captureElementSnapshot.filter(
132
- (elementInfo) => {
133
- if (elementInfo.attributes.nodeType === import_constants.NodeType.TEXT) {
134
- return false;
149
+ function getElementInfos(page) {
150
+ return __async(this, null, function* () {
151
+ const captureElementSnapshot = yield page.getElementInfos();
152
+ const elementsPositionInfoWithoutText = captureElementSnapshot.filter(
153
+ (elementInfo) => {
154
+ if (elementInfo.attributes.nodeType === import_constants.NodeType.TEXT) {
155
+ return false;
156
+ }
157
+ return true;
135
158
  }
136
- return true;
137
- }
138
- );
139
- return {
140
- elementsPositionInfo: captureElementSnapshot,
141
- captureElementSnapshot,
142
- elementsPositionInfoWithoutText
143
- };
159
+ );
160
+ return {
161
+ elementsPositionInfo: captureElementSnapshot,
162
+ captureElementSnapshot,
163
+ elementsPositionInfoWithoutText
164
+ };
165
+ });
144
166
  }
145
167
  // Annotate the CommonJS export names for ESM import in node:
146
168
  0 && (module.exports = {