@midscene/visualizer 0.5.2-beta-20241010035503.0 → 0.5.2

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.
@@ -83,6 +83,17 @@ const frameKit = () => {
83
83
  callback(performance.now());
84
84
  });
85
85
  },
86
+ timeout: (callback, ms) => {
87
+ if (cancelFlag) {
88
+ throw new Error(ERROR_FRAME_CANCEL);
89
+ }
90
+ setTimeout(() => {
91
+ if (cancelFlag) {
92
+ throw new Error(ERROR_FRAME_CANCEL);
93
+ }
94
+ callback();
95
+ }, ms);
96
+ },
86
97
  cancel: () => {
87
98
  console.log("set frame cancel");
88
99
  cancelFlag = true;
@@ -420,7 +431,7 @@ const Player = () => {
420
431
  if (!scripts) {
421
432
  throw new Error("scripts is required");
422
433
  }
423
- const { frame, cancel } = frameKit();
434
+ const { frame, cancel, timeout } = frameKit();
424
435
  cancelFn = cancel;
425
436
  const allImages = scripts.filter((item) => !!item.img).map((item) => item.img);
426
437
  yield Promise.all([...allImages, mouseLoading].map(preloadImage));
@@ -431,6 +442,7 @@ const Player = () => {
431
442
  const totalDuration = scripts.reduce((acc, item) => {
432
443
  return acc + item.duration + (item.insightCameraDuration || 0);
433
444
  }, 0);
445
+ const progressUpdateInterval = 300;
434
446
  const startTime = performance.now();
435
447
  setAnimationProgress(0);
436
448
  const updateProgress = () => {
@@ -439,7 +451,7 @@ const Player = () => {
439
451
  1
440
452
  );
441
453
  setAnimationProgress(progress);
442
- return frame(updateProgress);
454
+ return timeout(updateProgress, progressUpdateInterval);
443
455
  };
444
456
  frame(updateProgress);
445
457
  for (const index in scripts) {
@@ -509,7 +521,7 @@ const Player = () => {
509
521
  Promise.resolve(
510
522
  (() => __async(void 0, null, function* () {
511
523
  yield init();
512
- yield play();
524
+ setReplayMark(Date.now());
513
525
  }))()
514
526
  );
515
527
  return () => {
@@ -33,7 +33,7 @@ const cameraStateForRect = (rect, imageWidth, imageHeight) => {
33
33
  } else {
34
34
  rectWidthOnPage = rect.height / imageHeight * imageWidth;
35
35
  }
36
- const cameraPaddingRatio = rectWidthOnPage < 50 ? 0.3 : 0.2;
36
+ const cameraPaddingRatio = rectWidthOnPage > 400 ? 0.1 : rectWidthOnPage > 50 ? 0.2 : 0.3;
37
37
  const cameraWidth = Math.min(
38
38
  imageWidth,
39
39
  rectWidthOnPage + imageWidth * cameraPaddingRatio * 2