@midscene/shared 0.7.2 → 0.7.3-beta-20241104100519.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/img.js CHANGED
@@ -26,18 +26,40 @@ 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/img/index.ts
31
51
  var img_exports = {};
32
52
  __export(img_exports, {
33
53
  base64Encoded: () => base64Encoded,
34
54
  base64ToPngFormat: () => base64ToPngFormat,
55
+ bufferFromBase64: () => bufferFromBase64,
35
56
  calculateNewDimensions: () => calculateNewDimensions,
36
57
  compositeElementInfoImg: () => compositeElementInfoImg,
37
58
  imageInfo: () => imageInfo,
38
59
  imageInfoOfBase64: () => imageInfoOfBase64,
39
60
  processImageElementInfo: () => processImageElementInfo,
40
61
  resizeImg: () => resizeImg,
62
+ resizeImgBase64: () => resizeImgBase64,
41
63
  saveBase64Image: () => saveBase64Image,
42
64
  transformImgPathToBase64: () => transformImgPathToBase64,
43
65
  trimImage: () => trimImage
@@ -48,26 +70,52 @@ module.exports = __toCommonJS(img_exports);
48
70
  var import_node_assert = __toESM(require("assert"));
49
71
  var import_node_buffer = require("buffer");
50
72
  var import_node_fs = require("fs");
51
- var import_jimp = __toESM(require("jimp"));
52
- async function imageInfo(image) {
53
- let jimpImage;
54
- if (typeof image === "string") {
55
- jimpImage = await import_jimp.default.read(image);
56
- } else if (import_node_buffer.Buffer.isBuffer(image)) {
57
- jimpImage = await import_jimp.default.read(image);
58
- } else {
59
- throw new Error("Invalid image input: must be a string path or a Buffer");
60
- }
61
- const { width, height } = jimpImage.bitmap;
62
- (0, import_node_assert.default)(
63
- width && height,
64
- `Invalid image: ${typeof image === "string" ? image : "Buffer"}`
65
- );
66
- return { width, height };
73
+
74
+ // src/img/get-jimp.ts
75
+ var ifInBrowser = typeof window !== "undefined";
76
+ function getJimp() {
77
+ return __async(this, null, function* () {
78
+ if (ifInBrowser) {
79
+ yield import("jimp/browser/lib/jimp.js");
80
+ return window.Jimp;
81
+ }
82
+ return (yield import("jimp")).default;
83
+ });
84
+ }
85
+
86
+ // src/img/info.ts
87
+ function imageInfo(image) {
88
+ return __async(this, null, function* () {
89
+ const Jimp = yield getJimp();
90
+ let jimpImage;
91
+ if (typeof image === "string") {
92
+ jimpImage = yield Jimp.read(image);
93
+ } else if (import_node_buffer.Buffer.isBuffer(image)) {
94
+ jimpImage = yield Jimp.read(image);
95
+ } else if (image instanceof Jimp) {
96
+ jimpImage = image;
97
+ } else {
98
+ throw new Error("Invalid image input: must be a string path or a Buffer");
99
+ }
100
+ const { width, height } = jimpImage.bitmap;
101
+ (0, import_node_assert.default)(
102
+ width && height,
103
+ `Invalid image: ${typeof image === "string" ? image : "Buffer"}`
104
+ );
105
+ return { width, height, jimpImage };
106
+ });
107
+ }
108
+ function imageInfoOfBase64(imageBase64) {
109
+ return __async(this, null, function* () {
110
+ const buffer = yield bufferFromBase64(imageBase64);
111
+ return imageInfo(buffer);
112
+ });
67
113
  }
68
- async function imageInfoOfBase64(imageBase64) {
69
- const base64Data = imageBase64.replace(/^data:image\/\w+;base64,/, "");
70
- return imageInfo(import_node_buffer.Buffer.from(base64Data, "base64"));
114
+ function bufferFromBase64(imageBase64) {
115
+ return __async(this, null, function* () {
116
+ const base64Data = imageBase64.replace(/^data:image\/\w+;base64,/, "");
117
+ return import_node_buffer.Buffer.from(base64Data, "base64");
118
+ });
71
119
  }
72
120
  function base64Encoded(image, withHeader = true) {
73
121
  const imageBuffer = (0, import_node_fs.readFileSync)(image);
@@ -88,31 +136,52 @@ function base64ToPngFormat(base64) {
88
136
 
89
137
  // src/img/transform.ts
90
138
  var import_node_buffer2 = require("buffer");
91
- var import_jimp2 = __toESM(require("jimp"));
92
- async function saveBase64Image(options) {
93
- const { base64Data, outputPath } = options;
94
- const base64Image = base64Data.split(";base64,").pop() || base64Data;
95
- const imageBuffer = import_node_buffer2.Buffer.from(base64Image, "base64");
96
- const image = await import_jimp2.default.read(imageBuffer);
97
- await image.writeAsync(outputPath);
139
+ function saveBase64Image(options) {
140
+ return __async(this, null, function* () {
141
+ const { base64Data, outputPath } = options;
142
+ const base64Image = base64Data.split(";base64,").pop() || base64Data;
143
+ const imageBuffer = import_node_buffer2.Buffer.from(base64Image, "base64");
144
+ const Jimp = yield getJimp();
145
+ const image = yield Jimp.read(imageBuffer);
146
+ yield image.writeAsync(outputPath);
147
+ });
148
+ }
149
+ function transformImgPathToBase64(inputPath) {
150
+ return __async(this, null, function* () {
151
+ const Jimp = yield getJimp();
152
+ const image = yield Jimp.read(inputPath);
153
+ const buffer = yield image.getBufferAsync(Jimp.MIME_PNG);
154
+ return buffer.toString("base64");
155
+ });
98
156
  }
99
- async function transformImgPathToBase64(inputPath) {
100
- const image = await import_jimp2.default.read(inputPath);
101
- const buffer = await image.getBufferAsync(import_jimp2.default.MIME_PNG);
102
- return buffer.toString("base64");
157
+ function resizeImg(inputData, newSize) {
158
+ return __async(this, null, function* () {
159
+ if (typeof inputData === "string")
160
+ throw Error("inputData is base64, use resizeImgBase64 instead");
161
+ const Jimp = yield getJimp();
162
+ const image = yield Jimp.read(inputData);
163
+ const { width, height } = image.bitmap;
164
+ if (!width || !height) {
165
+ throw Error("Undefined width or height from the input image.");
166
+ }
167
+ const finalNewSize = newSize || calculateNewDimensions(width, height);
168
+ image.resize(finalNewSize.width, finalNewSize.height);
169
+ const resizedBuffer = yield image.getBufferAsync(Jimp.MIME_PNG);
170
+ return resizedBuffer;
171
+ });
103
172
  }
104
- async function resizeImg(inputData, newSize) {
105
- const isBase64 = typeof inputData === "string";
106
- const imageBuffer = isBase64 ? import_node_buffer2.Buffer.from(inputData.split(";base64,").pop() || inputData, "base64") : inputData;
107
- const image = await import_jimp2.default.read(imageBuffer);
108
- const { width, height } = image.bitmap;
109
- if (!width || !height) {
110
- throw Error("Undefined width or height from the input image.");
111
- }
112
- const finalNewSize = newSize || calculateNewDimensions(width, height);
113
- image.resize(finalNewSize.width, finalNewSize.height);
114
- const resizedBuffer = await image.getBufferAsync(import_jimp2.default.MIME_PNG);
115
- return isBase64 ? resizedBuffer.toString("base64") : resizedBuffer;
173
+ function resizeImgBase64(inputData, newSize) {
174
+ return __async(this, null, function* () {
175
+ const splitFlag = ";base64,";
176
+ const dataSplitted = inputData.split(splitFlag);
177
+ if (dataSplitted.length !== 2) {
178
+ throw Error("Invalid base64 data");
179
+ }
180
+ const imageBuffer = import_node_buffer2.Buffer.from(dataSplitted[1], "base64");
181
+ const buffer = yield resizeImg(imageBuffer, newSize);
182
+ const content = buffer.toString("base64");
183
+ return `${dataSplitted[0]}${splitFlag}${content}`;
184
+ });
116
185
  }
117
186
  function calculateNewDimensions(originalWidth, originalHeight) {
118
187
  const maxWidth = 2048;
@@ -133,169 +202,183 @@ function calculateNewDimensions(originalWidth, originalHeight) {
133
202
  height: Math.round(newHeight)
134
203
  };
135
204
  }
136
- async function trimImage(image) {
137
- const jimpImage = await import_jimp2.default.read(
138
- import_node_buffer2.Buffer.isBuffer(image) ? image : import_node_buffer2.Buffer.from(image)
139
- );
140
- const { width, height } = jimpImage.bitmap;
141
- if (width <= 3 || height <= 3) {
142
- return null;
143
- }
144
- const trimmedImage = jimpImage.autocrop();
145
- const { width: trimmedWidth, height: trimmedHeight } = trimmedImage.bitmap;
146
- const trimOffsetLeft = (width - trimmedWidth) / 2;
147
- const trimOffsetTop = (height - trimmedHeight) / 2;
148
- if (trimOffsetLeft === 0 && trimOffsetTop === 0) {
149
- return null;
150
- }
151
- return {
152
- trimOffsetLeft: -trimOffsetLeft,
153
- trimOffsetTop: -trimOffsetTop,
154
- width: trimmedWidth,
155
- height: trimmedHeight
156
- };
205
+ function trimImage(image) {
206
+ return __async(this, null, function* () {
207
+ const Jimp = yield getJimp();
208
+ const jimpImage = yield Jimp.read(
209
+ import_node_buffer2.Buffer.isBuffer(image) ? image : import_node_buffer2.Buffer.from(image)
210
+ );
211
+ const { width, height } = jimpImage.bitmap;
212
+ if (width <= 3 || height <= 3) {
213
+ return null;
214
+ }
215
+ const trimmedImage = jimpImage.autocrop();
216
+ const { width: trimmedWidth, height: trimmedHeight } = trimmedImage.bitmap;
217
+ const trimOffsetLeft = (width - trimmedWidth) / 2;
218
+ const trimOffsetTop = (height - trimmedHeight) / 2;
219
+ if (trimOffsetLeft === 0 && trimOffsetTop === 0) {
220
+ return null;
221
+ }
222
+ return {
223
+ trimOffsetLeft: -trimOffsetLeft,
224
+ trimOffsetTop: -trimOffsetTop,
225
+ width: trimmedWidth,
226
+ height: trimmedHeight
227
+ };
228
+ });
157
229
  }
158
230
 
159
231
  // src/img/box-select.ts
160
232
  var import_node_assert2 = __toESM(require("assert"));
161
- var import_node_buffer3 = require("buffer");
162
- var import_jimp3 = __toESM(require("jimp"));
163
- var createSvgOverlay = (elements, imageWidth, imageHeight) => {
164
- const createPngOverlay = async (elements2, imageWidth2, imageHeight2) => {
165
- const image = new import_jimp3.default(imageWidth2, imageHeight2, 0);
166
- const colors = [
167
- { rect: 4278190335, text: 4294967295 }
168
- // red, white
169
- // { rect: 0x0000ffff, text: 0xffffffff }, // blue, white
170
- // { rect: 0x8b4513ff, text: 0xffffffff }, // brown, white
171
- ];
172
- const boxPadding = 5;
173
- for (let index = 0; index < elements2.length; index++) {
174
- const element = elements2[index];
175
- const color = colors[index % colors.length];
176
- const paddedRect = {
177
- left: Math.max(0, element.rect.left - boxPadding),
178
- top: Math.max(0, element.rect.top - boxPadding),
179
- width: Math.min(
180
- imageWidth2 - element.rect.left,
181
- element.rect.width + boxPadding * 2
182
- ),
183
- height: Math.min(
184
- imageHeight2 - element.rect.top,
185
- element.rect.height + boxPadding * 2
186
- )
187
- };
188
- image.scan(
189
- paddedRect.left,
190
- paddedRect.top,
191
- paddedRect.width,
192
- paddedRect.height,
193
- function(x, y, idx) {
194
- if (x === paddedRect.left || x === paddedRect.left + paddedRect.width - 1 || y === paddedRect.top || y === paddedRect.top + paddedRect.height - 1) {
195
- this.bitmap.data[idx + 0] = color.rect >> 24 & 255;
196
- this.bitmap.data[idx + 1] = color.rect >> 16 & 255;
197
- this.bitmap.data[idx + 2] = color.rect >> 8 & 255;
198
- this.bitmap.data[idx + 3] = color.rect & 255;
199
- }
200
- }
201
- );
202
- const textWidth = element.indexId.toString().length * 8;
203
- const textHeight = 12;
204
- const rectWidth = textWidth + 5;
205
- const rectHeight = textHeight + 4;
206
- let rectX = paddedRect.left - rectWidth;
207
- let rectY = paddedRect.top + paddedRect.height / 2 - textHeight / 2 - 2;
208
- const checkOverlap = (x, y) => {
209
- return elements2.slice(0, index).some((otherElement) => {
210
- return x < otherElement.rect.left + otherElement.rect.width && x + rectWidth > otherElement.rect.left && y < otherElement.rect.top + otherElement.rect.height && y + rectHeight > otherElement.rect.top;
211
- });
212
- };
213
- const isWithinBounds = (x, y) => {
214
- return x >= 0 && x + rectWidth <= imageWidth2 && y >= 0 && y + rectHeight <= imageHeight2;
215
- };
216
- if (checkOverlap(rectX, rectY) || !isWithinBounds(rectX, rectY)) {
217
- if (!checkOverlap(paddedRect.left, paddedRect.top - rectHeight - 2) && isWithinBounds(paddedRect.left, paddedRect.top - rectHeight - 2)) {
218
- rectX = paddedRect.left;
219
- rectY = paddedRect.top - rectHeight - 2;
220
- } else if (!checkOverlap(
221
- paddedRect.left,
222
- paddedRect.top + paddedRect.height + 2
223
- ) && isWithinBounds(
224
- paddedRect.left,
225
- paddedRect.top + paddedRect.height + 2
226
- )) {
227
- rectX = paddedRect.left;
228
- rectY = paddedRect.top + paddedRect.height + 2;
229
- } else if (!checkOverlap(
230
- paddedRect.left + paddedRect.width + 2,
231
- paddedRect.top
232
- ) && isWithinBounds(paddedRect.left + paddedRect.width + 2, paddedRect.top)) {
233
- rectX = paddedRect.left + paddedRect.width + 2;
234
- rectY = paddedRect.top;
235
- } else {
236
- rectX = paddedRect.left;
237
- rectY = paddedRect.top + 2;
233
+ var cachedFont = null;
234
+ var createSvgOverlay = (elements, imageWidth, imageHeight) => __async(void 0, null, function* () {
235
+ const Jimp = yield getJimp();
236
+ const image = new Jimp(imageWidth, imageHeight, 0);
237
+ const colors = [
238
+ { rect: 4278190335, text: 4294967295 }
239
+ // red, white
240
+ // { rect: 0x0000ffff, text: 0xffffffff }, // blue, white
241
+ // { rect: 0x8b4513ff, text: 0xffffffff }, // brown, white
242
+ ];
243
+ const boxPadding = 5;
244
+ for (let index = 0; index < elements.length; index++) {
245
+ const element = elements[index];
246
+ const color = colors[index % colors.length];
247
+ const paddedRect = {
248
+ left: Math.max(0, element.rect.left - boxPadding),
249
+ top: Math.max(0, element.rect.top - boxPadding),
250
+ width: Math.min(
251
+ imageWidth - element.rect.left,
252
+ element.rect.width + boxPadding * 2
253
+ ),
254
+ height: Math.min(
255
+ imageHeight - element.rect.top,
256
+ element.rect.height + boxPadding * 2
257
+ )
258
+ };
259
+ image.scan(
260
+ paddedRect.left,
261
+ paddedRect.top,
262
+ paddedRect.width,
263
+ paddedRect.height,
264
+ function(x, y, idx) {
265
+ if (x === paddedRect.left || x === paddedRect.left + paddedRect.width - 1 || y === paddedRect.top || y === paddedRect.top + paddedRect.height - 1) {
266
+ this.bitmap.data[idx + 0] = color.rect >> 24 & 255;
267
+ this.bitmap.data[idx + 1] = color.rect >> 16 & 255;
268
+ this.bitmap.data[idx + 2] = color.rect >> 8 & 255;
269
+ this.bitmap.data[idx + 3] = color.rect & 255;
238
270
  }
239
271
  }
240
- image.scan(rectX, rectY, rectWidth, rectHeight, function(x, y, idx) {
241
- this.bitmap.data[idx + 0] = color.rect >> 24 & 255;
242
- this.bitmap.data[idx + 1] = color.rect >> 16 & 255;
243
- this.bitmap.data[idx + 2] = color.rect >> 8 & 255;
244
- this.bitmap.data[idx + 3] = color.rect & 255;
272
+ );
273
+ const textWidth = element.indexId.toString().length * 8;
274
+ const textHeight = 12;
275
+ const rectWidth = textWidth + 5;
276
+ const rectHeight = textHeight + 4;
277
+ let rectX = paddedRect.left - rectWidth;
278
+ let rectY = paddedRect.top + paddedRect.height / 2 - textHeight / 2 - 2;
279
+ const checkOverlap = (x, y) => {
280
+ return elements.slice(0, index).some((otherElement) => {
281
+ return x < otherElement.rect.left + otherElement.rect.width && x + rectWidth > otherElement.rect.left && y < otherElement.rect.top + otherElement.rect.height && y + rectHeight > otherElement.rect.top;
245
282
  });
246
- const font = await import_jimp3.default.loadFont(import_jimp3.default.FONT_SANS_16_WHITE);
247
- image.print(
248
- font,
249
- rectX,
250
- rectY,
251
- {
252
- text: element.indexId.toString(),
253
- alignmentX: import_jimp3.default.HORIZONTAL_ALIGN_CENTER,
254
- alignmentY: import_jimp3.default.VERTICAL_ALIGN_MIDDLE
255
- },
256
- rectWidth,
257
- rectHeight
258
- );
283
+ };
284
+ const isWithinBounds = (x, y) => {
285
+ return x >= 0 && x + rectWidth <= imageWidth && y >= 0 && y + rectHeight <= imageHeight;
286
+ };
287
+ if (checkOverlap(rectX, rectY) || !isWithinBounds(rectX, rectY)) {
288
+ if (!checkOverlap(paddedRect.left, paddedRect.top - rectHeight - 2) && isWithinBounds(paddedRect.left, paddedRect.top - rectHeight - 2)) {
289
+ rectX = paddedRect.left;
290
+ rectY = paddedRect.top - rectHeight - 2;
291
+ } else if (!checkOverlap(
292
+ paddedRect.left,
293
+ paddedRect.top + paddedRect.height + 2
294
+ ) && isWithinBounds(paddedRect.left, paddedRect.top + paddedRect.height + 2)) {
295
+ rectX = paddedRect.left;
296
+ rectY = paddedRect.top + paddedRect.height + 2;
297
+ } else if (!checkOverlap(paddedRect.left + paddedRect.width + 2, paddedRect.top) && isWithinBounds(paddedRect.left + paddedRect.width + 2, paddedRect.top)) {
298
+ rectX = paddedRect.left + paddedRect.width + 2;
299
+ rectY = paddedRect.top;
300
+ } else {
301
+ rectX = paddedRect.left;
302
+ rectY = paddedRect.top + 2;
303
+ }
259
304
  }
260
- return image.getBufferAsync(import_jimp3.default.MIME_PNG);
261
- };
262
- return createPngOverlay(elements, imageWidth, imageHeight);
263
- };
264
- var compositeElementInfoImg = async (options) => {
265
- const { inputImgBase64, elementsPositionInfo } = options;
266
- const imageBuffer = import_node_buffer3.Buffer.from(inputImgBase64, "base64");
267
- const image = await import_jimp3.default.read(imageBuffer);
268
- const { width, height } = image.bitmap;
305
+ image.scan(rectX, rectY, rectWidth, rectHeight, function(x, y, idx) {
306
+ this.bitmap.data[idx + 0] = color.rect >> 24 & 255;
307
+ this.bitmap.data[idx + 1] = color.rect >> 16 & 255;
308
+ this.bitmap.data[idx + 2] = color.rect >> 8 & 255;
309
+ this.bitmap.data[idx + 3] = color.rect & 255;
310
+ });
311
+ try {
312
+ cachedFont = cachedFont || (yield Jimp.loadFont(Jimp.FONT_SANS_16_WHITE));
313
+ } catch (error) {
314
+ console.error("Error loading font", error);
315
+ }
316
+ image.print(
317
+ cachedFont,
318
+ rectX,
319
+ rectY,
320
+ {
321
+ text: element.indexId.toString(),
322
+ alignmentX: Jimp.HORIZONTAL_ALIGN_CENTER,
323
+ alignmentY: Jimp.VERTICAL_ALIGN_MIDDLE
324
+ },
325
+ rectWidth,
326
+ rectHeight
327
+ );
328
+ }
329
+ return image;
330
+ });
331
+ var compositeElementInfoImg = (options) => __async(void 0, null, function* () {
332
+ (0, import_node_assert2.default)(options.inputImgBase64, "inputImgBase64 is required");
333
+ let width = 0;
334
+ let height = 0;
335
+ let jimpImage;
336
+ const Jimp = yield getJimp();
337
+ if (options.size) {
338
+ width = options.size.width;
339
+ height = options.size.height;
340
+ }
341
+ if (!width || !height) {
342
+ const info = yield imageInfoOfBase64(options.inputImgBase64);
343
+ width = info.width;
344
+ height = info.height;
345
+ jimpImage = info.jimpImage;
346
+ } else {
347
+ const imageBuffer = yield bufferFromBase64(options.inputImgBase64);
348
+ jimpImage = yield Jimp.read(imageBuffer);
349
+ }
269
350
  if (!width || !height) {
270
351
  throw Error("Image processing failed because width or height is undefined");
271
352
  }
272
- const svgOverlay = await createSvgOverlay(
273
- elementsPositionInfo,
274
- width,
275
- height
276
- );
277
- return await import_jimp3.default.read(imageBuffer).then(async (image2) => {
278
- const svgImage = await import_jimp3.default.read(svgOverlay);
279
- return image2.composite(svgImage, 0, 0, {
280
- mode: import_jimp3.default.BLEND_SOURCE_OVER,
353
+ const { elementsPositionInfo } = options;
354
+ const result = yield Promise.resolve(jimpImage).then((image) => __async(void 0, null, function* () {
355
+ const svgOverlay = yield createSvgOverlay(
356
+ elementsPositionInfo,
357
+ width,
358
+ height
359
+ );
360
+ const svgImage = yield Jimp.read(svgOverlay);
361
+ const compositeImage = yield image.composite(svgImage, 0, 0, {
362
+ mode: Jimp.BLEND_SOURCE_OVER,
281
363
  opacitySource: 1,
282
364
  opacityDest: 1
283
365
  });
284
- }).then((compositeImage) => {
285
- return compositeImage.getBufferAsync(import_jimp3.default.MIME_PNG);
286
- }).then((buffer) => {
287
- return buffer.toString("base64");
288
- }).catch((error) => {
366
+ return compositeImage;
367
+ })).then((compositeImage) => __async(void 0, null, function* () {
368
+ const base64 = yield compositeImage.getBase64Async(Jimp.MIME_PNG);
369
+ return base64;
370
+ })).catch((error) => {
289
371
  throw error;
290
372
  });
291
- };
292
- var processImageElementInfo = async (options) => {
373
+ return result;
374
+ });
375
+ var processImageElementInfo = (options) => __async(void 0, null, function* () {
293
376
  const base64Image = options.inputImgBase64.split(";base64,").pop();
294
377
  (0, import_node_assert2.default)(base64Image, "base64Image is undefined");
295
378
  const [
296
379
  compositeElementInfoImgBase64,
297
380
  compositeElementInfoImgWithoutTextBase64
298
- ] = await Promise.all([
381
+ ] = yield Promise.all([
299
382
  compositeElementInfoImg({
300
383
  inputImgBase64: options.inputImgBase64,
301
384
  elementsPositionInfo: options.elementsPositionInfo
@@ -309,17 +392,19 @@ var processImageElementInfo = async (options) => {
309
392
  compositeElementInfoImgBase64,
310
393
  compositeElementInfoImgWithoutTextBase64
311
394
  };
312
- };
395
+ });
313
396
  // Annotate the CommonJS export names for ESM import in node:
314
397
  0 && (module.exports = {
315
398
  base64Encoded,
316
399
  base64ToPngFormat,
400
+ bufferFromBase64,
317
401
  calculateNewDimensions,
318
402
  compositeElementInfoImg,
319
403
  imageInfo,
320
404
  imageInfoOfBase64,
321
405
  processImageElementInfo,
322
406
  resizeImg,
407
+ resizeImgBase64,
323
408
  saveBase64Image,
324
409
  transformImgPathToBase64,
325
410
  trimImage
@@ -0,0 +1,3 @@
1
+ declare const _default: {};
2
+
3
+ export { _default as default };
package/dist/lib/index.js CHANGED
@@ -23,6 +23,4 @@ __export(src_exports, {
23
23
  default: () => src_default
24
24
  });
25
25
  module.exports = __toCommonJS(src_exports);
26
- function src_default() {
27
- return "hello world";
28
- }
26
+ var src_default = {};
@@ -0,0 +1,4 @@
1
+ declare const ifInBrowser: boolean;
2
+ declare function uuid(): string;
3
+
4
+ export { ifInBrowser, uuid };
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/utils.ts
21
+ var utils_exports = {};
22
+ __export(utils_exports, {
23
+ ifInBrowser: () => ifInBrowser,
24
+ uuid: () => uuid
25
+ });
26
+ module.exports = __toCommonJS(utils_exports);
27
+ var import_node_crypto = require("crypto");
28
+ var ifInBrowser = typeof window !== "undefined";
29
+ function uuid() {
30
+ if (ifInBrowser) {
31
+ return Math.random().toString(36).substring(2, 15);
32
+ }
33
+ return (0, import_node_crypto.randomUUID)();
34
+ }
35
+ // Annotate the CommonJS export names for ESM import in node:
36
+ 0 && (module.exports = {
37
+ ifInBrowser,
38
+ uuid
39
+ });
@@ -1,3 +1,3 @@
1
- declare function export_default(): string;
1
+ declare const _default: {};
2
2
 
3
- export { export_default as default };
3
+ export { _default as default };