@xiuchang-midscene/shared 2.0.2 → 2.0.3
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/oss/index.mjs +1 -1
- package/dist/lib/oss/index.js +1 -1
- package/package.json +1 -1
- package/src/oss/index.ts +1 -1
- package/dist/es/baseDB.mjs.bak +0 -109
- package/dist/es/build/copy-static.mjs.bak +0 -31
- package/dist/es/build/rspack-config.mjs.bak +0 -4
- package/dist/es/cli/cli-runner.mjs.bak +0 -140
- package/dist/es/cli/index.mjs.bak +0 -2
- package/dist/es/common.mjs.bak +0 -37
- package/dist/es/constants/example-code.mjs.bak +0 -223
- package/dist/es/constants/index.mjs.bak +0 -23
- package/dist/es/env/basic.mjs.bak +0 -6
- package/dist/es/env/constants.mjs.bak +0 -70
- package/dist/es/env/global-config-manager.mjs.bak +0 -94
- package/dist/es/env/helper.mjs.bak +0 -43
- package/dist/es/env/index.mjs.bak +0 -5
- package/dist/es/env/init-debug.mjs.bak +0 -18
- package/dist/es/env/model-config-manager.mjs.bak +0 -79
- package/dist/es/env/parse-model-config.mjs.bak +0 -132
- package/dist/es/env/types.mjs.bak +0 -220
- package/dist/es/env/utils.mjs.bak +0 -26
- package/dist/es/extractor/constants.mjs.bak +0 -2
- package/dist/es/extractor/debug.mjs.bak +0 -6
- package/dist/es/extractor/dom-util.mjs.bak +0 -92
- package/dist/es/extractor/index.mjs.bak +0 -5
- package/dist/es/extractor/locator.mjs.bak +0 -250
- package/dist/es/extractor/tree.mjs.bak +0 -78
- package/dist/es/extractor/util.mjs.bak +0 -245
- package/dist/es/extractor/web-extractor.mjs.bak +0 -303
- package/dist/es/img/box-select.mjs.bak +0 -824
- package/dist/es/img/canvas-fallback.mjs.bak +0 -238
- package/dist/es/img/get-photon.mjs.bak +0 -45
- package/dist/es/img/get-sharp.mjs.bak +0 -11
- package/dist/es/img/index.mjs.bak +0 -4
- package/dist/es/img/info.mjs.bak +0 -29
- package/dist/es/img/transform.mjs.bak +0 -295
- package/dist/es/index.mjs.bak +0 -4
- package/dist/es/logger.mjs.bak +0 -64
- package/dist/es/mcp/base-server.mjs.bak +0 -281
- package/dist/es/mcp/base-tools.mjs.bak +0 -91
- package/dist/es/mcp/chrome-path.mjs.bak +0 -35
- package/dist/es/mcp/index.mjs.bak +0 -7
- package/dist/es/mcp/inject-report-html-plugin.mjs.bak +0 -53
- package/dist/es/mcp/launcher-helper.mjs.bak +0 -52
- package/dist/es/mcp/tool-generator.mjs.bak +0 -297
- package/dist/es/mcp/types.mjs.bak +0 -3
- package/dist/es/node/fs.mjs.bak +0 -44
- package/dist/es/node/index.mjs.bak +0 -2
- package/dist/es/node/port.mjs.bak +0 -24
- package/dist/es/oss/demo.mjs.bak +0 -30
- package/dist/es/oss/index.mjs.bak +0 -90
- package/dist/es/polyfills/async-hooks.mjs.bak +0 -2
- package/dist/es/polyfills/index.mjs.bak +0 -1
- package/dist/es/types/index.mjs.bak +0 -3
- package/dist/es/us-keyboard-layout.mjs.bak +0 -1414
- package/dist/es/utils.mjs.bak +0 -72
- package/dist/es/zod-schema-utils.mjs.bak +0 -54
- package/dist/lib/baseDB.js.bak +0 -149
- package/dist/lib/build/copy-static.js.bak +0 -79
- package/dist/lib/build/rspack-config.js.bak +0 -38
- package/dist/lib/cli/cli-runner.js.bak +0 -196
- package/dist/lib/cli/index.js.bak +0 -48
- package/dist/lib/common.js.bak +0 -93
- package/dist/lib/constants/example-code.js.bak +0 -260
- package/dist/lib/constants/index.js.bak +0 -96
- package/dist/lib/env/basic.js.bak +0 -40
- package/dist/lib/env/constants.js.bak +0 -113
- package/dist/lib/env/global-config-manager.js.bak +0 -128
- package/dist/lib/env/helper.js.bak +0 -80
- package/dist/lib/env/index.js.bak +0 -90
- package/dist/lib/env/init-debug.js.bak +0 -52
- package/dist/lib/env/model-config-manager.js.bak +0 -113
- package/dist/lib/env/parse-model-config.js.bak +0 -178
- package/dist/lib/env/types.js.bak +0 -554
- package/dist/lib/env/utils.js.bak +0 -72
- package/dist/lib/extractor/constants.js.bak +0 -42
- package/dist/lib/extractor/debug.js.bak +0 -12
- package/dist/lib/extractor/dom-util.js.bak +0 -153
- package/dist/lib/extractor/index.js.bak +0 -81
- package/dist/lib/extractor/locator.js.bak +0 -296
- package/dist/lib/extractor/tree.js.bak +0 -124
- package/dist/lib/extractor/util.js.bak +0 -336
- package/dist/lib/extractor/web-extractor.js.bak +0 -349
- package/dist/lib/img/box-select.js.bak +0 -875
- package/dist/lib/img/canvas-fallback.js.bak +0 -305
- package/dist/lib/img/get-photon.js.bak +0 -82
- package/dist/lib/img/get-sharp.js.bak +0 -45
- package/dist/lib/img/index.js.bak +0 -95
- package/dist/lib/img/info.js.bak +0 -83
- package/dist/lib/img/transform.js.bak +0 -387
- package/dist/lib/index.js.bak +0 -47
- package/dist/lib/logger.js.bak +0 -114
- package/dist/lib/mcp/base-server.js.bak +0 -331
- package/dist/lib/mcp/base-tools.js.bak +0 -125
- package/dist/lib/mcp/chrome-path.js.bak +0 -72
- package/dist/lib/mcp/index.js.bak +0 -100
- package/dist/lib/mcp/inject-report-html-plugin.js.bak +0 -98
- package/dist/lib/mcp/launcher-helper.js.bak +0 -86
- package/dist/lib/mcp/tool-generator.js.bak +0 -334
- package/dist/lib/mcp/types.js.bak +0 -40
- package/dist/lib/node/fs.js.bak +0 -97
- package/dist/lib/node/index.js.bak +0 -65
- package/dist/lib/node/port.js.bak +0 -61
- package/dist/lib/oss/demo.js.bak +0 -36
- package/dist/lib/oss/index.js.bak +0 -138
- package/dist/lib/polyfills/async-hooks.js.bak +0 -36
- package/dist/lib/polyfills/index.js.bak +0 -58
- package/dist/lib/types/index.js.bak +0 -37
- package/dist/lib/us-keyboard-layout.js.bak +0 -1457
- package/dist/lib/utils.js.bak +0 -148
- package/dist/lib/zod-schema-utils.js.bak +0 -97
- package/dist/types/baseDB.d.ts.bak +0 -25
- package/dist/types/build/copy-static.d.ts.bak +0 -31
- package/dist/types/build/rspack-config.d.ts.bak +0 -8
- package/dist/types/cli/cli-runner.d.ts.bak +0 -14
- package/dist/types/cli/index.d.ts.bak +0 -2
- package/dist/types/common.d.ts.bak +0 -12
- package/dist/types/constants/example-code.d.ts.bak +0 -2
- package/dist/types/constants/index.d.ts.bak +0 -21
- package/dist/types/env/basic.d.ts.bak +0 -6
- package/dist/types/env/constants.d.ts.bak +0 -40
- package/dist/types/env/global-config-manager.d.ts.bak +0 -32
- package/dist/types/env/helper.d.ts.bak +0 -4
- package/dist/types/env/index.d.ts.bak +0 -4
- package/dist/types/env/init-debug.d.ts.bak +0 -1
- package/dist/types/env/model-config-manager.d.ts.bak +0 -25
- package/dist/types/env/parse-model-config.d.ts.bak +0 -31
- package/dist/types/env/types.d.ts.bak +0 -318
- package/dist/types/env/utils.d.ts.bak +0 -38
- package/dist/types/extractor/constants.d.ts.bak +0 -1
- package/dist/types/extractor/debug.d.ts.bak +0 -1
- package/dist/types/extractor/dom-util.d.ts.bak +0 -56
- package/dist/types/extractor/index.d.ts.bak +0 -32
- package/dist/types/extractor/locator.d.ts.bak +0 -9
- package/dist/types/extractor/tree.d.ts.bak +0 -6
- package/dist/types/extractor/util.d.ts.bak +0 -47
- package/dist/types/extractor/web-extractor.d.ts.bak +0 -19
- package/dist/types/img/box-select.d.ts.bak +0 -26
- package/dist/types/img/canvas-fallback.d.ts.bak +0 -105
- package/dist/types/img/get-photon.d.ts.bak +0 -19
- package/dist/types/img/get-sharp.d.ts.bak +0 -3
- package/dist/types/img/index.d.ts.bak +0 -3
- package/dist/types/img/info.d.ts.bak +0 -29
- package/dist/types/img/transform.d.ts.bak +0 -107
- package/dist/types/index.d.ts.bak +0 -4
- package/dist/types/logger.d.ts.bak +0 -5
- package/dist/types/mcp/base-server.d.ts.bak +0 -93
- package/dist/types/mcp/base-tools.d.ts.bak +0 -79
- package/dist/types/mcp/chrome-path.d.ts.bak +0 -2
- package/dist/types/mcp/index.d.ts.bak +0 -7
- package/dist/types/mcp/inject-report-html-plugin.d.ts.bak +0 -18
- package/dist/types/mcp/launcher-helper.d.ts.bak +0 -94
- package/dist/types/mcp/tool-generator.d.ts.bak +0 -10
- package/dist/types/mcp/types.d.ts.bak +0 -103
- package/dist/types/node/fs.d.ts.bak +0 -15
- package/dist/types/node/index.d.ts.bak +0 -2
- package/dist/types/node/port.d.ts.bak +0 -8
- package/dist/types/oss/demo.d.ts.bak +0 -1
- package/dist/types/oss/index.d.ts.bak +0 -34
- package/dist/types/polyfills/async-hooks.d.ts.bak +0 -6
- package/dist/types/polyfills/index.d.ts.bak +0 -4
- package/dist/types/types/index.d.ts.bak +0 -34
- package/dist/types/us-keyboard-layout.d.ts.bak +0 -32
- package/dist/types/utils.d.ts.bak +0 -34
- package/dist/types/zod-schema-utils.d.ts.bak +0 -23
|
@@ -1,387 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __webpack_require__ = {};
|
|
3
|
-
(()=>{
|
|
4
|
-
__webpack_require__.n = (module)=>{
|
|
5
|
-
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
6
|
-
__webpack_require__.d(getter, {
|
|
7
|
-
a: getter
|
|
8
|
-
});
|
|
9
|
-
return getter;
|
|
10
|
-
};
|
|
11
|
-
})();
|
|
12
|
-
(()=>{
|
|
13
|
-
__webpack_require__.d = (exports1, definition)=>{
|
|
14
|
-
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
15
|
-
enumerable: true,
|
|
16
|
-
get: definition[key]
|
|
17
|
-
});
|
|
18
|
-
};
|
|
19
|
-
})();
|
|
20
|
-
(()=>{
|
|
21
|
-
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
22
|
-
})();
|
|
23
|
-
(()=>{
|
|
24
|
-
__webpack_require__.r = (exports1)=>{
|
|
25
|
-
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
26
|
-
value: 'Module'
|
|
27
|
-
});
|
|
28
|
-
Object.defineProperty(exports1, '__esModule', {
|
|
29
|
-
value: true
|
|
30
|
-
});
|
|
31
|
-
};
|
|
32
|
-
})();
|
|
33
|
-
var __webpack_exports__ = {};
|
|
34
|
-
__webpack_require__.r(__webpack_exports__);
|
|
35
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
36
|
-
paddingToMatchBlockByBase64: ()=>paddingToMatchBlockByBase64,
|
|
37
|
-
localImg2Base64: ()=>localImg2Base64,
|
|
38
|
-
photonFromBase64: ()=>photonFromBase64,
|
|
39
|
-
httpImg2Base64: ()=>httpImg2Base64,
|
|
40
|
-
parseBase64: ()=>parseBase64,
|
|
41
|
-
resizeAndConvertImgBuffer: ()=>resizeAndConvertImgBuffer,
|
|
42
|
-
resizeImgBase64: ()=>resizeImgBase64,
|
|
43
|
-
saveBase64Image: ()=>saveBase64Image,
|
|
44
|
-
convertToJpegBase64: ()=>convertToJpegBase64,
|
|
45
|
-
preProcessImageUrl: ()=>preProcessImageUrl,
|
|
46
|
-
cropByRect: ()=>cropByRect,
|
|
47
|
-
scaleImage: ()=>scaleImage,
|
|
48
|
-
zoomForGPT4o: ()=>zoomForGPT4o,
|
|
49
|
-
createImgBase64ByFormat: ()=>createImgBase64ByFormat,
|
|
50
|
-
paddingToMatchBlock: ()=>paddingToMatchBlock,
|
|
51
|
-
photonToBase64: ()=>photonToBase64
|
|
52
|
-
});
|
|
53
|
-
const external_node_assert_namespaceObject = require("node:assert");
|
|
54
|
-
var external_node_assert_default = /*#__PURE__*/ __webpack_require__.n(external_node_assert_namespaceObject);
|
|
55
|
-
const external_node_buffer_namespaceObject = require("node:buffer");
|
|
56
|
-
const external_node_fs_namespaceObject = require("node:fs");
|
|
57
|
-
const promises_namespaceObject = require("node:fs/promises");
|
|
58
|
-
const external_node_path_namespaceObject = require("node:path");
|
|
59
|
-
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
60
|
-
const external_logger_js_namespaceObject = require("../logger.js");
|
|
61
|
-
const external_utils_js_namespaceObject = require("../utils.js");
|
|
62
|
-
const external_get_photon_js_namespaceObject = require("./get-photon.js");
|
|
63
|
-
var external_get_photon_js_default = /*#__PURE__*/ __webpack_require__.n(external_get_photon_js_namespaceObject);
|
|
64
|
-
const external_get_sharp_js_namespaceObject = require("./get-sharp.js");
|
|
65
|
-
var external_get_sharp_js_default = /*#__PURE__*/ __webpack_require__.n(external_get_sharp_js_namespaceObject);
|
|
66
|
-
const imgDebug = (0, external_logger_js_namespaceObject.getDebug)('img');
|
|
67
|
-
async function saveBase64Image(options) {
|
|
68
|
-
const { base64Data, outputPath } = options;
|
|
69
|
-
const { body } = parseBase64(base64Data);
|
|
70
|
-
const imageBuffer = external_node_buffer_namespaceObject.Buffer.from(body, 'base64');
|
|
71
|
-
await (0, promises_namespaceObject.writeFile)(outputPath, imageBuffer);
|
|
72
|
-
}
|
|
73
|
-
async function resizeAndConvertImgBuffer(inputFormat, inputData, newSize) {
|
|
74
|
-
if ('string' == typeof inputData) throw Error('inputData is base64, use resizeImgBase64 instead');
|
|
75
|
-
external_node_assert_default()(newSize && newSize.width > 0 && newSize.height > 0, 'newSize must be positive');
|
|
76
|
-
const resizeStartTime = Date.now();
|
|
77
|
-
imgDebug(`resizeImg start, target size: ${newSize.width}x${newSize.height}`);
|
|
78
|
-
if (external_utils_js_namespaceObject.ifInNode) try {
|
|
79
|
-
const Sharp = await external_get_sharp_js_default()();
|
|
80
|
-
const metadata = await Sharp(inputData).metadata();
|
|
81
|
-
const { width: originalWidth, height: originalHeight } = metadata;
|
|
82
|
-
if (!originalWidth || !originalHeight) throw Error('Undefined width or height from the input image.');
|
|
83
|
-
if (newSize.width === originalWidth && newSize.height === originalHeight) return {
|
|
84
|
-
buffer: inputData,
|
|
85
|
-
format: inputFormat
|
|
86
|
-
};
|
|
87
|
-
const resizedBuffer = await Sharp(inputData).resize(newSize.width, newSize.height).jpeg({
|
|
88
|
-
quality: 90
|
|
89
|
-
}).toBuffer();
|
|
90
|
-
const resizeEndTime = Date.now();
|
|
91
|
-
imgDebug(`resizeImg done (Sharp), target size: ${newSize.width}x${newSize.height}, cost: ${resizeEndTime - resizeStartTime}ms`);
|
|
92
|
-
return {
|
|
93
|
-
buffer: resizedBuffer,
|
|
94
|
-
format: 'jpeg'
|
|
95
|
-
};
|
|
96
|
-
} catch (error) {
|
|
97
|
-
imgDebug('Sharp failed, falling back to Photon:', error);
|
|
98
|
-
}
|
|
99
|
-
const { PhotonImage, SamplingFilter, resize } = await external_get_photon_js_default()();
|
|
100
|
-
const inputBytes = new Uint8Array(inputData);
|
|
101
|
-
const bytesliceResult = PhotonImage.new_from_byteslice(inputBytes);
|
|
102
|
-
const inputImage = bytesliceResult instanceof Promise ? await bytesliceResult : bytesliceResult;
|
|
103
|
-
const originalWidth = inputImage.get_width();
|
|
104
|
-
const originalHeight = inputImage.get_height();
|
|
105
|
-
if (!originalWidth || !originalHeight) {
|
|
106
|
-
inputImage.free();
|
|
107
|
-
throw Error('Undefined width or height from the input image.');
|
|
108
|
-
}
|
|
109
|
-
if (newSize.width === originalWidth && newSize.height === originalHeight) {
|
|
110
|
-
inputImage.free();
|
|
111
|
-
return {
|
|
112
|
-
buffer: inputData,
|
|
113
|
-
format: inputFormat
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
const outputImage = resize(inputImage, newSize.width, newSize.height, SamplingFilter.CatmullRom);
|
|
117
|
-
const outputBytes = outputImage.get_bytes_jpeg(90);
|
|
118
|
-
const resizedBuffer = external_node_buffer_namespaceObject.Buffer.from(outputBytes);
|
|
119
|
-
inputImage.free();
|
|
120
|
-
outputImage.free();
|
|
121
|
-
const resizeEndTime = Date.now();
|
|
122
|
-
imgDebug(`resizeImg done (Photon), target size: ${newSize.width}x${newSize.height}, cost: ${resizeEndTime - resizeStartTime}ms`);
|
|
123
|
-
return {
|
|
124
|
-
buffer: resizedBuffer,
|
|
125
|
-
format: 'jpeg'
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
const createImgBase64ByFormat = (format, body)=>`data:image/${format};base64,${body}`;
|
|
129
|
-
async function resizeImgBase64(inputBase64, newSize) {
|
|
130
|
-
const { body, mimeType } = parseBase64(inputBase64);
|
|
131
|
-
const imageBuffer = external_node_buffer_namespaceObject.Buffer.from(body, 'base64');
|
|
132
|
-
const { buffer, format } = await resizeAndConvertImgBuffer(mimeType.split('/')[1], imageBuffer, newSize);
|
|
133
|
-
return createImgBase64ByFormat(format, buffer.toString('base64'));
|
|
134
|
-
}
|
|
135
|
-
function zoomForGPT4o(originalWidth, originalHeight) {
|
|
136
|
-
const maxWidth = 2048;
|
|
137
|
-
const maxHeight = 768;
|
|
138
|
-
let newWidth = originalWidth;
|
|
139
|
-
let newHeight = originalHeight;
|
|
140
|
-
const aspectRatio = originalWidth / originalHeight;
|
|
141
|
-
if (originalWidth > maxWidth) {
|
|
142
|
-
newWidth = maxWidth;
|
|
143
|
-
newHeight = newWidth / aspectRatio;
|
|
144
|
-
}
|
|
145
|
-
if (newHeight > maxHeight) {
|
|
146
|
-
newHeight = maxHeight;
|
|
147
|
-
newWidth = newHeight * aspectRatio;
|
|
148
|
-
}
|
|
149
|
-
return {
|
|
150
|
-
width: Math.round(newWidth),
|
|
151
|
-
height: Math.round(newHeight)
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
async function photonFromBase64(base64) {
|
|
155
|
-
const { PhotonImage } = await external_get_photon_js_default()();
|
|
156
|
-
const { body } = parseBase64(base64);
|
|
157
|
-
const result = PhotonImage.new_from_base64(body);
|
|
158
|
-
return result instanceof Promise ? await result : result;
|
|
159
|
-
}
|
|
160
|
-
async function paddingToMatchBlock(image, blockSize = 28) {
|
|
161
|
-
const width = image.get_width();
|
|
162
|
-
const height = image.get_height();
|
|
163
|
-
const targetWidth = Math.ceil(width / blockSize) * blockSize;
|
|
164
|
-
const targetHeight = Math.ceil(height / blockSize) * blockSize;
|
|
165
|
-
if (targetWidth === width && targetHeight === height) return {
|
|
166
|
-
width,
|
|
167
|
-
height,
|
|
168
|
-
image
|
|
169
|
-
};
|
|
170
|
-
const { padding_right, padding_bottom, Rgba } = await external_get_photon_js_default()();
|
|
171
|
-
const rightPadding = targetWidth - width;
|
|
172
|
-
const bottomPadding = targetHeight - height;
|
|
173
|
-
let result = image;
|
|
174
|
-
if (rightPadding > 0) {
|
|
175
|
-
const white = new Rgba(255, 255, 255, 255);
|
|
176
|
-
result = padding_right(result, rightPadding, white);
|
|
177
|
-
}
|
|
178
|
-
if (bottomPadding > 0) {
|
|
179
|
-
const white = new Rgba(255, 255, 255, 255);
|
|
180
|
-
const previousResult = result;
|
|
181
|
-
result = padding_bottom(previousResult, bottomPadding, white);
|
|
182
|
-
if (previousResult !== image) previousResult.free();
|
|
183
|
-
}
|
|
184
|
-
return {
|
|
185
|
-
width: targetWidth,
|
|
186
|
-
height: targetHeight,
|
|
187
|
-
image: result
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
async function paddingToMatchBlockByBase64(imageBase64, blockSize = 28) {
|
|
191
|
-
const photonImage = await photonFromBase64(imageBase64);
|
|
192
|
-
try {
|
|
193
|
-
const paddedResult = await paddingToMatchBlock(photonImage, blockSize);
|
|
194
|
-
const result = {
|
|
195
|
-
width: paddedResult.width,
|
|
196
|
-
height: paddedResult.height,
|
|
197
|
-
imageBase64: await photonToBase64(paddedResult.image)
|
|
198
|
-
};
|
|
199
|
-
if (paddedResult.image !== photonImage) paddedResult.image.free();
|
|
200
|
-
return result;
|
|
201
|
-
} finally{
|
|
202
|
-
photonImage.free();
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
async function cropByRect(imageBase64, rect, paddingImage) {
|
|
206
|
-
const { crop } = await external_get_photon_js_default()();
|
|
207
|
-
const photonImage = await photonFromBase64(imageBase64);
|
|
208
|
-
const { left, top, width, height } = rect;
|
|
209
|
-
const cropped = crop(photonImage, left, top, left + width, top + height);
|
|
210
|
-
photonImage.free();
|
|
211
|
-
try {
|
|
212
|
-
if (paddingImage) {
|
|
213
|
-
const paddedResult = await paddingToMatchBlock(cropped);
|
|
214
|
-
const result = {
|
|
215
|
-
width: paddedResult.width,
|
|
216
|
-
height: paddedResult.height,
|
|
217
|
-
imageBase64: await photonToBase64(paddedResult.image)
|
|
218
|
-
};
|
|
219
|
-
if (paddedResult.image !== cropped) paddedResult.image.free();
|
|
220
|
-
return result;
|
|
221
|
-
}
|
|
222
|
-
return {
|
|
223
|
-
width: cropped.get_width(),
|
|
224
|
-
height: cropped.get_height(),
|
|
225
|
-
imageBase64: await photonToBase64(cropped)
|
|
226
|
-
};
|
|
227
|
-
} finally{
|
|
228
|
-
cropped.free();
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
async function photonToBase64(image, quality = 90) {
|
|
232
|
-
const bytes = image.get_bytes_jpeg(quality);
|
|
233
|
-
const base64Body = external_node_buffer_namespaceObject.Buffer.from(bytes).toString('base64');
|
|
234
|
-
return `data:image/jpeg;base64,${base64Body}`;
|
|
235
|
-
}
|
|
236
|
-
const httpImg2Base64 = async (url)=>{
|
|
237
|
-
const response = await fetch(url);
|
|
238
|
-
if (!response.ok) throw new Error(`Failed to fetch image: ${url}`);
|
|
239
|
-
const contentType = response.headers.get('content-type');
|
|
240
|
-
if (!contentType) throw new Error(`Failed to fetch image: ${url}`);
|
|
241
|
-
external_node_assert_default()(contentType.startsWith('image/'), `The url ${url} is not a image, because of content-type in header is ${contentType}.`);
|
|
242
|
-
const buffer = external_node_buffer_namespaceObject.Buffer.from(await response.arrayBuffer());
|
|
243
|
-
return `data:${contentType};base64,${buffer.toString('base64')}`;
|
|
244
|
-
};
|
|
245
|
-
const localImg2Base64 = (imgPath, withoutHeader = false)=>{
|
|
246
|
-
const body = (0, external_node_fs_namespaceObject.readFileSync)(imgPath).toString('base64');
|
|
247
|
-
if (withoutHeader) return body;
|
|
248
|
-
const type = external_node_path_default().extname(imgPath).slice(1);
|
|
249
|
-
const finalType = 'svg' === type ? 'svg+xml' : type || 'jpg';
|
|
250
|
-
return `data:image/${finalType};base64,${body}`;
|
|
251
|
-
};
|
|
252
|
-
const preProcessImageUrl = async (url, convertHttpImage2Base64)=>{
|
|
253
|
-
if ('string' != typeof url) throw new Error(`url must be a string, but got ${url} with type ${typeof url}`);
|
|
254
|
-
if (url.startsWith('data:')) return url;
|
|
255
|
-
if (!(url.startsWith('http://') || url.startsWith('https://'))) return await localImg2Base64(url);
|
|
256
|
-
if (!convertHttpImage2Base64) return url;
|
|
257
|
-
return await httpImg2Base64(url);
|
|
258
|
-
};
|
|
259
|
-
const parseBase64 = (fullBase64String)=>{
|
|
260
|
-
try {
|
|
261
|
-
const separator = ';base64,';
|
|
262
|
-
const index = fullBase64String.indexOf(separator);
|
|
263
|
-
if (-1 === index) throw new Error('Invalid base64 string');
|
|
264
|
-
return {
|
|
265
|
-
mimeType: fullBase64String.slice(5, index),
|
|
266
|
-
body: fullBase64String.slice(index + separator.length)
|
|
267
|
-
};
|
|
268
|
-
} catch (e) {
|
|
269
|
-
throw new Error(`parseBase64 fail because intput is not a valid base64 string: ${fullBase64String}`, {
|
|
270
|
-
cause: e
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
};
|
|
274
|
-
async function convertToJpegBase64(inputBase64, quality) {
|
|
275
|
-
const { body } = parseBase64(inputBase64);
|
|
276
|
-
const buffer = external_node_buffer_namespaceObject.Buffer.from(body, 'base64');
|
|
277
|
-
if (external_utils_js_namespaceObject.ifInNode) try {
|
|
278
|
-
const Sharp = await external_get_sharp_js_default()();
|
|
279
|
-
const jpegBuffer = await Sharp(buffer).jpeg({
|
|
280
|
-
quality
|
|
281
|
-
}).toBuffer();
|
|
282
|
-
return `data:image/jpeg;base64,${jpegBuffer.toString('base64')}`;
|
|
283
|
-
} catch (error) {
|
|
284
|
-
imgDebug('Sharp failed for JPEG conversion, falling back to Photon:', error);
|
|
285
|
-
}
|
|
286
|
-
const { PhotonImage } = await external_get_photon_js_default()();
|
|
287
|
-
const inputBytes = new Uint8Array(buffer);
|
|
288
|
-
const bytesliceResult = PhotonImage.new_from_byteslice(inputBytes);
|
|
289
|
-
const inputImage = bytesliceResult instanceof Promise ? await bytesliceResult : bytesliceResult;
|
|
290
|
-
const outputBytes = inputImage.get_bytes_jpeg(quality);
|
|
291
|
-
inputImage.free();
|
|
292
|
-
return `data:image/jpeg;base64,${external_node_buffer_namespaceObject.Buffer.from(outputBytes).toString('base64')}`;
|
|
293
|
-
}
|
|
294
|
-
async function scaleImage(imageBase64, scale) {
|
|
295
|
-
if (scale <= 0) throw new Error('Scale factor must be positive');
|
|
296
|
-
const { body } = parseBase64(imageBase64);
|
|
297
|
-
const buffer = external_node_buffer_namespaceObject.Buffer.from(body, 'base64');
|
|
298
|
-
const scaleStartTime = Date.now();
|
|
299
|
-
imgDebug(`scaleImage start, scale factor: ${scale}`);
|
|
300
|
-
if (external_utils_js_namespaceObject.ifInNode) try {
|
|
301
|
-
const Sharp = await external_get_sharp_js_default()();
|
|
302
|
-
const metadata = await Sharp(buffer).metadata();
|
|
303
|
-
const originalWidth = metadata.width || 0;
|
|
304
|
-
const originalHeight = metadata.height || 0;
|
|
305
|
-
if (0 === originalWidth || 0 === originalHeight) throw new Error('Failed to get image dimensions');
|
|
306
|
-
const newWidth = Math.round(originalWidth * scale);
|
|
307
|
-
const newHeight = Math.round(originalHeight * scale);
|
|
308
|
-
const resizedBuffer = await Sharp(buffer).resize(newWidth, newHeight, {
|
|
309
|
-
kernel: 'lanczos3',
|
|
310
|
-
fit: 'fill'
|
|
311
|
-
}).jpeg({
|
|
312
|
-
quality: 90
|
|
313
|
-
}).toBuffer();
|
|
314
|
-
const scaleEndTime = Date.now();
|
|
315
|
-
imgDebug(`scaleImage done (Sharp): ${originalWidth}x${originalHeight} -> ${newWidth}x${newHeight} (scale=${scale}), cost: ${scaleEndTime - scaleStartTime}ms`);
|
|
316
|
-
const base64 = `data:image/jpeg;base64,${resizedBuffer.toString('base64')}`;
|
|
317
|
-
return {
|
|
318
|
-
width: newWidth,
|
|
319
|
-
height: newHeight,
|
|
320
|
-
imageBase64: base64
|
|
321
|
-
};
|
|
322
|
-
} catch (error) {
|
|
323
|
-
imgDebug('Sharp failed, falling back to Photon:', error);
|
|
324
|
-
}
|
|
325
|
-
const { PhotonImage, SamplingFilter, resize } = await external_get_photon_js_default()();
|
|
326
|
-
const inputBytes = new Uint8Array(buffer);
|
|
327
|
-
const bytesliceResult = PhotonImage.new_from_byteslice(inputBytes);
|
|
328
|
-
const inputImage = bytesliceResult instanceof Promise ? await bytesliceResult : bytesliceResult;
|
|
329
|
-
const originalWidth = inputImage.get_width();
|
|
330
|
-
const originalHeight = inputImage.get_height();
|
|
331
|
-
if (!originalWidth || !originalHeight) {
|
|
332
|
-
inputImage.free();
|
|
333
|
-
throw new Error('Failed to get image dimensions');
|
|
334
|
-
}
|
|
335
|
-
const newWidth = Math.round(originalWidth * scale);
|
|
336
|
-
const newHeight = Math.round(originalHeight * scale);
|
|
337
|
-
const outputImage = resize(inputImage, newWidth, newHeight, SamplingFilter.CatmullRom);
|
|
338
|
-
const outputBytes = outputImage.get_bytes_jpeg(90);
|
|
339
|
-
const resizedBuffer = external_node_buffer_namespaceObject.Buffer.from(outputBytes);
|
|
340
|
-
inputImage.free();
|
|
341
|
-
outputImage.free();
|
|
342
|
-
const scaleEndTime = Date.now();
|
|
343
|
-
imgDebug(`scaleImage done (Photon): ${originalWidth}x${originalHeight} -> ${newWidth}x${newHeight} (scale=${scale}), cost: ${scaleEndTime - scaleStartTime}ms`);
|
|
344
|
-
const base64 = `data:image/jpeg;base64,${resizedBuffer.toString('base64')}`;
|
|
345
|
-
return {
|
|
346
|
-
width: newWidth,
|
|
347
|
-
height: newHeight,
|
|
348
|
-
imageBase64: base64
|
|
349
|
-
};
|
|
350
|
-
}
|
|
351
|
-
exports.convertToJpegBase64 = __webpack_exports__.convertToJpegBase64;
|
|
352
|
-
exports.createImgBase64ByFormat = __webpack_exports__.createImgBase64ByFormat;
|
|
353
|
-
exports.cropByRect = __webpack_exports__.cropByRect;
|
|
354
|
-
exports.httpImg2Base64 = __webpack_exports__.httpImg2Base64;
|
|
355
|
-
exports.localImg2Base64 = __webpack_exports__.localImg2Base64;
|
|
356
|
-
exports.paddingToMatchBlock = __webpack_exports__.paddingToMatchBlock;
|
|
357
|
-
exports.paddingToMatchBlockByBase64 = __webpack_exports__.paddingToMatchBlockByBase64;
|
|
358
|
-
exports.parseBase64 = __webpack_exports__.parseBase64;
|
|
359
|
-
exports.photonFromBase64 = __webpack_exports__.photonFromBase64;
|
|
360
|
-
exports.photonToBase64 = __webpack_exports__.photonToBase64;
|
|
361
|
-
exports.preProcessImageUrl = __webpack_exports__.preProcessImageUrl;
|
|
362
|
-
exports.resizeAndConvertImgBuffer = __webpack_exports__.resizeAndConvertImgBuffer;
|
|
363
|
-
exports.resizeImgBase64 = __webpack_exports__.resizeImgBase64;
|
|
364
|
-
exports.saveBase64Image = __webpack_exports__.saveBase64Image;
|
|
365
|
-
exports.scaleImage = __webpack_exports__.scaleImage;
|
|
366
|
-
exports.zoomForGPT4o = __webpack_exports__.zoomForGPT4o;
|
|
367
|
-
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
368
|
-
"convertToJpegBase64",
|
|
369
|
-
"createImgBase64ByFormat",
|
|
370
|
-
"cropByRect",
|
|
371
|
-
"httpImg2Base64",
|
|
372
|
-
"localImg2Base64",
|
|
373
|
-
"paddingToMatchBlock",
|
|
374
|
-
"paddingToMatchBlockByBase64",
|
|
375
|
-
"parseBase64",
|
|
376
|
-
"photonFromBase64",
|
|
377
|
-
"photonToBase64",
|
|
378
|
-
"preProcessImageUrl",
|
|
379
|
-
"resizeAndConvertImgBuffer",
|
|
380
|
-
"resizeImgBase64",
|
|
381
|
-
"saveBase64Image",
|
|
382
|
-
"scaleImage",
|
|
383
|
-
"zoomForGPT4o"
|
|
384
|
-
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
385
|
-
Object.defineProperty(exports, '__esModule', {
|
|
386
|
-
value: true
|
|
387
|
-
});
|
package/dist/lib/index.js.bak
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __webpack_require__ = {};
|
|
3
|
-
(()=>{
|
|
4
|
-
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
-
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: definition[key]
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
})();
|
|
11
|
-
(()=>{
|
|
12
|
-
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
-
})();
|
|
14
|
-
(()=>{
|
|
15
|
-
__webpack_require__.r = (exports1)=>{
|
|
16
|
-
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
-
value: 'Module'
|
|
18
|
-
});
|
|
19
|
-
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
-
value: true
|
|
21
|
-
});
|
|
22
|
-
};
|
|
23
|
-
})();
|
|
24
|
-
var __webpack_exports__ = {};
|
|
25
|
-
__webpack_require__.r(__webpack_exports__);
|
|
26
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
-
commonIgnoreWarnings: ()=>rspack_config_js_namespaceObject.commonIgnoreWarnings,
|
|
28
|
-
createCopyStaticPlugin: ()=>copy_static_js_namespaceObject.createCopyStaticPlugin,
|
|
29
|
-
default: ()=>src,
|
|
30
|
-
createPlaygroundCopyPlugin: ()=>copy_static_js_namespaceObject.createPlaygroundCopyPlugin
|
|
31
|
-
});
|
|
32
|
-
const copy_static_js_namespaceObject = require("./build/copy-static.js");
|
|
33
|
-
const rspack_config_js_namespaceObject = require("./build/rspack-config.js");
|
|
34
|
-
const src = {};
|
|
35
|
-
exports.commonIgnoreWarnings = __webpack_exports__.commonIgnoreWarnings;
|
|
36
|
-
exports.createCopyStaticPlugin = __webpack_exports__.createCopyStaticPlugin;
|
|
37
|
-
exports.createPlaygroundCopyPlugin = __webpack_exports__.createPlaygroundCopyPlugin;
|
|
38
|
-
exports["default"] = __webpack_exports__["default"];
|
|
39
|
-
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
40
|
-
"commonIgnoreWarnings",
|
|
41
|
-
"createCopyStaticPlugin",
|
|
42
|
-
"createPlaygroundCopyPlugin",
|
|
43
|
-
"default"
|
|
44
|
-
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
45
|
-
Object.defineProperty(exports, '__esModule', {
|
|
46
|
-
value: true
|
|
47
|
-
});
|
package/dist/lib/logger.js.bak
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __webpack_require__ = {};
|
|
3
|
-
(()=>{
|
|
4
|
-
__webpack_require__.n = (module)=>{
|
|
5
|
-
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
6
|
-
__webpack_require__.d(getter, {
|
|
7
|
-
a: getter
|
|
8
|
-
});
|
|
9
|
-
return getter;
|
|
10
|
-
};
|
|
11
|
-
})();
|
|
12
|
-
(()=>{
|
|
13
|
-
__webpack_require__.d = (exports1, definition)=>{
|
|
14
|
-
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
15
|
-
enumerable: true,
|
|
16
|
-
get: definition[key]
|
|
17
|
-
});
|
|
18
|
-
};
|
|
19
|
-
})();
|
|
20
|
-
(()=>{
|
|
21
|
-
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
22
|
-
})();
|
|
23
|
-
(()=>{
|
|
24
|
-
__webpack_require__.r = (exports1)=>{
|
|
25
|
-
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
26
|
-
value: 'Module'
|
|
27
|
-
});
|
|
28
|
-
Object.defineProperty(exports1, '__esModule', {
|
|
29
|
-
value: true
|
|
30
|
-
});
|
|
31
|
-
};
|
|
32
|
-
})();
|
|
33
|
-
var __webpack_exports__ = {};
|
|
34
|
-
__webpack_require__.r(__webpack_exports__);
|
|
35
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
36
|
-
enableDebug: ()=>enableDebug,
|
|
37
|
-
getDebug: ()=>getDebug
|
|
38
|
-
});
|
|
39
|
-
const external_node_fs_namespaceObject = require("node:fs");
|
|
40
|
-
var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
|
|
41
|
-
const external_node_path_namespaceObject = require("node:path");
|
|
42
|
-
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
43
|
-
const external_node_util_namespaceObject = require("node:util");
|
|
44
|
-
var external_node_util_default = /*#__PURE__*/ __webpack_require__.n(external_node_util_namespaceObject);
|
|
45
|
-
const external_debug_namespaceObject = require("debug");
|
|
46
|
-
var external_debug_default = /*#__PURE__*/ __webpack_require__.n(external_debug_namespaceObject);
|
|
47
|
-
const external_common_js_namespaceObject = require("./common.js");
|
|
48
|
-
const external_utils_js_namespaceObject = require("./utils.js");
|
|
49
|
-
const topicPrefix = 'midscene';
|
|
50
|
-
const logStreams = new Map();
|
|
51
|
-
const debugInstances = new Map();
|
|
52
|
-
function getLogStream(topic) {
|
|
53
|
-
const topicFileName = topic.replace(/:/g, '-');
|
|
54
|
-
if (!logStreams.has(topicFileName)) {
|
|
55
|
-
const logFile = external_node_path_default().join((0, external_common_js_namespaceObject.getMidsceneRunSubDir)('log'), `${topicFileName}.log`);
|
|
56
|
-
const stream = external_node_fs_default().createWriteStream(logFile, {
|
|
57
|
-
flags: 'a'
|
|
58
|
-
});
|
|
59
|
-
logStreams.set(topicFileName, stream);
|
|
60
|
-
}
|
|
61
|
-
return logStreams.get(topicFileName);
|
|
62
|
-
}
|
|
63
|
-
function writeLogToFile(topic, message) {
|
|
64
|
-
if (!external_utils_js_namespaceObject.ifInNode) return;
|
|
65
|
-
const stream = getLogStream(topic);
|
|
66
|
-
const now = new Date();
|
|
67
|
-
const isoDate = now.toLocaleDateString('sv-SE');
|
|
68
|
-
const isoTime = now.toLocaleTimeString('sv-SE');
|
|
69
|
-
const milliseconds = now.getMilliseconds().toString().padStart(3, '0');
|
|
70
|
-
const timezoneOffsetMinutes = now.getTimezoneOffset();
|
|
71
|
-
const sign = timezoneOffsetMinutes <= 0 ? '+' : '-';
|
|
72
|
-
const hours = Math.floor(Math.abs(timezoneOffsetMinutes) / 60).toString().padStart(2, '0');
|
|
73
|
-
const minutes = (Math.abs(timezoneOffsetMinutes) % 60).toString().padStart(2, '0');
|
|
74
|
-
const timezoneString = `${sign}${hours}:${minutes}`;
|
|
75
|
-
const localISOTime = `${isoDate}T${isoTime}.${milliseconds}${timezoneString}`;
|
|
76
|
-
stream.write(`[${localISOTime}] ${message}\n`);
|
|
77
|
-
}
|
|
78
|
-
function getDebug(topic, options) {
|
|
79
|
-
const fullTopic = `${topicPrefix}:${topic}`;
|
|
80
|
-
const withConsole = options?.console ?? false;
|
|
81
|
-
const cacheKey = withConsole ? `${fullTopic}:withConsole` : fullTopic;
|
|
82
|
-
if (!debugInstances.has(cacheKey)) if (withConsole) {
|
|
83
|
-
const baseFn = getDebug(topic);
|
|
84
|
-
const wrapper = (...args)=>{
|
|
85
|
-
baseFn(...args);
|
|
86
|
-
console.warn('[Midscene]', ...args);
|
|
87
|
-
};
|
|
88
|
-
debugInstances.set(cacheKey, wrapper);
|
|
89
|
-
} else {
|
|
90
|
-
const debugFn = external_debug_default()(fullTopic);
|
|
91
|
-
const wrapper = (...args)=>{
|
|
92
|
-
if (external_utils_js_namespaceObject.ifInNode) {
|
|
93
|
-
const message = external_node_util_default().format(...args);
|
|
94
|
-
writeLogToFile(topic, message);
|
|
95
|
-
}
|
|
96
|
-
debugFn(...args);
|
|
97
|
-
};
|
|
98
|
-
debugInstances.set(cacheKey, wrapper);
|
|
99
|
-
}
|
|
100
|
-
return debugInstances.get(cacheKey);
|
|
101
|
-
}
|
|
102
|
-
function enableDebug(topic) {
|
|
103
|
-
if (external_utils_js_namespaceObject.ifInNode) return;
|
|
104
|
-
external_debug_default().enable(`${topicPrefix}:${topic}`);
|
|
105
|
-
}
|
|
106
|
-
exports.enableDebug = __webpack_exports__.enableDebug;
|
|
107
|
-
exports.getDebug = __webpack_exports__.getDebug;
|
|
108
|
-
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
109
|
-
"enableDebug",
|
|
110
|
-
"getDebug"
|
|
111
|
-
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
112
|
-
Object.defineProperty(exports, '__esModule', {
|
|
113
|
-
value: true
|
|
114
|
-
});
|