@revideo/player-react 0.10.1-alpha.1116 → 0.10.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.
- package/dist/controls.d.ts +11 -0
- package/dist/controls.d.ts.map +1 -0
- package/dist/controls.js +40 -0
- package/dist/controls.js.map +1 -0
- package/dist/icons.d.ts +5 -0
- package/dist/icons.d.ts.map +1 -0
- package/dist/icons.js +14 -0
- package/dist/icons.js.map +1 -0
- package/dist/index.css +2 -507
- package/dist/index.d.ts +7 -7
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +116 -660
- package/dist/index.js.map +1 -0
- package/dist/internal.d.ts +2 -0
- package/dist/internal.d.ts.map +1 -0
- package/dist/internal.js +249 -0
- package/dist/internal.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/utils.d.ts +3 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +28 -0
- package/dist/utils.js.map +1 -0
- package/package.json +12 -14
- package/dist/index.d.mts +0 -41
- package/dist/index.mjs +0 -387
- package/dist/internal-LRAKNBSP.mjs +0 -243
package/dist/index.mjs
DELETED
|
@@ -1,387 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
// src/index.tsx
|
|
4
|
-
import React3, { useCallback, useEffect, useRef, useState as useState2 } from "react";
|
|
5
|
-
|
|
6
|
-
// src/controls.tsx
|
|
7
|
-
import React2, { useState } from "react";
|
|
8
|
-
|
|
9
|
-
// src/icons.tsx
|
|
10
|
-
import React from "react";
|
|
11
|
-
function PlayButton() {
|
|
12
|
-
return /* @__PURE__ */ React.createElement(
|
|
13
|
-
"svg",
|
|
14
|
-
{
|
|
15
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
16
|
-
viewBox: "0 0 24 24",
|
|
17
|
-
fill: "currentColor",
|
|
18
|
-
className: "w-6 h-6"
|
|
19
|
-
},
|
|
20
|
-
/* @__PURE__ */ React.createElement(
|
|
21
|
-
"path",
|
|
22
|
-
{
|
|
23
|
-
fillRule: "evenodd",
|
|
24
|
-
d: "M4.5 5.653c0-1.427 1.529-2.33 2.779-1.643l11.54 6.347c1.295.712 1.295 2.573 0 3.286L7.28 19.99c-1.25.687-2.779-.217-2.779-1.643V5.653Z",
|
|
25
|
-
clipRule: "evenodd"
|
|
26
|
-
}
|
|
27
|
-
)
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
function PauseButton() {
|
|
31
|
-
return /* @__PURE__ */ React.createElement(
|
|
32
|
-
"svg",
|
|
33
|
-
{
|
|
34
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
35
|
-
viewBox: "0 0 24 24",
|
|
36
|
-
fill: "currentColor",
|
|
37
|
-
className: "w-6 h-6"
|
|
38
|
-
},
|
|
39
|
-
/* @__PURE__ */ React.createElement(
|
|
40
|
-
"path",
|
|
41
|
-
{
|
|
42
|
-
fillRule: "evenodd",
|
|
43
|
-
d: "M6.75 5.25a.75.75 0 0 1 .75-.75H9a.75.75 0 0 1 .75.75v13.5a.75.75 0 0 1-.75.75H7.5a.75.75 0 0 1-.75-.75V5.25Zm7.5 0A.75.75 0 0 1 15 4.5h1.5a.75.75 0 0 1 .75.75v13.5a.75.75 0 0 1-.75.75H15a.75.75 0 0 1-.75-.75V5.25Z",
|
|
44
|
-
clipRule: "evenodd"
|
|
45
|
-
}
|
|
46
|
-
)
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
function SoundIcon() {
|
|
50
|
-
return /* @__PURE__ */ React.createElement(
|
|
51
|
-
"svg",
|
|
52
|
-
{
|
|
53
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
54
|
-
viewBox: "0 0 24 24",
|
|
55
|
-
fill: "currentColor",
|
|
56
|
-
className: "p-w-6 p-h-6"
|
|
57
|
-
},
|
|
58
|
-
/* @__PURE__ */ React.createElement("path", { d: "M18.36,19.36a1,1,0,0,1-.7-.29,1,1,0,0,1,0-1.41,8,8,0,0,0,0-11.32,1,1,0,0,1,1.41-1.41,10,10,0,0,1,0,14.14A1,1,0,0,1,18.36,19.36Z" }),
|
|
59
|
-
/* @__PURE__ */ React.createElement("path", { d: "M15.54,16.54a1,1,0,0,1-.71-.3,1,1,0,0,1,0-1.41,4,4,0,0,0,0-5.66,1,1,0,0,1,1.41-1.41,6,6,0,0,1,0,8.48A1,1,0,0,1,15.54,16.54Z" }),
|
|
60
|
-
/* @__PURE__ */ React.createElement("path", { d: "M11.38,4.08a1,1,0,0,0-1.09.21L6.59,8H4a2,2,0,0,0-2,2v4a2,2,0,0,0,2,2H6.59l3.7,3.71A1,1,0,0,0,11,20a.84.84,0,0,0,.38-.08A1,1,0,0,0,12,19V5A1,1,0,0,0,11.38,4.08Z" })
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
function MutedSoundIcon() {
|
|
64
|
-
return /* @__PURE__ */ React.createElement(
|
|
65
|
-
"svg",
|
|
66
|
-
{
|
|
67
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
68
|
-
viewBox: "0 0 24 24",
|
|
69
|
-
fill: "currentColor",
|
|
70
|
-
className: "p-w-6 p-h-6"
|
|
71
|
-
},
|
|
72
|
-
/* @__PURE__ */ React.createElement("path", { d: "M11.38,4.08a1,1,0,0,0-1.09.21L6.59,8H4a2,2,0,0,0-2,2v4a2,2,0,0,0,2,2H6.59l3.7,3.71A1,1,0,0,0,11,20a.84.84,0,0,0,.38-.08A1,1,0,0,0,12,19V5A1,1,0,0,0,11.38,4.08Z" }),
|
|
73
|
-
/* @__PURE__ */ React.createElement("path", { d: "M16,15.5a1,1,0,0,1-.71-.29,1,1,0,0,1,0-1.42l5-5a1,1,0,0,1,1.42,1.42l-5,5A1,1,0,0,1,16,15.5Z" }),
|
|
74
|
-
/* @__PURE__ */ React.createElement("path", { d: "M21,15.5a1,1,0,0,1-.71-.29l-5-5a1,1,0,0,1,1.42-1.42l5,5a1,1,0,0,1,0,1.42A1,1,0,0,1,21,15.5Z" })
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// src/utils.ts
|
|
79
|
-
function getFormattedTime(timeInSeconds, absoluteTimeInSeconds, timeDisplayFormat) {
|
|
80
|
-
function toFormattedTime(timeInSeconds2) {
|
|
81
|
-
const minutes = Math.floor(timeInSeconds2 / 60);
|
|
82
|
-
const seconds = Math.floor(timeInSeconds2 % 60).toString().padStart(2, "0");
|
|
83
|
-
const milliseconds = Math.floor(timeInSeconds2 % 1 * 1e3).toString().padStart(3, "0");
|
|
84
|
-
if (timeDisplayFormat === "MM:SS") {
|
|
85
|
-
return `${minutes}:${seconds}`;
|
|
86
|
-
}
|
|
87
|
-
if (timeDisplayFormat === "MM:SS.m") {
|
|
88
|
-
return `${minutes}:${seconds}.${milliseconds[0]}`;
|
|
89
|
-
}
|
|
90
|
-
if (timeDisplayFormat === "MM:SS.mm") {
|
|
91
|
-
return `${minutes}:${seconds}.${milliseconds.slice(0, 2)}`;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
return `${toFormattedTime(timeInSeconds)} / ${toFormattedTime(absoluteTimeInSeconds)}`;
|
|
95
|
-
}
|
|
96
|
-
function shouldShowControls(playing, isMouseOver, areControlsDisabled) {
|
|
97
|
-
if (areControlsDisabled) {
|
|
98
|
-
return false;
|
|
99
|
-
}
|
|
100
|
-
return !playing || isMouseOver;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// src/controls.tsx
|
|
104
|
-
function PlayPause({
|
|
105
|
-
playing,
|
|
106
|
-
setPlaying
|
|
107
|
-
}) {
|
|
108
|
-
return /* @__PURE__ */ React2.createElement("button", { type: "button", className: "p-1", onClick: () => setPlaying(!playing) }, playing ? /* @__PURE__ */ React2.createElement(PauseButton, null) : /* @__PURE__ */ React2.createElement(PlayButton, null));
|
|
109
|
-
}
|
|
110
|
-
function VolumeSlider({
|
|
111
|
-
volume,
|
|
112
|
-
setVolume
|
|
113
|
-
}) {
|
|
114
|
-
const [isHovering, setIsHovering] = useState(false);
|
|
115
|
-
const [isInteracting, setIsInteracting] = useState(false);
|
|
116
|
-
const [previousVolume, setPreviousVolume] = useState(1);
|
|
117
|
-
const handleIconClick = () => {
|
|
118
|
-
if (volume > 0) {
|
|
119
|
-
setPreviousVolume(volume);
|
|
120
|
-
setVolume(0);
|
|
121
|
-
} else {
|
|
122
|
-
setVolume(previousVolume);
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
return /* @__PURE__ */ React2.createElement(
|
|
126
|
-
"div",
|
|
127
|
-
{
|
|
128
|
-
className: "flex items-center space-x-2 relative",
|
|
129
|
-
onMouseEnter: () => setIsHovering(true),
|
|
130
|
-
onMouseLeave: () => {
|
|
131
|
-
if (!isInteracting) {
|
|
132
|
-
setIsHovering(false);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
},
|
|
136
|
-
/* @__PURE__ */ React2.createElement(
|
|
137
|
-
"div",
|
|
138
|
-
{
|
|
139
|
-
className: "w-6 h-6 flex items-center justify-center cursor-pointer",
|
|
140
|
-
onClick: handleIconClick
|
|
141
|
-
},
|
|
142
|
-
volume === 0 ? /* @__PURE__ */ React2.createElement(MutedSoundIcon, null) : /* @__PURE__ */ React2.createElement(SoundIcon, null)
|
|
143
|
-
),
|
|
144
|
-
(isHovering || isInteracting) && /* @__PURE__ */ React2.createElement("div", { className: "flex items-center h-1.5 whitespace-nowrap" }, /* @__PURE__ */ React2.createElement("div", { className: "relative w-20 h-1.5 bg-gray-300 rounded-full" }, /* @__PURE__ */ React2.createElement(
|
|
145
|
-
"div",
|
|
146
|
-
{
|
|
147
|
-
className: "absolute top-0 left-0 h-full bg-gray-100 rounded-full",
|
|
148
|
-
style: { width: `${volume * 100}%` }
|
|
149
|
-
}
|
|
150
|
-
), /* @__PURE__ */ React2.createElement(
|
|
151
|
-
"input",
|
|
152
|
-
{
|
|
153
|
-
type: "range",
|
|
154
|
-
min: 0,
|
|
155
|
-
max: 1,
|
|
156
|
-
step: 0.01,
|
|
157
|
-
value: volume,
|
|
158
|
-
onChange: (e) => {
|
|
159
|
-
const newVolume = Number(e.target.value);
|
|
160
|
-
setVolume(newVolume);
|
|
161
|
-
if (newVolume > 0) {
|
|
162
|
-
setPreviousVolume(newVolume);
|
|
163
|
-
}
|
|
164
|
-
},
|
|
165
|
-
onMouseDown: () => setIsInteracting(true),
|
|
166
|
-
onMouseUp: () => setIsInteracting(false),
|
|
167
|
-
onMouseLeave: () => setIsInteracting(false),
|
|
168
|
-
className: "absolute top-0 left-0 w-full h-full opacity-0 cursor-pointer"
|
|
169
|
-
}
|
|
170
|
-
)))
|
|
171
|
-
);
|
|
172
|
-
}
|
|
173
|
-
function Timeline({
|
|
174
|
-
currentTime,
|
|
175
|
-
duration,
|
|
176
|
-
setCurrentTime
|
|
177
|
-
}) {
|
|
178
|
-
const progressPercentage = currentTime / duration * 100;
|
|
179
|
-
return /* @__PURE__ */ React2.createElement("div", { className: "relative flex-1 w-full h-1.5 bg-gray-300 rounded-full overflow-hidden" }, /* @__PURE__ */ React2.createElement(
|
|
180
|
-
"div",
|
|
181
|
-
{
|
|
182
|
-
className: "absolute top-0 left-0 h-full bg-gray-100",
|
|
183
|
-
style: { width: `${progressPercentage}%` }
|
|
184
|
-
}
|
|
185
|
-
), /* @__PURE__ */ React2.createElement(
|
|
186
|
-
"input",
|
|
187
|
-
{
|
|
188
|
-
type: "range",
|
|
189
|
-
value: currentTime,
|
|
190
|
-
min: 0,
|
|
191
|
-
max: duration,
|
|
192
|
-
step: 0.01,
|
|
193
|
-
className: "absolute top-0 left-0 w-full h-full opacity-0 cursor-pointer",
|
|
194
|
-
onChange: (event) => setCurrentTime(Number(event.target.value))
|
|
195
|
-
}
|
|
196
|
-
));
|
|
197
|
-
}
|
|
198
|
-
function Controls({
|
|
199
|
-
duration,
|
|
200
|
-
playing,
|
|
201
|
-
setPlaying,
|
|
202
|
-
currentTime,
|
|
203
|
-
setForcedTime,
|
|
204
|
-
timeDisplayFormat,
|
|
205
|
-
volume,
|
|
206
|
-
setVolume
|
|
207
|
-
}) {
|
|
208
|
-
return /* @__PURE__ */ React2.createElement("div", { className: "text-white p-4 flex-col space-y-2 bg-gradient-to-t from-gray-500 to-transparent" }, /* @__PURE__ */ React2.createElement("div", { className: "flex items-center space-x-2" }, /* @__PURE__ */ React2.createElement(PlayPause, { playing, setPlaying }), /* @__PURE__ */ React2.createElement("div", { className: "flex items-center space-x-2" }, /* @__PURE__ */ React2.createElement(VolumeSlider, { volume, setVolume }), /* @__PURE__ */ React2.createElement("div", null, /* @__PURE__ */ React2.createElement("span", null, getFormattedTime(currentTime, duration, timeDisplayFormat)))), /* @__PURE__ */ React2.createElement("div", { className: "flex-grow" })), /* @__PURE__ */ React2.createElement(
|
|
209
|
-
Timeline,
|
|
210
|
-
{
|
|
211
|
-
currentTime,
|
|
212
|
-
duration,
|
|
213
|
-
setCurrentTime: setForcedTime
|
|
214
|
-
}
|
|
215
|
-
));
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
// src/index.tsx
|
|
219
|
-
function Player({
|
|
220
|
-
project,
|
|
221
|
-
controls = true,
|
|
222
|
-
variables = {},
|
|
223
|
-
playing = false,
|
|
224
|
-
currentTime = 0,
|
|
225
|
-
volume = 1,
|
|
226
|
-
looping = true,
|
|
227
|
-
fps = 30,
|
|
228
|
-
width = void 0,
|
|
229
|
-
height = void 0,
|
|
230
|
-
quality = void 0,
|
|
231
|
-
timeDisplayFormat = "MM:SS",
|
|
232
|
-
onDurationChange = () => {
|
|
233
|
-
},
|
|
234
|
-
onTimeUpdate = () => {
|
|
235
|
-
},
|
|
236
|
-
onPlayerReady = () => {
|
|
237
|
-
},
|
|
238
|
-
onPlayerResize = () => {
|
|
239
|
-
}
|
|
240
|
-
}) {
|
|
241
|
-
const [playingState, setPlaying] = useState2(playing);
|
|
242
|
-
const [isMouseOver, setIsMouseOver] = useState2(false);
|
|
243
|
-
const [currentTimeState, setCurrentTime] = useState2(currentTime);
|
|
244
|
-
const [volumeState, setVolumeState] = useState2(volume);
|
|
245
|
-
const [duration, setDuration] = useState2(-1);
|
|
246
|
-
const focus = useRef(false);
|
|
247
|
-
const playerRef = useRef(null);
|
|
248
|
-
const wrapperRef = useRef(null);
|
|
249
|
-
const lastRect = useRef(null);
|
|
250
|
-
const onClickHandler = controls ? () => setPlaying((prev) => !prev) : void 0;
|
|
251
|
-
useEffect(() => {
|
|
252
|
-
setPlaying(playing);
|
|
253
|
-
}, [playing]);
|
|
254
|
-
useEffect(() => {
|
|
255
|
-
const diff = Math.abs(currentTime - currentTimeState);
|
|
256
|
-
if (diff > 0.05) {
|
|
257
|
-
setForcedTime(currentTime);
|
|
258
|
-
}
|
|
259
|
-
}, [currentTime]);
|
|
260
|
-
useEffect(() => {
|
|
261
|
-
setForcedVolume(volume);
|
|
262
|
-
}, [volume]);
|
|
263
|
-
const handleTimeUpdate = (event) => {
|
|
264
|
-
const e = event;
|
|
265
|
-
setCurrentTime(e.detail);
|
|
266
|
-
onTimeUpdate(e.detail);
|
|
267
|
-
};
|
|
268
|
-
const handleDurationUpdate = (event) => {
|
|
269
|
-
const e = event;
|
|
270
|
-
setDuration(e.detail);
|
|
271
|
-
onDurationChange(e.detail);
|
|
272
|
-
};
|
|
273
|
-
const handleKeyDown = (event) => {
|
|
274
|
-
if (event.code === "Space" && focus.current) {
|
|
275
|
-
event.preventDefault();
|
|
276
|
-
setPlaying((prev) => !prev);
|
|
277
|
-
}
|
|
278
|
-
};
|
|
279
|
-
const handlePlayerReady = (event) => {
|
|
280
|
-
const player = event.detail;
|
|
281
|
-
if (player) {
|
|
282
|
-
onPlayerReady(player);
|
|
283
|
-
}
|
|
284
|
-
};
|
|
285
|
-
const handlePlayerResize = useCallback(
|
|
286
|
-
(entries) => {
|
|
287
|
-
const [firstEntry] = entries;
|
|
288
|
-
if (!firstEntry || !wrapperRef.current) {
|
|
289
|
-
return;
|
|
290
|
-
}
|
|
291
|
-
const newRect = wrapperRef.current.getBoundingClientRect();
|
|
292
|
-
if (!lastRect.current || newRect.width !== lastRect.current.width || newRect.height !== lastRect.current.height || newRect.x !== lastRect.current.x || newRect.y !== lastRect.current.y) {
|
|
293
|
-
lastRect.current = newRect;
|
|
294
|
-
onPlayerResize(newRect);
|
|
295
|
-
}
|
|
296
|
-
},
|
|
297
|
-
[onPlayerResize]
|
|
298
|
-
);
|
|
299
|
-
useEffect(() => {
|
|
300
|
-
if (!wrapperRef.current) return;
|
|
301
|
-
const resizeObserver = new ResizeObserver(handlePlayerResize);
|
|
302
|
-
resizeObserver.observe(wrapperRef.current);
|
|
303
|
-
return () => {
|
|
304
|
-
resizeObserver.disconnect();
|
|
305
|
-
};
|
|
306
|
-
}, [handlePlayerResize]);
|
|
307
|
-
useEffect(() => {
|
|
308
|
-
import("./internal-LRAKNBSP.mjs").then(() => {
|
|
309
|
-
if (playerRef.current) {
|
|
310
|
-
playerRef.current.setProject(project);
|
|
311
|
-
}
|
|
312
|
-
});
|
|
313
|
-
playerRef.current?.addEventListener("timeupdate", handleTimeUpdate);
|
|
314
|
-
playerRef.current?.addEventListener("duration", handleDurationUpdate);
|
|
315
|
-
playerRef.current?.addEventListener("playerready", handlePlayerReady);
|
|
316
|
-
document.addEventListener("keydown", handleKeyDown);
|
|
317
|
-
return () => {
|
|
318
|
-
playerRef.current?.removeEventListener("timeupdate", handleTimeUpdate);
|
|
319
|
-
playerRef.current?.removeEventListener("duration", handleDurationUpdate);
|
|
320
|
-
playerRef.current?.removeEventListener("playerready", handlePlayerReady);
|
|
321
|
-
document.removeEventListener("keydown", handleKeyDown);
|
|
322
|
-
};
|
|
323
|
-
}, [project]);
|
|
324
|
-
function setForcedTime(forcedTime) {
|
|
325
|
-
if (playerRef.current) {
|
|
326
|
-
playerRef.current.dispatchEvent(
|
|
327
|
-
new CustomEvent("seekto", { detail: forcedTime })
|
|
328
|
-
);
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
function setForcedVolume(volume2) {
|
|
332
|
-
setVolumeState(volume2);
|
|
333
|
-
if (playerRef.current) {
|
|
334
|
-
playerRef.current.dispatchEvent(
|
|
335
|
-
new CustomEvent("volumechange", { detail: volume2 })
|
|
336
|
-
);
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
return /* @__PURE__ */ React3.createElement("div", { className: "revideo-player-root", style: { display: "contents" } }, /* @__PURE__ */ React3.createElement(
|
|
340
|
-
"div",
|
|
341
|
-
{
|
|
342
|
-
ref: wrapperRef,
|
|
343
|
-
className: "relative cursor-default focus:outline-none",
|
|
344
|
-
onFocus: () => focus.current = true,
|
|
345
|
-
onBlur: () => focus.current = false,
|
|
346
|
-
tabIndex: 0,
|
|
347
|
-
onMouseEnter: () => setIsMouseOver(true),
|
|
348
|
-
onMouseLeave: () => setIsMouseOver(false)
|
|
349
|
-
},
|
|
350
|
-
/* @__PURE__ */ React3.createElement("div", { className: "relative" }, /* @__PURE__ */ React3.createElement(
|
|
351
|
-
"revideo-player",
|
|
352
|
-
{
|
|
353
|
-
ref: playerRef,
|
|
354
|
-
playing: String(playingState),
|
|
355
|
-
onClick: onClickHandler,
|
|
356
|
-
variables: JSON.stringify(variables),
|
|
357
|
-
looping: looping ? "true" : "false",
|
|
358
|
-
width,
|
|
359
|
-
height,
|
|
360
|
-
quality,
|
|
361
|
-
fps,
|
|
362
|
-
volume: volumeState
|
|
363
|
-
}
|
|
364
|
-
), /* @__PURE__ */ React3.createElement(
|
|
365
|
-
"div",
|
|
366
|
-
{
|
|
367
|
-
className: `absolute bottom-0 w-full transition-opacity duration-200 ${shouldShowControls(playingState, isMouseOver, !controls) ? "opacity-100" : "opacity-0"}`
|
|
368
|
-
},
|
|
369
|
-
/* @__PURE__ */ React3.createElement(
|
|
370
|
-
Controls,
|
|
371
|
-
{
|
|
372
|
-
duration,
|
|
373
|
-
playing: playingState,
|
|
374
|
-
setPlaying,
|
|
375
|
-
currentTime: currentTimeState,
|
|
376
|
-
setForcedTime,
|
|
377
|
-
timeDisplayFormat,
|
|
378
|
-
volume: volumeState,
|
|
379
|
-
setVolume: setForcedVolume
|
|
380
|
-
}
|
|
381
|
-
)
|
|
382
|
-
))
|
|
383
|
-
));
|
|
384
|
-
}
|
|
385
|
-
export {
|
|
386
|
-
Player
|
|
387
|
-
};
|
|
@@ -1,243 +0,0 @@
|
|
|
1
|
-
// src/internal.ts
|
|
2
|
-
import { Player, Stage, getFullPreviewSettings } from "@revideo/core";
|
|
3
|
-
import { Vector2 } from "@revideo/core";
|
|
4
|
-
var stylesNew = `
|
|
5
|
-
.overlay {
|
|
6
|
-
position: absolute;
|
|
7
|
-
left: 0;
|
|
8
|
-
right: 0;
|
|
9
|
-
top: 0;
|
|
10
|
-
bottom: 0;
|
|
11
|
-
display: flex;
|
|
12
|
-
align-items: center;
|
|
13
|
-
justify-content: center;
|
|
14
|
-
opacity: 0;
|
|
15
|
-
transition: opacity 0.1s;
|
|
16
|
-
z-index: 0;
|
|
17
|
-
}
|
|
18
|
-
.canvas {
|
|
19
|
-
width: 100%;
|
|
20
|
-
display: block;
|
|
21
|
-
opacity: 1;
|
|
22
|
-
transition: opacity 0.1s;
|
|
23
|
-
}
|
|
24
|
-
`;
|
|
25
|
-
var TEMPLATE = `<style>${stylesNew}</style><div class="overlay"></div>`;
|
|
26
|
-
var ID = "revideo-player";
|
|
27
|
-
var RevideoPlayer = class extends HTMLElement {
|
|
28
|
-
static get observedAttributes() {
|
|
29
|
-
return [
|
|
30
|
-
"playing",
|
|
31
|
-
"variables",
|
|
32
|
-
"looping",
|
|
33
|
-
"fps",
|
|
34
|
-
"quality",
|
|
35
|
-
"width",
|
|
36
|
-
"height",
|
|
37
|
-
"volume"
|
|
38
|
-
];
|
|
39
|
-
}
|
|
40
|
-
get fps() {
|
|
41
|
-
const attr = this.getAttribute("fps");
|
|
42
|
-
return attr ? parseFloat(attr) : this.defaultSettings?.fps ?? 60;
|
|
43
|
-
}
|
|
44
|
-
get quality() {
|
|
45
|
-
const attr = this.getAttribute("quality");
|
|
46
|
-
return attr ? parseFloat(attr) : this.defaultSettings?.resolutionScale ?? 1;
|
|
47
|
-
}
|
|
48
|
-
get width() {
|
|
49
|
-
const attr = this.getAttribute("width");
|
|
50
|
-
return attr ? parseFloat(attr) : this.defaultSettings?.size.width ?? 0;
|
|
51
|
-
}
|
|
52
|
-
get height() {
|
|
53
|
-
const attr = this.getAttribute("height");
|
|
54
|
-
return attr ? parseFloat(attr) : this.defaultSettings?.size.height ?? 0;
|
|
55
|
-
}
|
|
56
|
-
get variables() {
|
|
57
|
-
try {
|
|
58
|
-
const attr = this.getAttribute("variables");
|
|
59
|
-
return attr ? JSON.parse(attr) : {};
|
|
60
|
-
} catch {
|
|
61
|
-
this.project?.logger.warn(`Project variables could not be parsed.`);
|
|
62
|
-
return {};
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
root;
|
|
66
|
-
canvas;
|
|
67
|
-
overlay;
|
|
68
|
-
state = "initial" /* Initial */;
|
|
69
|
-
project = null;
|
|
70
|
-
player = null;
|
|
71
|
-
defaultSettings;
|
|
72
|
-
abortController = null;
|
|
73
|
-
playing = false;
|
|
74
|
-
stage = new Stage();
|
|
75
|
-
time = 0;
|
|
76
|
-
duration = 0;
|
|
77
|
-
// in frames
|
|
78
|
-
looping = true;
|
|
79
|
-
volume = 1;
|
|
80
|
-
volumeChangeRequested = true;
|
|
81
|
-
constructor() {
|
|
82
|
-
super();
|
|
83
|
-
this.root = this.attachShadow({ mode: "open" });
|
|
84
|
-
this.root.innerHTML = TEMPLATE;
|
|
85
|
-
this.overlay = this.root.querySelector(".overlay");
|
|
86
|
-
this.canvas = this.stage.finalBuffer;
|
|
87
|
-
this.canvas.classList.add("canvas");
|
|
88
|
-
this.root.prepend(this.canvas);
|
|
89
|
-
this.setState("initial" /* Initial */);
|
|
90
|
-
}
|
|
91
|
-
setProject(project) {
|
|
92
|
-
this.updateProject(project);
|
|
93
|
-
}
|
|
94
|
-
setState(state) {
|
|
95
|
-
this.state = state;
|
|
96
|
-
this.setPlaying(this.playing);
|
|
97
|
-
}
|
|
98
|
-
setPlaying(value) {
|
|
99
|
-
if (this.state === "ready" /* Ready */ && value) {
|
|
100
|
-
this.player?.togglePlayback(true);
|
|
101
|
-
this.playing = true;
|
|
102
|
-
} else {
|
|
103
|
-
this.player?.togglePlayback(false);
|
|
104
|
-
this.playing = false;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
async updateProject(project) {
|
|
108
|
-
const playing = this.playing;
|
|
109
|
-
this.setState("initial" /* Initial */);
|
|
110
|
-
this.abortController?.abort();
|
|
111
|
-
this.abortController = new AbortController();
|
|
112
|
-
this.project = project;
|
|
113
|
-
console.log(project);
|
|
114
|
-
this.defaultSettings = getFullPreviewSettings(this.project);
|
|
115
|
-
const player = new Player(this.project);
|
|
116
|
-
player.setVariables(this.variables);
|
|
117
|
-
player.toggleLoop(this.looping);
|
|
118
|
-
this.player?.onRender.unsubscribe(this.render);
|
|
119
|
-
this.player?.onFrameChanged.unsubscribe(this.handleFrameChanged);
|
|
120
|
-
this.player?.togglePlayback(false);
|
|
121
|
-
this.player?.deactivate();
|
|
122
|
-
this.player = player;
|
|
123
|
-
this.updateSettings();
|
|
124
|
-
this.setState("ready" /* Ready */);
|
|
125
|
-
this.dispatchEvent(new CustomEvent("playerready", { detail: this.player }));
|
|
126
|
-
this.setPlaying(playing);
|
|
127
|
-
this.player.onRender.subscribe(this.render);
|
|
128
|
-
this.player.onFrameChanged.subscribe(this.handleFrameChanged);
|
|
129
|
-
}
|
|
130
|
-
attributeChangedCallback(name, _, newValue) {
|
|
131
|
-
switch (name) {
|
|
132
|
-
case "playing":
|
|
133
|
-
this.setPlaying(newValue === "true");
|
|
134
|
-
break;
|
|
135
|
-
case "variables":
|
|
136
|
-
this.player?.setVariables(this.variables);
|
|
137
|
-
this.player?.requestSeek(this.player.playback.frame);
|
|
138
|
-
this.player?.playback.reload();
|
|
139
|
-
break;
|
|
140
|
-
case "looping":
|
|
141
|
-
this.looping = newValue === "true";
|
|
142
|
-
this.player?.toggleLoop(newValue === "true");
|
|
143
|
-
break;
|
|
144
|
-
case "fps":
|
|
145
|
-
case "quality":
|
|
146
|
-
case "width":
|
|
147
|
-
case "height":
|
|
148
|
-
this.updateSettings();
|
|
149
|
-
break;
|
|
150
|
-
case "volume":
|
|
151
|
-
this.volume = newValue;
|
|
152
|
-
this.volumeChangeRequested = true;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* Runs when the element is removed from the DOM.
|
|
157
|
-
*/
|
|
158
|
-
disconnectedCallback() {
|
|
159
|
-
this.player?.deactivate();
|
|
160
|
-
this.player?.onRender.unsubscribe(this.render);
|
|
161
|
-
this.removeEventListener("seekto", this.handleSeekTo);
|
|
162
|
-
this.removeEventListener("volumechange", this.handleVolumeChange);
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* Runs when the element is added to the DOM.
|
|
166
|
-
*/
|
|
167
|
-
connectedCallback() {
|
|
168
|
-
this.player?.activate();
|
|
169
|
-
this.player?.onRender.subscribe(this.render);
|
|
170
|
-
this.addEventListener("seekto", this.handleSeekTo);
|
|
171
|
-
this.addEventListener("volumechange", this.handleVolumeChange);
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* Triggered by the timeline.
|
|
175
|
-
*/
|
|
176
|
-
handleSeekTo = (event) => {
|
|
177
|
-
if (!this.project) {
|
|
178
|
-
return;
|
|
179
|
-
}
|
|
180
|
-
const e = event;
|
|
181
|
-
this.time = e.detail;
|
|
182
|
-
this.player?.requestSeek(e.detail * this.player.playback.fps);
|
|
183
|
-
this.volumeChangeRequested = true;
|
|
184
|
-
};
|
|
185
|
-
handleVolumeChange = (event) => {
|
|
186
|
-
if (!this.project) {
|
|
187
|
-
return;
|
|
188
|
-
}
|
|
189
|
-
const e = event;
|
|
190
|
-
this.volume = e.detail;
|
|
191
|
-
this.player?.playback.currentScene.adjustVolume(this.volume);
|
|
192
|
-
};
|
|
193
|
-
/**
|
|
194
|
-
* Triggered by the player.
|
|
195
|
-
*/
|
|
196
|
-
handleFrameChanged = (frame) => {
|
|
197
|
-
if (!this.project || !this.player) {
|
|
198
|
-
return;
|
|
199
|
-
}
|
|
200
|
-
this.time = frame / this.player.playback.fps;
|
|
201
|
-
if (this.volumeChangeRequested || frame === 0) {
|
|
202
|
-
this.player?.playback.currentScene.adjustVolume(this.volume);
|
|
203
|
-
this.volumeChangeRequested = false;
|
|
204
|
-
}
|
|
205
|
-
};
|
|
206
|
-
/**
|
|
207
|
-
* Called on every frame.
|
|
208
|
-
*/
|
|
209
|
-
render = async () => {
|
|
210
|
-
if (this.player && this.project) {
|
|
211
|
-
await this.stage.render(
|
|
212
|
-
this.player.playback.currentScene,
|
|
213
|
-
this.player.playback.previousScene
|
|
214
|
-
);
|
|
215
|
-
this.dispatchEvent(new CustomEvent("timeupdate", { detail: this.time }));
|
|
216
|
-
const durationInFrames = this.player.playback.duration;
|
|
217
|
-
if (durationInFrames === this.duration) {
|
|
218
|
-
return;
|
|
219
|
-
}
|
|
220
|
-
this.duration = durationInFrames;
|
|
221
|
-
const durationInSeconds = durationInFrames / this.player.playback.fps;
|
|
222
|
-
this.dispatchEvent(
|
|
223
|
-
new CustomEvent("duration", { detail: durationInSeconds })
|
|
224
|
-
);
|
|
225
|
-
}
|
|
226
|
-
};
|
|
227
|
-
updateSettings() {
|
|
228
|
-
if (!this.defaultSettings) {
|
|
229
|
-
return;
|
|
230
|
-
}
|
|
231
|
-
const settings = {
|
|
232
|
-
...this.defaultSettings,
|
|
233
|
-
size: new Vector2(this.width, this.height),
|
|
234
|
-
resolutionScale: this.quality,
|
|
235
|
-
fps: this.fps
|
|
236
|
-
};
|
|
237
|
-
this.stage.configure(settings);
|
|
238
|
-
this.player?.configure(settings);
|
|
239
|
-
}
|
|
240
|
-
};
|
|
241
|
-
if (!customElements.get(ID)) {
|
|
242
|
-
customElements.define(ID, RevideoPlayer);
|
|
243
|
-
}
|