@midscene/shared 0.17.1-beta-20250519125046.0 → 0.17.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/img.d.ts CHANGED
@@ -122,6 +122,7 @@ declare const compositeElementInfoImg: (options: {
122
122
  height: number;
123
123
  };
124
124
  annotationPadding?: number;
125
+ prompt?: string;
125
126
  }) => Promise<string>;
126
127
  declare const processImageElementInfo: (options: {
127
128
  inputImgBase64: string;
package/dist/es/img.js CHANGED
@@ -229,7 +229,7 @@ var loadFonts = async () => {
229
229
  return fonts;
230
230
  }
231
231
  };
232
- var createSvgOverlay = async (elements, imageWidth, imageHeight, boxPadding = 5) => {
232
+ var createSvgOverlay = async (elements, imageWidth, imageHeight, boxPadding = 5, prompt) => {
233
233
  const Jimp = await getJimp();
234
234
  const image = new Jimp(imageWidth, imageHeight, 0);
235
235
  const colors = [
@@ -244,6 +244,41 @@ var createSvgOverlay = async (elements, imageWidth, imageHeight, boxPadding = 5)
244
244
  { rect: 1342206975, text: 4294967295 }
245
245
  // purple, white
246
246
  ];
247
+ if (prompt) {
248
+ try {
249
+ cachedFont = cachedFont || await loadFonts();
250
+ const promptPadding = 10;
251
+ const promptMargin = 20;
252
+ const promptHeight = 30;
253
+ const promptY = imageHeight - promptHeight - promptMargin;
254
+ image.scan(
255
+ 0,
256
+ promptY,
257
+ imageWidth,
258
+ promptHeight,
259
+ (x, y, idx) => {
260
+ image.bitmap.data[idx + 0] = 0;
261
+ image.bitmap.data[idx + 1] = 0;
262
+ image.bitmap.data[idx + 2] = 0;
263
+ image.bitmap.data[idx + 3] = 204;
264
+ }
265
+ );
266
+ image.print(
267
+ cachedFont,
268
+ promptPadding,
269
+ promptY,
270
+ {
271
+ text: prompt,
272
+ alignmentX: Jimp.HORIZONTAL_ALIGN_LEFT,
273
+ alignmentY: Jimp.VERTICAL_ALIGN_MIDDLE
274
+ },
275
+ imageWidth - promptPadding * 2,
276
+ promptHeight
277
+ );
278
+ } catch (error) {
279
+ console.error("Error drawing prompt text", error);
280
+ }
281
+ }
247
282
  for (let index = 0; index < elements.length; index++) {
248
283
  const element = elements[index];
249
284
  const color = colors[index % colors.length];
@@ -367,13 +402,14 @@ var compositeElementInfoImg = async (options) => {
367
402
  if (!width || !height) {
368
403
  throw Error("Image processing failed because width or height is undefined");
369
404
  }
370
- const { elementsPositionInfo } = options;
405
+ const { elementsPositionInfo, prompt } = options;
371
406
  const result = await Promise.resolve(jimpImage).then(async (image) => {
372
407
  const svgOverlay = await createSvgOverlay(
373
408
  elementsPositionInfo,
374
409
  width,
375
410
  height,
376
- options.annotationPadding
411
+ options.annotationPadding,
412
+ prompt
377
413
  );
378
414
  const svgImage = await Jimp.read(svgOverlay);
379
415
  const compositeImage = await image.composite(svgImage, 0, 0, {
package/dist/lib/img.d.ts CHANGED
@@ -122,6 +122,7 @@ declare const compositeElementInfoImg: (options: {
122
122
  height: number;
123
123
  };
124
124
  annotationPadding?: number;
125
+ prompt?: string;
125
126
  }) => Promise<string>;
126
127
  declare const processImageElementInfo: (options: {
127
128
  inputImgBase64: string;
package/dist/lib/img.js CHANGED
@@ -284,7 +284,7 @@ var loadFonts = async () => {
284
284
  return fonts;
285
285
  }
286
286
  };
287
- var createSvgOverlay = async (elements, imageWidth, imageHeight, boxPadding = 5) => {
287
+ var createSvgOverlay = async (elements, imageWidth, imageHeight, boxPadding = 5, prompt) => {
288
288
  const Jimp = await getJimp();
289
289
  const image = new Jimp(imageWidth, imageHeight, 0);
290
290
  const colors = [
@@ -299,6 +299,41 @@ var createSvgOverlay = async (elements, imageWidth, imageHeight, boxPadding = 5)
299
299
  { rect: 1342206975, text: 4294967295 }
300
300
  // purple, white
301
301
  ];
302
+ if (prompt) {
303
+ try {
304
+ cachedFont = cachedFont || await loadFonts();
305
+ const promptPadding = 10;
306
+ const promptMargin = 20;
307
+ const promptHeight = 30;
308
+ const promptY = imageHeight - promptHeight - promptMargin;
309
+ image.scan(
310
+ 0,
311
+ promptY,
312
+ imageWidth,
313
+ promptHeight,
314
+ (x, y, idx) => {
315
+ image.bitmap.data[idx + 0] = 0;
316
+ image.bitmap.data[idx + 1] = 0;
317
+ image.bitmap.data[idx + 2] = 0;
318
+ image.bitmap.data[idx + 3] = 204;
319
+ }
320
+ );
321
+ image.print(
322
+ cachedFont,
323
+ promptPadding,
324
+ promptY,
325
+ {
326
+ text: prompt,
327
+ alignmentX: Jimp.HORIZONTAL_ALIGN_LEFT,
328
+ alignmentY: Jimp.VERTICAL_ALIGN_MIDDLE
329
+ },
330
+ imageWidth - promptPadding * 2,
331
+ promptHeight
332
+ );
333
+ } catch (error) {
334
+ console.error("Error drawing prompt text", error);
335
+ }
336
+ }
302
337
  for (let index = 0; index < elements.length; index++) {
303
338
  const element = elements[index];
304
339
  const color = colors[index % colors.length];
@@ -422,13 +457,14 @@ var compositeElementInfoImg = async (options) => {
422
457
  if (!width || !height) {
423
458
  throw Error("Image processing failed because width or height is undefined");
424
459
  }
425
- const { elementsPositionInfo } = options;
460
+ const { elementsPositionInfo, prompt } = options;
426
461
  const result = await Promise.resolve(jimpImage).then(async (image) => {
427
462
  const svgOverlay = await createSvgOverlay(
428
463
  elementsPositionInfo,
429
464
  width,
430
465
  height,
431
- options.annotationPadding
466
+ options.annotationPadding,
467
+ prompt
432
468
  );
433
469
  const svgImage = await Jimp.read(svgOverlay);
434
470
  const compositeImage = await image.composite(svgImage, 0, 0, {
@@ -122,6 +122,7 @@ declare const compositeElementInfoImg: (options: {
122
122
  height: number;
123
123
  };
124
124
  annotationPadding?: number;
125
+ prompt?: string;
125
126
  }) => Promise<string>;
126
127
  declare const processImageElementInfo: (options: {
127
128
  inputImgBase64: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midscene/shared",
3
- "version": "0.17.1-beta-20250519125046.0",
3
+ "version": "0.17.1",
4
4
  "repository": "https://github.com/web-infra-dev/midscene",
5
5
  "homepage": "https://midscenejs.com/",
6
6
  "types": "./dist/types/index.d.ts",
@@ -26,6 +26,7 @@ const createSvgOverlay = async (
26
26
  imageWidth: number,
27
27
  imageHeight: number,
28
28
  boxPadding = 5,
29
+ prompt?: string,
29
30
  ): Promise<Jimp> => {
30
31
  const Jimp = await getJimp();
31
32
  const image = new Jimp(imageWidth, imageHeight, 0x00000000);
@@ -39,6 +40,47 @@ const createSvgOverlay = async (
39
40
  { rect: 0x500073ff, text: 0xffffffff }, // purple, white
40
41
  ];
41
42
 
43
+ // Draw prompt text if provided
44
+ if (prompt) {
45
+ try {
46
+ cachedFont = cachedFont || (await loadFonts());
47
+ const promptPadding = 10;
48
+ const promptMargin = 20;
49
+ const promptHeight = 30;
50
+ const promptY = imageHeight - promptHeight - promptMargin;
51
+
52
+ // Draw prompt background
53
+ image.scan(
54
+ 0,
55
+ promptY,
56
+ imageWidth,
57
+ promptHeight,
58
+ (x: number, y: number, idx: number): void => {
59
+ image.bitmap.data[idx + 0] = 0x00; // R
60
+ image.bitmap.data[idx + 1] = 0x00; // G
61
+ image.bitmap.data[idx + 2] = 0x00; // B
62
+ image.bitmap.data[idx + 3] = 0xcc; // A (80% opacity)
63
+ },
64
+ );
65
+
66
+ // Draw prompt text
67
+ image.print(
68
+ cachedFont,
69
+ promptPadding,
70
+ promptY,
71
+ {
72
+ text: prompt,
73
+ alignmentX: Jimp.HORIZONTAL_ALIGN_LEFT,
74
+ alignmentY: Jimp.VERTICAL_ALIGN_MIDDLE,
75
+ },
76
+ imageWidth - promptPadding * 2,
77
+ promptHeight,
78
+ );
79
+ } catch (error) {
80
+ console.error('Error drawing prompt text', error);
81
+ }
82
+ }
83
+
42
84
  for (let index = 0; index < elements.length; index++) {
43
85
  const element = elements[index];
44
86
  const color = colors[index % colors.length];
@@ -195,6 +237,7 @@ export const compositeElementInfoImg = async (options: {
195
237
  elementsPositionInfo: Array<BaseElement>;
196
238
  size?: { width: number; height: number };
197
239
  annotationPadding?: number;
240
+ prompt?: string;
198
241
  }) => {
199
242
  assert(options.inputImgBase64, 'inputImgBase64 is required');
200
243
  let width = 0;
@@ -227,7 +270,7 @@ export const compositeElementInfoImg = async (options: {
227
270
  throw Error('Image processing failed because width or height is undefined');
228
271
  }
229
272
 
230
- const { elementsPositionInfo } = options;
273
+ const { elementsPositionInfo, prompt } = options;
231
274
 
232
275
  const result = await Promise.resolve(jimpImage)
233
276
  .then(async (image: Jimp) => {
@@ -237,6 +280,7 @@ export const compositeElementInfoImg = async (options: {
237
280
  width,
238
281
  height,
239
282
  options.annotationPadding,
283
+ prompt,
240
284
  );
241
285
  const svgImage = await Jimp.read(svgOverlay);
242
286
  const compositeImage = await image.composite(svgImage, 0, 0, {