@rpascene/shared 0.30.8
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/README.md +9 -0
- package/dist/es/baseDB.mjs +109 -0
- package/dist/es/build/copy-static.mjs +29 -0
- package/dist/es/common.mjs +37 -0
- package/dist/es/constants/example-code.mjs +202 -0
- package/dist/es/constants/index.mjs +74 -0
- package/dist/es/env/basic.mjs +6 -0
- package/dist/es/env/constants.mjs +97 -0
- package/dist/es/env/decide-model-config.mjs +172 -0
- package/dist/es/env/global-config-manager.mjs +82 -0
- package/dist/es/env/helper.mjs +45 -0
- package/dist/es/env/index.mjs +5 -0
- package/dist/es/env/init-debug.mjs +18 -0
- package/dist/es/env/model-config-manager.mjs +99 -0
- package/dist/es/env/parse.mjs +69 -0
- package/dist/es/env/types.mjs +265 -0
- package/dist/es/env/utils.mjs +18 -0
- package/dist/es/extractor/constants.mjs +2 -0
- package/dist/es/extractor/cs_postmessage.mjs +61 -0
- package/dist/es/extractor/customLocator.mjs +646 -0
- package/dist/es/extractor/debug.mjs +6 -0
- package/dist/es/extractor/dom-util.mjs +92 -0
- package/dist/es/extractor/index.mjs +7 -0
- package/dist/es/extractor/locator.mjs +95 -0
- package/dist/es/extractor/tree.mjs +81 -0
- package/dist/es/extractor/util.mjs +244 -0
- package/dist/es/extractor/web-extractor.mjs +361 -0
- package/dist/es/img/box-select.mjs +184 -0
- package/dist/es/img/draw-box.mjs +42 -0
- package/dist/es/img/get-jimp.mjs +10 -0
- package/dist/es/img/get-photon.mjs +19 -0
- package/dist/es/img/get-sharp.mjs +11 -0
- package/dist/es/img/index.mjs +5 -0
- package/dist/es/img/info.mjs +32 -0
- package/dist/es/img/transform.mjs +192 -0
- package/dist/es/index.mjs +3 -0
- package/dist/es/logger.mjs +61 -0
- package/dist/es/node/fs.mjs +44 -0
- package/dist/es/node/index.mjs +1 -0
- package/dist/es/polyfills/async-hooks.mjs +2 -0
- package/dist/es/polyfills/index.mjs +1 -0
- package/dist/es/types/index.mjs +3 -0
- package/dist/es/us-keyboard-layout.mjs +1414 -0
- package/dist/es/us-keyboard-layout.mjs.LICENSE.txt +5 -0
- package/dist/es/utils.mjs +66 -0
- package/dist/lib/baseDB.js +149 -0
- package/dist/lib/build/copy-static.js +77 -0
- package/dist/lib/common.js +93 -0
- package/dist/lib/constants/example-code.js +239 -0
- package/dist/lib/constants/index.js +153 -0
- package/dist/lib/env/basic.js +40 -0
- package/dist/lib/env/constants.js +143 -0
- package/dist/lib/env/decide-model-config.js +212 -0
- package/dist/lib/env/global-config-manager.js +116 -0
- package/dist/lib/env/helper.js +85 -0
- package/dist/lib/env/index.js +94 -0
- package/dist/lib/env/init-debug.js +52 -0
- package/dist/lib/env/model-config-manager.js +133 -0
- package/dist/lib/env/parse.js +106 -0
- package/dist/lib/env/types.js +650 -0
- package/dist/lib/env/utils.js +61 -0
- package/dist/lib/extractor/constants.js +42 -0
- package/dist/lib/extractor/cs_postmessage.js +98 -0
- package/dist/lib/extractor/customLocator.js +698 -0
- package/dist/lib/extractor/debug.js +12 -0
- package/dist/lib/extractor/dom-util.js +150 -0
- package/dist/lib/extractor/index.js +153 -0
- package/dist/lib/extractor/locator.js +141 -0
- package/dist/lib/extractor/tree.js +127 -0
- package/dist/lib/extractor/util.js +335 -0
- package/dist/lib/extractor/web-extractor.js +407 -0
- package/dist/lib/img/box-select.js +232 -0
- package/dist/lib/img/draw-box.js +89 -0
- package/dist/lib/img/get-jimp.js +72 -0
- package/dist/lib/img/get-photon.js +76 -0
- package/dist/lib/img/get-sharp.js +63 -0
- package/dist/lib/img/index.js +102 -0
- package/dist/lib/img/info.js +86 -0
- package/dist/lib/img/transform.js +279 -0
- package/dist/lib/index.js +43 -0
- package/dist/lib/logger.js +114 -0
- package/dist/lib/node/fs.js +97 -0
- package/dist/lib/node/index.js +60 -0
- package/dist/lib/polyfills/async-hooks.js +36 -0
- package/dist/lib/polyfills/index.js +60 -0
- package/dist/lib/types/index.js +37 -0
- package/dist/lib/us-keyboard-layout.js +1457 -0
- package/dist/lib/us-keyboard-layout.js.LICENSE.txt +5 -0
- package/dist/lib/utils.js +136 -0
- package/dist/types/baseDB.d.ts +25 -0
- package/dist/types/build/copy-static.d.ts +31 -0
- package/dist/types/common.d.ts +12 -0
- package/dist/types/constants/example-code.d.ts +2 -0
- package/dist/types/constants/index.d.ts +23 -0
- package/dist/types/env/basic.d.ts +6 -0
- package/dist/types/env/constants.d.ts +40 -0
- package/dist/types/env/decide-model-config.d.ts +14 -0
- package/dist/types/env/global-config-manager.d.ts +32 -0
- package/dist/types/env/helper.d.ts +6 -0
- package/dist/types/env/index.d.ts +4 -0
- package/dist/types/env/init-debug.d.ts +1 -0
- package/dist/types/env/model-config-manager.d.ts +24 -0
- package/dist/types/env/parse.d.ts +12 -0
- package/dist/types/env/types.d.ts +295 -0
- package/dist/types/env/utils.d.ts +7 -0
- package/dist/types/extractor/constants.d.ts +1 -0
- package/dist/types/extractor/cs_postmessage.d.ts +2 -0
- package/dist/types/extractor/customLocator.d.ts +69 -0
- package/dist/types/extractor/debug.d.ts +1 -0
- package/dist/types/extractor/dom-util.d.ts +26 -0
- package/dist/types/extractor/index.d.ts +36 -0
- package/dist/types/extractor/locator.d.ts +7 -0
- package/dist/types/extractor/tree.d.ts +9 -0
- package/dist/types/extractor/util.d.ts +43 -0
- package/dist/types/extractor/web-extractor.d.ts +19 -0
- package/dist/types/img/box-select.d.ts +25 -0
- package/dist/types/img/draw-box.d.ts +15 -0
- package/dist/types/img/get-jimp.d.ts +2 -0
- package/dist/types/img/get-photon.d.ts +8 -0
- package/dist/types/img/get-sharp.d.ts +3 -0
- package/dist/types/img/index.d.ts +4 -0
- package/dist/types/img/info.d.ts +29 -0
- package/dist/types/img/transform.d.ts +88 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/logger.d.ts +4 -0
- package/dist/types/node/fs.d.ts +15 -0
- package/dist/types/node/index.d.ts +1 -0
- package/dist/types/polyfills/async-hooks.d.ts +6 -0
- package/dist/types/polyfills/index.d.ts +4 -0
- package/dist/types/types/index.d.ts +37 -0
- package/dist/types/us-keyboard-layout.d.ts +32 -0
- package/dist/types/utils.d.ts +22 -0
- package/package.json +102 -0
- package/src/baseDB.ts +158 -0
- package/src/build/copy-static.ts +62 -0
- package/src/common.ts +67 -0
- package/src/constants/example-code.ts +202 -0
- package/src/constants/index.ts +81 -0
- package/src/env/basic.ts +12 -0
- package/src/env/constants.ts +291 -0
- package/src/env/decide-model-config.ts +319 -0
- package/src/env/global-config-manager.ts +174 -0
- package/src/env/helper.ts +80 -0
- package/src/env/index.ts +4 -0
- package/src/env/init-debug.ts +29 -0
- package/src/env/model-config-manager.ts +145 -0
- package/src/env/parse.ts +131 -0
- package/src/env/types.ts +573 -0
- package/src/env/utils.ts +39 -0
- package/src/extractor/constants.ts +5 -0
- package/src/extractor/cs_postmessage.ts +101 -0
- package/src/extractor/customLocator.ts +1138 -0
- package/src/extractor/debug.ts +10 -0
- package/src/extractor/dom-util.ts +141 -0
- package/src/extractor/index.ts +54 -0
- package/src/extractor/locator.ts +179 -0
- package/src/extractor/tree.ts +179 -0
- package/src/extractor/util.ts +468 -0
- package/src/extractor/web-extractor.ts +559 -0
- package/src/img/box-select.ts +346 -0
- package/src/img/draw-box.ts +60 -0
- package/src/img/get-jimp.ts +12 -0
- package/src/img/get-photon.ts +48 -0
- package/src/img/get-sharp.ts +18 -0
- package/src/img/index.ts +24 -0
- package/src/img/info.ts +79 -0
- package/src/img/jimp.d.ts +4 -0
- package/src/img/transform.ts +396 -0
- package/src/index.ts +6 -0
- package/src/logger.ts +93 -0
- package/src/node/fs.ts +84 -0
- package/src/node/index.ts +1 -0
- package/src/polyfills/async-hooks.ts +6 -0
- package/src/polyfills/index.ts +4 -0
- package/src/types/index.ts +53 -0
- package/src/us-keyboard-layout.ts +723 -0
- package/src/utils.ts +127 -0
|
@@ -0,0 +1,279 @@
|
|
|
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
|
+
preProcessImageUrl: ()=>preProcessImageUrl,
|
|
37
|
+
localImg2Base64: ()=>localImg2Base64,
|
|
38
|
+
paddingToMatchBlock: ()=>paddingToMatchBlock,
|
|
39
|
+
zoomForGPT4o: ()=>zoomForGPT4o,
|
|
40
|
+
cropByRect: ()=>cropByRect,
|
|
41
|
+
resizeAndConvertImgBuffer: ()=>resizeAndConvertImgBuffer,
|
|
42
|
+
saveBase64Image: ()=>saveBase64Image,
|
|
43
|
+
createImgBase64ByFormat: ()=>createImgBase64ByFormat,
|
|
44
|
+
httpImg2Base64: ()=>httpImg2Base64,
|
|
45
|
+
jimpToBase64: ()=>jimpToBase64,
|
|
46
|
+
parseBase64: ()=>parseBase64,
|
|
47
|
+
jimpFromBase64: ()=>jimpFromBase64,
|
|
48
|
+
resizeImgBase64: ()=>resizeImgBase64,
|
|
49
|
+
paddingToMatchBlockByBase64: ()=>paddingToMatchBlockByBase64
|
|
50
|
+
});
|
|
51
|
+
const external_node_assert_namespaceObject = require("node:assert");
|
|
52
|
+
var external_node_assert_default = /*#__PURE__*/ __webpack_require__.n(external_node_assert_namespaceObject);
|
|
53
|
+
const external_node_buffer_namespaceObject = require("node:buffer");
|
|
54
|
+
const external_node_fs_namespaceObject = require("node:fs");
|
|
55
|
+
const external_node_path_namespaceObject = require("node:path");
|
|
56
|
+
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
57
|
+
const external_logger_js_namespaceObject = require("../logger.js");
|
|
58
|
+
const external_utils_js_namespaceObject = require("../utils.js");
|
|
59
|
+
const external_get_jimp_js_namespaceObject = require("./get-jimp.js");
|
|
60
|
+
var external_get_jimp_js_default = /*#__PURE__*/ __webpack_require__.n(external_get_jimp_js_namespaceObject);
|
|
61
|
+
const external_get_photon_js_namespaceObject = require("./get-photon.js");
|
|
62
|
+
var external_get_photon_js_default = /*#__PURE__*/ __webpack_require__.n(external_get_photon_js_namespaceObject);
|
|
63
|
+
const external_get_sharp_js_namespaceObject = require("./get-sharp.js");
|
|
64
|
+
var external_get_sharp_js_default = /*#__PURE__*/ __webpack_require__.n(external_get_sharp_js_namespaceObject);
|
|
65
|
+
const imgDebug = (0, external_logger_js_namespaceObject.getDebug)('img');
|
|
66
|
+
async function saveBase64Image(options) {
|
|
67
|
+
const { base64Data, outputPath } = options;
|
|
68
|
+
const { body } = parseBase64(base64Data);
|
|
69
|
+
const imageBuffer = external_node_buffer_namespaceObject.Buffer.from(body, 'base64');
|
|
70
|
+
const Jimp = await external_get_jimp_js_default()();
|
|
71
|
+
const image = await Jimp.read(imageBuffer);
|
|
72
|
+
await image.writeAsync(outputPath);
|
|
73
|
+
}
|
|
74
|
+
async function resizeAndConvertImgBuffer(inputFormat, inputData, newSize) {
|
|
75
|
+
if ('string' == typeof inputData) throw Error('inputData is base64, use resizeImgBase64 instead');
|
|
76
|
+
external_node_assert_default()(newSize && newSize.width > 0 && newSize.height > 0, 'newSize must be positive');
|
|
77
|
+
const resizeStartTime = Date.now();
|
|
78
|
+
imgDebug(`resizeImg start, target size: ${newSize.width}x${newSize.height}`);
|
|
79
|
+
if (external_utils_js_namespaceObject.ifInNode) try {
|
|
80
|
+
const Sharp = await external_get_sharp_js_default()();
|
|
81
|
+
const metadata = await Sharp(inputData).metadata();
|
|
82
|
+
const { width: originalWidth, height: originalHeight } = metadata;
|
|
83
|
+
if (!originalWidth || !originalHeight) throw Error('Undefined width or height from the input image.');
|
|
84
|
+
if (newSize.width === originalWidth && newSize.height === originalHeight) return {
|
|
85
|
+
buffer: inputData,
|
|
86
|
+
format: inputFormat
|
|
87
|
+
};
|
|
88
|
+
const resizedBuffer = await Sharp(inputData).resize(newSize.width, newSize.height).jpeg({
|
|
89
|
+
quality: 90
|
|
90
|
+
}).toBuffer();
|
|
91
|
+
const resizeEndTime = Date.now();
|
|
92
|
+
imgDebug(`resizeImg done (Sharp), target size: ${newSize.width}x${newSize.height}, cost: ${resizeEndTime - resizeStartTime}ms`);
|
|
93
|
+
return {
|
|
94
|
+
buffer: resizedBuffer,
|
|
95
|
+
format: 'jpeg'
|
|
96
|
+
};
|
|
97
|
+
} catch (error) {
|
|
98
|
+
imgDebug('Sharp failed, falling back to Photon:', error);
|
|
99
|
+
}
|
|
100
|
+
const { PhotonImage, SamplingFilter, resize } = await external_get_photon_js_default()();
|
|
101
|
+
const inputBytes = new Uint8Array(inputData);
|
|
102
|
+
const inputImage = PhotonImage.new_from_byteslice(inputBytes);
|
|
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 jimpFromBase64(base64) {
|
|
155
|
+
const Jimp = await external_get_jimp_js_default()();
|
|
156
|
+
const { body } = parseBase64(base64);
|
|
157
|
+
const imageBuffer = external_node_buffer_namespaceObject.Buffer.from(body, 'base64');
|
|
158
|
+
return Jimp.read(imageBuffer);
|
|
159
|
+
}
|
|
160
|
+
async function paddingToMatchBlock(image, blockSize = 28) {
|
|
161
|
+
const { width, height } = image.bitmap;
|
|
162
|
+
const targetWidth = Math.ceil(width / blockSize) * blockSize;
|
|
163
|
+
const targetHeight = Math.ceil(height / blockSize) * blockSize;
|
|
164
|
+
if (targetWidth === width && targetHeight === height) return {
|
|
165
|
+
width,
|
|
166
|
+
height,
|
|
167
|
+
image
|
|
168
|
+
};
|
|
169
|
+
const Jimp = await external_get_jimp_js_default()();
|
|
170
|
+
const paddedImage = new Jimp(targetWidth, targetHeight, 0xffffffff);
|
|
171
|
+
paddedImage.composite(image, 0, 0);
|
|
172
|
+
return {
|
|
173
|
+
width: targetWidth,
|
|
174
|
+
height: targetHeight,
|
|
175
|
+
image: paddedImage
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
async function paddingToMatchBlockByBase64(imageBase64, blockSize = 28) {
|
|
179
|
+
const jimpImage = await jimpFromBase64(imageBase64);
|
|
180
|
+
const paddedResult = await paddingToMatchBlock(jimpImage, blockSize);
|
|
181
|
+
return {
|
|
182
|
+
width: paddedResult.width,
|
|
183
|
+
height: paddedResult.height,
|
|
184
|
+
imageBase64: await jimpToBase64(paddedResult.image)
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
async function cropByRect(imageBase64, rect, paddingImage) {
|
|
188
|
+
const jimpImage = await jimpFromBase64(imageBase64);
|
|
189
|
+
const { left, top, width, height } = rect;
|
|
190
|
+
jimpImage.crop(left, top, width, height);
|
|
191
|
+
if (paddingImage) {
|
|
192
|
+
const paddedResult = await paddingToMatchBlock(jimpImage);
|
|
193
|
+
return {
|
|
194
|
+
width: paddedResult.width,
|
|
195
|
+
height: paddedResult.height,
|
|
196
|
+
imageBase64: await jimpToBase64(paddedResult.image)
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
return {
|
|
200
|
+
width: jimpImage.bitmap.width,
|
|
201
|
+
height: jimpImage.bitmap.height,
|
|
202
|
+
imageBase64: await jimpToBase64(jimpImage)
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
async function jimpToBase64(image) {
|
|
206
|
+
const Jimp = await external_get_jimp_js_default()();
|
|
207
|
+
return image.getBase64Async(Jimp.MIME_JPEG);
|
|
208
|
+
}
|
|
209
|
+
const httpImg2Base64 = async (url)=>{
|
|
210
|
+
const response = await fetch(url);
|
|
211
|
+
if (!response.ok) throw new Error(`Failed to fetch image: ${url}`);
|
|
212
|
+
const contentType = response.headers.get('content-type');
|
|
213
|
+
if (!contentType) throw new Error(`Failed to fetch image: ${url}`);
|
|
214
|
+
external_node_assert_default()(contentType.startsWith('image/'), `The url ${url} is not a image, because of content-type in header is ${contentType}.`);
|
|
215
|
+
const buffer = external_node_buffer_namespaceObject.Buffer.from(await response.arrayBuffer());
|
|
216
|
+
return `data:${contentType};base64,${buffer.toString('base64')}`;
|
|
217
|
+
};
|
|
218
|
+
const localImg2Base64 = (imgPath, withoutHeader = false)=>{
|
|
219
|
+
const body = (0, external_node_fs_namespaceObject.readFileSync)(imgPath).toString('base64');
|
|
220
|
+
if (withoutHeader) return body;
|
|
221
|
+
const type = external_node_path_default().extname(imgPath).slice(1);
|
|
222
|
+
const finalType = 'svg' === type ? 'svg+xml' : type || 'jpg';
|
|
223
|
+
return `data:image/${finalType};base64,${body}`;
|
|
224
|
+
};
|
|
225
|
+
const preProcessImageUrl = async (url, convertHttpImage2Base64)=>{
|
|
226
|
+
if ('string' != typeof url) throw new Error(`url must be a string, but got ${url} with type ${typeof url}`);
|
|
227
|
+
if (url.startsWith('data:')) return url;
|
|
228
|
+
if (!(url.startsWith('http://') || url.startsWith('https://'))) return await localImg2Base64(url);
|
|
229
|
+
if (!convertHttpImage2Base64) return url;
|
|
230
|
+
return await httpImg2Base64(url);
|
|
231
|
+
};
|
|
232
|
+
const parseBase64 = (fullBase64String)=>{
|
|
233
|
+
try {
|
|
234
|
+
const separator = ';base64,';
|
|
235
|
+
const index = fullBase64String.indexOf(separator);
|
|
236
|
+
if (-1 === index) throw new Error('Invalid base64 string');
|
|
237
|
+
return {
|
|
238
|
+
mimeType: fullBase64String.slice(5, index),
|
|
239
|
+
body: fullBase64String.slice(index + separator.length)
|
|
240
|
+
};
|
|
241
|
+
} catch (e) {
|
|
242
|
+
throw new Error(`parseBase64 fail because intput is not a valid base64 string: ${fullBase64String}`, {
|
|
243
|
+
cause: e
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
exports.createImgBase64ByFormat = __webpack_exports__.createImgBase64ByFormat;
|
|
248
|
+
exports.cropByRect = __webpack_exports__.cropByRect;
|
|
249
|
+
exports.httpImg2Base64 = __webpack_exports__.httpImg2Base64;
|
|
250
|
+
exports.jimpFromBase64 = __webpack_exports__.jimpFromBase64;
|
|
251
|
+
exports.jimpToBase64 = __webpack_exports__.jimpToBase64;
|
|
252
|
+
exports.localImg2Base64 = __webpack_exports__.localImg2Base64;
|
|
253
|
+
exports.paddingToMatchBlock = __webpack_exports__.paddingToMatchBlock;
|
|
254
|
+
exports.paddingToMatchBlockByBase64 = __webpack_exports__.paddingToMatchBlockByBase64;
|
|
255
|
+
exports.parseBase64 = __webpack_exports__.parseBase64;
|
|
256
|
+
exports.preProcessImageUrl = __webpack_exports__.preProcessImageUrl;
|
|
257
|
+
exports.resizeAndConvertImgBuffer = __webpack_exports__.resizeAndConvertImgBuffer;
|
|
258
|
+
exports.resizeImgBase64 = __webpack_exports__.resizeImgBase64;
|
|
259
|
+
exports.saveBase64Image = __webpack_exports__.saveBase64Image;
|
|
260
|
+
exports.zoomForGPT4o = __webpack_exports__.zoomForGPT4o;
|
|
261
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
262
|
+
"createImgBase64ByFormat",
|
|
263
|
+
"cropByRect",
|
|
264
|
+
"httpImg2Base64",
|
|
265
|
+
"jimpFromBase64",
|
|
266
|
+
"jimpToBase64",
|
|
267
|
+
"localImg2Base64",
|
|
268
|
+
"paddingToMatchBlock",
|
|
269
|
+
"paddingToMatchBlockByBase64",
|
|
270
|
+
"parseBase64",
|
|
271
|
+
"preProcessImageUrl",
|
|
272
|
+
"resizeAndConvertImgBuffer",
|
|
273
|
+
"resizeImgBase64",
|
|
274
|
+
"saveBase64Image",
|
|
275
|
+
"zoomForGPT4o"
|
|
276
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
277
|
+
Object.defineProperty(exports, '__esModule', {
|
|
278
|
+
value: true
|
|
279
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
createPlaygroundCopyPlugin: ()=>copy_static_js_namespaceObject.createPlaygroundCopyPlugin,
|
|
28
|
+
createCopyStaticPlugin: ()=>copy_static_js_namespaceObject.createCopyStaticPlugin,
|
|
29
|
+
default: ()=>src
|
|
30
|
+
});
|
|
31
|
+
const copy_static_js_namespaceObject = require("./build/copy-static.js");
|
|
32
|
+
const src = {};
|
|
33
|
+
exports.createCopyStaticPlugin = __webpack_exports__.createCopyStaticPlugin;
|
|
34
|
+
exports.createPlaygroundCopyPlugin = __webpack_exports__.createPlaygroundCopyPlugin;
|
|
35
|
+
exports["default"] = __webpack_exports__["default"];
|
|
36
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
37
|
+
"createCopyStaticPlugin",
|
|
38
|
+
"createPlaygroundCopyPlugin",
|
|
39
|
+
"default"
|
|
40
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
41
|
+
Object.defineProperty(exports, '__esModule', {
|
|
42
|
+
value: true
|
|
43
|
+
});
|
|
@@ -0,0 +1,114 @@
|
|
|
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
|
+
cleanupLogStreams: ()=>cleanupLogStreams
|
|
39
|
+
});
|
|
40
|
+
const external_node_fs_namespaceObject = require("node:fs");
|
|
41
|
+
var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
|
|
42
|
+
const external_node_path_namespaceObject = require("node:path");
|
|
43
|
+
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
44
|
+
const external_node_util_namespaceObject = require("node:util");
|
|
45
|
+
var external_node_util_default = /*#__PURE__*/ __webpack_require__.n(external_node_util_namespaceObject);
|
|
46
|
+
const external_debug_namespaceObject = require("debug");
|
|
47
|
+
var external_debug_default = /*#__PURE__*/ __webpack_require__.n(external_debug_namespaceObject);
|
|
48
|
+
const external_common_js_namespaceObject = require("./common.js");
|
|
49
|
+
const external_utils_js_namespaceObject = require("./utils.js");
|
|
50
|
+
const topicPrefix = 'rpascene';
|
|
51
|
+
const logStreams = new Map();
|
|
52
|
+
const debugInstances = new Map();
|
|
53
|
+
function getLogStream(topic) {
|
|
54
|
+
const topicFileName = topic.replace(/:/g, '-');
|
|
55
|
+
if (!logStreams.has(topicFileName)) {
|
|
56
|
+
const logFile = external_node_path_default().join((0, external_common_js_namespaceObject.getRpasceneRunSubDir)('log'), `${topicFileName}.log`);
|
|
57
|
+
const stream = external_node_fs_default().createWriteStream(logFile, {
|
|
58
|
+
flags: 'a'
|
|
59
|
+
});
|
|
60
|
+
logStreams.set(topicFileName, stream);
|
|
61
|
+
}
|
|
62
|
+
return logStreams.get(topicFileName);
|
|
63
|
+
}
|
|
64
|
+
function writeLogToFile(topic, message) {
|
|
65
|
+
if (!external_utils_js_namespaceObject.ifInNode) return;
|
|
66
|
+
const stream = getLogStream(topic);
|
|
67
|
+
const now = new Date();
|
|
68
|
+
const isoDate = now.toLocaleDateString('sv-SE');
|
|
69
|
+
const isoTime = now.toLocaleTimeString('sv-SE');
|
|
70
|
+
const milliseconds = now.getMilliseconds().toString().padStart(3, '0');
|
|
71
|
+
const timezoneOffsetMinutes = now.getTimezoneOffset();
|
|
72
|
+
const sign = timezoneOffsetMinutes <= 0 ? '+' : '-';
|
|
73
|
+
const hours = Math.floor(Math.abs(timezoneOffsetMinutes) / 60).toString().padStart(2, '0');
|
|
74
|
+
const minutes = (Math.abs(timezoneOffsetMinutes) % 60).toString().padStart(2, '0');
|
|
75
|
+
const timezoneString = `${sign}${hours}:${minutes}`;
|
|
76
|
+
const localISOTime = `${isoDate}T${isoTime}.${milliseconds}${timezoneString}`;
|
|
77
|
+
stream.write(`[${localISOTime}] ${message}\n`);
|
|
78
|
+
}
|
|
79
|
+
function getDebug(topic) {
|
|
80
|
+
const fullTopic = `${topicPrefix}:${topic}`;
|
|
81
|
+
if (!debugInstances.has(fullTopic)) {
|
|
82
|
+
const debugFn = external_debug_default()(fullTopic);
|
|
83
|
+
const wrapper = (...args)=>{
|
|
84
|
+
if (external_utils_js_namespaceObject.ifInNode) {
|
|
85
|
+
const message = external_node_util_default().format(...args);
|
|
86
|
+
writeLogToFile(topic, message);
|
|
87
|
+
}
|
|
88
|
+
debugFn(...args);
|
|
89
|
+
};
|
|
90
|
+
debugInstances.set(fullTopic, wrapper);
|
|
91
|
+
}
|
|
92
|
+
return debugInstances.get(fullTopic);
|
|
93
|
+
}
|
|
94
|
+
function enableDebug(topic) {
|
|
95
|
+
if (external_utils_js_namespaceObject.ifInNode) return;
|
|
96
|
+
external_debug_default().enable(`${topicPrefix}:${topic}`);
|
|
97
|
+
}
|
|
98
|
+
function cleanupLogStreams() {
|
|
99
|
+
if (!external_utils_js_namespaceObject.ifInNode) return;
|
|
100
|
+
for (const stream of logStreams.values())stream.end();
|
|
101
|
+
logStreams.clear();
|
|
102
|
+
debugInstances.clear();
|
|
103
|
+
}
|
|
104
|
+
exports.cleanupLogStreams = __webpack_exports__.cleanupLogStreams;
|
|
105
|
+
exports.enableDebug = __webpack_exports__.enableDebug;
|
|
106
|
+
exports.getDebug = __webpack_exports__.getDebug;
|
|
107
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
108
|
+
"cleanupLogStreams",
|
|
109
|
+
"enableDebug",
|
|
110
|
+
"getDebug"
|
|
111
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
112
|
+
Object.defineProperty(exports, '__esModule', {
|
|
113
|
+
value: true
|
|
114
|
+
});
|