@checksub_team/peaks_timeline 1.16.1 → 2.0.0-alpha.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/package.json +1 -1
- package/peaks.js +4716 -4409
- 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/components/line-group.js +692 -0
- package/src/components/line-groups.js +585 -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 -801
- package/src/{source-group.js → components/source-group.js} +1661 -1640
- package/src/{sources-layer.js → components/sources-layer.js} +716 -730
- 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 +110 -71
- package/src/models/line.js +156 -0
- package/src/{segment.js → models/segment.js} +420 -419
- package/src/{source.js → models/source.js} +1311 -1315
- package/src/player.js +2 -2
- package/src/{timeline-segments.js → segment-handler.js} +435 -435
- package/src/{timeline-sources.js → source-handler.js} +521 -514
- package/src/utils.js +5 -1
- package/src/{timeline-zoomview.js → view.js} +136 -137
- package/src/line.js +0 -690
- package/src/lines.js +0 -427
- /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,514 +1,521 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file
|
|
3
|
-
*
|
|
4
|
-
* Defines the {@link
|
|
5
|
-
*
|
|
6
|
-
* @module
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
define([
|
|
10
|
-
'./source',
|
|
11
|
-
'./utils'
|
|
12
|
-
], function(Source, Utils) {
|
|
13
|
-
'use strict';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Source parameters.
|
|
17
|
-
*
|
|
18
|
-
* @typedef {Object} SourceOptions
|
|
19
|
-
* @global
|
|
20
|
-
* @param {String} id A unique identifier for the source.
|
|
21
|
-
* @param {String} title Name of the source.
|
|
22
|
-
* @param {String} url Reference to the media element this source is representing.
|
|
23
|
-
* @param {Number} startTime Source start time, in seconds.
|
|
24
|
-
* @param {Number} endTime Source end time, in seconds.
|
|
25
|
-
* @param {String} color Color of the background.
|
|
26
|
-
* @param {Boolean} wrapped If <code>true</code> the source representation
|
|
27
|
-
* will be reduced to a line, taking less space.
|
|
28
|
-
* @param {Number} position Position of the source on the timeline.
|
|
29
|
-
* Correspond to the index of the line.
|
|
30
|
-
* @param {Boolean} segments If <code>true</code> this source will display segments;
|
|
31
|
-
*/
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Handles all functionality related to the adding, removing and manipulation
|
|
35
|
-
* of sources.
|
|
36
|
-
*
|
|
37
|
-
* @class
|
|
38
|
-
* @alias
|
|
39
|
-
*
|
|
40
|
-
* @param {Peaks} peaks The parent Peaks object.
|
|
41
|
-
*/
|
|
42
|
-
|
|
43
|
-
function
|
|
44
|
-
this._peaks = peaks;
|
|
45
|
-
this._sources = [];
|
|
46
|
-
this._sourcesById = {};
|
|
47
|
-
this.
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
*
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
*
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
this.
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Creates a new Source object.
|
|
156
|
-
*
|
|
157
|
-
* @private
|
|
158
|
-
* @param {SourceOptions} options
|
|
159
|
-
* @return {Source}
|
|
160
|
-
*/
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
// Watch for anyone still trying to use the old
|
|
164
|
-
// createSource(startTime, endTime, ...) API
|
|
165
|
-
if (!Utils.isObject(options)) {
|
|
166
|
-
throw new TypeError('peaks.sources.add(): expected a Source object parameter');
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
var customParams = [];
|
|
170
|
-
|
|
171
|
-
Object.entries(options).forEach(function([key, value]) {
|
|
172
|
-
if (key.startsWith('custom_')) {
|
|
173
|
-
customParams.push(key, value);
|
|
174
|
-
}
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
var source = new Source(
|
|
178
|
-
this._peaks,
|
|
179
|
-
options.id || this._getNextSourceId(),
|
|
180
|
-
options.
|
|
181
|
-
options.
|
|
182
|
-
options.
|
|
183
|
-
options.
|
|
184
|
-
options.
|
|
185
|
-
options.
|
|
186
|
-
options.
|
|
187
|
-
options.
|
|
188
|
-
options.
|
|
189
|
-
options.
|
|
190
|
-
options.
|
|
191
|
-
options.
|
|
192
|
-
options.
|
|
193
|
-
options.
|
|
194
|
-
options.
|
|
195
|
-
options.
|
|
196
|
-
options.
|
|
197
|
-
options.
|
|
198
|
-
options.
|
|
199
|
-
options.
|
|
200
|
-
options.
|
|
201
|
-
options.
|
|
202
|
-
options.
|
|
203
|
-
options.
|
|
204
|
-
options.
|
|
205
|
-
options.
|
|
206
|
-
options.
|
|
207
|
-
options.
|
|
208
|
-
options.
|
|
209
|
-
options.
|
|
210
|
-
options.
|
|
211
|
-
options.
|
|
212
|
-
options.
|
|
213
|
-
options.
|
|
214
|
-
options.
|
|
215
|
-
options.draggable,
|
|
216
|
-
options.orderable,
|
|
217
|
-
options.resizable,
|
|
218
|
-
options.cuttable,
|
|
219
|
-
options.deletable,
|
|
220
|
-
options.wrapping,
|
|
221
|
-
options.previewHeight,
|
|
222
|
-
options.binaryHeight,
|
|
223
|
-
options.indicators,
|
|
224
|
-
options.markers,
|
|
225
|
-
options.buttons,
|
|
226
|
-
options.markerColor,
|
|
227
|
-
options.markerWidth,
|
|
228
|
-
options.volume,
|
|
229
|
-
options.volumeRange,
|
|
230
|
-
options.loading,
|
|
231
|
-
...customParams
|
|
232
|
-
);
|
|
233
|
-
|
|
234
|
-
return source;
|
|
235
|
-
};
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
* Returns all sources.
|
|
239
|
-
*
|
|
240
|
-
* @returns {Array<Source>}
|
|
241
|
-
*/
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
return this._sources;
|
|
245
|
-
};
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
*
|
|
289
|
-
*
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
});
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
*
|
|
357
|
-
*
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
*
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
*
|
|
403
|
-
*
|
|
404
|
-
*
|
|
405
|
-
*
|
|
406
|
-
*
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
*
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
fnFilter = function(source) {
|
|
464
|
-
return source.startTime === startTime;
|
|
465
|
-
};
|
|
466
|
-
}
|
|
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
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @file
|
|
3
|
+
*
|
|
4
|
+
* Defines the {@link SourceHandler} class.
|
|
5
|
+
*
|
|
6
|
+
* @module source-handler
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
define([
|
|
10
|
+
'./models/source',
|
|
11
|
+
'./utils'
|
|
12
|
+
], function(Source, Utils) {
|
|
13
|
+
'use strict';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Source parameters.
|
|
17
|
+
*
|
|
18
|
+
* @typedef {Object} SourceOptions
|
|
19
|
+
* @global
|
|
20
|
+
* @param {String} id A unique identifier for the source.
|
|
21
|
+
* @param {String} title Name of the source.
|
|
22
|
+
* @param {String} url Reference to the media element this source is representing.
|
|
23
|
+
* @param {Number} startTime Source start time, in seconds.
|
|
24
|
+
* @param {Number} endTime Source end time, in seconds.
|
|
25
|
+
* @param {String} color Color of the background.
|
|
26
|
+
* @param {Boolean} wrapped If <code>true</code> the source representation
|
|
27
|
+
* will be reduced to a line, taking less space.
|
|
28
|
+
* @param {Number} position Position of the source on the timeline.
|
|
29
|
+
* Correspond to the index of the line.
|
|
30
|
+
* @param {Boolean} segments If <code>true</code> this source will display segments;
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Handles all functionality related to the adding, removing and manipulation
|
|
35
|
+
* of sources.
|
|
36
|
+
*
|
|
37
|
+
* @class
|
|
38
|
+
* @alias SourceHandler
|
|
39
|
+
*
|
|
40
|
+
* @param {Peaks} peaks The parent Peaks object.
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
function SourceHandler(peaks) {
|
|
44
|
+
this._peaks = peaks;
|
|
45
|
+
this._sources = [];
|
|
46
|
+
this._sourcesById = {};
|
|
47
|
+
this._sourcesByLineId = {};
|
|
48
|
+
this._colorIndex = 0;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
SourceHandler.prototype.cutSource = function(sourceToCut, cuttingTime) {
|
|
52
|
+
var originalMediaEndTime = sourceToCut.mediaEndTime;
|
|
53
|
+
var originalEndTime = sourceToCut.endTime;
|
|
54
|
+
|
|
55
|
+
// Cut the source
|
|
56
|
+
sourceToCut.update({
|
|
57
|
+
endTime: sourceToCut.startTime + cuttingTime,
|
|
58
|
+
mediaEndTime: sourceToCut.mediaStartTime + cuttingTime
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
// Create the copy (cut)
|
|
62
|
+
var newSourceOptions = {
|
|
63
|
+
id: Utils.createUuidv4(),
|
|
64
|
+
lineId: sourceToCut.lineId,
|
|
65
|
+
originId: sourceToCut.id,
|
|
66
|
+
elementId: sourceToCut.elementId,
|
|
67
|
+
title: sourceToCut.title,
|
|
68
|
+
titleAlignments: sourceToCut.titleAlignments,
|
|
69
|
+
url: sourceToCut.url,
|
|
70
|
+
previewUrl: sourceToCut.previewUrl,
|
|
71
|
+
binaryUrl: sourceToCut.binaryUrl,
|
|
72
|
+
kind: sourceToCut.kind,
|
|
73
|
+
subkind: sourceToCut.subkind,
|
|
74
|
+
duration: sourceToCut.duration,
|
|
75
|
+
startTime: sourceToCut.endTime,
|
|
76
|
+
endTime: originalEndTime,
|
|
77
|
+
mediaStartTime: sourceToCut.mediaEndTime,
|
|
78
|
+
mediaEndTime: originalMediaEndTime,
|
|
79
|
+
color: sourceToCut.color,
|
|
80
|
+
backgroundColor: sourceToCut.backgroundColor,
|
|
81
|
+
hoverBackgroundColor: sourceToCut.hoverBackgroundColor,
|
|
82
|
+
selectedBackgroundColor: sourceToCut.selectedBackgroundColor,
|
|
83
|
+
borderColor: sourceToCut.borderColor,
|
|
84
|
+
selectedBorderColor: sourceToCut.selectedBorderColor,
|
|
85
|
+
warningColor: sourceToCut.warningColor,
|
|
86
|
+
warningWidth: sourceToCut.warningWidth,
|
|
87
|
+
volumeSliderColor: sourceToCut.volumeSliderColor,
|
|
88
|
+
volumeSliderWidth: sourceToCut.volumeSliderWidth,
|
|
89
|
+
volumeSliderDraggingWidth: sourceToCut.volumeSliderDraggingWidth,
|
|
90
|
+
textFont: sourceToCut.textFont,
|
|
91
|
+
textFontSize: sourceToCut.textFontSize,
|
|
92
|
+
textColor: sourceToCut.textColor,
|
|
93
|
+
textBackgroundColor: sourceToCut.textBackgroundColor,
|
|
94
|
+
textPosition: sourceToCut.textPosition,
|
|
95
|
+
textAutoScroll: sourceToCut.textAutoScroll,
|
|
96
|
+
borderWidth: sourceToCut.borderWidth,
|
|
97
|
+
borderRadius: sourceToCut.borderRadius,
|
|
98
|
+
wrapped: sourceToCut.wrapped,
|
|
99
|
+
draggable: sourceToCut.draggable,
|
|
100
|
+
orderable: sourceToCut.orderable,
|
|
101
|
+
resizable: sourceToCut.resizable,
|
|
102
|
+
cuttable: sourceToCut.cuttable,
|
|
103
|
+
deletable: sourceToCut.deletable,
|
|
104
|
+
wrapping: sourceToCut.wrapping,
|
|
105
|
+
previewHeight: sourceToCut.previewHeight,
|
|
106
|
+
binaryHeight: sourceToCut.binaryHeight,
|
|
107
|
+
markers: sourceToCut.markers,
|
|
108
|
+
buttons: sourceToCut.buttons,
|
|
109
|
+
markerColor: sourceToCut.markerColor,
|
|
110
|
+
markerWidth: sourceToCut.markerWidth,
|
|
111
|
+
volume: sourceToCut.volume,
|
|
112
|
+
volumeRange: sourceToCut.volumeRange,
|
|
113
|
+
loading: sourceToCut.loading
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
for (var key in sourceToCut) {
|
|
117
|
+
if (key.startsWith('custom_')) {
|
|
118
|
+
newSourceOptions[key] = sourceToCut[key];
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
var newSource = this._add([newSourceOptions])[0];
|
|
123
|
+
|
|
124
|
+
this._peaks.emit('sources.updated', [sourceToCut, newSource]);
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Returns a new unique Source id value.
|
|
129
|
+
*
|
|
130
|
+
* @private
|
|
131
|
+
* @returns {String}
|
|
132
|
+
*/
|
|
133
|
+
|
|
134
|
+
SourceHandler.prototype._getNextSourceId = function() {
|
|
135
|
+
return 'peaks.source.' + Utils.createUuidv4();
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Adds a new Source object.
|
|
140
|
+
*
|
|
141
|
+
* @private
|
|
142
|
+
* @param {Source} Source
|
|
143
|
+
*/
|
|
144
|
+
|
|
145
|
+
SourceHandler.prototype._addSource = function(source) {
|
|
146
|
+
this._sources.push(source);
|
|
147
|
+
this._sourcesById[source.id] = source;
|
|
148
|
+
if (Utils.isNullOrUndefined(this._sourcesByLineId[source.lineId])) {
|
|
149
|
+
this._sourcesByLineId[source.lineId] = {};
|
|
150
|
+
}
|
|
151
|
+
this._sourcesByLineId[source.lineId][source.id] = source;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Creates a new Source object.
|
|
156
|
+
*
|
|
157
|
+
* @private
|
|
158
|
+
* @param {SourceOptions} options
|
|
159
|
+
* @return {Source}
|
|
160
|
+
*/
|
|
161
|
+
|
|
162
|
+
SourceHandler.prototype._createSource = function(options) {
|
|
163
|
+
// Watch for anyone still trying to use the old
|
|
164
|
+
// createSource(startTime, endTime, ...) API
|
|
165
|
+
if (!Utils.isObject(options)) {
|
|
166
|
+
throw new TypeError('peaks.sources.add(): expected a Source object parameter');
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
var customParams = [];
|
|
170
|
+
|
|
171
|
+
Object.entries(options).forEach(function([key, value]) {
|
|
172
|
+
if (key.startsWith('custom_')) {
|
|
173
|
+
customParams.push(key, value);
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
var source = new Source(
|
|
178
|
+
this._peaks,
|
|
179
|
+
options.id || this._getNextSourceId(),
|
|
180
|
+
options.lineId,
|
|
181
|
+
options.originId,
|
|
182
|
+
options.elementId,
|
|
183
|
+
options.title,
|
|
184
|
+
options.titleAlignments,
|
|
185
|
+
options.url,
|
|
186
|
+
options.previewUrl,
|
|
187
|
+
options.binaryUrl,
|
|
188
|
+
options.kind,
|
|
189
|
+
options.subkind,
|
|
190
|
+
options.duration,
|
|
191
|
+
options.startTime,
|
|
192
|
+
options.endTime,
|
|
193
|
+
options.mediaStartTime,
|
|
194
|
+
options.mediaEndTime,
|
|
195
|
+
options.color,
|
|
196
|
+
options.backgroundColor,
|
|
197
|
+
options.hoverBackgroundColor,
|
|
198
|
+
options.selectedBackgroundColor,
|
|
199
|
+
options.borderColor,
|
|
200
|
+
options.selectedBorderColor,
|
|
201
|
+
options.warningColor,
|
|
202
|
+
options.warningWidth,
|
|
203
|
+
options.volumeSliderColor,
|
|
204
|
+
options.volumeSliderWidth,
|
|
205
|
+
options.volumeSliderDraggingWidth,
|
|
206
|
+
options.textFont,
|
|
207
|
+
options.textFontSize,
|
|
208
|
+
options.textColor,
|
|
209
|
+
options.textBackgroundColor,
|
|
210
|
+
options.textPosition,
|
|
211
|
+
options.textAutoScroll,
|
|
212
|
+
options.borderWidth,
|
|
213
|
+
options.borderRadius,
|
|
214
|
+
options.wrapped,
|
|
215
|
+
options.draggable,
|
|
216
|
+
options.orderable,
|
|
217
|
+
options.resizable,
|
|
218
|
+
options.cuttable,
|
|
219
|
+
options.deletable,
|
|
220
|
+
options.wrapping,
|
|
221
|
+
options.previewHeight,
|
|
222
|
+
options.binaryHeight,
|
|
223
|
+
options.indicators,
|
|
224
|
+
options.markers,
|
|
225
|
+
options.buttons,
|
|
226
|
+
options.markerColor,
|
|
227
|
+
options.markerWidth,
|
|
228
|
+
options.volume,
|
|
229
|
+
options.volumeRange,
|
|
230
|
+
options.loading,
|
|
231
|
+
...customParams
|
|
232
|
+
);
|
|
233
|
+
|
|
234
|
+
return source;
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Returns all sources.
|
|
239
|
+
*
|
|
240
|
+
* @returns {Array<Source>}
|
|
241
|
+
*/
|
|
242
|
+
|
|
243
|
+
SourceHandler.prototype.getSources = function() {
|
|
244
|
+
return this._sources;
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
SourceHandler.prototype.getSourcesByLineId = function(lineId) {
|
|
248
|
+
return Utils.isNullOrUndefined(lineId) ? this._sourcesByLineId : this._sourcesByLineId[lineId];
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Returns all sources, serialized to a plain object.
|
|
253
|
+
*
|
|
254
|
+
* @returns {Array<Object>}
|
|
255
|
+
*/
|
|
256
|
+
|
|
257
|
+
SourceHandler.prototype.getSourcesSerialized = function() {
|
|
258
|
+
return this._sources.map(function(source) {
|
|
259
|
+
return source.toSerializable();
|
|
260
|
+
});
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Returns the Source with the given id, or <code>null</code> if not found.
|
|
265
|
+
*
|
|
266
|
+
* @param {String} id
|
|
267
|
+
* @returns {Source|null}
|
|
268
|
+
*/
|
|
269
|
+
|
|
270
|
+
SourceHandler.prototype.getSource = function(id) {
|
|
271
|
+
return this._sourcesById[id] || null;
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Returns all sources that overlap a given point in time.
|
|
276
|
+
*
|
|
277
|
+
* @param {Number} time
|
|
278
|
+
* @returns {Array<Source>}
|
|
279
|
+
*/
|
|
280
|
+
|
|
281
|
+
SourceHandler.prototype.getSourcesAtTime = function(time) {
|
|
282
|
+
return this._sources.filter(function(source) {
|
|
283
|
+
return time >= source.startTime && time <= source.endTime;
|
|
284
|
+
});
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Returns all sources that overlap a given time region.
|
|
289
|
+
*
|
|
290
|
+
* @param {Number} startTime The start of the time region, in seconds.
|
|
291
|
+
* @param {Number} endTime The end of the time region, in seconds.
|
|
292
|
+
*
|
|
293
|
+
* @returns {Array<Source>}
|
|
294
|
+
*/
|
|
295
|
+
|
|
296
|
+
SourceHandler.prototype.find = function(startTime, endTime) {
|
|
297
|
+
return this._sources.filter(function(source) {
|
|
298
|
+
return source.isVisible(startTime, endTime);
|
|
299
|
+
});
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Adds one or more sources to the timeline.
|
|
304
|
+
*
|
|
305
|
+
* @param {SourceOptions|Array<SourceOptions>} sourceOrSources
|
|
306
|
+
*/
|
|
307
|
+
|
|
308
|
+
SourceHandler.prototype.add = function(/* sourceOrSources */) {
|
|
309
|
+
var sources = Array.isArray(arguments[0]) ?
|
|
310
|
+
arguments[0] :
|
|
311
|
+
Array.prototype.slice.call(arguments);
|
|
312
|
+
|
|
313
|
+
this._add(sources);
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
SourceHandler.prototype._add = function(sources) {
|
|
317
|
+
var self = this;
|
|
318
|
+
|
|
319
|
+
sources = sources.map(function(sourceOptions) {
|
|
320
|
+
if (
|
|
321
|
+
!Utils.isString(sourceOptions.lineId) ||
|
|
322
|
+
Utils.isNullOrUndefined(self._peaks.lineHandler.getLine(sourceOptions.lineId))
|
|
323
|
+
) {
|
|
324
|
+
throw new Error('peaks.sources.add(): line with id ' + sourceOptions.lineId +
|
|
325
|
+
' does not exist');
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
const source = self._createSource(sourceOptions);
|
|
329
|
+
|
|
330
|
+
if (Utils.objectHasProperty(self._sourcesById, source.id)) {
|
|
331
|
+
const src = Object.values(self._sourcesById)[0];
|
|
332
|
+
|
|
333
|
+
throw new Error('peaks.sources.add(): duplicate id. \n\n Source I = ' +
|
|
334
|
+
JSON.stringify(
|
|
335
|
+
src.toSerializable()
|
|
336
|
+
) + ' Source II = ' +
|
|
337
|
+
JSON.stringify(
|
|
338
|
+
source.toSerializable()
|
|
339
|
+
)
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
return source;
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
sources.forEach(function(source) {
|
|
347
|
+
self._addSource(source);
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
this._peaks.emit('handler.sources.add', sources);
|
|
351
|
+
|
|
352
|
+
return sources;
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Returns the indexes of sources that match the given predicate.
|
|
357
|
+
*
|
|
358
|
+
* @private
|
|
359
|
+
* @param {Function} predicate Predicate function to find matching sources.
|
|
360
|
+
* @returns {Array<Number>} An array of indexes into the sources array of
|
|
361
|
+
* the matching elements.
|
|
362
|
+
*/
|
|
363
|
+
|
|
364
|
+
SourceHandler.prototype._findSource = function(predicate) {
|
|
365
|
+
var indexes = [];
|
|
366
|
+
|
|
367
|
+
for (var i = 0, length = this._sources.length; i < length; i++) {
|
|
368
|
+
if (predicate(this._sources[i])) {
|
|
369
|
+
indexes.push(i);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
return indexes;
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* destroys the sources at the given array indexes.
|
|
378
|
+
*
|
|
379
|
+
* @private
|
|
380
|
+
* @param {Array<Number>} indexes The array indexes to destroy.
|
|
381
|
+
* @returns {Array<Source>} The destroyd {@link Source} objects.
|
|
382
|
+
*/
|
|
383
|
+
|
|
384
|
+
SourceHandler.prototype._destroyIndexes = function(indexes) {
|
|
385
|
+
var destroyed = [];
|
|
386
|
+
|
|
387
|
+
for (var i = 0; i < indexes.length; i++) {
|
|
388
|
+
var index = indexes[i] - destroyed.length;
|
|
389
|
+
|
|
390
|
+
var itemDestroyed = this._sources.splice(index, 1)[0];
|
|
391
|
+
|
|
392
|
+
delete this._sourcesById[itemDestroyed.id];
|
|
393
|
+
delete this._sourcesByLineId[itemDestroyed.lineId][itemDestroyed.id];
|
|
394
|
+
|
|
395
|
+
destroyed.push(itemDestroyed);
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
return destroyed;
|
|
399
|
+
};
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* destroys all sources that match a given predicate function.
|
|
403
|
+
*
|
|
404
|
+
* After removing the sources, this function also emits a
|
|
405
|
+
* <code>sources.destroy</code> event with the destroyed {@link Source}
|
|
406
|
+
* objects.
|
|
407
|
+
*
|
|
408
|
+
* @private
|
|
409
|
+
* @param {Function} predicate A predicate function that identifies which
|
|
410
|
+
* sources to destroy.
|
|
411
|
+
* @returns {Array<Source>} The destroyed {@link Source} objects.
|
|
412
|
+
*/
|
|
413
|
+
|
|
414
|
+
SourceHandler.prototype._destroySources = function(predicate) {
|
|
415
|
+
var indexes = this._findSource(predicate);
|
|
416
|
+
|
|
417
|
+
var destroyed = this._destroyIndexes(indexes);
|
|
418
|
+
|
|
419
|
+
this._peaks.emit('handler.sources.destroy', destroyed);
|
|
420
|
+
|
|
421
|
+
return destroyed;
|
|
422
|
+
};
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* destroys the given source.
|
|
426
|
+
*
|
|
427
|
+
* @param {Source} Source The source to destroy.
|
|
428
|
+
* @returns {Array<Source>} The destroyd source.
|
|
429
|
+
*/
|
|
430
|
+
|
|
431
|
+
SourceHandler.prototype.destroy = function(source) {
|
|
432
|
+
return this._destroySources(function(s) {
|
|
433
|
+
return s === source;
|
|
434
|
+
});
|
|
435
|
+
};
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* destroys any sources with the given id.
|
|
439
|
+
*
|
|
440
|
+
* @param {String} id
|
|
441
|
+
* @returns {Array<Source>} The destroyed {@link Source} objects.
|
|
442
|
+
*/
|
|
443
|
+
|
|
444
|
+
SourceHandler.prototype.destroyById = function(sourceId) {
|
|
445
|
+
return this._destroySources(function(source) {
|
|
446
|
+
return source.id === sourceId;
|
|
447
|
+
});
|
|
448
|
+
};
|
|
449
|
+
|
|
450
|
+
/**
|
|
451
|
+
* destroys any sources with the given start time, and optional end time.
|
|
452
|
+
*
|
|
453
|
+
* @param {Number} startTime sources with this start time are destroyd.
|
|
454
|
+
* @param {Number?} endTime If present, only sources with both the given
|
|
455
|
+
* start time and end time are destroyd.
|
|
456
|
+
* @returns {Array<Source>} The destroyd {@link Source} objects.
|
|
457
|
+
*/
|
|
458
|
+
|
|
459
|
+
SourceHandler.prototype.destroyByTime = function(startTime, endTime) {
|
|
460
|
+
var fnFilter;
|
|
461
|
+
|
|
462
|
+
if (endTime > 0) {
|
|
463
|
+
fnFilter = function(source) {
|
|
464
|
+
return source.startTime === startTime && source.endTime === endTime;
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
else {
|
|
468
|
+
fnFilter = function(source) {
|
|
469
|
+
return source.startTime === startTime;
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
return this._destroySources(fnFilter);
|
|
474
|
+
};
|
|
475
|
+
|
|
476
|
+
/**
|
|
477
|
+
* destroys all sources.
|
|
478
|
+
*/
|
|
479
|
+
|
|
480
|
+
SourceHandler.prototype.destroyAll = function() {
|
|
481
|
+
this._destroySources(function() {
|
|
482
|
+
return true;
|
|
483
|
+
});
|
|
484
|
+
};
|
|
485
|
+
|
|
486
|
+
/**
|
|
487
|
+
* Set the wrapping of the source with the given ID to false.
|
|
488
|
+
* The source will be shown in its complete form.
|
|
489
|
+
*
|
|
490
|
+
* @param {String} sourceId The id of the source.
|
|
491
|
+
*/
|
|
492
|
+
|
|
493
|
+
SourceHandler.prototype.showById = function(sourceId) {
|
|
494
|
+
if (this._sourcesById[sourceId].wrapped === false) {
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
this._sourcesById[sourceId].wrapped = false;
|
|
499
|
+
|
|
500
|
+
this._peaks.emit('handler.sources.show', [this._sourcesById[sourceId]]);
|
|
501
|
+
};
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* Set the wrapping of the source with the given ID to true.
|
|
505
|
+
* The source will be shown in its reduced form.
|
|
506
|
+
*
|
|
507
|
+
* @param {String} sourceId The id of the source.
|
|
508
|
+
*/
|
|
509
|
+
|
|
510
|
+
SourceHandler.prototype.hideById = function(sourceId) {
|
|
511
|
+
if (this._sourcesById[sourceId].wrapped === true) {
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
this._sourcesById[sourceId].wrapped = true;
|
|
516
|
+
|
|
517
|
+
this._peaks.emit('handler.sources.hide', [this._sourcesById[sourceId]]);
|
|
518
|
+
};
|
|
519
|
+
|
|
520
|
+
return SourceHandler;
|
|
521
|
+
});
|