@checksub_team/peaks_timeline 1.16.0-alpha.1 → 2.0.0-alpha.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/package.json +1 -1
- package/peaks.js +4345 -4185
- package/peaks.js.d.ts +5 -5
- package/src/{timeline-axis.js → components/axis.js} +244 -244
- package/src/{data-retriever.js → components/data-retriever.js} +117 -117
- package/src/{default-segment-marker.js → components/default-segment-marker.js} +132 -132
- package/src/{invoker.js → components/invoker.js} +81 -81
- package/src/{line.js → components/line-group.js} +213 -240
- package/src/components/line-groups.js +584 -0
- package/src/{line-indicator.js → components/line-indicator.js} +308 -303
- package/src/{marker-factories.js → components/marker-factories.js} +1 -1
- package/src/{mode-layer.js → components/mode-layer.js} +8 -12
- package/src/{playhead-layer.js → components/playhead-layer.js} +3 -3
- package/src/{segment-marker.js → components/segment-marker.js} +2 -2
- package/src/{segment-shape.js → components/segment-shape.js} +508 -508
- package/src/{segments-group.js → components/segments-group.js} +805 -805
- package/src/{source-group.js → components/source-group.js} +1641 -1649
- package/src/{sources-layer.js → components/sources-layer.js} +716 -725
- package/src/{waveform-builder.js → components/waveform-builder.js} +2 -2
- package/src/{waveform-shape.js → components/waveform-shape.js} +214 -214
- package/src/keyboard-handler.js +9 -9
- package/src/line-handler.js +179 -0
- package/src/main.js +99 -71
- package/src/models/line.js +156 -0
- package/src/{segment.js → models/segment.js} +420 -419
- package/src/{source.js → models/source.js} +1262 -1269
- package/src/player.js +2 -2
- package/src/{timeline-segments.js → segment-handler.js} +427 -435
- package/src/{timeline-sources.js → source-handler.js} +510 -512
- package/src/utils.js +5 -1
- package/src/{timeline-zoomview.js → view.js} +133 -138
- package/src/lines.js +0 -550
- /package/src/{data.js → components/data.js} +0 -0
- /package/src/{loader.js → components/loader.js} +0 -0
- /package/src/{mouse-drag-handler.js → components/mouse-drag-handler.js} +0 -0
- /package/src/{svgs.js → components/svgs.js} +0 -0
|
@@ -1,35 +1,32 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file
|
|
3
3
|
*
|
|
4
|
-
* Defines the {@link
|
|
4
|
+
* Defines the {@link lineGroup} class.
|
|
5
5
|
*
|
|
6
|
-
* @module
|
|
6
|
+
* @module lineGroup
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
define([
|
|
10
10
|
'./source-group',
|
|
11
|
-
'
|
|
12
|
-
'
|
|
13
|
-
], function(SourceGroup,
|
|
11
|
+
'../utils',
|
|
12
|
+
'konva'
|
|
13
|
+
], function(SourceGroup, Utils, Konva) {
|
|
14
14
|
'use strict';
|
|
15
15
|
|
|
16
|
-
function
|
|
16
|
+
function LineGroup(peaks, view, line) {
|
|
17
17
|
this._peaks = peaks;
|
|
18
18
|
this._view = view;
|
|
19
19
|
|
|
20
|
-
this.
|
|
21
|
-
this._position =
|
|
20
|
+
this._line = line;
|
|
21
|
+
this._position = null;
|
|
22
22
|
|
|
23
23
|
this._firstSourceId = null;
|
|
24
24
|
this._sources = {};
|
|
25
25
|
|
|
26
26
|
this._sourcesGroup = {};
|
|
27
27
|
this._wrapped = false;
|
|
28
|
-
this._y = y;
|
|
29
28
|
|
|
30
29
|
this._group = new Konva.Group({
|
|
31
|
-
x: 0,
|
|
32
|
-
y: y - this._view.getFrameOffsetY(),
|
|
33
30
|
draggable: true,
|
|
34
31
|
dragBoundFunc: function() {
|
|
35
32
|
return {
|
|
@@ -44,37 +41,35 @@ define([
|
|
|
44
41
|
this._unwrappedCount = 0;
|
|
45
42
|
}
|
|
46
43
|
|
|
47
|
-
|
|
44
|
+
LineGroup.prototype.getPosition = function() {
|
|
48
45
|
return this._position;
|
|
49
46
|
};
|
|
50
47
|
|
|
51
|
-
|
|
52
|
-
return this.
|
|
48
|
+
LineGroup.prototype.getId = function() {
|
|
49
|
+
return this._line.id;
|
|
53
50
|
};
|
|
54
51
|
|
|
55
|
-
|
|
56
|
-
return this.
|
|
57
|
-
this._segmentsGroup.isEmpty() :
|
|
58
|
-
Object.keys(this._sources).length === 0;
|
|
52
|
+
LineGroup.prototype.getLine = function() {
|
|
53
|
+
return this._line;
|
|
59
54
|
};
|
|
60
55
|
|
|
61
|
-
|
|
56
|
+
LineGroup.prototype.countRemainingElements = function() {
|
|
62
57
|
return this.isSegmentsLine() ?
|
|
63
58
|
this._segmentsGroup.countRemainingElements() :
|
|
64
59
|
Object.keys(this._sources).length;
|
|
65
60
|
};
|
|
66
61
|
|
|
67
|
-
|
|
62
|
+
LineGroup.prototype.isSegmentsLine = function() {
|
|
68
63
|
return Boolean(this._segmentsGroup);
|
|
69
64
|
};
|
|
70
65
|
|
|
71
|
-
|
|
66
|
+
LineGroup.prototype.updateSegments = function(frameStartTime, frameEndTime) {
|
|
72
67
|
if (this.isSegmentsLine()) {
|
|
73
68
|
this._segmentsGroup.updateSegments(frameStartTime, frameEndTime);
|
|
74
69
|
}
|
|
75
70
|
};
|
|
76
71
|
|
|
77
|
-
|
|
72
|
+
LineGroup.prototype.lineLength = function() {
|
|
78
73
|
var length = 0;
|
|
79
74
|
|
|
80
75
|
if (this.isSegmentsLine()) {
|
|
@@ -96,48 +91,11 @@ define([
|
|
|
96
91
|
return length;
|
|
97
92
|
};
|
|
98
93
|
|
|
99
|
-
|
|
94
|
+
LineGroup.prototype.lineHeight = function() {
|
|
100
95
|
return this._height;
|
|
101
96
|
};
|
|
102
97
|
|
|
103
|
-
|
|
104
|
-
if (this._sourceHeights[from]) {
|
|
105
|
-
var oldHeight = this._height;
|
|
106
|
-
|
|
107
|
-
if (this._sourceHeights[to]) {
|
|
108
|
-
this._sourceHeights[to] += this._sourceHeights[from];
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
this._sourceHeights[to] = this._sourceHeights[from];
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
if (to > this._height) {
|
|
115
|
-
this._height = to;
|
|
116
|
-
}
|
|
117
|
-
else if (from === this._height) {
|
|
118
|
-
this._height = 0;
|
|
119
|
-
for (var height in this._sourceHeights) {
|
|
120
|
-
if (Utils.objectHasProperty(this._sourceHeights, height)) {
|
|
121
|
-
var parsedHeight = parseInt(height, 10);
|
|
122
|
-
|
|
123
|
-
if (parsedHeight !== from) {
|
|
124
|
-
if (parsedHeight > this._height) {
|
|
125
|
-
this._height = parsedHeight;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
if (this._height !== oldHeight) {
|
|
133
|
-
this._peaks.emit('line.heightChanged', this._position);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
delete this._sourceHeights[from];
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
Line.prototype._addHeight = function(height) {
|
|
98
|
+
LineGroup.prototype._addHeight = function(height) {
|
|
141
99
|
if (this._sourceHeights[height]) {
|
|
142
100
|
this._sourceHeights[height]++;
|
|
143
101
|
}
|
|
@@ -149,7 +107,7 @@ define([
|
|
|
149
107
|
}
|
|
150
108
|
};
|
|
151
109
|
|
|
152
|
-
|
|
110
|
+
LineGroup.prototype._subtractHeight = function(height) {
|
|
153
111
|
if (Object.keys(this._sources).length === 0) {
|
|
154
112
|
this._height = this._peaks.options.emptyLineHeight;
|
|
155
113
|
this._sourceHeights = {};
|
|
@@ -174,7 +132,7 @@ define([
|
|
|
174
132
|
}
|
|
175
133
|
};
|
|
176
134
|
|
|
177
|
-
|
|
135
|
+
LineGroup.prototype.updateLineHeight = function(source, action) {
|
|
178
136
|
var oldHeight = this._height;
|
|
179
137
|
var sourceGroup = this._sourcesGroup[source.id];
|
|
180
138
|
var sourceGroupHeight;
|
|
@@ -205,16 +163,16 @@ define([
|
|
|
205
163
|
}
|
|
206
164
|
|
|
207
165
|
if (this._height !== oldHeight) {
|
|
208
|
-
this._peaks.emit('line.heightChanged', this.
|
|
166
|
+
this._peaks.emit('line.heightChanged', this._line);
|
|
209
167
|
}
|
|
210
168
|
};
|
|
211
169
|
|
|
212
|
-
|
|
213
|
-
return this.
|
|
214
|
-
&& this.
|
|
170
|
+
LineGroup.prototype.isVisible = function() {
|
|
171
|
+
return this.y() < this._view.getHeight()
|
|
172
|
+
&& this.y() + this._height > 0;
|
|
215
173
|
};
|
|
216
174
|
|
|
217
|
-
|
|
175
|
+
LineGroup.prototype.addToLayer = function(layer) {
|
|
218
176
|
layer.add(this._group);
|
|
219
177
|
};
|
|
220
178
|
|
|
@@ -224,110 +182,128 @@ define([
|
|
|
224
182
|
* @param {SourceGroup} sourceGroup - The source group of the source (optional).
|
|
225
183
|
* @returns {void}
|
|
226
184
|
*/
|
|
227
|
-
|
|
185
|
+
LineGroup.prototype.addSource = function(source, sourceGroup, sourcesAround) {
|
|
228
186
|
if (sourceGroup) {
|
|
229
187
|
this._sourcesGroup[source.id] = sourceGroup;
|
|
188
|
+
if (!sourceGroup.getParent() || !sourceGroup.isDescendantOf(this._group)) {
|
|
189
|
+
sourceGroup.moveTo(this._group);
|
|
190
|
+
}
|
|
230
191
|
}
|
|
231
192
|
|
|
232
193
|
if (!this._sources[source.id]) {
|
|
233
|
-
var
|
|
194
|
+
var sourceData = {
|
|
234
195
|
source: source,
|
|
235
196
|
prevSourceId: null,
|
|
236
197
|
nextSourceId: null
|
|
237
198
|
};
|
|
238
199
|
|
|
239
|
-
if (this._firstSourceId) {
|
|
240
|
-
|
|
200
|
+
if (Utils.isNullOrUndefined(this._firstSourceId)) {
|
|
201
|
+
this._firstSourceId = source.id;
|
|
202
|
+
this._sources[source.id] = sourceData;
|
|
203
|
+
}
|
|
204
|
+
else if (Utils.isNullOrUndefined(sourcesAround)) {
|
|
205
|
+
this._addSourceWherePossible(sourceData);
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
if (sourcesAround.left) {
|
|
209
|
+
this._sources[sourcesAround.left.id].nextSourceId = source.id;
|
|
210
|
+
sourceData.prevSourceId = sourcesAround.left.id;
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
this._firstSourceId = source.id;
|
|
214
|
+
}
|
|
215
|
+
if (sourcesAround.right) {
|
|
216
|
+
this._sources[sourcesAround.right.id].prevSourceId = source.id;
|
|
217
|
+
sourceData.nextSourceId = sourcesAround.right.id;
|
|
218
|
+
}
|
|
219
|
+
this._sources[source.id] = sourceData;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
this.updateLineHeight(source, 'add');
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
LineGroup.prototype._addSourceWherePossible = function(sourceData) {
|
|
227
|
+
const source = sourceData.source;
|
|
228
|
+
var currentSource = null;
|
|
229
|
+
|
|
230
|
+
do {
|
|
231
|
+
if (!currentSource) {
|
|
232
|
+
currentSource = this._sources[this._firstSourceId];
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
currentSource = this._sources[currentSource.nextSourceId];
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
if (source.endTime <= currentSource.source.startTime) {
|
|
239
|
+
var startLimit = currentSource.prevSourceId
|
|
240
|
+
? this._sources[currentSource.prevSourceId].source.endTime
|
|
241
|
+
: 0;
|
|
241
242
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
243
|
+
const { newStartTime, newEndTime } = this._canBePlacedBetween(
|
|
244
|
+
source.startTime,
|
|
245
|
+
source.endTime,
|
|
246
|
+
startLimit,
|
|
247
|
+
currentSource.source.startTime
|
|
248
|
+
);
|
|
249
|
+
|
|
250
|
+
if (!Utils.isNullOrUndefined(newStartTime) && !Utils.isNullOrUndefined(newEndTime)) {
|
|
251
|
+
source.updateTimes(newStartTime, newEndTime);
|
|
252
|
+
|
|
253
|
+
if (currentSource.prevSourceId) {
|
|
254
|
+
this._sources[currentSource.prevSourceId].nextSourceId = source.id;
|
|
255
|
+
sourceData.prevSourceId = currentSource.prevSourceId;
|
|
245
256
|
}
|
|
246
257
|
else {
|
|
247
|
-
|
|
258
|
+
this._firstSourceId = source.id;
|
|
248
259
|
}
|
|
249
260
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
? this._sources[currentSource.prevSourceId].source.endTime
|
|
253
|
-
: 0;
|
|
254
|
-
|
|
255
|
-
const { newStartTime, newEndTime } = this._canBePlacedBetween(
|
|
256
|
-
source.startTime,
|
|
257
|
-
source.endTime,
|
|
258
|
-
startLimit,
|
|
259
|
-
currentSource.source.startTime
|
|
260
|
-
);
|
|
261
|
-
|
|
262
|
-
if (newStartTime !== null && newEndTime !== null) {
|
|
263
|
-
source.updateTimes(newStartTime, newEndTime);
|
|
264
|
-
|
|
265
|
-
if (currentSource.prevSourceId) {
|
|
266
|
-
this._sources[currentSource.prevSourceId].nextSourceId = source.id;
|
|
267
|
-
newSource.prevSourceId = currentSource.prevSourceId;
|
|
268
|
-
}
|
|
269
|
-
else {
|
|
270
|
-
this._firstSourceId = source.id;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
currentSource.prevSourceId = source.id;
|
|
274
|
-
newSource.nextSourceId = currentSource.source.id;
|
|
275
|
-
|
|
276
|
-
this._sources[source.id] = newSource;
|
|
277
|
-
break;
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
} while (currentSource.nextSourceId);
|
|
281
|
-
|
|
282
|
-
if (!newSource.prevSourceId && !newSource.nextSourceId) {
|
|
283
|
-
if (source.startTime < currentSource.source.endTime) {
|
|
284
|
-
// Overlapping with last source
|
|
285
|
-
var timeWidth = source.endTime - source.startTime;
|
|
261
|
+
currentSource.prevSourceId = source.id;
|
|
262
|
+
sourceData.nextSourceId = currentSource.source.id;
|
|
286
263
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
currentSource.source.endTime + timeWidth
|
|
290
|
-
);
|
|
291
|
-
}
|
|
292
|
-
currentSource.nextSourceId = source.id;
|
|
293
|
-
newSource.prevSourceId = currentSource.source.id;
|
|
294
|
-
this._sources[source.id] = newSource;
|
|
264
|
+
this._sources[source.id] = sourceData;
|
|
265
|
+
break;
|
|
295
266
|
}
|
|
296
267
|
}
|
|
297
|
-
|
|
298
|
-
this._firstSourceId = source.id;
|
|
299
|
-
this._sources[source.id] = newSource;
|
|
300
|
-
}
|
|
268
|
+
} while (currentSource.nextSourceId);
|
|
301
269
|
|
|
302
|
-
|
|
303
|
-
|
|
270
|
+
if (!sourceData.prevSourceId && !sourceData.nextSourceId) {
|
|
271
|
+
if (source.startTime < currentSource.source.endTime) {
|
|
272
|
+
// Overlapping with last source
|
|
273
|
+
var timeWidth = source.endTime - source.startTime;
|
|
304
274
|
|
|
305
|
-
|
|
306
|
-
|
|
275
|
+
source.updateTimes(
|
|
276
|
+
currentSource.source.endTime,
|
|
277
|
+
currentSource.source.endTime + timeWidth
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
currentSource.nextSourceId = source.id;
|
|
281
|
+
sourceData.prevSourceId = currentSource.source.id;
|
|
282
|
+
this._sources[source.id] = sourceData;
|
|
307
283
|
}
|
|
308
284
|
};
|
|
309
285
|
|
|
310
|
-
|
|
286
|
+
LineGroup.prototype.addSegments = function(segmentsGroup) {
|
|
311
287
|
this._segmentsGroup = segmentsGroup;
|
|
312
288
|
|
|
313
289
|
this._height = this._segmentsGroup.getCurrentHeight();
|
|
314
290
|
|
|
315
|
-
segmentsGroup.
|
|
291
|
+
segmentsGroup.moveTo(this._group);
|
|
316
292
|
};
|
|
317
293
|
|
|
318
|
-
|
|
294
|
+
LineGroup.prototype.refreshSegmentsHeight = function() {
|
|
319
295
|
if (this.isSegmentsLine) {
|
|
320
296
|
var oldHeight = this._height;
|
|
321
297
|
|
|
322
298
|
this._height = this._segmentsGroup.getCurrentHeight();
|
|
323
299
|
|
|
324
300
|
if (this._height !== oldHeight) {
|
|
325
|
-
this._peaks.emit('line.heightChanged', this.
|
|
301
|
+
this._peaks.emit('line.heightChanged', this._line);
|
|
326
302
|
}
|
|
327
303
|
}
|
|
328
304
|
};
|
|
329
305
|
|
|
330
|
-
|
|
306
|
+
LineGroup.prototype._canBePlacedBetween = function(startTime, endTime, startLimit, endLimit) {
|
|
331
307
|
var timeWidth = Utils.roundTime(endTime - startTime);
|
|
332
308
|
var newStartTime, newEndTime;
|
|
333
309
|
|
|
@@ -351,88 +327,87 @@ define([
|
|
|
351
327
|
return { newStartTime, newEndTime };
|
|
352
328
|
};
|
|
353
329
|
|
|
354
|
-
|
|
355
|
-
|
|
330
|
+
LineGroup.prototype.removeSourceGroup = function(source) {
|
|
331
|
+
const sourceGroup = this._sourcesGroup[source.id];
|
|
356
332
|
|
|
357
333
|
delete this._sourcesGroup[source.id];
|
|
358
334
|
|
|
359
|
-
if (
|
|
360
|
-
|
|
335
|
+
if (sourceGroup) {
|
|
336
|
+
sourceGroup.hideButKeepFocus();
|
|
337
|
+
}
|
|
361
338
|
|
|
362
|
-
|
|
339
|
+
return sourceGroup;
|
|
340
|
+
};
|
|
363
341
|
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
this._peaks.emit('line.remove', this._position);
|
|
367
|
-
}.bind(this), 0);
|
|
368
|
-
return sourceGroup;
|
|
369
|
-
}
|
|
342
|
+
LineGroup.prototype.removeSource = function(source) {
|
|
343
|
+
const sourceGroup = this.removeSourceGroup(source);
|
|
370
344
|
|
|
371
|
-
|
|
372
|
-
this._sources[sourceData.prevSourceId].nextSourceId
|
|
373
|
-
= sourceData.nextSourceId;
|
|
374
|
-
}
|
|
345
|
+
var sourceData = this._sources[source.id];
|
|
375
346
|
|
|
376
|
-
|
|
377
|
-
this._sources[sourceData.nextSourceId].prevSourceId
|
|
378
|
-
= sourceData.prevSourceId;
|
|
379
|
-
}
|
|
347
|
+
delete this._sources[source.id];
|
|
380
348
|
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
349
|
+
if (Object.keys(this._sources).length === 0) {
|
|
350
|
+
this._peaks.destroyLine(this._line.id, true);
|
|
351
|
+
return sourceGroup;
|
|
352
|
+
}
|
|
384
353
|
|
|
385
|
-
|
|
354
|
+
if (sourceData.prevSourceId) {
|
|
355
|
+
this._sources[sourceData.prevSourceId].nextSourceId
|
|
356
|
+
= sourceData.nextSourceId;
|
|
386
357
|
}
|
|
387
358
|
|
|
388
|
-
|
|
389
|
-
|
|
359
|
+
if (sourceData.nextSourceId) {
|
|
360
|
+
this._sources[sourceData.nextSourceId].prevSourceId
|
|
361
|
+
= sourceData.prevSourceId;
|
|
362
|
+
}
|
|
390
363
|
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
364
|
+
if (this._firstSourceId === source.id) {
|
|
365
|
+
this._firstSourceId = sourceData.nextSourceId;
|
|
366
|
+
}
|
|
394
367
|
|
|
395
|
-
|
|
396
|
-
return this._group.y();
|
|
397
|
-
};
|
|
368
|
+
this.updateLineHeight(source, 'remove');
|
|
398
369
|
|
|
399
|
-
|
|
400
|
-
return this._y;
|
|
370
|
+
return sourceGroup;
|
|
401
371
|
};
|
|
402
372
|
|
|
403
|
-
|
|
404
|
-
this._group
|
|
405
|
-
if (changeInitialY) {
|
|
406
|
-
this._y = value;
|
|
407
|
-
}
|
|
373
|
+
LineGroup.prototype.getKonvaGroup = function() {
|
|
374
|
+
return this._group;
|
|
408
375
|
};
|
|
409
376
|
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
377
|
+
LineGroup.prototype.y = function(value) {
|
|
378
|
+
if (typeof value !== 'number') {
|
|
379
|
+
return this._group.y();
|
|
380
|
+
}
|
|
381
|
+
this._group.y(value);
|
|
413
382
|
};
|
|
414
383
|
|
|
415
|
-
|
|
384
|
+
LineGroup.prototype.manageOrder = function(sources, startTime, endTime) {
|
|
416
385
|
const firstSource = sources[0];
|
|
417
386
|
const lastSource = sources[sources.length - 1];
|
|
418
387
|
const cursorTime = this._view.pixelsToTime(this._view.getPointerPosition().x);
|
|
419
388
|
var newStartTime = startTime;
|
|
420
389
|
var newEndTime = endTime;
|
|
390
|
+
var tmpTimes;
|
|
421
391
|
|
|
422
|
-
var sourceDuration = endTime - startTime;
|
|
392
|
+
var sourceDuration = Utils.roundTime(endTime - startTime);
|
|
423
393
|
|
|
424
|
-
if (newStartTime
|
|
394
|
+
if (typeof newStartTime === 'number' && typeof newEndTime === 'number') {
|
|
425
395
|
if (this._sources[firstSource.id].prevSourceId) {
|
|
426
396
|
// there is another source to the left
|
|
427
397
|
var previousStartTime = this._sources[this._sources[firstSource.id].prevSourceId].source.startTime;
|
|
428
398
|
|
|
429
|
-
if (cursorTime + this._view.getTimeOffset() < previousStartTime) {
|
|
399
|
+
if (Utils.roundTime(cursorTime + this._view.getTimeOffset()) < previousStartTime) {
|
|
430
400
|
// we want to change order
|
|
431
|
-
|
|
401
|
+
tmpTimes = this._changeSourcesPosition(
|
|
432
402
|
sources,
|
|
433
403
|
sourceDuration,
|
|
434
404
|
cursorTime + this._view.getTimeOffset()
|
|
435
|
-
)
|
|
405
|
+
);
|
|
406
|
+
|
|
407
|
+
if (typeof tmpTimes.newStartTime === 'number' && typeof tmpTimes.newEndTime === 'number') {
|
|
408
|
+
newStartTime = tmpTimes.newStartTime;
|
|
409
|
+
newEndTime = tmpTimes.newEndTime;
|
|
410
|
+
}
|
|
436
411
|
}
|
|
437
412
|
}
|
|
438
413
|
|
|
@@ -440,13 +415,18 @@ define([
|
|
|
440
415
|
// there is another source to the right
|
|
441
416
|
var nextEndTime = this._sources[this._sources[lastSource.id].nextSourceId].source.endTime;
|
|
442
417
|
|
|
443
|
-
if (cursorTime + this._view.getTimeOffset() > nextEndTime) {
|
|
418
|
+
if (Utils.roundTime(cursorTime + this._view.getTimeOffset()) > nextEndTime) {
|
|
444
419
|
// we want to change order
|
|
445
|
-
|
|
420
|
+
tmpTimes = this._changeSourcesPosition(
|
|
446
421
|
sources,
|
|
447
422
|
sourceDuration,
|
|
448
423
|
cursorTime + this._view.getTimeOffset()
|
|
449
|
-
)
|
|
424
|
+
);
|
|
425
|
+
|
|
426
|
+
if (typeof tmpTimes.newStartTime === 'number' && typeof tmpTimes.newEndTime === 'number') {
|
|
427
|
+
newStartTime = tmpTimes.newStartTime;
|
|
428
|
+
newEndTime = tmpTimes.newEndTime;
|
|
429
|
+
}
|
|
450
430
|
}
|
|
451
431
|
}
|
|
452
432
|
}
|
|
@@ -454,7 +434,7 @@ define([
|
|
|
454
434
|
return { newStartTime, newEndTime };
|
|
455
435
|
};
|
|
456
436
|
|
|
457
|
-
|
|
437
|
+
LineGroup.prototype._changeSourcesPosition = function(sources, sourceDuration, time) {
|
|
458
438
|
var currentRange = {
|
|
459
439
|
start: null,
|
|
460
440
|
end: null
|
|
@@ -495,7 +475,7 @@ define([
|
|
|
495
475
|
endLimit
|
|
496
476
|
));
|
|
497
477
|
|
|
498
|
-
if (newStartTime
|
|
478
|
+
if (typeof newStartTime === 'number' && typeof newEndTime === 'number') {
|
|
499
479
|
let prevSourceId = currentRange.start
|
|
500
480
|
? currentRange.start.source.id
|
|
501
481
|
: null;
|
|
@@ -513,7 +493,7 @@ define([
|
|
|
513
493
|
return { newStartTime, newEndTime };
|
|
514
494
|
};
|
|
515
495
|
|
|
516
|
-
|
|
496
|
+
LineGroup.prototype._moveSource = function(source, prevSourceId) {
|
|
517
497
|
// Remove source from the list
|
|
518
498
|
var sourceObj = this._sources[source.id];
|
|
519
499
|
var prevSource = this._sources[sourceObj.prevSourceId];
|
|
@@ -551,7 +531,7 @@ define([
|
|
|
551
531
|
this._sources[source.id] = sourceObj;
|
|
552
532
|
};
|
|
553
533
|
|
|
554
|
-
|
|
534
|
+
LineGroup.prototype.manageCollision = function(sources, newStartTime, newEndTime) {
|
|
555
535
|
var originalStartTime = newStartTime;
|
|
556
536
|
var originalEndTime = newEndTime;
|
|
557
537
|
var startLimited = false;
|
|
@@ -561,48 +541,42 @@ define([
|
|
|
561
541
|
|
|
562
542
|
if (typeof newStartTime === 'number') {
|
|
563
543
|
// startMarker changed
|
|
564
|
-
if (firstSource.
|
|
565
|
-
//
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
newStartTime = previousSource.endTime;
|
|
574
|
-
startLimited = true;
|
|
575
|
-
}
|
|
544
|
+
if (this._sources[firstSource.id].prevSourceId) {
|
|
545
|
+
// there is another source to the left
|
|
546
|
+
var previousSource = this._sources[this._sources[firstSource.id].prevSourceId]
|
|
547
|
+
.source;
|
|
548
|
+
|
|
549
|
+
if (newStartTime < previousSource.endTime) {
|
|
550
|
+
// there is collision
|
|
551
|
+
newStartTime = previousSource.endTime;
|
|
552
|
+
startLimited = true;
|
|
576
553
|
}
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
554
|
+
}
|
|
555
|
+
else {
|
|
556
|
+
if (newStartTime < 0) {
|
|
557
|
+
newStartTime = 0;
|
|
558
|
+
startLimited = true;
|
|
582
559
|
}
|
|
583
560
|
}
|
|
584
561
|
}
|
|
585
562
|
|
|
586
563
|
if (typeof newEndTime === 'number') {
|
|
587
564
|
// endMarker changed
|
|
588
|
-
if (lastSource.
|
|
589
|
-
//
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
newEndTime = nextSource.startTime;
|
|
598
|
-
endLimited = true;
|
|
599
|
-
}
|
|
565
|
+
if (this._sources[lastSource.id].nextSourceId) {
|
|
566
|
+
// there is another source to the right
|
|
567
|
+
var nextSource = this._sources[this._sources[lastSource.id].nextSourceId]
|
|
568
|
+
.source;
|
|
569
|
+
|
|
570
|
+
if (newEndTime > nextSource.startTime) {
|
|
571
|
+
// there is collision
|
|
572
|
+
newEndTime = nextSource.startTime;
|
|
573
|
+
endLimited = true;
|
|
600
574
|
}
|
|
601
575
|
}
|
|
602
576
|
}
|
|
603
577
|
|
|
604
578
|
// Update the other edge if dragging and collision
|
|
605
|
-
if (newStartTime
|
|
579
|
+
if (typeof newStartTime === 'number' && typeof newEndTime === 'number') {
|
|
606
580
|
var timeWidth = originalEndTime - originalStartTime;
|
|
607
581
|
|
|
608
582
|
if (startLimited) {
|
|
@@ -616,12 +590,12 @@ define([
|
|
|
616
590
|
|
|
617
591
|
// Check for minimal size of source
|
|
618
592
|
// We assume that only 1 source can be resized at a time
|
|
619
|
-
if (newStartTime
|
|
593
|
+
if (typeof newStartTime === 'number' && typeof newEndTime !== 'number') {
|
|
620
594
|
if (Utils.roundTime(sources[0].endTime - newStartTime) < sources[0].minSize) {
|
|
621
595
|
newStartTime = Utils.roundTime(sources[0].endTime - sources[0].minSize);
|
|
622
596
|
}
|
|
623
597
|
}
|
|
624
|
-
else if (newEndTime
|
|
598
|
+
else if (typeof newEndTime === 'number' && typeof newStartTime !== 'number') {
|
|
625
599
|
if (Utils.roundTime(newEndTime - sources[0].startTime) < sources[0].minSize) {
|
|
626
600
|
newEndTime = Utils.roundTime(sources[0].startTime + sources[0].minSize);
|
|
627
601
|
}
|
|
@@ -640,37 +614,37 @@ define([
|
|
|
640
614
|
return { newStartTime, newEndTime };
|
|
641
615
|
};
|
|
642
616
|
|
|
643
|
-
|
|
617
|
+
LineGroup.prototype.getSourcesAfter = function(time) {
|
|
644
618
|
const sources = [];
|
|
645
619
|
var currentId = this._firstSourceId;
|
|
646
620
|
|
|
647
621
|
while (currentId) {
|
|
648
|
-
var
|
|
622
|
+
var sourceData = this._sources[currentId];
|
|
649
623
|
|
|
650
|
-
if (
|
|
624
|
+
if (sourceData.source.startTime >= time) {
|
|
651
625
|
while (currentId) {
|
|
652
|
-
|
|
626
|
+
sourceData = this._sources[currentId];
|
|
653
627
|
|
|
654
|
-
sources.push(
|
|
655
|
-
currentId =
|
|
628
|
+
sources.push(sourceData.source);
|
|
629
|
+
currentId = sourceData.nextSourceId;
|
|
656
630
|
}
|
|
657
631
|
break;
|
|
658
632
|
}
|
|
659
|
-
currentId =
|
|
633
|
+
currentId = sourceData.nextSourceId;
|
|
660
634
|
}
|
|
661
635
|
|
|
662
636
|
return sources;
|
|
663
637
|
};
|
|
664
638
|
|
|
665
|
-
|
|
639
|
+
LineGroup.prototype.getSourcesAround = function(time) {
|
|
666
640
|
var left = null;
|
|
667
641
|
var right = null;
|
|
668
642
|
var overlapping = null;
|
|
669
643
|
var currentId = this._firstSourceId;
|
|
670
644
|
|
|
671
645
|
while (currentId) {
|
|
672
|
-
var
|
|
673
|
-
var source =
|
|
646
|
+
var sourceData = this._sources[currentId];
|
|
647
|
+
var source = sourceData.source;
|
|
674
648
|
|
|
675
649
|
if (time < source.startTime) {
|
|
676
650
|
right = source;
|
|
@@ -683,7 +657,7 @@ define([
|
|
|
683
657
|
else {
|
|
684
658
|
left = source;
|
|
685
659
|
}
|
|
686
|
-
currentId =
|
|
660
|
+
currentId = sourceData.nextSourceId;
|
|
687
661
|
}
|
|
688
662
|
|
|
689
663
|
if (overlapping) {
|
|
@@ -694,26 +668,25 @@ define([
|
|
|
694
668
|
}
|
|
695
669
|
};
|
|
696
670
|
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
if (Utils.objectHasProperty(this._sources, sourceId)) {
|
|
700
|
-
this._sources[sourceId].source.position = pos;
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
|
|
671
|
+
LineGroup.prototype.updatePosition = function(pos) {
|
|
672
|
+
this._line.position = pos;
|
|
704
673
|
this._position = pos;
|
|
705
674
|
};
|
|
706
675
|
|
|
707
|
-
|
|
676
|
+
LineGroup.prototype.hasSource = function(sourceId) {
|
|
677
|
+
return Boolean(this._sources[sourceId]);
|
|
678
|
+
};
|
|
679
|
+
|
|
680
|
+
LineGroup.prototype.destroy = function() {
|
|
708
681
|
this._firstSourceId = null;
|
|
709
682
|
this._sources = {};
|
|
710
683
|
this._sourcesGroup = {};
|
|
711
684
|
this._group.destroy();
|
|
712
685
|
};
|
|
713
686
|
|
|
714
|
-
|
|
687
|
+
LineGroup.prototype.allowInteractions = function(bool) {
|
|
715
688
|
this._group.listening(bool);
|
|
716
689
|
};
|
|
717
690
|
|
|
718
|
-
return
|
|
691
|
+
return LineGroup;
|
|
719
692
|
});
|