@midscene/visualizer 0.6.2 → 0.6.3-beta-20241017035917.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.
@@ -29,8 +29,6 @@ import { DropShadowFilter } from "pixi-filters";
29
29
  import { useBlackboardPreference, useInsightDump } from "./store";
30
30
  const itemFillAlpha = 0.4;
31
31
  const highlightAlpha = 0.4;
32
- const bgOnAlpha = 1;
33
- const bgOffAlpha = 0.3;
34
32
  const noop = () => {
35
33
  };
36
34
  const rectMarkForItem = (rect, name, ifHighlight, onPointOver, onPointerOut) => {
@@ -72,7 +70,7 @@ const BlackBoard = () => {
72
70
  const highlightElements = useInsightDump((store) => store.highlightElements);
73
71
  const highlightIds = highlightElements.map((e) => e.id);
74
72
  const { context } = dump;
75
- const { size, screenshotBase64 } = context;
73
+ const { size, screenshotBase64, screenshotBase64WithElementMarker } = context;
76
74
  const screenWidth = size.width;
77
75
  const screenHeight = size.height;
78
76
  const domRef = useRef(null);
@@ -81,7 +79,8 @@ const BlackBoard = () => {
81
79
  const highlightContainer = useMemo(() => new PIXI.Container(), []);
82
80
  const elementMarkContainer = useMemo(() => new PIXI.Container(), []);
83
81
  const pixiBgRef = useRef();
84
- const { bgVisible, setBgVisible, elementsVisible, setTextsVisible } = useBlackboardPreference();
82
+ const { markerVisible, setMarkerVisible, elementsVisible, setTextsVisible } = useBlackboardPreference();
83
+ const ifMarkerAvailable = !!screenshotBase64WithElementMarker;
85
84
  useEffect(() => {
86
85
  Promise.resolve(
87
86
  (() => __async(void 0, null, function* () {
@@ -127,14 +126,27 @@ const BlackBoard = () => {
127
126
  if (!app.stage)
128
127
  return;
129
128
  const screenshotTexture = PIXI.Texture.from(img);
130
- const screenshotSprite = new PIXI.Sprite(screenshotTexture);
131
- screenshotSprite.x = 0;
132
- screenshotSprite.y = 0;
133
- screenshotSprite.width = screenWidth;
134
- screenshotSprite.height = screenHeight;
135
- app.stage.addChildAt(screenshotSprite, 0);
136
- pixiBgRef.current = screenshotSprite;
137
- screenshotSprite.alpha = bgVisible ? bgOnAlpha : bgOffAlpha;
129
+ const backgroundSprite = new PIXI.Sprite(screenshotTexture);
130
+ backgroundSprite.x = 0;
131
+ backgroundSprite.y = 0;
132
+ backgroundSprite.width = screenWidth;
133
+ backgroundSprite.height = screenHeight;
134
+ app.stage.addChildAt(backgroundSprite, 0);
135
+ if (ifMarkerAvailable) {
136
+ const markerImg = new Image();
137
+ markerImg.src = screenshotBase64WithElementMarker;
138
+ markerImg.onload = () => {
139
+ const markerTexture = PIXI.Texture.from(markerImg);
140
+ const markerSprite = new PIXI.Sprite(markerTexture);
141
+ markerSprite.x = 0;
142
+ markerSprite.y = 0;
143
+ markerSprite.width = screenWidth;
144
+ markerSprite.height = screenHeight;
145
+ app.stage.addChildAt(markerSprite, 1);
146
+ pixiBgRef.current = markerSprite;
147
+ markerSprite.visible = markerVisible;
148
+ };
149
+ }
138
150
  };
139
151
  }, [app.stage, appInitialed]);
140
152
  const { highlightElementRects } = useMemo(() => {
@@ -179,10 +191,10 @@ const BlackBoard = () => {
179
191
  // bgVisible,
180
192
  // elementsVisible,
181
193
  ]);
182
- const onSetBg = (e) => {
183
- setBgVisible(e.target.checked);
194
+ const onSetMarkerVisible = (e) => {
195
+ setMarkerVisible(e.target.checked);
184
196
  if (pixiBgRef.current) {
185
- pixiBgRef.current.alpha = e.target.checked ? bgOnAlpha : bgOffAlpha;
197
+ pixiBgRef.current.visible = e.target.checked;
186
198
  }
187
199
  };
188
200
  const onSetElementsVisible = (e) => {
@@ -211,7 +223,15 @@ const BlackBoard = () => {
211
223
  }
212
224
  ),
213
225
  /* @__PURE__ */ jsx("div", { className: "blackboard-filter", children: /* @__PURE__ */ jsxs("div", { className: "overlay-control", children: [
214
- /* @__PURE__ */ jsx(Checkbox, { checked: bgVisible, onChange: onSetBg, children: "Screenshot" }),
226
+ /* @__PURE__ */ jsx(
227
+ Checkbox,
228
+ {
229
+ checked: markerVisible,
230
+ onChange: onSetMarkerVisible,
231
+ disabled: !ifMarkerAvailable,
232
+ children: "Marker"
233
+ }
234
+ ),
215
235
  /* @__PURE__ */ jsx(Checkbox, { checked: elementsVisible, onChange: onSetElementsVisible, children: "Elements" })
216
236
  ] }) }),
217
237
  /* @__PURE__ */ jsx("div", { className: "bottom-tip", children: bottomTipA })
@@ -2,7 +2,7 @@
2
2
  width: fit-content;
3
3
  max-width: 100%;
4
4
  max-height: 100%;
5
- padding: 12px;
5
+ padding: 12px 0;
6
6
  padding-bottom: 0;
7
7
  background: #434443DD;
8
8
  box-sizing: border-box;
@@ -20,6 +20,7 @@
20
20
  align-items: center;
21
21
  justify-content: center;
22
22
  overflow: hidden;
23
+ padding: 0 12px;
23
24
  }
24
25
  .player-container .canvas-container canvas {
25
26
  max-width: 100%;
@@ -54,6 +55,7 @@
54
55
  display: flex;
55
56
  flex-direction: row;
56
57
  flex-shrink: 0;
58
+ padding: 0 12px;
57
59
  }
58
60
  .player-container .player-controls .status-icon {
59
61
  transition: 0.2s;
@@ -445,7 +445,7 @@ const Player = () => {
445
445
  const totalDuration = scripts.reduce((acc, item) => {
446
446
  return acc + item.duration + (item.insightCameraDuration || 0);
447
447
  }, 0);
448
- const progressUpdateInterval = 300;
448
+ const progressUpdateInterval = 200;
449
449
  const startTime = performance.now();
450
450
  setAnimationProgress(0);
451
451
  const updateProgress = () => {
@@ -454,7 +454,9 @@ const Player = () => {
454
454
  1
455
455
  );
456
456
  setAnimationProgress(progress);
457
- return timeout(updateProgress, progressUpdateInterval);
457
+ if (progress < 1) {
458
+ return timeout(updateProgress, progressUpdateInterval);
459
+ }
458
460
  };
459
461
  frame(updateProgress);
460
462
  for (const index in scripts) {
@@ -21,6 +21,7 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
21
21
  import "./player.css";
22
22
  import { mousePointer, paramStr, typeStr } from "../utils";
23
23
  const stillDuration = 1200;
24
+ const stillAfterInsightDuration = 300;
24
25
  const locateDuration = 800;
25
26
  const actionDuration = 1e3;
26
27
  const clearInsightDuration = 200;
@@ -138,9 +139,18 @@ const generateAnimationScripts = (execution, imageWidth, imageHeight) => {
138
139
  throw new Error("insight dump is required");
139
140
  }
140
141
  const insightContentLength = insightDump.context.content.length;
142
+ if (insightDump.context.screenshotBase64WithElementMarker) {
143
+ scripts.push({
144
+ type: "img",
145
+ img: insightDump.context.screenshotBase64,
146
+ duration: stillAfterInsightDuration,
147
+ title,
148
+ subTitle
149
+ });
150
+ }
141
151
  scripts.push({
142
152
  type: "insight",
143
- img: insightDump.context.screenshotBase64,
153
+ img: insightDump.context.screenshotBase64WithElementMarker || insightDump.context.screenshotBase64,
144
154
  insightDump,
145
155
  camera: currentCameraState === fullPageCameraState || !insightCameraState ? void 0 : mergeTwoCameraState(currentCameraState, insightCameraState),
146
156
  duration: insightContentLength > 20 ? locateDuration : locateDuration * 0.5,
@@ -150,7 +160,7 @@ const generateAnimationScripts = (execution, imageWidth, imageHeight) => {
150
160
  });
151
161
  scripts.push({
152
162
  type: "sleep",
153
- duration: 800,
163
+ duration: stillAfterInsightDuration,
154
164
  title,
155
165
  subTitle
156
166
  });
@@ -21,10 +21,10 @@ import * as Z from "zustand";
21
21
  import { generateAnimationScripts } from "./replay-scripts";
22
22
  const { create } = Z;
23
23
  const useBlackboardPreference = create((set) => ({
24
- bgVisible: true,
24
+ markerVisible: true,
25
25
  elementsVisible: true,
26
- setBgVisible: (visible) => {
27
- set({ bgVisible: visible });
26
+ setMarkerVisible: (visible) => {
27
+ set({ markerVisible: visible });
28
28
  },
29
29
  setTextsVisible: (visible) => {
30
30
  set({ elementsVisible: visible });
@@ -88,11 +88,13 @@ const useExecutionDump = create((set, get) => {
88
88
  let height = 0;
89
89
  dump.executions.forEach((execution) => {
90
90
  execution.tasks.forEach((task) => {
91
- var _a, _b, _c, _d, _e, _f, _g, _h;
91
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
92
92
  if (task.type === "Insight") {
93
93
  const insightTask = task;
94
- width = ((_d = (_c = (_b = (_a = insightTask.log) == null ? void 0 : _a.dump) == null ? void 0 : _b.context) == null ? void 0 : _c.size) == null ? void 0 : _d.width) || 1920;
95
- height = ((_h = (_g = (_f = (_e = insightTask.log) == null ? void 0 : _e.dump) == null ? void 0 : _f.context) == null ? void 0 : _g.size) == null ? void 0 : _h.height) || 1080;
94
+ if ((_d = (_c = (_b = (_a = insightTask.log) == null ? void 0 : _a.dump) == null ? void 0 : _b.context) == null ? void 0 : _c.size) == null ? void 0 : _d.width) {
95
+ width = (_h = (_g = (_f = (_e = insightTask.log) == null ? void 0 : _e.dump) == null ? void 0 : _f.context) == null ? void 0 : _g.size) == null ? void 0 : _h.width;
96
+ height = (_l = (_k = (_j = (_i = insightTask.log) == null ? void 0 : _i.dump) == null ? void 0 : _j.context) == null ? void 0 : _k.size) == null ? void 0 : _l.height;
97
+ }
96
98
  }
97
99
  });
98
100
  });
package/dist/index.css CHANGED
@@ -282,7 +282,7 @@ footer.mt-8 {
282
282
  width: fit-content;
283
283
  max-width: 100%;
284
284
  max-height: 100%;
285
- padding: 12px;
285
+ padding: 12px 0;
286
286
  padding-bottom: 0;
287
287
  background: #434443DD;
288
288
  box-sizing: border-box;
@@ -300,6 +300,7 @@ footer.mt-8 {
300
300
  align-items: center;
301
301
  justify-content: center;
302
302
  overflow: hidden;
303
+ padding: 0 12px;
303
304
  }
304
305
  .player-container .canvas-container canvas {
305
306
  max-width: 100%;
@@ -334,6 +335,7 @@ footer.mt-8 {
334
335
  display: flex;
335
336
  flex-direction: row;
336
337
  flex-shrink: 0;
338
+ padding: 0 12px;
337
339
  }
338
340
  .player-container .player-controls .status-icon {
339
341
  transition: 0.2s;