@midscene/visualizer 1.7.3 → 1.7.4

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.
@@ -48,7 +48,10 @@ const downloadReport = (content)=>{
48
48
  const a = document.createElement('a');
49
49
  a.href = url;
50
50
  a.download = 'midscene_report.html';
51
+ a.style.display = 'none';
52
+ document.body.appendChild(a);
51
53
  a.click();
54
+ document.body.removeChild(a);
52
55
  setTimeout(()=>URL.revokeObjectURL(url), 0);
53
56
  };
54
57
  function deriveTaskId(scriptFrames, stepsFrame) {
@@ -69,6 +69,19 @@ const cameraStateForRect = (rect, imageWidth, imageHeight)=>{
69
69
  width: Math.round(cameraWidth)
70
70
  };
71
71
  };
72
+ const createFullPageCameraState = (imageWidth, imageHeight)=>cameraStateForRect({
73
+ left: 0,
74
+ top: 0,
75
+ width: imageWidth,
76
+ height: imageHeight
77
+ }, imageWidth, imageHeight);
78
+ const resolveTaskShotSize = (task, fallbackWidth, fallbackHeight)=>{
79
+ var _task_uiContext_shotSize, _task_uiContext, _task_uiContext_shotSize1, _task_uiContext1;
80
+ return {
81
+ width: (null == task ? void 0 : null == (_task_uiContext = task.uiContext) ? void 0 : null == (_task_uiContext_shotSize = _task_uiContext.shotSize) ? void 0 : _task_uiContext_shotSize.width) || fallbackWidth,
82
+ height: (null == task ? void 0 : null == (_task_uiContext1 = task.uiContext) ? void 0 : null == (_task_uiContext_shotSize1 = _task_uiContext1.shotSize) ? void 0 : _task_uiContext_shotSize1.height) || fallbackHeight
83
+ };
84
+ };
72
85
  const mergeTwoCameraState = (cameraState1, cameraState2)=>{
73
86
  const newLeft = Math.min(cameraState1.left, cameraState2.left);
74
87
  const newTop = Math.min(cameraState1.top, cameraState2.top);
@@ -195,12 +208,6 @@ const generateAnimationScripts = (execution, task, imageWidth, imageHeight, exec
195
208
  }
196
209
  }
197
210
  if (0 === tasksIncluded.length) return null;
198
- const fullPageCameraState = cameraStateForRect({
199
- left: 0,
200
- top: 0,
201
- width: imageWidth,
202
- height: imageHeight
203
- }, imageWidth, imageHeight);
204
211
  const getTaskId = (taskIndex)=>{
205
212
  var _tasksIncluded_taskIndex;
206
213
  return null == (_tasksIncluded_taskIndex = tasksIncluded[taskIndex]) ? void 0 : _tasksIncluded_taskIndex.taskId;
@@ -323,7 +330,7 @@ const generateAnimationScripts = (execution, task, imageWidth, imageHeight, exec
323
330
  }, asScreenshot(screenshot)));
324
331
  }
325
332
  } else if ('Action Space' === task.type) {
326
- var _task_recorder_, _task_recorder, _task_uiContext_shotSize2, _task_uiContext2, _task_uiContext_shotSize3, _task_uiContext3;
333
+ var _task_recorder_, _task_recorder;
327
334
  const title = typeStr(task);
328
335
  const subTitle = paramStr(task);
329
336
  scripts.push({
@@ -345,14 +352,15 @@ const generateAnimationScripts = (execution, task, imageWidth, imageHeight, exec
345
352
  }
346
353
  scripts.push(setPointerScript(mousePointer, title, subTitle, currentTaskId));
347
354
  const screenshot = null == (_task_recorder = task.recorder) ? void 0 : null == (_task_recorder_ = _task_recorder[0]) ? void 0 : _task_recorder_.screenshot;
355
+ const { width, height } = resolveTaskShotSize(task, imageWidth, imageHeight);
348
356
  scripts.push(createScript({
349
357
  type: 'img',
350
358
  duration: actionDuration,
351
- camera: 'Sleep' === task.subType ? fullPageCameraState : void 0,
359
+ camera: 'Sleep' === task.subType ? createFullPageCameraState(width, height) : void 0,
352
360
  title,
353
361
  subTitle,
354
- imageWidth: (null == (_task_uiContext2 = task.uiContext) ? void 0 : null == (_task_uiContext_shotSize2 = _task_uiContext2.shotSize) ? void 0 : _task_uiContext_shotSize2.width) || imageWidth,
355
- imageHeight: (null == (_task_uiContext3 = task.uiContext) ? void 0 : null == (_task_uiContext_shotSize3 = _task_uiContext3.shotSize) ? void 0 : _task_uiContext_shotSize3.height) || imageHeight,
362
+ imageWidth: width,
363
+ imageHeight: height,
356
364
  taskId: currentTaskId
357
365
  }, asScreenshot(screenshot)));
358
366
  } else {
@@ -361,33 +369,34 @@ const generateAnimationScripts = (execution, task, imageWidth, imageHeight, exec
361
369
  const subTitle = paramStr(task);
362
370
  const screenshot = null == (_task_recorder1 = task.recorder) ? void 0 : null == (_task_recorder_1 = _task_recorder1[task.recorder.length - 1]) ? void 0 : _task_recorder_1.screenshot;
363
371
  if (screenshot) {
364
- var _task_uiContext_shotSize4, _task_uiContext4, _task_uiContext_shotSize5, _task_uiContext5;
372
+ const { width, height } = resolveTaskShotSize(task, imageWidth, imageHeight);
365
373
  scripts.push(createScript({
366
374
  type: 'img',
367
375
  duration: stillDuration,
368
- camera: fullPageCameraState,
376
+ camera: createFullPageCameraState(width, height),
369
377
  title,
370
378
  subTitle,
371
- imageWidth: (null == (_task_uiContext4 = task.uiContext) ? void 0 : null == (_task_uiContext_shotSize4 = _task_uiContext4.shotSize) ? void 0 : _task_uiContext_shotSize4.width) || imageWidth,
372
- imageHeight: (null == (_task_uiContext5 = task.uiContext) ? void 0 : null == (_task_uiContext_shotSize5 = _task_uiContext5.shotSize) ? void 0 : _task_uiContext_shotSize5.height) || imageHeight,
379
+ imageWidth: width,
380
+ imageHeight: height,
373
381
  taskId: currentTaskId
374
382
  }, asScreenshot(screenshot)));
375
383
  }
376
384
  }
377
385
  if ('finished' !== task.status) {
378
- var _task_recorder_2, _task_recorder2, _task_uiContext_shotSize6, _task_uiContext6, _task_uiContext_shotSize7, _task_uiContext7;
386
+ var _task_recorder_2, _task_recorder2;
379
387
  const errorTitle = typeStr(task);
380
388
  const errorMsg = task.errorMessage || 'unknown error';
381
389
  const errorSubTitle = errorMsg.indexOf('NOT_IMPLEMENTED_AS_DESIGNED') > 0 ? 'Further actions cannot be performed in the current environment' : errorMsg;
382
390
  const screenshot = null == (_task_recorder2 = task.recorder) ? void 0 : null == (_task_recorder_2 = _task_recorder2[task.recorder.length - 1]) ? void 0 : _task_recorder_2.screenshot;
391
+ const { width, height } = resolveTaskShotSize(task, imageWidth, imageHeight);
383
392
  scripts.push(createScript({
384
393
  type: 'img',
385
- camera: fullPageCameraState,
394
+ camera: createFullPageCameraState(width, height),
386
395
  duration: stillDuration,
387
396
  title: errorTitle,
388
397
  subTitle: errorSubTitle,
389
- imageWidth: (null == (_task_uiContext6 = task.uiContext) ? void 0 : null == (_task_uiContext_shotSize6 = _task_uiContext6.shotSize) ? void 0 : _task_uiContext_shotSize6.width) || imageWidth,
390
- imageHeight: (null == (_task_uiContext7 = task.uiContext) ? void 0 : null == (_task_uiContext_shotSize7 = _task_uiContext7.shotSize) ? void 0 : _task_uiContext_shotSize7.height) || imageHeight,
398
+ imageWidth: width,
399
+ imageHeight: height,
391
400
  taskId: currentTaskId
392
401
  }, asScreenshot(screenshot)));
393
402
  }
@@ -402,12 +411,16 @@ const generateAnimationScripts = (execution, task, imageWidth, imageHeight, exec
402
411
  });
403
412
  insightOnTop = false;
404
413
  }
414
+ const lastTaskShotSize = tasksIncluded.length > 0 ? resolveTaskShotSize(tasksIncluded[tasksIncluded.length - 1], imageWidth, imageHeight) : {
415
+ width: imageWidth,
416
+ height: imageHeight
417
+ };
405
418
  scripts.push({
406
419
  title: 'End',
407
420
  subTitle: initSubTitle,
408
421
  type: 'img',
409
422
  duration: lastFrameDuration,
410
- camera: fullPageCameraState,
423
+ camera: createFullPageCameraState(lastTaskShotSize.width, lastTaskShotSize.height),
411
424
  taskId: void 0
412
425
  });
413
426
  return scripts;
@@ -87,7 +87,10 @@ const downloadReport = (content)=>{
87
87
  const a = document.createElement('a');
88
88
  a.href = url;
89
89
  a.download = 'midscene_report.html';
90
+ a.style.display = 'none';
91
+ document.body.appendChild(a);
90
92
  a.click();
93
+ document.body.removeChild(a);
91
94
  setTimeout(()=>URL.revokeObjectURL(url), 0);
92
95
  };
93
96
  function deriveTaskId(scriptFrames, stepsFrame) {
@@ -101,6 +101,19 @@ const cameraStateForRect = (rect, imageWidth, imageHeight)=>{
101
101
  width: Math.round(cameraWidth)
102
102
  };
103
103
  };
104
+ const createFullPageCameraState = (imageWidth, imageHeight)=>cameraStateForRect({
105
+ left: 0,
106
+ top: 0,
107
+ width: imageWidth,
108
+ height: imageHeight
109
+ }, imageWidth, imageHeight);
110
+ const resolveTaskShotSize = (task, fallbackWidth, fallbackHeight)=>{
111
+ var _task_uiContext_shotSize, _task_uiContext, _task_uiContext_shotSize1, _task_uiContext1;
112
+ return {
113
+ width: (null == task ? void 0 : null == (_task_uiContext = task.uiContext) ? void 0 : null == (_task_uiContext_shotSize = _task_uiContext.shotSize) ? void 0 : _task_uiContext_shotSize.width) || fallbackWidth,
114
+ height: (null == task ? void 0 : null == (_task_uiContext1 = task.uiContext) ? void 0 : null == (_task_uiContext_shotSize1 = _task_uiContext1.shotSize) ? void 0 : _task_uiContext_shotSize1.height) || fallbackHeight
115
+ };
116
+ };
104
117
  const mergeTwoCameraState = (cameraState1, cameraState2)=>{
105
118
  const newLeft = Math.min(cameraState1.left, cameraState2.left);
106
119
  const newTop = Math.min(cameraState1.top, cameraState2.top);
@@ -227,12 +240,6 @@ const generateAnimationScripts = (execution, task, imageWidth, imageHeight, exec
227
240
  }
228
241
  }
229
242
  if (0 === tasksIncluded.length) return null;
230
- const fullPageCameraState = cameraStateForRect({
231
- left: 0,
232
- top: 0,
233
- width: imageWidth,
234
- height: imageHeight
235
- }, imageWidth, imageHeight);
236
243
  const getTaskId = (taskIndex)=>{
237
244
  var _tasksIncluded_taskIndex;
238
245
  return null == (_tasksIncluded_taskIndex = tasksIncluded[taskIndex]) ? void 0 : _tasksIncluded_taskIndex.taskId;
@@ -355,7 +362,7 @@ const generateAnimationScripts = (execution, task, imageWidth, imageHeight, exec
355
362
  }, asScreenshot(screenshot)));
356
363
  }
357
364
  } else if ('Action Space' === task.type) {
358
- var _task_recorder_, _task_recorder, _task_uiContext_shotSize2, _task_uiContext2, _task_uiContext_shotSize3, _task_uiContext3;
365
+ var _task_recorder_, _task_recorder;
359
366
  const title = (0, agent_namespaceObject.typeStr)(task);
360
367
  const subTitle = (0, agent_namespaceObject.paramStr)(task);
361
368
  scripts.push({
@@ -377,14 +384,15 @@ const generateAnimationScripts = (execution, task, imageWidth, imageHeight, exec
377
384
  }
378
385
  scripts.push(setPointerScript(external_index_js_namespaceObject.mousePointer, title, subTitle, currentTaskId));
379
386
  const screenshot = null == (_task_recorder = task.recorder) ? void 0 : null == (_task_recorder_ = _task_recorder[0]) ? void 0 : _task_recorder_.screenshot;
387
+ const { width, height } = resolveTaskShotSize(task, imageWidth, imageHeight);
380
388
  scripts.push(createScript({
381
389
  type: 'img',
382
390
  duration: actionDuration,
383
- camera: 'Sleep' === task.subType ? fullPageCameraState : void 0,
391
+ camera: 'Sleep' === task.subType ? createFullPageCameraState(width, height) : void 0,
384
392
  title,
385
393
  subTitle,
386
- imageWidth: (null == (_task_uiContext2 = task.uiContext) ? void 0 : null == (_task_uiContext_shotSize2 = _task_uiContext2.shotSize) ? void 0 : _task_uiContext_shotSize2.width) || imageWidth,
387
- imageHeight: (null == (_task_uiContext3 = task.uiContext) ? void 0 : null == (_task_uiContext_shotSize3 = _task_uiContext3.shotSize) ? void 0 : _task_uiContext_shotSize3.height) || imageHeight,
394
+ imageWidth: width,
395
+ imageHeight: height,
388
396
  taskId: currentTaskId
389
397
  }, asScreenshot(screenshot)));
390
398
  } else {
@@ -393,33 +401,34 @@ const generateAnimationScripts = (execution, task, imageWidth, imageHeight, exec
393
401
  const subTitle = (0, agent_namespaceObject.paramStr)(task);
394
402
  const screenshot = null == (_task_recorder1 = task.recorder) ? void 0 : null == (_task_recorder_1 = _task_recorder1[task.recorder.length - 1]) ? void 0 : _task_recorder_1.screenshot;
395
403
  if (screenshot) {
396
- var _task_uiContext_shotSize4, _task_uiContext4, _task_uiContext_shotSize5, _task_uiContext5;
404
+ const { width, height } = resolveTaskShotSize(task, imageWidth, imageHeight);
397
405
  scripts.push(createScript({
398
406
  type: 'img',
399
407
  duration: stillDuration,
400
- camera: fullPageCameraState,
408
+ camera: createFullPageCameraState(width, height),
401
409
  title,
402
410
  subTitle,
403
- imageWidth: (null == (_task_uiContext4 = task.uiContext) ? void 0 : null == (_task_uiContext_shotSize4 = _task_uiContext4.shotSize) ? void 0 : _task_uiContext_shotSize4.width) || imageWidth,
404
- imageHeight: (null == (_task_uiContext5 = task.uiContext) ? void 0 : null == (_task_uiContext_shotSize5 = _task_uiContext5.shotSize) ? void 0 : _task_uiContext_shotSize5.height) || imageHeight,
411
+ imageWidth: width,
412
+ imageHeight: height,
405
413
  taskId: currentTaskId
406
414
  }, asScreenshot(screenshot)));
407
415
  }
408
416
  }
409
417
  if ('finished' !== task.status) {
410
- var _task_recorder_2, _task_recorder2, _task_uiContext_shotSize6, _task_uiContext6, _task_uiContext_shotSize7, _task_uiContext7;
418
+ var _task_recorder_2, _task_recorder2;
411
419
  const errorTitle = (0, agent_namespaceObject.typeStr)(task);
412
420
  const errorMsg = task.errorMessage || 'unknown error';
413
421
  const errorSubTitle = errorMsg.indexOf('NOT_IMPLEMENTED_AS_DESIGNED') > 0 ? 'Further actions cannot be performed in the current environment' : errorMsg;
414
422
  const screenshot = null == (_task_recorder2 = task.recorder) ? void 0 : null == (_task_recorder_2 = _task_recorder2[task.recorder.length - 1]) ? void 0 : _task_recorder_2.screenshot;
423
+ const { width, height } = resolveTaskShotSize(task, imageWidth, imageHeight);
415
424
  scripts.push(createScript({
416
425
  type: 'img',
417
- camera: fullPageCameraState,
426
+ camera: createFullPageCameraState(width, height),
418
427
  duration: stillDuration,
419
428
  title: errorTitle,
420
429
  subTitle: errorSubTitle,
421
- imageWidth: (null == (_task_uiContext6 = task.uiContext) ? void 0 : null == (_task_uiContext_shotSize6 = _task_uiContext6.shotSize) ? void 0 : _task_uiContext_shotSize6.width) || imageWidth,
422
- imageHeight: (null == (_task_uiContext7 = task.uiContext) ? void 0 : null == (_task_uiContext_shotSize7 = _task_uiContext7.shotSize) ? void 0 : _task_uiContext_shotSize7.height) || imageHeight,
430
+ imageWidth: width,
431
+ imageHeight: height,
423
432
  taskId: currentTaskId
424
433
  }, asScreenshot(screenshot)));
425
434
  }
@@ -434,12 +443,16 @@ const generateAnimationScripts = (execution, task, imageWidth, imageHeight, exec
434
443
  });
435
444
  insightOnTop = false;
436
445
  }
446
+ const lastTaskShotSize = tasksIncluded.length > 0 ? resolveTaskShotSize(tasksIncluded[tasksIncluded.length - 1], imageWidth, imageHeight) : {
447
+ width: imageWidth,
448
+ height: imageHeight
449
+ };
437
450
  scripts.push({
438
451
  title: 'End',
439
452
  subTitle: initSubTitle,
440
453
  type: 'img',
441
454
  duration: lastFrameDuration,
442
- camera: fullPageCameraState,
455
+ camera: createFullPageCameraState(lastTaskShotSize.width, lastTaskShotSize.height),
443
456
  taskId: void 0
444
457
  });
445
458
  return scripts;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midscene/visualizer",
3
- "version": "1.7.3",
3
+ "version": "1.7.4",
4
4
  "repository": "https://github.com/web-infra-dev/midscene",
5
5
  "homepage": "https://midscenejs.com/",
6
6
  "types": "./dist/types/index.d.ts",
@@ -58,10 +58,10 @@
58
58
  "antd": "^5.21.6",
59
59
  "buffer": "6.0.3",
60
60
  "dayjs": "^1.11.11",
61
- "@midscene/core": "1.7.3",
62
- "@midscene/playground": "1.7.3",
63
- "@midscene/shared": "1.7.3",
64
- "@midscene/web": "1.7.3"
61
+ "@midscene/core": "1.7.4",
62
+ "@midscene/playground": "1.7.4",
63
+ "@midscene/web": "1.7.4",
64
+ "@midscene/shared": "1.7.4"
65
65
  },
66
66
  "license": "MIT",
67
67
  "scripts": {