@midscene/visualizer 0.30.10 → 0.30.11-beta-20251218071621.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/component/blackboard/index.css +8 -0
- package/dist/es/component/blackboard/index.mjs +137 -68
- package/dist/es/component/config-selector/index.mjs +102 -4
- package/dist/es/component/context-preview/index.mjs +1 -2
- package/dist/es/component/env-config/index.mjs +1 -2
- package/dist/es/component/env-config-reminder/index.css +8 -0
- package/dist/es/component/env-config-reminder/index.mjs +1 -2
- package/dist/es/component/form-field/index.mjs +5 -10
- package/dist/es/component/history-selector/index.css +38 -1
- package/dist/es/component/history-selector/index.mjs +1 -2
- package/dist/es/component/logo/index.mjs +7 -3
- package/dist/es/component/misc/index.mjs +1 -4
- package/dist/es/component/nav-actions/index.mjs +1 -2
- package/dist/es/component/nav-actions/style.css +1 -1
- package/dist/es/component/player/index.css +26 -0
- package/dist/es/component/player/index.mjs +376 -364
- package/dist/es/component/playground/index.css +291 -31
- package/dist/es/component/playground-result/index.css +10 -0
- package/dist/es/component/playground-result/index.mjs +129 -10
- package/dist/es/component/prompt-input/index.css +281 -31
- package/dist/es/component/prompt-input/index.mjs +83 -25
- package/dist/es/component/screenshot-viewer/index.css +214 -0
- package/dist/es/component/screenshot-viewer/index.mjs +282 -0
- package/dist/es/component/service-mode-control/index.mjs +1 -2
- package/dist/es/component/shiny-text/index.css +35 -3
- package/dist/es/component/shiny-text/index.mjs +3 -3
- package/dist/es/component/universal-playground/index.css +61 -1
- package/dist/es/component/universal-playground/index.mjs +106 -83
- package/dist/es/component/universal-playground/providers/context-provider.mjs +56 -18
- package/dist/es/component/universal-playground/providers/indexeddb-storage-provider.mjs +213 -139
- package/dist/es/component/universal-playground/providers/storage-provider.mjs +199 -121
- package/dist/es/hooks/usePlaygroundExecution.mjs +297 -146
- package/dist/es/hooks/usePlaygroundState.mjs +141 -75
- package/dist/es/hooks/useSafeOverrideAIConfig.mjs +2 -6
- package/dist/es/hooks/useServerValid.mjs +37 -12
- package/dist/es/hooks/useTheme.mjs +25 -0
- package/dist/es/icons/avatar.mjs +46 -4
- package/dist/es/icons/close.mjs +46 -4
- package/dist/es/icons/global-perspective.mjs +47 -5
- package/dist/es/icons/history.mjs +48 -6
- package/dist/es/icons/magnifying-glass.mjs +47 -5
- package/dist/es/icons/player-setting.mjs +48 -6
- package/dist/es/icons/setting.mjs +47 -5
- package/dist/es/icons/show-marker.mjs +47 -5
- package/dist/es/index.mjs +4 -4
- package/dist/es/store/history.mjs +46 -7
- package/dist/es/store/store.mjs +68 -2
- package/dist/es/types.mjs +1 -1
- package/dist/es/utils/constants.mjs +7 -3
- package/dist/es/utils/index.mjs +4 -1
- package/dist/es/utils/pixi-loader.mjs +37 -11
- package/dist/es/utils/replay-scripts.mjs +160 -111
- package/dist/lib/component/blackboard/index.css +8 -0
- package/dist/lib/component/blackboard/index.js +139 -70
- package/dist/lib/component/config-selector/index.js +103 -5
- package/dist/lib/component/context-preview/index.js +3 -4
- package/dist/lib/component/env-config/index.js +3 -4
- package/dist/lib/component/env-config-reminder/index.css +8 -0
- package/dist/lib/component/env-config-reminder/index.js +3 -4
- package/dist/lib/component/form-field/index.js +10 -15
- package/dist/lib/component/history-selector/index.css +38 -1
- package/dist/lib/component/history-selector/index.js +3 -4
- package/dist/lib/component/index.js +6 -8
- package/dist/lib/component/logo/index.js +9 -5
- package/dist/lib/component/misc/index.js +6 -9
- package/dist/lib/component/nav-actions/index.js +3 -4
- package/dist/lib/component/nav-actions/style.css +1 -1
- package/dist/lib/component/player/index.css +26 -0
- package/dist/lib/component/player/index.js +376 -365
- package/dist/lib/component/playground/index.css +291 -31
- package/dist/lib/component/playground/index.js +31 -33
- package/dist/lib/component/playground-result/index.css +10 -0
- package/dist/lib/component/playground-result/index.js +131 -12
- package/dist/lib/component/prompt-input/index.css +281 -31
- package/dist/lib/component/prompt-input/index.js +84 -26
- package/dist/lib/component/screenshot-viewer/index.css +214 -0
- package/dist/lib/component/screenshot-viewer/index.js +316 -0
- package/dist/lib/component/service-mode-control/index.js +3 -4
- package/dist/lib/component/shiny-text/index.css +35 -3
- package/dist/lib/component/shiny-text/index.js +5 -5
- package/dist/lib/component/universal-playground/index.css +61 -1
- package/dist/lib/component/universal-playground/index.js +108 -84
- package/dist/lib/component/universal-playground/providers/context-provider.js +58 -20
- package/dist/lib/component/universal-playground/providers/indexeddb-storage-provider.js +217 -143
- package/dist/lib/component/universal-playground/providers/storage-provider.js +207 -129
- package/dist/lib/hooks/usePlaygroundExecution.js +299 -148
- package/dist/lib/hooks/usePlaygroundState.js +143 -77
- package/dist/lib/hooks/useSafeOverrideAIConfig.js +4 -8
- package/dist/lib/hooks/useServerValid.js +39 -14
- package/dist/lib/hooks/useTheme.js +59 -0
- package/dist/lib/icons/avatar.js +48 -6
- package/dist/lib/icons/close.js +48 -6
- package/dist/lib/icons/global-perspective.js +49 -7
- package/dist/lib/icons/history.js +50 -8
- package/dist/lib/icons/magnifying-glass.js +49 -7
- package/dist/lib/icons/player-setting.js +50 -8
- package/dist/lib/icons/setting.js +49 -7
- package/dist/lib/icons/show-marker.js +49 -7
- package/dist/lib/index.js +44 -34
- package/dist/lib/store/history.js +48 -9
- package/dist/lib/store/store.js +74 -8
- package/dist/lib/types.js +3 -3
- package/dist/lib/utils/color.js +2 -2
- package/dist/lib/utils/constants.js +20 -4
- package/dist/lib/utils/index.js +10 -4
- package/dist/lib/utils/pixi-loader.js +41 -15
- package/dist/lib/utils/playground-utils.js +4 -4
- package/dist/lib/utils/replay-scripts.js +164 -115
- package/dist/types/component/config-selector/index.d.ts +2 -0
- package/dist/types/component/player/index.d.ts +0 -1
- package/dist/types/component/playground-result/index.d.ts +1 -0
- package/dist/types/component/prompt-input/index.d.ts +2 -1
- package/dist/types/component/screenshot-viewer/index.d.ts +15 -0
- package/dist/types/hooks/usePlaygroundExecution.d.ts +1 -1
- package/dist/types/hooks/usePlaygroundState.d.ts +3 -3
- package/dist/types/hooks/useTheme.d.ts +7 -0
- package/dist/types/index.d.ts +3 -3
- package/dist/types/store/store.d.ts +18 -1
- package/dist/types/types.d.ts +14 -4
- package/dist/types/utils/constants.d.ts +5 -1
- package/dist/types/utils/index.d.ts +1 -0
- package/dist/types/utils/replay-scripts.d.ts +1 -1
- package/package.json +12 -22
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
"use client";
|
|
2
2
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
3
|
import "pixi.js/unsafe-eval";
|
|
4
4
|
import { Application, Container, Sprite } from "pixi.js";
|
|
@@ -6,14 +6,38 @@ import { useEffect, useMemo, useRef, useState } from "react";
|
|
|
6
6
|
import "./index.css";
|
|
7
7
|
import { mouseLoading, mousePointer } from "../../utils/index.mjs";
|
|
8
8
|
import { CaretRightOutlined, DownloadOutlined, ExportOutlined, LoadingOutlined } from "@ant-design/icons";
|
|
9
|
-
import {
|
|
10
|
-
import { Dropdown, Spin, Switch, Tooltip } from "antd";
|
|
9
|
+
import { Dropdown, Spin, Switch, Tooltip, message } from "antd";
|
|
11
10
|
import global_perspective from "../../icons/global-perspective.mjs";
|
|
12
11
|
import player_setting from "../../icons/player-setting.mjs";
|
|
13
|
-
import
|
|
14
|
-
import { useBlackboardPreference } from "../../store/store.mjs";
|
|
12
|
+
import { useGlobalPreference } from "../../store/store.mjs";
|
|
15
13
|
import { getTextureFromCache, loadTexture } from "../../utils/pixi-loader.mjs";
|
|
16
14
|
import { rectMarkForItem } from "../blackboard/index.mjs";
|
|
15
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
16
|
+
try {
|
|
17
|
+
var info = gen[key](arg);
|
|
18
|
+
var value = info.value;
|
|
19
|
+
} catch (error) {
|
|
20
|
+
reject(error);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (info.done) resolve(value);
|
|
24
|
+
else Promise.resolve(value).then(_next, _throw);
|
|
25
|
+
}
|
|
26
|
+
function _async_to_generator(fn) {
|
|
27
|
+
return function() {
|
|
28
|
+
var self = this, args = arguments;
|
|
29
|
+
return new Promise(function(resolve, reject) {
|
|
30
|
+
var gen = fn.apply(self, args);
|
|
31
|
+
function _next(value) {
|
|
32
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
33
|
+
}
|
|
34
|
+
function _throw(err) {
|
|
35
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
36
|
+
}
|
|
37
|
+
_next(void 0);
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
}
|
|
17
41
|
function _define_property(obj, key, value) {
|
|
18
42
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
19
43
|
value: value,
|
|
@@ -24,6 +48,38 @@ function _define_property(obj, key, value) {
|
|
|
24
48
|
else obj[key] = value;
|
|
25
49
|
return obj;
|
|
26
50
|
}
|
|
51
|
+
function _object_spread(target) {
|
|
52
|
+
for(var i = 1; i < arguments.length; i++){
|
|
53
|
+
var source = null != arguments[i] ? arguments[i] : {};
|
|
54
|
+
var ownKeys = Object.keys(source);
|
|
55
|
+
if ("function" == typeof Object.getOwnPropertySymbols) ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
56
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
57
|
+
}));
|
|
58
|
+
ownKeys.forEach(function(key) {
|
|
59
|
+
_define_property(target, key, source[key]);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
return target;
|
|
63
|
+
}
|
|
64
|
+
function player_ownKeys(object, enumerableOnly) {
|
|
65
|
+
var keys = Object.keys(object);
|
|
66
|
+
if (Object.getOwnPropertySymbols) {
|
|
67
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
68
|
+
if (enumerableOnly) symbols = symbols.filter(function(sym) {
|
|
69
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
70
|
+
});
|
|
71
|
+
keys.push.apply(keys, symbols);
|
|
72
|
+
}
|
|
73
|
+
return keys;
|
|
74
|
+
}
|
|
75
|
+
function _object_spread_props(target, source) {
|
|
76
|
+
source = null != source ? source : {};
|
|
77
|
+
if (Object.getOwnPropertyDescriptors) Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
78
|
+
else player_ownKeys(Object(source)).forEach(function(key) {
|
|
79
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
80
|
+
});
|
|
81
|
+
return target;
|
|
82
|
+
}
|
|
27
83
|
const canvasPaddingLeft = 0;
|
|
28
84
|
const canvasPaddingTop = 0;
|
|
29
85
|
const cubicBezier = (t, p0, p1, p2, p3)=>{
|
|
@@ -84,17 +140,32 @@ class RecordingSession {
|
|
|
84
140
|
mediaRecorder.ondataavailable = (event)=>{
|
|
85
141
|
if (event.data.size > 0) this.chunks.push(event.data);
|
|
86
142
|
};
|
|
143
|
+
mediaRecorder.onerror = (event)=>{
|
|
144
|
+
console.error('MediaRecorder error:', event);
|
|
145
|
+
message.error('Video recording failed. Please try again.');
|
|
146
|
+
this.recording = false;
|
|
147
|
+
this.mediaRecorder = null;
|
|
148
|
+
};
|
|
87
149
|
this.mediaRecorder = mediaRecorder;
|
|
88
150
|
this.recording = true;
|
|
89
151
|
return this.mediaRecorder.start();
|
|
90
152
|
}
|
|
91
153
|
stop() {
|
|
92
|
-
var _this_mediaRecorder;
|
|
93
154
|
if (!this.recording || !this.mediaRecorder) return void console.warn('not recording');
|
|
94
155
|
this.mediaRecorder.onstop = ()=>{
|
|
156
|
+
if (0 === this.chunks.length) {
|
|
157
|
+
console.error('No video data captured');
|
|
158
|
+
message.error('Video export failed: No data captured.');
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
95
161
|
const blob = new Blob(this.chunks, {
|
|
96
162
|
type: 'video/webm'
|
|
97
163
|
});
|
|
164
|
+
if (0 === blob.size) {
|
|
165
|
+
console.error('Video blob is empty');
|
|
166
|
+
message.error('Video export failed: Empty file.');
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
98
169
|
const url = URL.createObjectURL(blob);
|
|
99
170
|
const a = document.createElement('a');
|
|
100
171
|
a.href = url;
|
|
@@ -102,7 +173,7 @@ class RecordingSession {
|
|
|
102
173
|
a.click();
|
|
103
174
|
URL.revokeObjectURL(url);
|
|
104
175
|
};
|
|
105
|
-
|
|
176
|
+
this.mediaRecorder.stop();
|
|
106
177
|
this.recording = false;
|
|
107
178
|
this.mediaRecorder = null;
|
|
108
179
|
}
|
|
@@ -119,19 +190,13 @@ function Player(props) {
|
|
|
119
190
|
var _scripts_;
|
|
120
191
|
const [titleText, setTitleText] = useState('');
|
|
121
192
|
const [subTitleText, setSubTitleText] = useState('');
|
|
122
|
-
const { autoZoom, setAutoZoom
|
|
193
|
+
const { autoZoom, setAutoZoom } = useGlobalPreference();
|
|
123
194
|
useEffect(()=>{
|
|
124
195
|
if ((null == props ? void 0 : props.autoZoom) !== void 0) setAutoZoom(props.autoZoom);
|
|
125
196
|
}, [
|
|
126
197
|
null == props ? void 0 : props.autoZoom,
|
|
127
198
|
setAutoZoom
|
|
128
199
|
]);
|
|
129
|
-
useEffect(()=>{
|
|
130
|
-
if ((null == props ? void 0 : props.elementsVisible) !== void 0) setElementsVisible(props.elementsVisible);
|
|
131
|
-
}, [
|
|
132
|
-
null == props ? void 0 : props.elementsVisible,
|
|
133
|
-
setElementsVisible
|
|
134
|
-
]);
|
|
135
200
|
const scripts = null == props ? void 0 : props.replayScripts;
|
|
136
201
|
const imageWidth = (null == props ? void 0 : props.imageWidth) || 1920;
|
|
137
202
|
const imageHeight = (null == props ? void 0 : props.imageHeight) || 1080;
|
|
@@ -154,12 +219,6 @@ function Player(props) {
|
|
|
154
219
|
container.zIndex = LAYER_ORDER_INSIGHT;
|
|
155
220
|
return container;
|
|
156
221
|
}, []);
|
|
157
|
-
useEffect(()=>{
|
|
158
|
-
insightMarkContainer.visible = elementsVisible;
|
|
159
|
-
}, [
|
|
160
|
-
elementsVisible,
|
|
161
|
-
insightMarkContainer
|
|
162
|
-
]);
|
|
163
222
|
const basicCameraState = {
|
|
164
223
|
left: 0,
|
|
165
224
|
top: 0,
|
|
@@ -175,49 +234,47 @@ function Player(props) {
|
|
|
175
234
|
cancelFlag.current = true;
|
|
176
235
|
};
|
|
177
236
|
}, []);
|
|
178
|
-
const cameraState = useRef({
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
237
|
+
const cameraState = useRef(_object_spread({}, basicCameraState));
|
|
238
|
+
const resizeCanvasIfNeeded = (newWidth, newHeight)=>_async_to_generator(function*() {
|
|
239
|
+
if (app.screen.width !== newWidth || app.screen.height !== newHeight) {
|
|
240
|
+
app.renderer.resize(newWidth, newHeight);
|
|
241
|
+
if (divContainerRef.current) {
|
|
242
|
+
const aspectRatio = newWidth / newHeight;
|
|
243
|
+
divContainerRef.current.style.setProperty('--canvas-aspect-ratio', aspectRatio.toString());
|
|
244
|
+
}
|
|
245
|
+
const newBasicCameraState = {
|
|
246
|
+
left: 0,
|
|
247
|
+
top: 0,
|
|
248
|
+
width: newWidth,
|
|
249
|
+
pointerLeft: Math.round(newWidth / 2),
|
|
250
|
+
pointerTop: Math.round(newHeight / 2)
|
|
251
|
+
};
|
|
252
|
+
cameraState.current = newBasicCameraState;
|
|
187
253
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
const mainImgLabel = 'main-img';
|
|
213
|
-
const child = windowContentContainer.getChildByLabel(mainImgLabel);
|
|
214
|
-
if (child) windowContentContainer.removeChild(child);
|
|
215
|
-
sprite.label = mainImgLabel;
|
|
216
|
-
sprite.zIndex = LAYER_ORDER_IMG;
|
|
217
|
-
sprite.width = targetWidth;
|
|
218
|
-
sprite.height = targetHeight;
|
|
219
|
-
windowContentContainer.addChild(sprite);
|
|
220
|
-
};
|
|
254
|
+
})();
|
|
255
|
+
const repaintImage = (scriptWidth, scriptHeight)=>_async_to_generator(function*() {
|
|
256
|
+
const imgToUpdate = currentImg.current;
|
|
257
|
+
if (!imgToUpdate) return void console.warn('no image to update');
|
|
258
|
+
const targetWidth = scriptWidth || imageWidth;
|
|
259
|
+
const targetHeight = scriptHeight || imageHeight;
|
|
260
|
+
yield resizeCanvasIfNeeded(targetWidth, targetHeight);
|
|
261
|
+
if (!getTextureFromCache(imgToUpdate)) {
|
|
262
|
+
console.warn('image not loaded', imgToUpdate);
|
|
263
|
+
yield loadTexture(imgToUpdate);
|
|
264
|
+
}
|
|
265
|
+
const texture = getTextureFromCache(imgToUpdate);
|
|
266
|
+
if (!texture) throw new Error('texture not found');
|
|
267
|
+
const sprite = Sprite.from(texture);
|
|
268
|
+
if (!sprite) throw new Error('sprite not found');
|
|
269
|
+
const mainImgLabel = 'main-img';
|
|
270
|
+
const child = windowContentContainer.getChildByLabel(mainImgLabel);
|
|
271
|
+
if (child) windowContentContainer.removeChild(child);
|
|
272
|
+
sprite.label = mainImgLabel;
|
|
273
|
+
sprite.zIndex = LAYER_ORDER_IMG;
|
|
274
|
+
sprite.width = targetWidth;
|
|
275
|
+
sprite.height = targetHeight;
|
|
276
|
+
windowContentContainer.addChild(sprite);
|
|
277
|
+
})();
|
|
221
278
|
const spinningPointer = (frame)=>{
|
|
222
279
|
var _pointerSprite_current, _pointerSprite_current1;
|
|
223
280
|
if (!spinningPointerSprite.current) {
|
|
@@ -248,31 +305,31 @@ function Player(props) {
|
|
|
248
305
|
};
|
|
249
306
|
return stopFn;
|
|
250
307
|
};
|
|
251
|
-
const updatePointer =
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
308
|
+
const updatePointer = (img, x, y)=>_async_to_generator(function*() {
|
|
309
|
+
var _pointerSprite_current, _pointerSprite_current1;
|
|
310
|
+
if (!getTextureFromCache(img)) {
|
|
311
|
+
console.warn('image not loaded', img);
|
|
312
|
+
yield loadTexture(img);
|
|
313
|
+
}
|
|
314
|
+
const texture = getTextureFromCache(img);
|
|
315
|
+
if (!texture) throw new Error('texture not found');
|
|
316
|
+
const sprite = Sprite.from(texture);
|
|
317
|
+
let targetX = null == (_pointerSprite_current = pointerSprite.current) ? void 0 : _pointerSprite_current.x;
|
|
318
|
+
let targetY = null == (_pointerSprite_current1 = pointerSprite.current) ? void 0 : _pointerSprite_current1.y;
|
|
319
|
+
if ('number' == typeof x) targetX = x;
|
|
320
|
+
if ('number' == typeof y) targetY = y;
|
|
321
|
+
if (void 0 === targetX || void 0 === targetY) return void console.warn('invalid pointer position', x, y);
|
|
322
|
+
if (pointerSprite.current) {
|
|
323
|
+
const pointer = windowContentContainer.getChildByLabel('pointer');
|
|
324
|
+
if (pointer) windowContentContainer.removeChild(pointer);
|
|
325
|
+
}
|
|
326
|
+
pointerSprite.current = sprite;
|
|
327
|
+
pointerSprite.current.x = targetX;
|
|
328
|
+
pointerSprite.current.y = targetY;
|
|
329
|
+
pointerSprite.current.label = 'pointer';
|
|
330
|
+
pointerSprite.current.zIndex = LAYER_ORDER_POINTER;
|
|
331
|
+
windowContentContainer.addChild(pointerSprite.current);
|
|
332
|
+
})();
|
|
276
333
|
const updateCamera = (state, currentWidth)=>{
|
|
277
334
|
cameraState.current = state;
|
|
278
335
|
const effectiveWidth = currentWidth || app.screen.width || imageWidth;
|
|
@@ -289,90 +346,81 @@ function Player(props) {
|
|
|
289
346
|
}
|
|
290
347
|
}
|
|
291
348
|
};
|
|
292
|
-
const cameraAnimation =
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
349
|
+
const cameraAnimation = (targetState, duration, frame)=>_async_to_generator(function*() {
|
|
350
|
+
const currentCanvasWidth = app.screen.width || imageWidth;
|
|
351
|
+
const currentCanvasHeight = app.screen.height || imageHeight;
|
|
352
|
+
if (!autoZoom) {
|
|
353
|
+
const currentState = _object_spread({}, cameraState.current);
|
|
354
|
+
const startPointerLeft = currentState.pointerLeft;
|
|
355
|
+
const startPointerTop = currentState.pointerTop;
|
|
356
|
+
const startTime = performance.now();
|
|
357
|
+
const shouldMovePointer = 'number' == typeof targetState.pointerLeft && 'number' == typeof targetState.pointerTop && (targetState.pointerLeft !== startPointerLeft || targetState.pointerTop !== startPointerTop);
|
|
358
|
+
if (!shouldMovePointer) return;
|
|
359
|
+
yield new Promise((resolve)=>{
|
|
360
|
+
const animate = (currentTime)=>{
|
|
361
|
+
const elapsedTime = currentTime - startTime;
|
|
362
|
+
const rawProgress = Math.min(elapsedTime / duration, 1);
|
|
363
|
+
const progress = cubicMouse(rawProgress);
|
|
364
|
+
const nextState = _object_spread_props(_object_spread({}, currentState), {
|
|
365
|
+
pointerLeft: startPointerLeft + (targetState.pointerLeft - startPointerLeft) * progress,
|
|
366
|
+
pointerTop: startPointerTop + (targetState.pointerTop - startPointerTop) * progress
|
|
367
|
+
});
|
|
368
|
+
updateCamera(nextState, currentCanvasWidth);
|
|
369
|
+
if (elapsedTime < duration) frame(animate);
|
|
370
|
+
else resolve();
|
|
371
|
+
};
|
|
372
|
+
frame(animate);
|
|
373
|
+
});
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
const currentState = _object_spread({}, cameraState.current);
|
|
377
|
+
const startLeft = currentState.left;
|
|
378
|
+
const startTop = currentState.top;
|
|
299
379
|
const startPointerLeft = currentState.pointerLeft;
|
|
300
380
|
const startPointerTop = currentState.pointerTop;
|
|
381
|
+
const startScale = currentState.width / currentCanvasWidth;
|
|
301
382
|
const startTime = performance.now();
|
|
302
383
|
const shouldMovePointer = 'number' == typeof targetState.pointerLeft && 'number' == typeof targetState.pointerTop && (targetState.pointerLeft !== startPointerLeft || targetState.pointerTop !== startPointerTop);
|
|
303
|
-
|
|
304
|
-
|
|
384
|
+
const pointerMoveDuration = shouldMovePointer ? 0.375 * duration : 0;
|
|
385
|
+
const cameraMoveStart = pointerMoveDuration;
|
|
386
|
+
const cameraMoveDuration = duration - pointerMoveDuration;
|
|
387
|
+
yield new Promise((resolve)=>{
|
|
305
388
|
const animate = (currentTime)=>{
|
|
389
|
+
const nextState = _object_spread({}, cameraState.current);
|
|
306
390
|
const elapsedTime = currentTime - startTime;
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
391
|
+
if (shouldMovePointer) if (elapsedTime <= pointerMoveDuration) {
|
|
392
|
+
const rawMouseProgress = Math.min(elapsedTime / pointerMoveDuration, 1);
|
|
393
|
+
const mouseProgress = cubicMouse(rawMouseProgress);
|
|
394
|
+
nextState.pointerLeft = startPointerLeft + (targetState.pointerLeft - startPointerLeft) * mouseProgress;
|
|
395
|
+
nextState.pointerTop = startPointerTop + (targetState.pointerTop - startPointerTop) * mouseProgress;
|
|
396
|
+
} else {
|
|
397
|
+
nextState.pointerLeft = targetState.pointerLeft;
|
|
398
|
+
nextState.pointerTop = targetState.pointerTop;
|
|
399
|
+
}
|
|
400
|
+
if (elapsedTime > cameraMoveStart) {
|
|
401
|
+
const cameraElapsedTime = elapsedTime - cameraMoveStart;
|
|
402
|
+
const rawCameraProgress = Math.min(cameraElapsedTime / cameraMoveDuration, 1);
|
|
403
|
+
const cameraProgress = cubicImage(rawCameraProgress);
|
|
404
|
+
const targetScale = targetState.width / currentCanvasWidth;
|
|
405
|
+
const progressScale = startScale + (targetScale - startScale) * cameraProgress;
|
|
406
|
+
const progressWidth = currentCanvasWidth * progressScale;
|
|
407
|
+
const progressHeight = currentCanvasHeight * progressScale;
|
|
408
|
+
nextState.width = progressWidth;
|
|
409
|
+
const progressLeft = startLeft + (targetState.left - startLeft) * cameraProgress;
|
|
410
|
+
const progressTop = startTop + (targetState.top - startTop) * cameraProgress;
|
|
411
|
+
const horizontalExceed = progressLeft + progressWidth - currentCanvasWidth;
|
|
412
|
+
const verticalExceed = progressTop + progressHeight - currentCanvasHeight;
|
|
413
|
+
nextState.left = horizontalExceed > 0 ? progressLeft + horizontalExceed : progressLeft;
|
|
414
|
+
nextState.top = verticalExceed > 0 ? progressTop + verticalExceed : progressTop;
|
|
415
|
+
}
|
|
314
416
|
updateCamera(nextState, currentCanvasWidth);
|
|
315
417
|
if (elapsedTime < duration) frame(animate);
|
|
316
418
|
else resolve();
|
|
317
419
|
};
|
|
318
420
|
frame(animate);
|
|
319
421
|
});
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
const currentState = {
|
|
323
|
-
...cameraState.current
|
|
324
|
-
};
|
|
325
|
-
const startLeft = currentState.left;
|
|
326
|
-
const startTop = currentState.top;
|
|
327
|
-
const startPointerLeft = currentState.pointerLeft;
|
|
328
|
-
const startPointerTop = currentState.pointerTop;
|
|
329
|
-
const startScale = currentState.width / currentCanvasWidth;
|
|
330
|
-
const startTime = performance.now();
|
|
331
|
-
const shouldMovePointer = 'number' == typeof targetState.pointerLeft && 'number' == typeof targetState.pointerTop && (targetState.pointerLeft !== startPointerLeft || targetState.pointerTop !== startPointerTop);
|
|
332
|
-
const pointerMoveDuration = shouldMovePointer ? 0.375 * duration : 0;
|
|
333
|
-
const cameraMoveStart = pointerMoveDuration;
|
|
334
|
-
const cameraMoveDuration = duration - pointerMoveDuration;
|
|
335
|
-
await new Promise((resolve)=>{
|
|
336
|
-
const animate = (currentTime)=>{
|
|
337
|
-
const nextState = {
|
|
338
|
-
...cameraState.current
|
|
339
|
-
};
|
|
340
|
-
const elapsedTime = currentTime - startTime;
|
|
341
|
-
if (shouldMovePointer) if (elapsedTime <= pointerMoveDuration) {
|
|
342
|
-
const rawMouseProgress = Math.min(elapsedTime / pointerMoveDuration, 1);
|
|
343
|
-
const mouseProgress = cubicMouse(rawMouseProgress);
|
|
344
|
-
nextState.pointerLeft = startPointerLeft + (targetState.pointerLeft - startPointerLeft) * mouseProgress;
|
|
345
|
-
nextState.pointerTop = startPointerTop + (targetState.pointerTop - startPointerTop) * mouseProgress;
|
|
346
|
-
} else {
|
|
347
|
-
nextState.pointerLeft = targetState.pointerLeft;
|
|
348
|
-
nextState.pointerTop = targetState.pointerTop;
|
|
349
|
-
}
|
|
350
|
-
if (elapsedTime > cameraMoveStart) {
|
|
351
|
-
const cameraElapsedTime = elapsedTime - cameraMoveStart;
|
|
352
|
-
const rawCameraProgress = Math.min(cameraElapsedTime / cameraMoveDuration, 1);
|
|
353
|
-
const cameraProgress = cubicImage(rawCameraProgress);
|
|
354
|
-
const targetScale = targetState.width / currentCanvasWidth;
|
|
355
|
-
const progressScale = startScale + (targetScale - startScale) * cameraProgress;
|
|
356
|
-
const progressWidth = currentCanvasWidth * progressScale;
|
|
357
|
-
const progressHeight = currentCanvasHeight * progressScale;
|
|
358
|
-
nextState.width = progressWidth;
|
|
359
|
-
const progressLeft = startLeft + (targetState.left - startLeft) * cameraProgress;
|
|
360
|
-
const progressTop = startTop + (targetState.top - startTop) * cameraProgress;
|
|
361
|
-
const horizontalExceed = progressLeft + progressWidth - currentCanvasWidth;
|
|
362
|
-
const verticalExceed = progressTop + progressHeight - currentCanvasHeight;
|
|
363
|
-
nextState.left = horizontalExceed > 0 ? progressLeft + horizontalExceed : progressLeft;
|
|
364
|
-
nextState.top = verticalExceed > 0 ? progressTop + verticalExceed : progressTop;
|
|
365
|
-
}
|
|
366
|
-
updateCamera(nextState, currentCanvasWidth);
|
|
367
|
-
if (elapsedTime < duration) frame(animate);
|
|
368
|
-
else resolve();
|
|
369
|
-
};
|
|
370
|
-
frame(animate);
|
|
371
|
-
});
|
|
372
|
-
};
|
|
373
|
-
const fadeInGraphics = function(graphics, duration, frame) {
|
|
374
|
-
let targetAlpha = arguments.length > 3 && void 0 !== arguments[3] ? arguments[3] : 1;
|
|
375
|
-
return new Promise((resolve)=>{
|
|
422
|
+
})();
|
|
423
|
+
const fadeInGraphics = (graphics, duration, frame, targetAlpha = 1)=>new Promise((resolve)=>{
|
|
376
424
|
const startTime = performance.now();
|
|
377
425
|
const animate = (currentTime)=>{
|
|
378
426
|
const elapsedTime = currentTime - startTime;
|
|
@@ -383,178 +431,195 @@ function Player(props) {
|
|
|
383
431
|
};
|
|
384
432
|
frame(animate);
|
|
385
433
|
});
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
const
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
const element = elementsToAdd.splice(randomIndex, 1)[0];
|
|
404
|
-
if (element) {
|
|
405
|
-
const [insightMarkGraphic] = rectMarkForItem(element.rect, element.content, 'element');
|
|
406
|
-
insightMarkGraphic.alpha = 0;
|
|
407
|
-
insightMarkContainer.addChild(insightMarkGraphic);
|
|
408
|
-
childrenCount++;
|
|
409
|
-
fadeInGraphics(insightMarkGraphic, singleElementFadeInDuration, frame);
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
if (elapsedTime < duration) frame(animate);
|
|
413
|
-
else {
|
|
414
|
-
while(elementsToAdd.length > 0){
|
|
434
|
+
const fadeOutItem = (graphics, duration, frame)=>_async_to_generator(function*() {
|
|
435
|
+
return fadeInGraphics(graphics, duration, frame, 0);
|
|
436
|
+
})();
|
|
437
|
+
const insightElementsAnimation = (elements, highlightElements, searchArea, duration, frame)=>_async_to_generator(function*() {
|
|
438
|
+
insightMarkContainer.removeChildren();
|
|
439
|
+
const elementsToAdd = [
|
|
440
|
+
...elements
|
|
441
|
+
];
|
|
442
|
+
const totalLength = elementsToAdd.length;
|
|
443
|
+
let childrenCount = 0;
|
|
444
|
+
yield new Promise((resolve)=>{
|
|
445
|
+
const startTime = performance.now();
|
|
446
|
+
const animate = (currentTime)=>{
|
|
447
|
+
const elapsedTime = currentTime - startTime;
|
|
448
|
+
const progress = cubicInsightElement(Math.min(elapsedTime / duration, 1));
|
|
449
|
+
const elementsToAddNow = Math.floor(progress * totalLength);
|
|
450
|
+
while(childrenCount < elementsToAddNow){
|
|
415
451
|
const randomIndex = Math.floor(Math.random() * elementsToAdd.length);
|
|
416
452
|
const element = elementsToAdd.splice(randomIndex, 1)[0];
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
453
|
+
if (element) {
|
|
454
|
+
const [insightMarkGraphic] = rectMarkForItem(element.rect, element.content, 'element');
|
|
455
|
+
insightMarkGraphic.alpha = 0;
|
|
456
|
+
insightMarkContainer.addChild(insightMarkGraphic);
|
|
457
|
+
childrenCount++;
|
|
458
|
+
fadeInGraphics(insightMarkGraphic, singleElementFadeInDuration, frame);
|
|
459
|
+
}
|
|
420
460
|
}
|
|
421
|
-
if (
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
461
|
+
if (elapsedTime < duration) frame(animate);
|
|
462
|
+
else {
|
|
463
|
+
while(elementsToAdd.length > 0){
|
|
464
|
+
const randomIndex = Math.floor(Math.random() * elementsToAdd.length);
|
|
465
|
+
const element = elementsToAdd.splice(randomIndex, 1)[0];
|
|
466
|
+
const [insightMarkGraphic] = rectMarkForItem(element.rect, element.content, 'element');
|
|
467
|
+
insightMarkGraphic.alpha = 1;
|
|
468
|
+
insightMarkContainer.addChild(insightMarkGraphic);
|
|
469
|
+
}
|
|
470
|
+
if (searchArea) {
|
|
471
|
+
const [searchAreaGraphic] = rectMarkForItem(searchArea, 'Search Area', 'searchArea');
|
|
472
|
+
searchAreaGraphic.alpha = 1;
|
|
473
|
+
insightMarkContainer.addChild(searchAreaGraphic);
|
|
474
|
+
}
|
|
475
|
+
highlightElements.map((element)=>{
|
|
476
|
+
const [insightMarkGraphic] = rectMarkForItem(element.rect, element.content || '', 'highlight');
|
|
477
|
+
insightMarkGraphic.alpha = 1;
|
|
478
|
+
insightMarkContainer.addChild(insightMarkGraphic);
|
|
479
|
+
});
|
|
480
|
+
resolve();
|
|
425
481
|
}
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
windowContentContainer.x = 0;
|
|
449
|
-
windowContentContainer.y = 0;
|
|
450
|
-
app.stage.addChild(windowContentContainer);
|
|
451
|
-
insightMarkContainer.x = 0;
|
|
452
|
-
insightMarkContainer.y = 0;
|
|
453
|
-
windowContentContainer.addChild(insightMarkContainer);
|
|
454
|
-
};
|
|
482
|
+
};
|
|
483
|
+
frame(animate);
|
|
484
|
+
});
|
|
485
|
+
})();
|
|
486
|
+
const init = ()=>_async_to_generator(function*() {
|
|
487
|
+
if (!divContainerRef.current || !scripts) return;
|
|
488
|
+
yield app.init({
|
|
489
|
+
width: imageWidth,
|
|
490
|
+
height: imageHeight,
|
|
491
|
+
background: 0xf4f4f4,
|
|
492
|
+
autoDensity: true,
|
|
493
|
+
antialias: true
|
|
494
|
+
});
|
|
495
|
+
if (!divContainerRef.current) return;
|
|
496
|
+
divContainerRef.current.appendChild(app.canvas);
|
|
497
|
+
windowContentContainer.x = 0;
|
|
498
|
+
windowContentContainer.y = 0;
|
|
499
|
+
app.stage.addChild(windowContentContainer);
|
|
500
|
+
insightMarkContainer.x = 0;
|
|
501
|
+
insightMarkContainer.y = 0;
|
|
502
|
+
windowContentContainer.addChild(insightMarkContainer);
|
|
503
|
+
})();
|
|
455
504
|
const [isRecording, setIsRecording] = useState(false);
|
|
456
505
|
const recorderSessionRef = useRef(null);
|
|
457
|
-
const
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
506
|
+
const cancelAnimationRef = useRef(null);
|
|
507
|
+
const handleExport = ()=>_async_to_generator(function*() {
|
|
508
|
+
if (recorderSessionRef.current) return void console.warn('recorderSession exists');
|
|
509
|
+
if (!app.canvas) return void console.warn('canvas is not initialized');
|
|
510
|
+
if (cancelAnimationRef.current) {
|
|
511
|
+
cancelAnimationRef.current();
|
|
512
|
+
cancelAnimationRef.current = null;
|
|
513
|
+
yield new Promise((resolve)=>setTimeout(resolve, 100));
|
|
514
|
+
}
|
|
515
|
+
recorderSessionRef.current = new RecordingSession(app.canvas);
|
|
516
|
+
setIsRecording(true);
|
|
517
|
+
triggerReplay();
|
|
518
|
+
})();
|
|
464
519
|
const play = ()=>{
|
|
465
520
|
let cancelFn;
|
|
466
|
-
Promise.resolve((
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
var _item_context;
|
|
501
|
-
if (!item.img) throw new Error('img is required');
|
|
502
|
-
currentImg.current = item.img;
|
|
503
|
-
await repaintImage(item.imageWidth, item.imageHeight);
|
|
504
|
-
const elements = (null == (_item_context = item.context) ? void 0 : _item_context.tree) ? treeToList(item.context.tree) : [];
|
|
505
|
-
const highlightElements = item.highlightElement ? [
|
|
506
|
-
item.highlightElement
|
|
507
|
-
] : [];
|
|
508
|
-
await insightElementsAnimation(elements, highlightElements, item.searchArea, item.duration, frame);
|
|
509
|
-
if (item.camera) {
|
|
510
|
-
if (!item.insightCameraDuration) throw new Error('insightCameraDuration is required');
|
|
511
|
-
await cameraAnimation(item.camera, item.insightCameraDuration, frame);
|
|
512
|
-
}
|
|
513
|
-
} else if ('clear-insight' === item.type) {
|
|
514
|
-
await fadeOutItem(insightMarkContainer, item.duration, frame);
|
|
515
|
-
insightMarkContainer.removeChildren();
|
|
516
|
-
insightMarkContainer.alpha = 1;
|
|
517
|
-
} else if ('img' === item.type) {
|
|
518
|
-
if (item.img && item.img !== currentImg.current) {
|
|
521
|
+
Promise.resolve((()=>_async_to_generator(function*() {
|
|
522
|
+
if (!app) throw new Error('app is not initialized');
|
|
523
|
+
if (!scripts) throw new Error("scripts is required");
|
|
524
|
+
const { frame, cancel, timeout } = frameKit();
|
|
525
|
+
cancelFn = cancel;
|
|
526
|
+
cancelAnimationRef.current = cancel;
|
|
527
|
+
const allImages = scripts.filter((item)=>!!item.img).map((item)=>item.img);
|
|
528
|
+
yield Promise.all([
|
|
529
|
+
...allImages,
|
|
530
|
+
mouseLoading,
|
|
531
|
+
mousePointer
|
|
532
|
+
].map(loadTexture));
|
|
533
|
+
insightMarkContainer.removeChildren();
|
|
534
|
+
yield updatePointer(mousePointer, imageWidth / 2, imageHeight / 2);
|
|
535
|
+
yield repaintImage();
|
|
536
|
+
yield updateCamera(_object_spread({}, basicCameraState));
|
|
537
|
+
const totalDuration = scripts.reduce((acc, item)=>acc + item.duration + (item.camera && item.insightCameraDuration ? item.insightCameraDuration : 0), 0);
|
|
538
|
+
const progressUpdateInterval = 200;
|
|
539
|
+
const startTime = performance.now();
|
|
540
|
+
setAnimationProgress(0);
|
|
541
|
+
const updateProgress = ()=>{
|
|
542
|
+
const progress = Math.min((performance.now() - startTime) / totalDuration, 1);
|
|
543
|
+
setAnimationProgress(progress);
|
|
544
|
+
if (progress < 1) return timeout(updateProgress, progressUpdateInterval);
|
|
545
|
+
};
|
|
546
|
+
frame(updateProgress);
|
|
547
|
+
if (recorderSessionRef.current) recorderSessionRef.current.start();
|
|
548
|
+
for(const index in scripts){
|
|
549
|
+
const item = scripts[index];
|
|
550
|
+
setTitleText(item.title || '');
|
|
551
|
+
setSubTitleText(item.subTitle || '');
|
|
552
|
+
if ('sleep' === item.type) yield sleep(item.duration);
|
|
553
|
+
else if ('insight' === item.type) {
|
|
554
|
+
if (!item.img) throw new Error('img is required');
|
|
519
555
|
currentImg.current = item.img;
|
|
520
|
-
|
|
556
|
+
yield repaintImage(item.imageWidth, item.imageHeight);
|
|
557
|
+
const highlightElements = item.highlightElement ? [
|
|
558
|
+
item.highlightElement
|
|
559
|
+
] : [];
|
|
560
|
+
yield insightElementsAnimation([], highlightElements, item.searchArea, item.duration, frame);
|
|
561
|
+
if (item.camera) {
|
|
562
|
+
if (!item.insightCameraDuration) throw new Error('insightCameraDuration is required');
|
|
563
|
+
yield cameraAnimation(item.camera, item.insightCameraDuration, frame);
|
|
564
|
+
}
|
|
565
|
+
} else if ('clear-insight' === item.type) {
|
|
566
|
+
yield fadeOutItem(insightMarkContainer, item.duration, frame);
|
|
567
|
+
insightMarkContainer.removeChildren();
|
|
568
|
+
insightMarkContainer.alpha = 1;
|
|
569
|
+
} else if ('img' === item.type) {
|
|
570
|
+
if (item.img && item.img !== currentImg.current) {
|
|
571
|
+
currentImg.current = item.img;
|
|
572
|
+
yield repaintImage(item.imageWidth, item.imageHeight);
|
|
573
|
+
}
|
|
574
|
+
if (item.camera) yield cameraAnimation(item.camera, item.duration, frame);
|
|
575
|
+
else yield sleep(item.duration);
|
|
576
|
+
} else if ('pointer' === item.type) {
|
|
577
|
+
if (!item.img) throw new Error('pointer img is required');
|
|
578
|
+
yield updatePointer(item.img);
|
|
579
|
+
} else if ('spinning-pointer' === item.type) {
|
|
580
|
+
const stop = spinningPointer(frame);
|
|
581
|
+
yield sleep(item.duration);
|
|
582
|
+
stop();
|
|
521
583
|
}
|
|
522
|
-
if (item.camera) await cameraAnimation(item.camera, item.duration, frame);
|
|
523
|
-
else await sleep(item.duration);
|
|
524
|
-
} else if ('pointer' === item.type) {
|
|
525
|
-
if (!item.img) throw new Error('pointer img is required');
|
|
526
|
-
await updatePointer(item.img);
|
|
527
|
-
} else if ('spinning-pointer' === item.type) {
|
|
528
|
-
const stop = spinningPointer(frame);
|
|
529
|
-
await sleep(item.duration);
|
|
530
|
-
stop();
|
|
531
584
|
}
|
|
532
|
-
|
|
585
|
+
if (recorderSessionRef.current) {
|
|
586
|
+
yield sleep(1200);
|
|
587
|
+
recorderSessionRef.current.stop();
|
|
588
|
+
recorderSessionRef.current = null;
|
|
589
|
+
setIsRecording(false);
|
|
590
|
+
}
|
|
591
|
+
})())().catch((e)=>{
|
|
592
|
+
console.error('player error', e);
|
|
593
|
+
if ((null == e ? void 0 : e.message) === ERROR_FRAME_CANCEL) return void console.log('Animation cancelled (expected behavior)');
|
|
594
|
+
const wasRecording = !!recorderSessionRef.current;
|
|
533
595
|
if (recorderSessionRef.current) {
|
|
534
|
-
|
|
535
|
-
|
|
596
|
+
try {
|
|
597
|
+
recorderSessionRef.current.stop();
|
|
598
|
+
} catch (stopError) {
|
|
599
|
+
console.error('Error stopping recorder:', stopError);
|
|
600
|
+
}
|
|
536
601
|
recorderSessionRef.current = null;
|
|
537
|
-
setIsRecording(false);
|
|
538
602
|
}
|
|
539
|
-
|
|
540
|
-
|
|
603
|
+
setIsRecording(false);
|
|
604
|
+
if (wasRecording) message.error('Failed to export video. Please try again.');
|
|
541
605
|
}));
|
|
542
606
|
return ()=>{
|
|
543
607
|
null == cancelFn || cancelFn();
|
|
608
|
+
cancelAnimationRef.current = null;
|
|
544
609
|
};
|
|
545
610
|
};
|
|
546
611
|
useEffect(()=>{
|
|
547
|
-
Promise.resolve((
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
612
|
+
Promise.resolve((()=>_async_to_generator(function*() {
|
|
613
|
+
yield init();
|
|
614
|
+
if (divContainerRef.current && imageWidth && imageHeight) {
|
|
615
|
+
const aspectRatio = imageWidth / imageHeight;
|
|
616
|
+
divContainerRef.current.style.setProperty('--canvas-aspect-ratio', aspectRatio.toString());
|
|
617
|
+
divContainerRef.current.setAttribute('data-fit-mode', fitMode);
|
|
618
|
+
const playerContainer = divContainerRef.current.closest('.player-container');
|
|
619
|
+
if (playerContainer) playerContainer.setAttribute('data-fit-mode', fitMode);
|
|
620
|
+
}
|
|
621
|
+
triggerReplay();
|
|
622
|
+
})())());
|
|
558
623
|
return ()=>{
|
|
559
624
|
try {
|
|
560
625
|
app.destroy(true, {
|
|
@@ -770,59 +835,6 @@ function Player(props) {
|
|
|
770
835
|
})
|
|
771
836
|
]
|
|
772
837
|
})
|
|
773
|
-
},
|
|
774
|
-
{
|
|
775
|
-
key: 'elementsVisible',
|
|
776
|
-
style: {
|
|
777
|
-
height: '39px',
|
|
778
|
-
margin: 0,
|
|
779
|
-
padding: '0 12px'
|
|
780
|
-
},
|
|
781
|
-
label: /*#__PURE__*/ jsxs("div", {
|
|
782
|
-
style: {
|
|
783
|
-
display: 'flex',
|
|
784
|
-
alignItems: 'center',
|
|
785
|
-
justifyContent: 'space-between',
|
|
786
|
-
width: '100%',
|
|
787
|
-
height: '39px'
|
|
788
|
-
},
|
|
789
|
-
children: [
|
|
790
|
-
/*#__PURE__*/ jsxs("div", {
|
|
791
|
-
style: {
|
|
792
|
-
display: 'flex',
|
|
793
|
-
alignItems: 'center',
|
|
794
|
-
gap: '4px'
|
|
795
|
-
},
|
|
796
|
-
children: [
|
|
797
|
-
/*#__PURE__*/ jsx(show_marker, {
|
|
798
|
-
style: {
|
|
799
|
-
width: '16px',
|
|
800
|
-
height: '16px'
|
|
801
|
-
}
|
|
802
|
-
}),
|
|
803
|
-
/*#__PURE__*/ jsx("span", {
|
|
804
|
-
style: {
|
|
805
|
-
fontSize: '12px',
|
|
806
|
-
marginRight: '16px'
|
|
807
|
-
},
|
|
808
|
-
children: "Show element markers"
|
|
809
|
-
})
|
|
810
|
-
]
|
|
811
|
-
}),
|
|
812
|
-
/*#__PURE__*/ jsx(Switch, {
|
|
813
|
-
size: "small",
|
|
814
|
-
checked: elementsVisible,
|
|
815
|
-
onChange: (checked)=>{
|
|
816
|
-
setElementsVisible(checked);
|
|
817
|
-
triggerReplay();
|
|
818
|
-
},
|
|
819
|
-
onClick: (_, e)=>{
|
|
820
|
-
var _e_stopPropagation;
|
|
821
|
-
return null == e ? void 0 : null == (_e_stopPropagation = e.stopPropagation) ? void 0 : _e_stopPropagation.call(e);
|
|
822
|
-
}
|
|
823
|
-
})
|
|
824
|
-
]
|
|
825
|
-
})
|
|
826
838
|
}
|
|
827
839
|
]
|
|
828
840
|
},
|