@midscene/core 0.0.1 → 0.1.1
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/ai-model.js +4218 -9
- package/dist/es/image.js +28 -14
- package/dist/es/index.js +4364 -151
- package/dist/es/utils.js +20 -11
- package/dist/lib/ai-model.js +4231 -42
- package/dist/lib/image.js +35 -21
- package/dist/lib/index.js +4348 -155
- package/dist/lib/utils.js +21 -11
- package/dist/types/ai-model.d.ts +1 -1
- package/dist/types/image.d.ts +3 -4
- package/dist/types/index.d.ts +15 -5
- package/dist/types/utils.d.ts +9 -3
- package/package.json +5 -1
- package/.eslintignore +0 -3
- package/.eslintrc.js +0 -9
- package/CONTRIBUTING.md +0 -5
- package/demo_data/demo.actions.json +0 -160
- package/demo_data/demo.insight.json +0 -3571
- package/demo_data/index.d.ts +0 -1
- package/demo_data/index.js +0 -6
- package/modern.config.ts +0 -18
- package/third-party-licenses.txt +0 -415
- package/tsconfig.json +0 -22
- package/vitest.config.ts +0 -20
package/dist/es/image.js
CHANGED
|
@@ -75,7 +75,12 @@ function calculateNewDimensions(originalWidth, originalHeight) {
|
|
|
75
75
|
};
|
|
76
76
|
}
|
|
77
77
|
async function trimImage(image) {
|
|
78
|
-
const
|
|
78
|
+
const imgInstance = Sharp2(image);
|
|
79
|
+
const instanceInfo = await imgInstance.metadata();
|
|
80
|
+
if (!instanceInfo.width || instanceInfo.width <= 3 || !instanceInfo.height || instanceInfo.height <= 3) {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
const { info } = await imgInstance.trim().toBuffer({
|
|
79
84
|
resolveWithObject: true
|
|
80
85
|
});
|
|
81
86
|
if (typeof info.trimOffsetLeft === "undefined" || typeof info.trimOffsetTop === "undefined") {
|
|
@@ -88,18 +93,27 @@ async function trimImage(image) {
|
|
|
88
93
|
height: info.height
|
|
89
94
|
};
|
|
90
95
|
}
|
|
91
|
-
async function alignCoordByTrim(image,
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
+
async function alignCoordByTrim(image, centerRect) {
|
|
97
|
+
const imgInfo = await Sharp2(image).metadata();
|
|
98
|
+
if (!(imgInfo == null ? void 0 : imgInfo.width) || !imgInfo.height || imgInfo.width <= 3 || imgInfo.height <= 3) {
|
|
99
|
+
return centerRect;
|
|
100
|
+
}
|
|
101
|
+
try {
|
|
102
|
+
const img = await Sharp2(image).extract(centerRect).toBuffer();
|
|
103
|
+
const trimInfo = await trimImage(img);
|
|
104
|
+
if (!trimInfo) {
|
|
105
|
+
return centerRect;
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
left: centerRect.left - trimInfo.trimOffsetLeft,
|
|
109
|
+
top: centerRect.top - trimInfo.trimOffsetTop,
|
|
110
|
+
width: trimInfo.width,
|
|
111
|
+
height: trimInfo.height
|
|
112
|
+
};
|
|
113
|
+
} catch (e) {
|
|
114
|
+
console.log(imgInfo);
|
|
115
|
+
throw e;
|
|
96
116
|
}
|
|
97
|
-
return {
|
|
98
|
-
left: center.left - trimInfo.trimOffsetLeft,
|
|
99
|
-
top: center.top - trimInfo.trimOffsetTop,
|
|
100
|
-
width: trimInfo.width,
|
|
101
|
-
height: trimInfo.height
|
|
102
|
-
};
|
|
103
117
|
}
|
|
104
118
|
|
|
105
119
|
// src/image/visualization.ts
|
|
@@ -140,8 +154,8 @@ function getTmpDir() {
|
|
|
140
154
|
mkdirSync(path, { recursive: true });
|
|
141
155
|
return path;
|
|
142
156
|
}
|
|
143
|
-
function getTmpFile(
|
|
144
|
-
const filename = `${randomUUID()}.${
|
|
157
|
+
function getTmpFile(fileExtWithoutDot) {
|
|
158
|
+
const filename = `${randomUUID()}.${fileExtWithoutDot}`;
|
|
145
159
|
return join(getTmpDir(), filename);
|
|
146
160
|
}
|
|
147
161
|
|