@midscene/visualizer 0.26.2-beta-20250812091127.0 → 0.26.3-beta-20250813021342.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/es/blank_polyfill.mjs +2 -0
- package/dist/es/component/blackboard.css +12 -5
- package/dist/es/component/blackboard.mjs +266 -0
- package/dist/es/component/color.mjs +35 -0
- package/dist/es/component/describer.css +9 -5
- package/dist/es/component/describer.mjs +128 -0
- package/dist/es/component/env-config.mjs +112 -0
- package/dist/es/component/github-star.css +1 -0
- package/dist/es/component/github-star.mjs +20 -0
- package/dist/es/component/logo.css +5 -3
- package/dist/es/component/logo.mjs +20 -0
- package/dist/es/component/misc.mjs +54 -0
- package/dist/es/component/pixi-loader.mjs +16 -0
- package/dist/es/component/player.css +88 -70
- package/dist/es/component/player.mjs +628 -0
- package/dist/es/component/playground/ConfigSelector.mjs +53 -0
- package/dist/es/component/playground/ContextPreview.mjs +39 -0
- package/dist/es/component/playground/HistorySelector.mjs +193 -0
- package/dist/es/component/playground/PlaygroundResult.mjs +60 -0
- package/dist/es/component/playground/PromptInput.mjs +225 -0
- package/dist/es/component/playground/ServiceModeControl.mjs +100 -0
- package/dist/es/component/playground/index.css +140 -98
- package/dist/es/component/playground/playground-constants.mjs +45 -0
- package/dist/es/component/playground/playground-utils.mjs +89 -0
- package/dist/es/component/playground/useServerValid.mjs +27 -0
- package/dist/es/component/playground/useStaticPageAgent.mjs +12 -0
- package/dist/es/component/replay-scripts.mjs +271 -0
- package/dist/es/component/shiny-text.css +33 -22
- package/dist/es/component/shiny-text.mjs +15 -0
- package/dist/es/component/store/history.mjs +55 -0
- package/dist/es/component/store/store.mjs +128 -0
- package/dist/es/icons/close.mjs +19 -0
- package/dist/es/icons/history.mjs +30 -0
- package/dist/es/icons/magnifying-glass.mjs +39 -0
- package/dist/es/icons/setting.mjs +20 -0
- package/dist/es/index.mjs +21 -0
- package/dist/es/init.mjs +10 -0
- package/dist/es/{utils.js → utils.mjs} +51 -75
- package/dist/lib/blank_polyfill.js +34 -38
- package/dist/lib/component/blackboard.css +12 -5
- package/dist/lib/component/blackboard.js +293 -306
- package/dist/lib/component/color.js +64 -74
- package/dist/lib/component/describer.css +9 -5
- package/dist/lib/component/describer.js +158 -198
- package/dist/lib/component/env-config.js +142 -147
- package/dist/lib/component/github-star.css +1 -0
- package/dist/lib/component/github-star.js +51 -62
- package/dist/lib/component/logo.css +5 -3
- package/dist/lib/component/logo.js +53 -56
- package/dist/lib/component/misc.js +85 -84
- package/dist/lib/component/pixi-loader.js +49 -80
- package/dist/lib/component/player.css +88 -70
- package/dist/lib/component/player.js +627 -738
- package/dist/lib/component/playground/ConfigSelector.js +91 -92
- package/dist/lib/component/playground/ContextPreview.js +80 -72
- package/dist/lib/component/playground/HistorySelector.js +234 -197
- package/dist/lib/component/playground/PlaygroundResult.js +100 -103
- package/dist/lib/component/playground/PromptInput.js +250 -237
- package/dist/lib/component/playground/ServiceModeControl.js +124 -124
- package/dist/lib/component/playground/index.css +140 -98
- package/dist/lib/component/playground/playground-constants.js +97 -73
- package/dist/lib/component/playground/playground-types.js +17 -31
- package/dist/lib/component/playground/playground-utils.js +140 -168
- package/dist/lib/component/playground/useServerValid.js +55 -86
- package/dist/lib/component/playground/useStaticPageAgent.js +45 -51
- package/dist/lib/component/replay-scripts.js +291 -373
- package/dist/lib/component/shiny-text.css +33 -22
- package/dist/lib/component/shiny-text.js +46 -57
- package/dist/lib/component/store/history.js +58 -64
- package/dist/lib/component/store/store.js +132 -128
- package/dist/lib/icons/close.js +53 -0
- package/dist/lib/icons/history.js +64 -0
- package/dist/lib/icons/magnifying-glass.js +73 -0
- package/dist/lib/icons/setting.js +54 -0
- package/dist/lib/index.js +158 -124
- package/dist/lib/init.js +39 -46
- package/dist/lib/utils.js +105 -109
- package/dist/types/blank_polyfill.d.ts +2 -2
- package/dist/types/component/playground/ConfigSelector.d.ts +1 -0
- package/dist/types/component/playground/ContextPreview.d.ts +1 -0
- package/dist/types/component/playground/HistorySelector.d.ts +1 -0
- package/dist/types/component/playground/PlaygroundResult.d.ts +1 -0
- package/dist/types/component/playground/PromptInput.d.ts +1 -0
- package/dist/types/component/playground/ServiceModeControl.d.ts +1 -0
- package/package.json +16 -18
- package/dist/es/assets/close.909351c0.svg +0 -4
- package/dist/es/assets/history.164a4eab.svg +0 -4
- package/dist/es/assets/magnifying-glass.9498e70e.svg +0 -12
- package/dist/es/assets/setting.80ab7285.svg +0 -11
- package/dist/es/blank_polyfill.js +0 -10
- package/dist/es/component/blackboard.js +0 -286
- package/dist/es/component/color.js +0 -49
- package/dist/es/component/describer.js +0 -173
- package/dist/es/component/env-config.js +0 -117
- package/dist/es/component/github-star.js +0 -31
- package/dist/es/component/logo.js +0 -25
- package/dist/es/component/misc.js +0 -63
- package/dist/es/component/pixi-loader.js +0 -51
- package/dist/es/component/player.js +0 -746
- package/dist/es/component/playground/ConfigSelector.js +0 -64
- package/dist/es/component/playground/ContextPreview.js +0 -42
- package/dist/es/component/playground/HistorySelector.js +0 -168
- package/dist/es/component/playground/PlaygroundResult.js +0 -73
- package/dist/es/component/playground/PromptInput.js +0 -212
- package/dist/es/component/playground/ServiceModeControl.js +0 -100
- package/dist/es/component/playground/playground-constants.js +0 -39
- package/dist/es/component/playground/playground-types.js +0 -6
- package/dist/es/component/playground/playground-utils.js +0 -141
- package/dist/es/component/playground/useServerValid.js +0 -58
- package/dist/es/component/playground/useStaticPageAgent.js +0 -20
- package/dist/es/component/replay-scripts.js +0 -361
- package/dist/es/component/shiny-text.js +0 -30
- package/dist/es/component/store/history.js +0 -34
- package/dist/es/component/store/store.js +0 -99
- package/dist/es/index.js +0 -79
- package/dist/es/init.js +0 -17
- package/dist/index.css +0 -595
- package/dist/index.js +0 -1
- package/dist/lib/assets/close.909351c0.svg +0 -4
- package/dist/lib/assets/history.164a4eab.svg +0 -4
- package/dist/lib/assets/magnifying-glass.9498e70e.svg +0 -12
- package/dist/lib/assets/setting.80ab7285.svg +0 -11
- package/dist/lib/component/common.css +0 -0
- /package/dist/es/component/{common.css → playground/playground-types.mjs} +0 -0
|
@@ -0,0 +1,628 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import "pixi.js/unsafe-eval";
|
|
4
|
+
import { Application, Container, Sprite } from "pixi.js";
|
|
5
|
+
import { useEffect, useMemo, useRef, useState } from "react";
|
|
6
|
+
import "./player.css";
|
|
7
|
+
import { mouseLoading, mousePointer } from "../utils.mjs";
|
|
8
|
+
import { CaretRightOutlined, DownloadOutlined, ExportOutlined, LoadingOutlined } from "@ant-design/icons";
|
|
9
|
+
import { treeToList } from "@midscene/shared/extractor";
|
|
10
|
+
import { Spin, Tooltip } from "antd";
|
|
11
|
+
import { rectMarkForItem } from "./blackboard.mjs";
|
|
12
|
+
import { getTextureFromCache, loadTexture } from "./pixi-loader.mjs";
|
|
13
|
+
function _define_property(obj, key, value) {
|
|
14
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
15
|
+
value: value,
|
|
16
|
+
enumerable: true,
|
|
17
|
+
configurable: true,
|
|
18
|
+
writable: true
|
|
19
|
+
});
|
|
20
|
+
else obj[key] = value;
|
|
21
|
+
return obj;
|
|
22
|
+
}
|
|
23
|
+
const canvasPaddingLeft = 0;
|
|
24
|
+
const canvasPaddingTop = 0;
|
|
25
|
+
const cubicBezier = (t, p0, p1, p2, p3)=>{
|
|
26
|
+
const t2 = 1 - t;
|
|
27
|
+
return p0 * t2 * t2 * t2 + 3 * p1 * t * t2 * t2 + 3 * p2 * t * t * t2 + p3 * t * t * t;
|
|
28
|
+
};
|
|
29
|
+
const cubicImage = (t)=>linear(t);
|
|
30
|
+
const cubicInsightElement = (t)=>cubicBezier(t, 0, 0.5, 0.5, 1);
|
|
31
|
+
const cubicMouse = (t)=>linear(t);
|
|
32
|
+
const linear = (t)=>t;
|
|
33
|
+
const sleep = (ms)=>new Promise((resolve)=>setTimeout(resolve, ms));
|
|
34
|
+
const ERROR_FRAME_CANCEL = 'frame cancel (this is an error on purpose)';
|
|
35
|
+
const frameKit = ()=>{
|
|
36
|
+
let cancelFlag = false;
|
|
37
|
+
return {
|
|
38
|
+
frame: (callback)=>{
|
|
39
|
+
if (cancelFlag) throw new Error(ERROR_FRAME_CANCEL);
|
|
40
|
+
requestAnimationFrame(()=>{
|
|
41
|
+
if (cancelFlag) throw new Error(ERROR_FRAME_CANCEL);
|
|
42
|
+
callback(performance.now());
|
|
43
|
+
});
|
|
44
|
+
},
|
|
45
|
+
timeout: (callback, ms)=>{
|
|
46
|
+
if (cancelFlag) throw new Error(ERROR_FRAME_CANCEL);
|
|
47
|
+
setTimeout(()=>{
|
|
48
|
+
if (cancelFlag) throw new Error(ERROR_FRAME_CANCEL);
|
|
49
|
+
callback();
|
|
50
|
+
}, ms);
|
|
51
|
+
},
|
|
52
|
+
cancel: ()=>{
|
|
53
|
+
cancelFlag = true;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
const singleElementFadeInDuration = 80;
|
|
58
|
+
const LAYER_ORDER_IMG = 0;
|
|
59
|
+
const LAYER_ORDER_INSIGHT = 1;
|
|
60
|
+
const LAYER_ORDER_POINTER = 2;
|
|
61
|
+
const LAYER_ORDER_SPINNING_POINTER = 3;
|
|
62
|
+
const downloadReport = (content)=>{
|
|
63
|
+
const blob = new Blob([
|
|
64
|
+
content
|
|
65
|
+
], {
|
|
66
|
+
type: 'text/html'
|
|
67
|
+
});
|
|
68
|
+
const url = URL.createObjectURL(blob);
|
|
69
|
+
const a = document.createElement('a');
|
|
70
|
+
a.href = url;
|
|
71
|
+
a.download = 'midscene_report.html';
|
|
72
|
+
a.click();
|
|
73
|
+
};
|
|
74
|
+
class RecordingSession {
|
|
75
|
+
start() {
|
|
76
|
+
const stream = this.canvas.captureStream(60);
|
|
77
|
+
const mediaRecorder = new MediaRecorder(stream, {
|
|
78
|
+
mimeType: 'video/webm'
|
|
79
|
+
});
|
|
80
|
+
mediaRecorder.ondataavailable = (event)=>{
|
|
81
|
+
if (event.data.size > 0) this.chunks.push(event.data);
|
|
82
|
+
};
|
|
83
|
+
this.mediaRecorder = mediaRecorder;
|
|
84
|
+
this.recording = true;
|
|
85
|
+
return this.mediaRecorder.start();
|
|
86
|
+
}
|
|
87
|
+
stop() {
|
|
88
|
+
var _this_mediaRecorder;
|
|
89
|
+
if (!this.recording || !this.mediaRecorder) return void console.warn('not recording');
|
|
90
|
+
this.mediaRecorder.onstop = ()=>{
|
|
91
|
+
const blob = new Blob(this.chunks, {
|
|
92
|
+
type: 'video/webm'
|
|
93
|
+
});
|
|
94
|
+
const url = URL.createObjectURL(blob);
|
|
95
|
+
const a = document.createElement('a');
|
|
96
|
+
a.href = url;
|
|
97
|
+
a.download = 'midscene_replay.webm';
|
|
98
|
+
a.click();
|
|
99
|
+
URL.revokeObjectURL(url);
|
|
100
|
+
};
|
|
101
|
+
null == (_this_mediaRecorder = this.mediaRecorder) || _this_mediaRecorder.stop();
|
|
102
|
+
this.recording = false;
|
|
103
|
+
this.mediaRecorder = null;
|
|
104
|
+
}
|
|
105
|
+
constructor(canvas){
|
|
106
|
+
_define_property(this, "canvas", void 0);
|
|
107
|
+
_define_property(this, "mediaRecorder", null);
|
|
108
|
+
_define_property(this, "chunks", void 0);
|
|
109
|
+
_define_property(this, "recording", false);
|
|
110
|
+
this.canvas = canvas;
|
|
111
|
+
this.chunks = [];
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
function Player(props) {
|
|
115
|
+
var _scripts_;
|
|
116
|
+
const [titleText, setTitleText] = useState('');
|
|
117
|
+
const [subTitleText, setSubTitleText] = useState('');
|
|
118
|
+
const scripts = null == props ? void 0 : props.replayScripts;
|
|
119
|
+
const imageWidth = (null == props ? void 0 : props.imageWidth) || 1920;
|
|
120
|
+
const imageHeight = (null == props ? void 0 : props.imageHeight) || 1080;
|
|
121
|
+
const fitMode = (null == props ? void 0 : props.fitMode) || 'height';
|
|
122
|
+
const currentImg = useRef((null == scripts ? void 0 : null == (_scripts_ = scripts[0]) ? void 0 : _scripts_.img) || null);
|
|
123
|
+
const divContainerRef = useRef(null);
|
|
124
|
+
const app = useMemo(()=>new Application(), []);
|
|
125
|
+
const pointerSprite = useRef(null);
|
|
126
|
+
const spinningPointerSprite = useRef(null);
|
|
127
|
+
const [replayMark, setReplayMark] = useState(0);
|
|
128
|
+
const triggerReplay = ()=>{
|
|
129
|
+
setReplayMark(Date.now());
|
|
130
|
+
};
|
|
131
|
+
const windowContentContainer = useMemo(()=>{
|
|
132
|
+
const container = new Container();
|
|
133
|
+
return container;
|
|
134
|
+
}, []);
|
|
135
|
+
const insightMarkContainer = useMemo(()=>{
|
|
136
|
+
const container = new Container();
|
|
137
|
+
container.zIndex = LAYER_ORDER_INSIGHT;
|
|
138
|
+
return container;
|
|
139
|
+
}, []);
|
|
140
|
+
const basicCameraState = {
|
|
141
|
+
left: 0,
|
|
142
|
+
top: 0,
|
|
143
|
+
width: imageWidth,
|
|
144
|
+
pointerLeft: Math.round(imageWidth / 2),
|
|
145
|
+
pointerTop: Math.round(imageHeight / 2)
|
|
146
|
+
};
|
|
147
|
+
const [animationProgress, setAnimationProgress] = useState(-1);
|
|
148
|
+
const cancelFlag = useRef(false);
|
|
149
|
+
useEffect(()=>{
|
|
150
|
+
cancelFlag.current = false;
|
|
151
|
+
return ()=>{
|
|
152
|
+
cancelFlag.current = true;
|
|
153
|
+
};
|
|
154
|
+
}, []);
|
|
155
|
+
const cameraState = useRef({
|
|
156
|
+
...basicCameraState
|
|
157
|
+
});
|
|
158
|
+
const repaintImage = async ()=>{
|
|
159
|
+
const imgToUpdate = currentImg.current;
|
|
160
|
+
if (!imgToUpdate) return void console.warn('no image to update');
|
|
161
|
+
if (!getTextureFromCache(imgToUpdate)) {
|
|
162
|
+
console.warn('image not loaded', imgToUpdate);
|
|
163
|
+
await loadTexture(imgToUpdate);
|
|
164
|
+
}
|
|
165
|
+
const texture = getTextureFromCache(imgToUpdate);
|
|
166
|
+
if (!texture) throw new Error('texture not found');
|
|
167
|
+
const sprite = Sprite.from(texture);
|
|
168
|
+
if (!sprite) throw new Error('sprite not found');
|
|
169
|
+
const mainImgLabel = 'main-img';
|
|
170
|
+
const child = windowContentContainer.getChildByLabel(mainImgLabel);
|
|
171
|
+
if (child) windowContentContainer.removeChild(child);
|
|
172
|
+
sprite.label = mainImgLabel;
|
|
173
|
+
sprite.zIndex = LAYER_ORDER_IMG;
|
|
174
|
+
sprite.width = imageWidth;
|
|
175
|
+
sprite.height = imageHeight;
|
|
176
|
+
windowContentContainer.addChild(sprite);
|
|
177
|
+
};
|
|
178
|
+
const spinningPointer = (frame)=>{
|
|
179
|
+
var _pointerSprite_current, _pointerSprite_current1;
|
|
180
|
+
if (!spinningPointerSprite.current) {
|
|
181
|
+
spinningPointerSprite.current = Sprite.from(mouseLoading);
|
|
182
|
+
spinningPointerSprite.current.zIndex = LAYER_ORDER_SPINNING_POINTER;
|
|
183
|
+
spinningPointerSprite.current.anchor.set(0.5, 0.5);
|
|
184
|
+
spinningPointerSprite.current.scale.set(0.5);
|
|
185
|
+
spinningPointerSprite.current.label = 'spinning-pointer';
|
|
186
|
+
}
|
|
187
|
+
spinningPointerSprite.current.x = (null == (_pointerSprite_current = pointerSprite.current) ? void 0 : _pointerSprite_current.x) || 0;
|
|
188
|
+
spinningPointerSprite.current.y = (null == (_pointerSprite_current1 = pointerSprite.current) ? void 0 : _pointerSprite_current1.y) || 0;
|
|
189
|
+
windowContentContainer.addChild(spinningPointerSprite.current);
|
|
190
|
+
let startTime;
|
|
191
|
+
let isCancelled = false;
|
|
192
|
+
const animate = (currentTime)=>{
|
|
193
|
+
if (isCancelled) return;
|
|
194
|
+
if (!startTime) startTime = currentTime;
|
|
195
|
+
const elapsedTime = currentTime - startTime;
|
|
196
|
+
const progress = (Math.sin(elapsedTime / 500 - Math.PI / 2) + 1) / 2;
|
|
197
|
+
const rotation = progress * Math.PI * 2;
|
|
198
|
+
if (spinningPointerSprite.current) spinningPointerSprite.current.rotation = rotation;
|
|
199
|
+
frame(animate);
|
|
200
|
+
};
|
|
201
|
+
frame(animate);
|
|
202
|
+
const stopFn = ()=>{
|
|
203
|
+
if (spinningPointerSprite.current) windowContentContainer.removeChild(spinningPointerSprite.current);
|
|
204
|
+
isCancelled = true;
|
|
205
|
+
};
|
|
206
|
+
return stopFn;
|
|
207
|
+
};
|
|
208
|
+
const updatePointer = async (img, x, y)=>{
|
|
209
|
+
var _pointerSprite_current, _pointerSprite_current1;
|
|
210
|
+
if (!getTextureFromCache(img)) {
|
|
211
|
+
console.warn('image not loaded', img);
|
|
212
|
+
await loadTexture(img);
|
|
213
|
+
}
|
|
214
|
+
const texture = getTextureFromCache(img);
|
|
215
|
+
if (!texture) throw new Error('texture not found');
|
|
216
|
+
const sprite = Sprite.from(texture);
|
|
217
|
+
let targetX = null == (_pointerSprite_current = pointerSprite.current) ? void 0 : _pointerSprite_current.x;
|
|
218
|
+
let targetY = null == (_pointerSprite_current1 = pointerSprite.current) ? void 0 : _pointerSprite_current1.y;
|
|
219
|
+
if ('number' == typeof x) targetX = x;
|
|
220
|
+
if ('number' == typeof y) targetY = y;
|
|
221
|
+
if (void 0 === targetX || void 0 === targetY) return void console.warn('invalid pointer position', x, y);
|
|
222
|
+
if (pointerSprite.current) {
|
|
223
|
+
const pointer = windowContentContainer.getChildByLabel('pointer');
|
|
224
|
+
if (pointer) windowContentContainer.removeChild(pointer);
|
|
225
|
+
}
|
|
226
|
+
pointerSprite.current = sprite;
|
|
227
|
+
pointerSprite.current.x = targetX;
|
|
228
|
+
pointerSprite.current.y = targetY;
|
|
229
|
+
pointerSprite.current.label = 'pointer';
|
|
230
|
+
pointerSprite.current.zIndex = LAYER_ORDER_POINTER;
|
|
231
|
+
windowContentContainer.addChild(pointerSprite.current);
|
|
232
|
+
};
|
|
233
|
+
const updateCamera = (state)=>{
|
|
234
|
+
cameraState.current = state;
|
|
235
|
+
const newScale = Math.max(1, imageWidth / state.width);
|
|
236
|
+
windowContentContainer.scale.set(newScale);
|
|
237
|
+
windowContentContainer.x = Math.round(canvasPaddingLeft - state.left * newScale);
|
|
238
|
+
windowContentContainer.y = Math.round(canvasPaddingTop - state.top * newScale);
|
|
239
|
+
const pointer = windowContentContainer.getChildByLabel('pointer');
|
|
240
|
+
if (pointer) {
|
|
241
|
+
pointer.scale.set(1 / newScale);
|
|
242
|
+
if ('number' == typeof state.pointerLeft && 'number' == typeof state.pointerTop) {
|
|
243
|
+
pointer.x = state.pointerLeft;
|
|
244
|
+
pointer.y = state.pointerTop;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
const cameraAnimation = async (targetState, duration, frame)=>{
|
|
249
|
+
const currentState = {
|
|
250
|
+
...cameraState.current
|
|
251
|
+
};
|
|
252
|
+
const startLeft = currentState.left;
|
|
253
|
+
const startTop = currentState.top;
|
|
254
|
+
const startPointerLeft = currentState.pointerLeft;
|
|
255
|
+
const startPointerTop = currentState.pointerTop;
|
|
256
|
+
const startScale = currentState.width / imageWidth;
|
|
257
|
+
const startTime = performance.now();
|
|
258
|
+
const shouldMovePointer = 'number' == typeof targetState.pointerLeft && 'number' == typeof targetState.pointerTop && (targetState.pointerLeft !== startPointerLeft || targetState.pointerTop !== startPointerTop);
|
|
259
|
+
const pointerMoveDuration = shouldMovePointer ? 0.375 * duration : 0;
|
|
260
|
+
const cameraMoveStart = pointerMoveDuration;
|
|
261
|
+
const cameraMoveDuration = duration - pointerMoveDuration;
|
|
262
|
+
await new Promise((resolve)=>{
|
|
263
|
+
const animate = (currentTime)=>{
|
|
264
|
+
const nextState = {
|
|
265
|
+
...cameraState.current
|
|
266
|
+
};
|
|
267
|
+
const elapsedTime = currentTime - startTime;
|
|
268
|
+
if (shouldMovePointer) if (elapsedTime <= pointerMoveDuration) {
|
|
269
|
+
const rawMouseProgress = Math.min(elapsedTime / pointerMoveDuration, 1);
|
|
270
|
+
const mouseProgress = cubicMouse(rawMouseProgress);
|
|
271
|
+
nextState.pointerLeft = startPointerLeft + (targetState.pointerLeft - startPointerLeft) * mouseProgress;
|
|
272
|
+
nextState.pointerTop = startPointerTop + (targetState.pointerTop - startPointerTop) * mouseProgress;
|
|
273
|
+
} else {
|
|
274
|
+
nextState.pointerLeft = targetState.pointerLeft;
|
|
275
|
+
nextState.pointerTop = targetState.pointerTop;
|
|
276
|
+
}
|
|
277
|
+
if (elapsedTime > cameraMoveStart) {
|
|
278
|
+
const cameraElapsedTime = elapsedTime - cameraMoveStart;
|
|
279
|
+
const rawCameraProgress = Math.min(cameraElapsedTime / cameraMoveDuration, 1);
|
|
280
|
+
const cameraProgress = cubicImage(rawCameraProgress);
|
|
281
|
+
const targetScale = targetState.width / imageWidth;
|
|
282
|
+
const progressScale = startScale + (targetScale - startScale) * cameraProgress;
|
|
283
|
+
const progressWidth = imageWidth * progressScale;
|
|
284
|
+
const progressHeight = imageHeight * progressScale;
|
|
285
|
+
nextState.width = progressWidth;
|
|
286
|
+
const progressLeft = startLeft + (targetState.left - startLeft) * cameraProgress;
|
|
287
|
+
const progressTop = startTop + (targetState.top - startTop) * cameraProgress;
|
|
288
|
+
const horizontalExceed = progressLeft + progressWidth - imageWidth;
|
|
289
|
+
const verticalExceed = progressTop + progressHeight - imageHeight;
|
|
290
|
+
nextState.left = horizontalExceed > 0 ? progressLeft + horizontalExceed : progressLeft;
|
|
291
|
+
nextState.top = verticalExceed > 0 ? progressTop + verticalExceed : progressTop;
|
|
292
|
+
}
|
|
293
|
+
updateCamera(nextState);
|
|
294
|
+
if (elapsedTime < duration) frame(animate);
|
|
295
|
+
else resolve();
|
|
296
|
+
};
|
|
297
|
+
frame(animate);
|
|
298
|
+
});
|
|
299
|
+
};
|
|
300
|
+
const fadeInGraphics = function(graphics, duration, frame) {
|
|
301
|
+
let targetAlpha = arguments.length > 3 && void 0 !== arguments[3] ? arguments[3] : 1;
|
|
302
|
+
return new Promise((resolve)=>{
|
|
303
|
+
const startTime = performance.now();
|
|
304
|
+
const animate = (currentTime)=>{
|
|
305
|
+
const elapsedTime = currentTime - startTime;
|
|
306
|
+
const progress = Math.min(elapsedTime / duration, 1);
|
|
307
|
+
graphics.alpha = 0 === targetAlpha ? 1 - linear(progress) : linear(progress);
|
|
308
|
+
if (elapsedTime < duration) frame(animate);
|
|
309
|
+
else resolve();
|
|
310
|
+
};
|
|
311
|
+
frame(animate);
|
|
312
|
+
});
|
|
313
|
+
};
|
|
314
|
+
const fadeOutItem = async (graphics, duration, frame)=>fadeInGraphics(graphics, duration, frame, 0);
|
|
315
|
+
const insightElementsAnimation = async (elements, highlightElements, searchArea, duration, frame)=>{
|
|
316
|
+
insightMarkContainer.removeChildren();
|
|
317
|
+
const elementsToAdd = [
|
|
318
|
+
...elements
|
|
319
|
+
];
|
|
320
|
+
const totalLength = elementsToAdd.length;
|
|
321
|
+
let childrenCount = 0;
|
|
322
|
+
await new Promise((resolve)=>{
|
|
323
|
+
const startTime = performance.now();
|
|
324
|
+
const animate = (currentTime)=>{
|
|
325
|
+
const elapsedTime = currentTime - startTime;
|
|
326
|
+
const progress = cubicInsightElement(Math.min(elapsedTime / duration, 1));
|
|
327
|
+
const elementsToAddNow = Math.floor(progress * totalLength);
|
|
328
|
+
while(childrenCount < elementsToAddNow){
|
|
329
|
+
const randomIndex = Math.floor(Math.random() * elementsToAdd.length);
|
|
330
|
+
const element = elementsToAdd.splice(randomIndex, 1)[0];
|
|
331
|
+
if (element) {
|
|
332
|
+
const [insightMarkGraphic] = rectMarkForItem(element.rect, element.content, 'element');
|
|
333
|
+
insightMarkGraphic.alpha = 0;
|
|
334
|
+
insightMarkContainer.addChild(insightMarkGraphic);
|
|
335
|
+
childrenCount++;
|
|
336
|
+
fadeInGraphics(insightMarkGraphic, singleElementFadeInDuration, frame);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
if (elapsedTime < duration) frame(animate);
|
|
340
|
+
else {
|
|
341
|
+
while(elementsToAdd.length > 0){
|
|
342
|
+
const randomIndex = Math.floor(Math.random() * elementsToAdd.length);
|
|
343
|
+
const element = elementsToAdd.splice(randomIndex, 1)[0];
|
|
344
|
+
const [insightMarkGraphic] = rectMarkForItem(element.rect, element.content, 'element');
|
|
345
|
+
insightMarkGraphic.alpha = 1;
|
|
346
|
+
insightMarkContainer.addChild(insightMarkGraphic);
|
|
347
|
+
}
|
|
348
|
+
if (searchArea) {
|
|
349
|
+
const [searchAreaGraphic] = rectMarkForItem(searchArea, 'Search Area', 'searchArea');
|
|
350
|
+
searchAreaGraphic.alpha = 1;
|
|
351
|
+
insightMarkContainer.addChild(searchAreaGraphic);
|
|
352
|
+
}
|
|
353
|
+
highlightElements.map((element)=>{
|
|
354
|
+
const [insightMarkGraphic] = rectMarkForItem(element.rect, element.content || '', 'highlight');
|
|
355
|
+
insightMarkGraphic.alpha = 1;
|
|
356
|
+
insightMarkContainer.addChild(insightMarkGraphic);
|
|
357
|
+
});
|
|
358
|
+
resolve();
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
frame(animate);
|
|
362
|
+
});
|
|
363
|
+
};
|
|
364
|
+
const init = async ()=>{
|
|
365
|
+
if (!divContainerRef.current || !scripts) return;
|
|
366
|
+
await app.init({
|
|
367
|
+
width: imageWidth,
|
|
368
|
+
height: imageHeight,
|
|
369
|
+
background: 0xf4f4f4,
|
|
370
|
+
autoDensity: true,
|
|
371
|
+
antialias: true
|
|
372
|
+
});
|
|
373
|
+
if (!divContainerRef.current) return;
|
|
374
|
+
divContainerRef.current.appendChild(app.canvas);
|
|
375
|
+
windowContentContainer.x = 0;
|
|
376
|
+
windowContentContainer.y = 0;
|
|
377
|
+
app.stage.addChild(windowContentContainer);
|
|
378
|
+
insightMarkContainer.x = 0;
|
|
379
|
+
insightMarkContainer.y = 0;
|
|
380
|
+
windowContentContainer.addChild(insightMarkContainer);
|
|
381
|
+
};
|
|
382
|
+
const [isRecording, setIsRecording] = useState(false);
|
|
383
|
+
const recorderSessionRef = useRef(null);
|
|
384
|
+
const handleExport = ()=>{
|
|
385
|
+
if (recorderSessionRef.current) return void console.warn('recorderSession exists');
|
|
386
|
+
if (!app.canvas) return void console.warn('canvas is not initialized');
|
|
387
|
+
recorderSessionRef.current = new RecordingSession(app.canvas);
|
|
388
|
+
setIsRecording(true);
|
|
389
|
+
triggerReplay();
|
|
390
|
+
};
|
|
391
|
+
const play = ()=>{
|
|
392
|
+
let cancelFn;
|
|
393
|
+
Promise.resolve((async ()=>{
|
|
394
|
+
if (!app) throw new Error('app is not initialized');
|
|
395
|
+
if (!scripts) throw new Error("scripts is required");
|
|
396
|
+
const { frame, cancel, timeout } = frameKit();
|
|
397
|
+
cancelFn = cancel;
|
|
398
|
+
const allImages = scripts.filter((item)=>!!item.img).map((item)=>item.img);
|
|
399
|
+
await Promise.all([
|
|
400
|
+
...allImages,
|
|
401
|
+
mouseLoading,
|
|
402
|
+
mousePointer
|
|
403
|
+
].map(loadTexture));
|
|
404
|
+
insightMarkContainer.removeChildren();
|
|
405
|
+
await updatePointer(mousePointer, imageWidth / 2, imageHeight / 2);
|
|
406
|
+
await repaintImage();
|
|
407
|
+
await updateCamera({
|
|
408
|
+
...basicCameraState
|
|
409
|
+
});
|
|
410
|
+
const totalDuration = scripts.reduce((acc, item)=>acc + item.duration + (item.camera && item.insightCameraDuration ? item.insightCameraDuration : 0), 0);
|
|
411
|
+
const progressUpdateInterval = 200;
|
|
412
|
+
const startTime = performance.now();
|
|
413
|
+
setAnimationProgress(0);
|
|
414
|
+
const updateProgress = ()=>{
|
|
415
|
+
const progress = Math.min((performance.now() - startTime) / totalDuration, 1);
|
|
416
|
+
setAnimationProgress(progress);
|
|
417
|
+
if (progress < 1) return timeout(updateProgress, progressUpdateInterval);
|
|
418
|
+
};
|
|
419
|
+
frame(updateProgress);
|
|
420
|
+
if (recorderSessionRef.current) recorderSessionRef.current.start();
|
|
421
|
+
for(const index in scripts){
|
|
422
|
+
const item = scripts[index];
|
|
423
|
+
setTitleText(item.title || '');
|
|
424
|
+
setSubTitleText(item.subTitle || '');
|
|
425
|
+
if ('sleep' === item.type) await sleep(item.duration);
|
|
426
|
+
else if ('insight' === item.type) {
|
|
427
|
+
var _item_context;
|
|
428
|
+
if (!item.img) throw new Error('img is required');
|
|
429
|
+
currentImg.current = item.img;
|
|
430
|
+
await repaintImage();
|
|
431
|
+
const elements = (null == (_item_context = item.context) ? void 0 : _item_context.tree) ? treeToList(item.context.tree) : [];
|
|
432
|
+
const highlightElements = item.highlightElement ? [
|
|
433
|
+
item.highlightElement
|
|
434
|
+
] : [];
|
|
435
|
+
await insightElementsAnimation(elements, highlightElements, item.searchArea, item.duration, frame);
|
|
436
|
+
if (item.camera) {
|
|
437
|
+
if (!item.insightCameraDuration) throw new Error('insightCameraDuration is required');
|
|
438
|
+
await cameraAnimation(item.camera, item.insightCameraDuration, frame);
|
|
439
|
+
}
|
|
440
|
+
} else if ('clear-insight' === item.type) {
|
|
441
|
+
await fadeOutItem(insightMarkContainer, item.duration, frame);
|
|
442
|
+
insightMarkContainer.removeChildren();
|
|
443
|
+
insightMarkContainer.alpha = 1;
|
|
444
|
+
} else if ('img' === item.type) {
|
|
445
|
+
if (item.img && item.img !== currentImg.current) {
|
|
446
|
+
currentImg.current = item.img;
|
|
447
|
+
await repaintImage();
|
|
448
|
+
}
|
|
449
|
+
if (item.camera) await cameraAnimation(item.camera, item.duration, frame);
|
|
450
|
+
else await sleep(item.duration);
|
|
451
|
+
} else if ('pointer' === item.type) {
|
|
452
|
+
if (!item.img) throw new Error('pointer img is required');
|
|
453
|
+
await updatePointer(item.img);
|
|
454
|
+
} else if ('spinning-pointer' === item.type) {
|
|
455
|
+
const stop = spinningPointer(frame);
|
|
456
|
+
await sleep(item.duration);
|
|
457
|
+
stop();
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
if (recorderSessionRef.current) {
|
|
461
|
+
recorderSessionRef.current.stop();
|
|
462
|
+
recorderSessionRef.current = null;
|
|
463
|
+
setIsRecording(false);
|
|
464
|
+
}
|
|
465
|
+
})().catch((e)=>{
|
|
466
|
+
console.error('player error', e);
|
|
467
|
+
}));
|
|
468
|
+
return ()=>{
|
|
469
|
+
null == cancelFn || cancelFn();
|
|
470
|
+
};
|
|
471
|
+
};
|
|
472
|
+
useEffect(()=>{
|
|
473
|
+
Promise.resolve((async ()=>{
|
|
474
|
+
await init();
|
|
475
|
+
if (divContainerRef.current && imageWidth && imageHeight) {
|
|
476
|
+
const aspectRatio = imageWidth / imageHeight;
|
|
477
|
+
divContainerRef.current.style.setProperty('--canvas-aspect-ratio', aspectRatio.toString());
|
|
478
|
+
divContainerRef.current.setAttribute('data-fit-mode', fitMode);
|
|
479
|
+
const playerContainer = divContainerRef.current.closest('.player-container');
|
|
480
|
+
if (playerContainer) playerContainer.setAttribute('data-fit-mode', fitMode);
|
|
481
|
+
}
|
|
482
|
+
triggerReplay();
|
|
483
|
+
})());
|
|
484
|
+
return ()=>{
|
|
485
|
+
try {
|
|
486
|
+
app.destroy(true, {
|
|
487
|
+
children: true,
|
|
488
|
+
texture: true
|
|
489
|
+
});
|
|
490
|
+
} catch (e) {
|
|
491
|
+
console.warn('destroy failed', e);
|
|
492
|
+
}
|
|
493
|
+
};
|
|
494
|
+
}, [
|
|
495
|
+
imageWidth,
|
|
496
|
+
imageHeight,
|
|
497
|
+
fitMode
|
|
498
|
+
]);
|
|
499
|
+
useEffect(()=>{
|
|
500
|
+
if (replayMark) return play();
|
|
501
|
+
}, [
|
|
502
|
+
replayMark
|
|
503
|
+
]);
|
|
504
|
+
const [mouseOverStatusIcon, setMouseOverStatusIcon] = useState(false);
|
|
505
|
+
const progressString = Math.round(100 * animationProgress);
|
|
506
|
+
const transitionStyle = 0 === animationProgress ? 'none' : '0.3s';
|
|
507
|
+
const canReplayNow = 1 === animationProgress;
|
|
508
|
+
useEffect(()=>{
|
|
509
|
+
if (canReplayNow) {
|
|
510
|
+
const listener = (event)=>{
|
|
511
|
+
if (' ' === event.key) triggerReplay();
|
|
512
|
+
};
|
|
513
|
+
window.addEventListener('keydown', listener);
|
|
514
|
+
return ()=>{
|
|
515
|
+
window.removeEventListener('keydown', listener);
|
|
516
|
+
};
|
|
517
|
+
}
|
|
518
|
+
}, [
|
|
519
|
+
canReplayNow
|
|
520
|
+
]);
|
|
521
|
+
let statusIconElement;
|
|
522
|
+
let statusOnClick = ()=>{};
|
|
523
|
+
if (animationProgress < 1) statusIconElement = /*#__PURE__*/ jsx(Spin, {
|
|
524
|
+
indicator: /*#__PURE__*/ jsx(LoadingOutlined, {
|
|
525
|
+
spin: true,
|
|
526
|
+
color: "#333"
|
|
527
|
+
}),
|
|
528
|
+
size: "default"
|
|
529
|
+
});
|
|
530
|
+
else if (mouseOverStatusIcon) {
|
|
531
|
+
statusIconElement = /*#__PURE__*/ jsx(Spin, {
|
|
532
|
+
indicator: /*#__PURE__*/ jsx(CaretRightOutlined, {
|
|
533
|
+
color: "#333"
|
|
534
|
+
}),
|
|
535
|
+
size: "default"
|
|
536
|
+
});
|
|
537
|
+
statusOnClick = ()=>triggerReplay();
|
|
538
|
+
} else statusIconElement = /*#__PURE__*/ jsx(Spin, {
|
|
539
|
+
indicator: /*#__PURE__*/ jsx(CaretRightOutlined, {
|
|
540
|
+
color: "#333"
|
|
541
|
+
}),
|
|
542
|
+
size: "default"
|
|
543
|
+
});
|
|
544
|
+
return /*#__PURE__*/ jsxs("div", {
|
|
545
|
+
className: "player-container",
|
|
546
|
+
children: [
|
|
547
|
+
/*#__PURE__*/ jsx("div", {
|
|
548
|
+
className: "canvas-container",
|
|
549
|
+
ref: divContainerRef
|
|
550
|
+
}),
|
|
551
|
+
/*#__PURE__*/ jsx("div", {
|
|
552
|
+
className: "player-timeline-wrapper",
|
|
553
|
+
children: /*#__PURE__*/ jsx("div", {
|
|
554
|
+
className: "player-timeline",
|
|
555
|
+
children: /*#__PURE__*/ jsx("div", {
|
|
556
|
+
className: "player-timeline-progress",
|
|
557
|
+
style: {
|
|
558
|
+
width: `${progressString}%`,
|
|
559
|
+
transition: transitionStyle
|
|
560
|
+
}
|
|
561
|
+
})
|
|
562
|
+
})
|
|
563
|
+
}),
|
|
564
|
+
/*#__PURE__*/ jsx("div", {
|
|
565
|
+
className: "player-tools-wrapper",
|
|
566
|
+
children: /*#__PURE__*/ jsx("div", {
|
|
567
|
+
className: "player-tools",
|
|
568
|
+
children: /*#__PURE__*/ jsxs("div", {
|
|
569
|
+
className: "player-control",
|
|
570
|
+
children: [
|
|
571
|
+
/*#__PURE__*/ jsxs("div", {
|
|
572
|
+
className: "status-text",
|
|
573
|
+
children: [
|
|
574
|
+
/*#__PURE__*/ jsx("div", {
|
|
575
|
+
className: "title",
|
|
576
|
+
children: titleText
|
|
577
|
+
}),
|
|
578
|
+
/*#__PURE__*/ jsx(Tooltip, {
|
|
579
|
+
title: subTitleText,
|
|
580
|
+
children: /*#__PURE__*/ jsx("div", {
|
|
581
|
+
className: "subtitle",
|
|
582
|
+
children: subTitleText
|
|
583
|
+
})
|
|
584
|
+
})
|
|
585
|
+
]
|
|
586
|
+
}),
|
|
587
|
+
isRecording ? null : /*#__PURE__*/ jsx("div", {
|
|
588
|
+
className: "status-icon",
|
|
589
|
+
onMouseEnter: ()=>setMouseOverStatusIcon(true),
|
|
590
|
+
onMouseLeave: ()=>setMouseOverStatusIcon(false),
|
|
591
|
+
onClick: statusOnClick,
|
|
592
|
+
children: statusIconElement
|
|
593
|
+
}),
|
|
594
|
+
(null == props ? void 0 : props.reportFileContent) ? /*#__PURE__*/ jsx(Tooltip, {
|
|
595
|
+
title: "Download Report",
|
|
596
|
+
children: /*#__PURE__*/ jsx("div", {
|
|
597
|
+
className: "status-icon",
|
|
598
|
+
onMouseEnter: ()=>setMouseOverStatusIcon(true),
|
|
599
|
+
onMouseLeave: ()=>setMouseOverStatusIcon(false),
|
|
600
|
+
onClick: ()=>downloadReport(props.reportFileContent),
|
|
601
|
+
children: /*#__PURE__*/ jsx(DownloadOutlined, {
|
|
602
|
+
color: "#333"
|
|
603
|
+
})
|
|
604
|
+
})
|
|
605
|
+
}) : null,
|
|
606
|
+
/*#__PURE__*/ jsx(Tooltip, {
|
|
607
|
+
title: isRecording ? 'Generating...' : 'Export Video',
|
|
608
|
+
children: /*#__PURE__*/ jsx("div", {
|
|
609
|
+
className: "status-icon",
|
|
610
|
+
onClick: isRecording ? void 0 : handleExport,
|
|
611
|
+
style: {
|
|
612
|
+
opacity: isRecording ? 0.5 : 1,
|
|
613
|
+
cursor: isRecording ? 'not-allowed' : 'pointer'
|
|
614
|
+
},
|
|
615
|
+
children: isRecording ? /*#__PURE__*/ jsx(Spin, {
|
|
616
|
+
size: "default",
|
|
617
|
+
percent: progressString
|
|
618
|
+
}) : /*#__PURE__*/ jsx(ExportOutlined, {})
|
|
619
|
+
})
|
|
620
|
+
})
|
|
621
|
+
]
|
|
622
|
+
})
|
|
623
|
+
})
|
|
624
|
+
})
|
|
625
|
+
]
|
|
626
|
+
});
|
|
627
|
+
}
|
|
628
|
+
export { Player };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Checkbox, Dropdown } from "antd";
|
|
3
|
+
import setting from "../../icons/setting.mjs";
|
|
4
|
+
import { useEnvConfig } from "../store/store.mjs";
|
|
5
|
+
import { deepThinkTip, trackingTip } from "./playground-constants.mjs";
|
|
6
|
+
import "./index.css";
|
|
7
|
+
const ConfigSelector = (param)=>{
|
|
8
|
+
let { showDeepThinkOption = false, enableTracking = false } = param;
|
|
9
|
+
const forceSameTabNavigation = useEnvConfig((state)=>state.forceSameTabNavigation);
|
|
10
|
+
const setForceSameTabNavigation = useEnvConfig((state)=>state.setForceSameTabNavigation);
|
|
11
|
+
const deepThink = useEnvConfig((state)=>state.deepThink);
|
|
12
|
+
const setDeepThink = useEnvConfig((state)=>state.setDeepThink);
|
|
13
|
+
if (!enableTracking && !showDeepThinkOption) return null;
|
|
14
|
+
const configItems = buildConfigItems();
|
|
15
|
+
return /*#__PURE__*/ jsx("div", {
|
|
16
|
+
className: "selector-trigger",
|
|
17
|
+
children: /*#__PURE__*/ jsx(Dropdown, {
|
|
18
|
+
menu: {
|
|
19
|
+
items: configItems
|
|
20
|
+
},
|
|
21
|
+
trigger: [
|
|
22
|
+
'click'
|
|
23
|
+
],
|
|
24
|
+
children: /*#__PURE__*/ jsx(setting, {
|
|
25
|
+
width: 24,
|
|
26
|
+
height: 24
|
|
27
|
+
})
|
|
28
|
+
})
|
|
29
|
+
});
|
|
30
|
+
function buildConfigItems() {
|
|
31
|
+
const items = [];
|
|
32
|
+
if (enableTracking) items.push({
|
|
33
|
+
label: /*#__PURE__*/ jsx(Checkbox, {
|
|
34
|
+
onChange: (e)=>setForceSameTabNavigation(e.target.checked),
|
|
35
|
+
checked: forceSameTabNavigation,
|
|
36
|
+
children: trackingTip
|
|
37
|
+
}),
|
|
38
|
+
key: 'track-config'
|
|
39
|
+
});
|
|
40
|
+
if (showDeepThinkOption) items.push({
|
|
41
|
+
label: /*#__PURE__*/ jsx(Checkbox, {
|
|
42
|
+
onChange: (e)=>{
|
|
43
|
+
setDeepThink(e.target.checked);
|
|
44
|
+
},
|
|
45
|
+
checked: deepThink,
|
|
46
|
+
children: deepThinkTip
|
|
47
|
+
}),
|
|
48
|
+
key: 'deep-think-config'
|
|
49
|
+
});
|
|
50
|
+
return items;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
export { ConfigSelector };
|