lexgui 0.1.31 → 0.1.32
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/build/components/timeline.js +768 -442
- package/build/components/videoeditor.js +539 -0
- package/build/lexgui.css +87 -3
- package/build/lexgui.js +272 -254
- package/build/lexgui.module.js +247 -229
- package/changelog.md +11 -0
- package/examples/index.html +2 -1
- package/examples/timeline.html +279 -0
- package/examples/video_editor.html +35 -0
- package/package.json +1 -1
|
@@ -0,0 +1,539 @@
|
|
|
1
|
+
import { LX } from 'lexgui';
|
|
2
|
+
|
|
3
|
+
if(!LX) {
|
|
4
|
+
throw("lexgui.js missing!");
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
LX.components.push( 'VideoEditor' );
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @class TimeBar
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
class TimeBar {
|
|
14
|
+
|
|
15
|
+
static TIMEBAR_PLAY = 1;
|
|
16
|
+
static TIMEBAR_TRIM = 2;
|
|
17
|
+
|
|
18
|
+
static BACKGROUND_COLOR = LX.getThemeColor("global-branch-darker");
|
|
19
|
+
static COLOR = LX.getThemeColor("global-button-color");
|
|
20
|
+
static ACTIVE_COLOR = LX.getThemeColor("global-selected-light");
|
|
21
|
+
|
|
22
|
+
constructor( area, type, options = {} ) {
|
|
23
|
+
|
|
24
|
+
this.type = type;
|
|
25
|
+
|
|
26
|
+
// Create canvas
|
|
27
|
+
this.canvas = document.createElement( 'canvas' );
|
|
28
|
+
this.canvas.width = area.size[0];
|
|
29
|
+
this.canvas.height = area.size[1];
|
|
30
|
+
area.attach( this.canvas );
|
|
31
|
+
|
|
32
|
+
this.ctx = this.canvas.getContext("2d");
|
|
33
|
+
|
|
34
|
+
const barHeight = options.barHeight ?? 5;
|
|
35
|
+
this.markerWidth = options.markerWidth ?? 8;
|
|
36
|
+
this.offset = options.offset ?? 5;
|
|
37
|
+
|
|
38
|
+
this.width = this.canvas.width - this.offset * 2;
|
|
39
|
+
this.height = barHeight;
|
|
40
|
+
|
|
41
|
+
this.position = new LX.vec2( this.offset, this.canvas.height * 0.5 - this.height * 0.5);
|
|
42
|
+
this.startX = this.position.x;
|
|
43
|
+
this.endX = this.width;
|
|
44
|
+
this.currentX = this.startX;
|
|
45
|
+
|
|
46
|
+
const y = this.offset * 2;
|
|
47
|
+
const w = this.markerWidth;
|
|
48
|
+
const h = this.canvas.height - y * 2;
|
|
49
|
+
this.trimRec = [this.startX, y, w, h];
|
|
50
|
+
|
|
51
|
+
this._draw();
|
|
52
|
+
|
|
53
|
+
this.lastPosition = new LX.vec2( 0, 0 );
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
_draw() {
|
|
57
|
+
const ctx = this.ctx;
|
|
58
|
+
|
|
59
|
+
ctx.save();
|
|
60
|
+
ctx.fillStyle = TimeBar.BACKGROUND_COLOR;
|
|
61
|
+
ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
|
62
|
+
ctx.fillRect(0, 0, this.canvas.width, this.canvas.height);
|
|
63
|
+
|
|
64
|
+
// // Draw background timeline
|
|
65
|
+
ctx.fillStyle = TimeBar.COLOR;
|
|
66
|
+
ctx.fillRect(this.position.x, this.position.y, this.width, this.height);
|
|
67
|
+
|
|
68
|
+
// Draw background trimed timeline
|
|
69
|
+
ctx.fillStyle = TimeBar.ACTIVE_COLOR;
|
|
70
|
+
ctx.fillRect(this.startX, this.position.y, this.endX - this.offset - this.startX, this.height);
|
|
71
|
+
|
|
72
|
+
ctx.restore();
|
|
73
|
+
|
|
74
|
+
// Min-Max time markers
|
|
75
|
+
this._addTrim('start', this.startX, { color: null, fillColor: TimeBar.ACTIVE_COLOR || '#5f88c9'});
|
|
76
|
+
this._addTrim('end', this.endX, { color: null, fillColor: TimeBar.ACTIVE_COLOR || '#5f88c9'});
|
|
77
|
+
this._addMarker('current', this.currentX, { color: '#e5e5e5', fillColor: TimeBar.ACTIVE_COLOR || '#5f88c9', width: this.markerWidth });
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
_addTrim(name, x, options) {
|
|
81
|
+
|
|
82
|
+
options = options || {};
|
|
83
|
+
|
|
84
|
+
const y = this.trimRec[1];
|
|
85
|
+
const w = this.trimRec[2];
|
|
86
|
+
const h = this.trimRec[3];
|
|
87
|
+
|
|
88
|
+
const ctx = this.ctx;
|
|
89
|
+
if(this.hovering == name) {
|
|
90
|
+
// Shadow
|
|
91
|
+
ctx.shadowColor = "white";
|
|
92
|
+
ctx.shadowBlur = 2;
|
|
93
|
+
}
|
|
94
|
+
ctx.globalAlpha = 1;
|
|
95
|
+
ctx.fillStyle = ctx.strokeStyle = options.fillColor || '#111' // "#FFF";
|
|
96
|
+
|
|
97
|
+
ctx.beginPath();
|
|
98
|
+
ctx.roundRect(x - w * 0.5, y, w, h, 2);
|
|
99
|
+
ctx.fill();
|
|
100
|
+
ctx.fillStyle = ctx.strokeStyle = options.fillColor || '#111' // "#FFF";
|
|
101
|
+
|
|
102
|
+
ctx.strokeStyle = "white";
|
|
103
|
+
ctx.beginPath();
|
|
104
|
+
ctx.lineWitdh = 2;
|
|
105
|
+
ctx.moveTo(x, y + 4);
|
|
106
|
+
ctx.lineTo(x, y + h - 4);
|
|
107
|
+
ctx.stroke();
|
|
108
|
+
ctx.shadowBlur = 0;
|
|
109
|
+
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
_addMarker(name, x, options) {
|
|
113
|
+
|
|
114
|
+
options = options || {};
|
|
115
|
+
|
|
116
|
+
let y = this.offset;
|
|
117
|
+
const w = options.width ? options.width : (this.dragging == name ? 6 : 4);
|
|
118
|
+
const h = this.canvas.height - this.offset * 2;
|
|
119
|
+
|
|
120
|
+
let ctx = this.ctx;
|
|
121
|
+
|
|
122
|
+
ctx.globalAlpha = 1;
|
|
123
|
+
|
|
124
|
+
ctx.fillStyle = ctx.strokeStyle = options.fillColor || '#111' // "#FFF";
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
if(this.hovering == name) {
|
|
128
|
+
// Shadow
|
|
129
|
+
ctx.shadowColor = "white";
|
|
130
|
+
ctx.shadowBlur = 2;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Current time line
|
|
134
|
+
ctx.fillStyle = ctx.strokeStyle = "white";
|
|
135
|
+
ctx.beginPath();
|
|
136
|
+
ctx.moveTo(x, y);
|
|
137
|
+
ctx.lineTo(x, y + h * 0.5);
|
|
138
|
+
ctx.stroke();
|
|
139
|
+
ctx.closePath();
|
|
140
|
+
ctx.fillStyle = ctx.strokeStyle = options.fillColor || '#111' // "#FFF";
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
y -= this.offset + 4;
|
|
144
|
+
// Current time ball grab
|
|
145
|
+
ctx.fillStyle = options.fillColor || '#e5e5e5';
|
|
146
|
+
ctx.beginPath();
|
|
147
|
+
ctx.roundRect(x - w * 0.5, y + this.offset, w, w, 5);
|
|
148
|
+
|
|
149
|
+
ctx.fill();
|
|
150
|
+
ctx.shadowBlur = 0;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
onMouseDown (e) {
|
|
154
|
+
|
|
155
|
+
e.preventDefault();
|
|
156
|
+
|
|
157
|
+
if(!this.canvas || e.target != this.canvas) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
const canvas = this.canvas;
|
|
161
|
+
|
|
162
|
+
// Process mouse
|
|
163
|
+
const x = e.offsetX;
|
|
164
|
+
const y = e.offsetY;
|
|
165
|
+
|
|
166
|
+
// Check if some marker is clicked
|
|
167
|
+
const threshold = this.markerWidth;
|
|
168
|
+
|
|
169
|
+
if(Math.abs(this.startX - x) < threshold && this.trimRec[1] < y && y < this.trimRec[3] + this.trimRec[1] ) {
|
|
170
|
+
this.dragging = 'start';
|
|
171
|
+
canvas.style.cursor = "grabbing";
|
|
172
|
+
}
|
|
173
|
+
else if(Math.abs(this.endX - x) < threshold && this.trimRec[1] < y && y < this.trimRec[3] + this.trimRec[1] ) {
|
|
174
|
+
this.dragging = 'end';
|
|
175
|
+
canvas.style.cursor = "grabbing";
|
|
176
|
+
}
|
|
177
|
+
else if(Math.abs(this.currentX - x) < threshold) {
|
|
178
|
+
this.dragging = 'current';
|
|
179
|
+
canvas.style.cursor = "grabbing";
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
if(x < this.startX) {
|
|
183
|
+
this.currentX = this.startX;
|
|
184
|
+
}
|
|
185
|
+
else if(x > this.endX) {
|
|
186
|
+
this.currentX = this.endX;
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
this.currentX = x;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
this._draw();
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
update (x) {
|
|
197
|
+
this.currentX = Math.min(Math.max(this.startX, x), this.endX);
|
|
198
|
+
this._draw();
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
onMouseUp (e) {
|
|
202
|
+
e.preventDefault();
|
|
203
|
+
|
|
204
|
+
this.dragging = false;
|
|
205
|
+
this.hovering = false;
|
|
206
|
+
|
|
207
|
+
if(!this.canvas) {
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const canvas = this.canvas;
|
|
212
|
+
canvas.style.cursor = "default";
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
onMouseMove (e) {
|
|
216
|
+
|
|
217
|
+
e.preventDefault();
|
|
218
|
+
|
|
219
|
+
// Process mouse
|
|
220
|
+
const x = e.target == this.canvas ? e.offsetX : e.offsetX - this.canvas.offsetLeft ;
|
|
221
|
+
const y = e.target == this.canvas ? e.offsetY : e.offsetY - this.canvas.offsetTop ;
|
|
222
|
+
const threshold = 5;
|
|
223
|
+
|
|
224
|
+
if(this.dragging) {
|
|
225
|
+
switch(this.dragging) {
|
|
226
|
+
case 'start':
|
|
227
|
+
if(x < this.position.x) {
|
|
228
|
+
this.currentX = this.startX = this.position.x;
|
|
229
|
+
}
|
|
230
|
+
else if(x > this.endX) {
|
|
231
|
+
this.currentX = this.startX = this.endX;
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
this.currentX = this.startX = x;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
if(this.onChangeStart) {
|
|
238
|
+
this.onChangeStart(this.startX);
|
|
239
|
+
}
|
|
240
|
+
if(this.onChangeCurrent) {
|
|
241
|
+
this.onChangeCurrent(this.currentX);
|
|
242
|
+
}
|
|
243
|
+
break;
|
|
244
|
+
case 'end':
|
|
245
|
+
if(x > this.width || x <= 0) {
|
|
246
|
+
this.currentX = this.endX = this.width;
|
|
247
|
+
}
|
|
248
|
+
else if(x < this.startX) {
|
|
249
|
+
this.currentX = this.endX = this.startX;
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
this.currentX = this.endX = x;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
if(this.onChangeEnd) {
|
|
256
|
+
this.onChangeEnd(this.endX);
|
|
257
|
+
}
|
|
258
|
+
if(this.onChangeCurrent) {
|
|
259
|
+
this.onChangeCurrent(this.currentX);
|
|
260
|
+
}
|
|
261
|
+
break;
|
|
262
|
+
case 'current':
|
|
263
|
+
|
|
264
|
+
if(x < this.startX) {
|
|
265
|
+
this.currentX = this.startX;
|
|
266
|
+
}
|
|
267
|
+
else if(x > this.endX) {
|
|
268
|
+
this.currentX = this.endX;
|
|
269
|
+
}
|
|
270
|
+
else {
|
|
271
|
+
this.currentX = x;
|
|
272
|
+
}
|
|
273
|
+
if(this.onChangeCurrent) {
|
|
274
|
+
this.onChangeCurrent(this.currentX);
|
|
275
|
+
}
|
|
276
|
+
break;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
if(!this.canvas) {
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
const canvas = this.canvas;
|
|
285
|
+
|
|
286
|
+
if(Math.abs(this.startX - x) < threshold && this.trimRec[1] < y && y < this.trimRec[3] + this.trimRec[1] ) {
|
|
287
|
+
this.hovering = 'start';
|
|
288
|
+
canvas.style.cursor = "grab";
|
|
289
|
+
}
|
|
290
|
+
else if(Math.abs(this.endX - x) < threshold) {
|
|
291
|
+
this.hovering = 'end';
|
|
292
|
+
canvas.style.cursor = "grab";
|
|
293
|
+
}
|
|
294
|
+
else if(Math.abs(this.currentX - x) < threshold) {
|
|
295
|
+
this.hovering = 'current';
|
|
296
|
+
canvas.style.cursor = "grab";
|
|
297
|
+
}
|
|
298
|
+
else {
|
|
299
|
+
this.hovering = false;
|
|
300
|
+
canvas.style.cursor = "default";
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
this._draw();
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
resize (size) {
|
|
307
|
+
this.canvas.width = size[0];
|
|
308
|
+
this.canvas.height = size[1];
|
|
309
|
+
|
|
310
|
+
const startRatio = this.startX / this.width;
|
|
311
|
+
const currentRatio = this.currentX / this.width;
|
|
312
|
+
const endRatio = this.endX / this.width;
|
|
313
|
+
this.width = this.canvas.width - this.offset * 2;
|
|
314
|
+
|
|
315
|
+
this.startX = Math.max(this.width * startRatio, this.offset);
|
|
316
|
+
this.currentX = Math.min(Math.max(this.width * currentRatio, this.offset), this.width);
|
|
317
|
+
this.endX = Math.min(this.width * endRatio, this.width);
|
|
318
|
+
|
|
319
|
+
this._draw();
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* @class VideoEditor
|
|
325
|
+
*/
|
|
326
|
+
|
|
327
|
+
class VideoEditor {
|
|
328
|
+
|
|
329
|
+
constructor( area, options = {} ) {
|
|
330
|
+
|
|
331
|
+
this.playing = false;
|
|
332
|
+
this.requestId = null;
|
|
333
|
+
|
|
334
|
+
this.currentTime = this.startTime = 0;
|
|
335
|
+
this.startTimeString = "0:0";
|
|
336
|
+
this.endTimeString = "0:0";
|
|
337
|
+
|
|
338
|
+
area.root.classList.add("lexvideoeditor");
|
|
339
|
+
let [videoArea, controlsArea] = area.split({ type: 'vertical', sizes:["80%", null], minimizable: false, resize: false });
|
|
340
|
+
controlsArea.root.classList.add('lexconstrolsarea');
|
|
341
|
+
|
|
342
|
+
// Create video element and load it
|
|
343
|
+
let video = this.video = document.createElement( 'video' );
|
|
344
|
+
this.video.src = options.src ?? '';
|
|
345
|
+
this.video.loop = true;
|
|
346
|
+
this._loadVideo(options);
|
|
347
|
+
videoArea.attach(video);
|
|
348
|
+
|
|
349
|
+
// Create playing timeline area and attach panels
|
|
350
|
+
let [topArea, bottomArea] = controlsArea.split({ type: 'vertical', sizes:["50%", null], minimizable: false, resize: false });
|
|
351
|
+
bottomArea.setSize([bottomArea.size[0], 40]);
|
|
352
|
+
let [leftArea, controlsRight] = bottomArea.split({ type: 'horizontal', sizes:["92%", null], minimizable: false, resize: false });
|
|
353
|
+
let [controlsLeft, timeBarArea] = leftArea.split({ type: 'horizontal', sizes:["10%", null], minimizable: false, resize: false });
|
|
354
|
+
|
|
355
|
+
topArea.root.classList.add('lexbar');
|
|
356
|
+
bottomArea.root.classList.add('lexbar');
|
|
357
|
+
this.controlsCurrentPanel = new LX.Panel({className: 'lexcontrolspanel lextime'});
|
|
358
|
+
this.controlsCurrentPanel.refresh = () => {
|
|
359
|
+
this.controlsCurrentPanel.clear();
|
|
360
|
+
this.controlsCurrentPanel.addLabel(this.currentTimeString, {float: "center"});
|
|
361
|
+
}
|
|
362
|
+
topArea.root.classList.add('lexflexarea')
|
|
363
|
+
topArea.attach(this.controlsCurrentPanel);
|
|
364
|
+
this.controlsCurrentPanel.refresh();
|
|
365
|
+
|
|
366
|
+
const style = getComputedStyle(bottomArea.root);
|
|
367
|
+
let padding = Number(style.getPropertyValue('padding').replace("px",""));
|
|
368
|
+
this.timebar = new TimeBar(timeBarArea, TimeBar.TIMEBAR_TRIM, {offset: padding});
|
|
369
|
+
|
|
370
|
+
// Create controls panel (play/pause button and start time)
|
|
371
|
+
this.controlsPanelLeft = new LX.Panel({className: 'lexcontrolspanel'});
|
|
372
|
+
this.controlsPanelLeft.refresh = () => {
|
|
373
|
+
this.controlsPanelLeft.clear();
|
|
374
|
+
this.controlsPanelLeft.sameLine();
|
|
375
|
+
this.controlsPanelLeft.addButton('', '<i class="fa-solid ' + (this.playing ? 'fa-pause' : 'fa-play') + '"></>', (v) => {
|
|
376
|
+
this.playing = !this.playing;
|
|
377
|
+
if(this.playing) {
|
|
378
|
+
|
|
379
|
+
this.video.play();
|
|
380
|
+
if(!this.requestId) {
|
|
381
|
+
this.requestId = requestAnimationFrame(this._update.bind(this))
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
else {
|
|
385
|
+
if(this.requestId) {
|
|
386
|
+
cancelAnimationFrame(this.requestId);
|
|
387
|
+
this.requestId = null;
|
|
388
|
+
}
|
|
389
|
+
this.video.pause();
|
|
390
|
+
}
|
|
391
|
+
this.controlsPanelLeft.refresh();
|
|
392
|
+
}, { width: '40px'});
|
|
393
|
+
|
|
394
|
+
this.controlsPanelLeft.addLabel(this.startTimeString, {width: 50});
|
|
395
|
+
this.controlsPanelLeft.endLine();
|
|
396
|
+
|
|
397
|
+
let availableWidth = leftArea.root.clientWidth - controlsLeft.root.clientWidth;
|
|
398
|
+
this.timebar.resize([availableWidth, timeBarArea.root.clientHeight]);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
this.controlsPanelLeft.refresh();
|
|
402
|
+
controlsLeft.root.style.minWidth = 'fit-content';
|
|
403
|
+
controlsLeft.attach(this.controlsPanelLeft);
|
|
404
|
+
|
|
405
|
+
// Create right controls panel (ens time)
|
|
406
|
+
this.controlsPanelRight = new LX.Panel({className: 'lexcontrolspanel'});
|
|
407
|
+
this.controlsPanelRight.refresh = () => {
|
|
408
|
+
this.controlsPanelRight.clear();
|
|
409
|
+
this.controlsPanelRight.addLabel(this.endTimeString, {width: 50});
|
|
410
|
+
}
|
|
411
|
+
this.controlsPanelRight.refresh();
|
|
412
|
+
controlsRight.root.style.minWidth = 'fit-content';
|
|
413
|
+
controlsRight.attach(this.controlsPanelRight);
|
|
414
|
+
|
|
415
|
+
this.timebar.onChangeCurrent = this._setCurrentValue.bind(this);
|
|
416
|
+
this.timebar.onChangeStart = this._setStartValue.bind(this);
|
|
417
|
+
this.timebar.onChangeEnd = this._setEndValue.bind(this);
|
|
418
|
+
|
|
419
|
+
window.addEventListener('resize', (v) => {
|
|
420
|
+
let availableWidth = leftArea.root.clientWidth - controlsLeft.root.clientWidth;
|
|
421
|
+
this.timebar.resize([availableWidth, timeBarArea.root.clientHeight]);
|
|
422
|
+
})
|
|
423
|
+
|
|
424
|
+
timeBarArea.onresize = (v) => {
|
|
425
|
+
let availableWidth = leftArea.root.clientWidth - controlsLeft.root.clientWidth;
|
|
426
|
+
this.timebar.resize([availableWidth, v.height]);
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
// Add canvas event listeneres
|
|
430
|
+
area.root.addEventListener( "mousedown", this.timebar.onMouseDown.bind(this.timebar) );
|
|
431
|
+
area.root.addEventListener( "mouseup", this.timebar.onMouseUp.bind(this.timebar) );
|
|
432
|
+
area.root.addEventListener( "mousemove", this.timebar.onMouseMove.bind(this.timebar) );
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
async _loadVideo( ) {
|
|
436
|
+
while(this.video.duration === Infinity || isNaN(this.video.duration) || !this.timebar) {
|
|
437
|
+
await new Promise(r => setTimeout(r, 1000));
|
|
438
|
+
this.video.currentTime = 10000000 * Math.random();
|
|
439
|
+
}
|
|
440
|
+
this.video.currentTime = 0;
|
|
441
|
+
this.endTime = this.video.duration;
|
|
442
|
+
|
|
443
|
+
this._setEndValue(this.timebar.endX);
|
|
444
|
+
this._setStartValue(this.timebar.startX);
|
|
445
|
+
this._setCurrentValue(this.timebar.currentX);
|
|
446
|
+
this.timebar.update(this.timebar.currentX);
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
_update () {
|
|
450
|
+
|
|
451
|
+
if(this.video.currentTime >= this.endTime) {
|
|
452
|
+
this.video.currentTime = this.startTime;
|
|
453
|
+
}
|
|
454
|
+
const x = this._timeToX(this.video.currentTime);
|
|
455
|
+
this._setCurrentValue(x, false);
|
|
456
|
+
this.timebar.update(x);
|
|
457
|
+
|
|
458
|
+
if(this.playing) {
|
|
459
|
+
this.requestId = requestAnimationFrame(this._update.bind(this));
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
_xToTime (x) {
|
|
464
|
+
return ((x - this.timebar.offset) / (this.timebar.width - this.timebar.offset)) * this.video.duration;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
_timeToX (time) {
|
|
468
|
+
return (time / this.video.duration) * (this.timebar.width - this.timebar.offset ) + this.timebar.offset;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
_setCurrentValue ( x, updateTime = true ) {
|
|
472
|
+
const t = this._xToTime(x);
|
|
473
|
+
|
|
474
|
+
if(updateTime) {
|
|
475
|
+
this.video.currentTime = t;
|
|
476
|
+
}
|
|
477
|
+
//console.log( "Computed: " + t)
|
|
478
|
+
let mzminutes = Math.floor(t / 60);
|
|
479
|
+
let mzseconds = Math.floor(t - (mzminutes * 60));
|
|
480
|
+
let mzmiliseconds = Math.floor((t - mzseconds)*100);
|
|
481
|
+
|
|
482
|
+
mzmiliseconds = mzmiliseconds < 10 ? ('0' + mzmiliseconds) : mzmiliseconds;
|
|
483
|
+
mzseconds = mzseconds < 10 ? ('0' + mzseconds) : mzseconds;
|
|
484
|
+
mzminutes = mzminutes < 10 ? ('0' + mzminutes) : mzminutes;
|
|
485
|
+
this.currentTimeString = mzminutes+':'+mzseconds+'.'+mzmiliseconds;
|
|
486
|
+
this.controlsCurrentPanel.refresh();
|
|
487
|
+
|
|
488
|
+
if(this.onSetTime) {
|
|
489
|
+
this.onSetTime(x);
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
_setStartValue ( x ) {
|
|
494
|
+
const t = this._xToTime(x);
|
|
495
|
+
this.startTime = this.video.currentTime = t;
|
|
496
|
+
|
|
497
|
+
let mzminutes = Math.floor(t / 60);
|
|
498
|
+
let mzseconds = Math.floor(t - (mzminutes * 60));
|
|
499
|
+
let mzmiliseconds = Math.floor((t - mzseconds)*100);
|
|
500
|
+
|
|
501
|
+
mzmiliseconds = mzmiliseconds < 10 ? ('0' + mzmiliseconds) : mzmiliseconds;
|
|
502
|
+
mzseconds = mzseconds < 10 ? ('0' + mzseconds) : mzseconds;
|
|
503
|
+
mzminutes = mzminutes < 10 ? ('0' + mzminutes) : mzminutes;
|
|
504
|
+
this.startTimeString = mzminutes+':'+mzseconds+'.'+mzmiliseconds;
|
|
505
|
+
this.controlsPanelLeft.refresh();
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
_setEndValue ( x ) {
|
|
509
|
+
const t = this._xToTime(x);
|
|
510
|
+
this.endTime = this.video.currentTime = t;
|
|
511
|
+
|
|
512
|
+
let mzminutes = Math.floor(t / 60);
|
|
513
|
+
let mzseconds = Math.floor(t - (mzminutes * 60));
|
|
514
|
+
let mzmiliseconds = Math.floor((t - mzseconds)*100);
|
|
515
|
+
|
|
516
|
+
mzmiliseconds = mzmiliseconds < 10 ? ('0' + mzmiliseconds) : mzmiliseconds;
|
|
517
|
+
mzseconds = mzseconds < 10 ? ('0' + mzseconds) : mzseconds;
|
|
518
|
+
mzminutes = mzminutes < 10 ? ('0' + mzminutes) : mzminutes;
|
|
519
|
+
|
|
520
|
+
this.endTimeString = mzminutes+':'+mzseconds+'.'+mzmiliseconds;
|
|
521
|
+
this.controlsPanelRight.refresh();
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
getStartTime ( ) {
|
|
525
|
+
return this.startTime;
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
getEndTime ( ) {
|
|
529
|
+
return this.endTime;
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
getTrimedTimes ( ) {
|
|
533
|
+
return {start: this.startTime, end: this.endTime};
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
LX.VideoEditor = VideoEditor;
|
|
538
|
+
|
|
539
|
+
export { VideoEditor }
|
package/build/lexgui.css
CHANGED
|
@@ -2489,7 +2489,7 @@ meter::-webkit-meter-even-less-good-value {
|
|
|
2489
2489
|
}
|
|
2490
2490
|
|
|
2491
2491
|
.lextimelinepanel {
|
|
2492
|
-
overflow: hidden;
|
|
2492
|
+
/* overflow: hidden; */
|
|
2493
2493
|
}
|
|
2494
2494
|
/* .lextimeline .lexarea, .lextimelinepanel {
|
|
2495
2495
|
background-color: var(--global-dark-background);
|
|
@@ -2513,7 +2513,7 @@ meter::-webkit-meter-even-less-good-value {
|
|
|
2513
2513
|
.lextimeline .lexinlinewidgets {
|
|
2514
2514
|
padding-right: 10px;
|
|
2515
2515
|
/* background-color: var(--global-color-secondary); */
|
|
2516
|
-
height: 100%;
|
|
2516
|
+
/* height: 100%; */
|
|
2517
2517
|
}
|
|
2518
2518
|
|
|
2519
2519
|
.lextimeline .lexbutton:hover {
|
|
@@ -2546,6 +2546,11 @@ meter::-webkit-meter-even-less-good-value {
|
|
|
2546
2546
|
height: unset;
|
|
2547
2547
|
}
|
|
2548
2548
|
|
|
2549
|
+
.lextimeline .lexbutton.accept:hover{
|
|
2550
|
+
background-color: var(--global-button-color-hovered);
|
|
2551
|
+
}
|
|
2552
|
+
|
|
2553
|
+
/**/
|
|
2549
2554
|
.lexmin {
|
|
2550
2555
|
display: inline-block;
|
|
2551
2556
|
color: var(--global-selected-light);
|
|
@@ -3639,4 +3644,83 @@ pre .line-gutter {
|
|
|
3639
3644
|
font-family: var(--global-title-font);
|
|
3640
3645
|
font-weight: 600;
|
|
3641
3646
|
color: var(--global-text);
|
|
3642
|
-
}
|
|
3647
|
+
}
|
|
3648
|
+
|
|
3649
|
+
/* Video Editor */
|
|
3650
|
+
|
|
3651
|
+
.lexvideoeditor {
|
|
3652
|
+
|
|
3653
|
+
}
|
|
3654
|
+
|
|
3655
|
+
.lexvideoeditor video {
|
|
3656
|
+
width: 100%;
|
|
3657
|
+
height: 100%;
|
|
3658
|
+
}
|
|
3659
|
+
|
|
3660
|
+
.lexvideoeditor .lexarea {
|
|
3661
|
+
/* background-color: var(--global-branch-darker)!important; */
|
|
3662
|
+
}
|
|
3663
|
+
|
|
3664
|
+
.lexvideoeditor .lexarea .lexflexarea {
|
|
3665
|
+
display: flex;
|
|
3666
|
+
justify-content: center;
|
|
3667
|
+
padding: 4px 0px;
|
|
3668
|
+
}
|
|
3669
|
+
|
|
3670
|
+
.lexvideoeditor .lexconstrolsarea {
|
|
3671
|
+
/* background-color: var(--global-branch-darker); */
|
|
3672
|
+
/* padding: 5px;
|
|
3673
|
+
margin: 10px; */
|
|
3674
|
+
/* width: calc(100% - 30px)!important; */
|
|
3675
|
+
min-height: 88px!important;
|
|
3676
|
+
border-radius: 8px;
|
|
3677
|
+
display: flex;
|
|
3678
|
+
align-content: center;
|
|
3679
|
+
flex-direction: column;
|
|
3680
|
+
justify-content: center;
|
|
3681
|
+
}
|
|
3682
|
+
|
|
3683
|
+
.lexvideoeditor .lexcontrolspanel {
|
|
3684
|
+
background-color: var(--global-branch-darker);
|
|
3685
|
+
margin: 0;
|
|
3686
|
+
display: flex;
|
|
3687
|
+
align-content: center;
|
|
3688
|
+
width: 100%!important;
|
|
3689
|
+
}
|
|
3690
|
+
|
|
3691
|
+
.lexvideoeditor .lexcontrolspanel.lextime {
|
|
3692
|
+
width: auto!important;
|
|
3693
|
+
border-radius: 5px;
|
|
3694
|
+
}
|
|
3695
|
+
|
|
3696
|
+
.lexvideoeditor .lextimebar {
|
|
3697
|
+
width: 100%;
|
|
3698
|
+
height: inherit;
|
|
3699
|
+
}
|
|
3700
|
+
|
|
3701
|
+
.lexvideoeditor .lexwidget.nobranch {
|
|
3702
|
+
padding: 0;
|
|
3703
|
+
width: 100%!important;
|
|
3704
|
+
}
|
|
3705
|
+
.lexvideoeditor .lextext {
|
|
3706
|
+
padding-left: 0;
|
|
3707
|
+
padding: 6px;
|
|
3708
|
+
}
|
|
3709
|
+
|
|
3710
|
+
.lexvideoeditor .lexbar {
|
|
3711
|
+
height: 40px!important;
|
|
3712
|
+
margin: 5px 10px;
|
|
3713
|
+
padding: 5px;
|
|
3714
|
+
width: calc(100% - 40px)!important;
|
|
3715
|
+
}
|
|
3716
|
+
/* .lexvideoeditor .lexvideotimebar {
|
|
3717
|
+
width: calc(100% - 40px);
|
|
3718
|
+
height: 100%;
|
|
3719
|
+
background-color: var(--global-branch-darker);
|
|
3720
|
+
} */
|
|
3721
|
+
|
|
3722
|
+
/* .lexvideoeditor .lexvideotimebar canvas {
|
|
3723
|
+
width: calc(100%);
|
|
3724
|
+
height: calc(100% );
|
|
3725
|
+
padding: 5px;
|
|
3726
|
+
} */
|