@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
package/src/main.js
CHANGED
|
@@ -9,22 +9,24 @@
|
|
|
9
9
|
define([
|
|
10
10
|
'colors.css',
|
|
11
11
|
'eventemitter2',
|
|
12
|
-
'./
|
|
13
|
-
'./
|
|
12
|
+
'./segment-handler',
|
|
13
|
+
'./source-handler',
|
|
14
|
+
'./line-handler',
|
|
14
15
|
'./keyboard-handler',
|
|
15
16
|
'./player',
|
|
16
|
-
'./
|
|
17
|
-
'./
|
|
17
|
+
'./view',
|
|
18
|
+
'./components/marker-factories',
|
|
18
19
|
'./utils'
|
|
19
20
|
], function(
|
|
20
21
|
Colors,
|
|
21
22
|
EventEmitter,
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
SegmentHandler,
|
|
24
|
+
SourceHandler,
|
|
25
|
+
LineHandler,
|
|
24
26
|
KeyboardHandler,
|
|
25
27
|
Player,
|
|
28
|
+
View,
|
|
26
29
|
MarkerFactories,
|
|
27
|
-
TimelineZoomView,
|
|
28
30
|
Utils) {
|
|
29
31
|
'use strict';
|
|
30
32
|
|
|
@@ -183,11 +185,7 @@ define([
|
|
|
183
185
|
/**
|
|
184
186
|
*
|
|
185
187
|
*/
|
|
186
|
-
template:
|
|
187
|
-
'<div class="timeline">',
|
|
188
|
-
'<div class="zoom-container"></div>',
|
|
189
|
-
'</div>'
|
|
190
|
-
].join(''),
|
|
188
|
+
template: '<div class="timeline"></div>',
|
|
191
189
|
|
|
192
190
|
/**
|
|
193
191
|
* An object containing an AudioContext, used when creating waveform data
|
|
@@ -204,28 +202,6 @@ define([
|
|
|
204
202
|
createSegmentMarker: MarkerFactories.createSegmentMarker,
|
|
205
203
|
createSegmentLabel: MarkerFactories.createSegmentLabel,
|
|
206
204
|
|
|
207
|
-
/**
|
|
208
|
-
* External sources information.
|
|
209
|
-
*
|
|
210
|
-
* ```js
|
|
211
|
-
* sources: {
|
|
212
|
-
* id: 'unique-identifier-for-this-source',
|
|
213
|
-
* title: 'Source #1',
|
|
214
|
-
* url: 'https://my-website/my-resource.mp3',
|
|
215
|
-
* dataUri: {
|
|
216
|
-
* arraybuffer: 'url/to/data.dat',
|
|
217
|
-
* json: 'url/to/data.json'
|
|
218
|
-
* },
|
|
219
|
-
* start: 1.03,
|
|
220
|
-
* end: 5.06,
|
|
221
|
-
* color: #0000ff,
|
|
222
|
-
* wrapped: false, //show only a line or peaks/preview
|
|
223
|
-
* position: 0 //position in the timeline (here on the first line)
|
|
224
|
-
* }
|
|
225
|
-
* ```
|
|
226
|
-
*/
|
|
227
|
-
sources: null,
|
|
228
|
-
|
|
229
205
|
/**
|
|
230
206
|
* Height of a line, in pixels.
|
|
231
207
|
* This height will correspond to the height of the background when the element is unwrapped.
|
|
@@ -415,7 +391,20 @@ define([
|
|
|
415
391
|
* Delay in milliseconds before a new line is created
|
|
416
392
|
* when dragging a source between 2 lines.
|
|
417
393
|
*/
|
|
418
|
-
automaticLineCreationDelay: 100
|
|
394
|
+
automaticLineCreationDelay: 100,
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* Default type of line indicator.
|
|
398
|
+
* Can be 'default', 'volume', 'noVolume', 'visibility', 'noVisibility'.
|
|
399
|
+
* This will be used when a new line is automatically created by a component.
|
|
400
|
+
*/
|
|
401
|
+
defaultLineIndicatorType: 'default',
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* Default text of the line indicator.
|
|
405
|
+
* This will be used when a new line is automatically created by a component.
|
|
406
|
+
*/
|
|
407
|
+
defaultLineIndicatorText: ''
|
|
419
408
|
};
|
|
420
409
|
|
|
421
410
|
/**
|
|
@@ -473,32 +462,31 @@ define([
|
|
|
473
462
|
});
|
|
474
463
|
|
|
475
464
|
/*
|
|
476
|
-
Setup the layout
|
|
465
|
+
* Setup the layout
|
|
477
466
|
*/
|
|
478
|
-
if (!instance.options.
|
|
479
|
-
callback(new TypeError('Peaks.init(): The
|
|
467
|
+
if (!instance.options.container) {
|
|
468
|
+
callback(new TypeError('Peaks.init(): The container option must be a valid DOM object'));
|
|
480
469
|
return;
|
|
481
470
|
}
|
|
482
471
|
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
if (!Utils.isHTMLElement(zoomviewContainer)) {
|
|
486
|
-
callback(new TypeError('Peaks.init(): The containers options must be valid HTML elements'));
|
|
472
|
+
if (!Utils.isHTMLElement(instance.options.container)) {
|
|
473
|
+
callback(new TypeError('Peaks.init(): The container must be a valid HTML element'));
|
|
487
474
|
return;
|
|
488
475
|
}
|
|
489
476
|
|
|
490
|
-
if (
|
|
477
|
+
if (instance.options.container && instance.options.container.clientWidth <= 0) {
|
|
491
478
|
callback(new TypeError('Peaks.init(): Please ensure that the container is visible and has non-zero width'));
|
|
492
479
|
return;
|
|
493
480
|
}
|
|
494
481
|
|
|
495
482
|
instance.player = new Player(instance);
|
|
496
|
-
instance.
|
|
497
|
-
instance.
|
|
483
|
+
instance.segmentHandler = new SegmentHandler(instance);
|
|
484
|
+
instance.sourceHandler = new SourceHandler(instance);
|
|
485
|
+
instance.lineHandler = new LineHandler(instance);
|
|
498
486
|
|
|
499
487
|
// Setup the UI components
|
|
500
|
-
instance.view = new
|
|
501
|
-
|
|
488
|
+
instance.view = new View(
|
|
489
|
+
instance.options.container,
|
|
502
490
|
instance
|
|
503
491
|
);
|
|
504
492
|
|
|
@@ -508,10 +496,6 @@ define([
|
|
|
508
496
|
|
|
509
497
|
instance._addWindowResizeHandler();
|
|
510
498
|
|
|
511
|
-
if (instance.options.sources) {
|
|
512
|
-
instance.sources.add(instance.options.sources);
|
|
513
|
-
}
|
|
514
|
-
|
|
515
499
|
document.fonts.ready.then(function() {
|
|
516
500
|
setTimeout(function() {
|
|
517
501
|
instance.emit('peaks.ready');
|
|
@@ -652,17 +636,34 @@ define([
|
|
|
652
636
|
*/
|
|
653
637
|
|
|
654
638
|
Peaks.prototype.addSource = function(source) {
|
|
655
|
-
this.
|
|
639
|
+
this.sourceHandler.add(source);
|
|
656
640
|
};
|
|
657
641
|
|
|
658
642
|
/**
|
|
659
643
|
* Destroy a source from the {@link Peaks} instance.
|
|
660
644
|
*
|
|
661
645
|
* @param {String} sourceId
|
|
646
|
+
* @param {Boolean} [notify=false] If true, emits a
|
|
647
|
+
* <code>source.destroyed</code> event with the destroyed {@link Source}
|
|
648
|
+
* object.
|
|
662
649
|
*/
|
|
663
650
|
|
|
664
651
|
Peaks.prototype.destroySource = function(sourceId, notify) {
|
|
665
|
-
this.
|
|
652
|
+
const sources = this.sourceHandler.destroyById(sourceId);
|
|
653
|
+
|
|
654
|
+
if (notify && sources.length > 0) {
|
|
655
|
+
this.emit('source.destroyed', sources[0]);
|
|
656
|
+
}
|
|
657
|
+
};
|
|
658
|
+
|
|
659
|
+
/**
|
|
660
|
+
* Cut a source on the cutting time.
|
|
661
|
+
*
|
|
662
|
+
* @param {Object} sourceToCut The source to cut.
|
|
663
|
+
* @param {Number} cuttingTime The time in seconds where to cut the source.
|
|
664
|
+
*/
|
|
665
|
+
Peaks.prototype.cutSource = function(sourceToCut, cuttingTime) {
|
|
666
|
+
this.sourceHandler.cutSource(sourceToCut, cuttingTime);
|
|
666
667
|
};
|
|
667
668
|
|
|
668
669
|
/**
|
|
@@ -672,7 +673,7 @@ define([
|
|
|
672
673
|
*/
|
|
673
674
|
|
|
674
675
|
Peaks.prototype.showSource = function(sourceId) {
|
|
675
|
-
this.
|
|
676
|
+
this.sourceHandler.showById(sourceId);
|
|
676
677
|
};
|
|
677
678
|
|
|
678
679
|
/**
|
|
@@ -682,11 +683,47 @@ define([
|
|
|
682
683
|
*/
|
|
683
684
|
|
|
684
685
|
Peaks.prototype.hideSource = function(sourceId) {
|
|
685
|
-
this.
|
|
686
|
+
this.sourceHandler.hideById(sourceId);
|
|
686
687
|
};
|
|
687
688
|
|
|
688
|
-
|
|
689
|
-
|
|
689
|
+
/**
|
|
690
|
+
* Add a new line to the {@link Peaks} instance.
|
|
691
|
+
*
|
|
692
|
+
* @param {LineOptions} lineOptions
|
|
693
|
+
*/
|
|
694
|
+
Peaks.prototype.addLine = function(lineOptions, notify) {
|
|
695
|
+
const lines = this.lineHandler.add(lineOptions);
|
|
696
|
+
|
|
697
|
+
if (notify && lines.length > 0) {
|
|
698
|
+
this.emit('line.added', lines[0]);
|
|
699
|
+
}
|
|
700
|
+
};
|
|
701
|
+
|
|
702
|
+
/**
|
|
703
|
+
* Destroy a line from the {@link Peaks} instance.
|
|
704
|
+
*
|
|
705
|
+
* @param {String} lineId
|
|
706
|
+
*/
|
|
707
|
+
Peaks.prototype.destroyLine = function(lineId, notify) {
|
|
708
|
+
const lines = this.lineHandler.removeById(lineId);
|
|
709
|
+
|
|
710
|
+
if (notify && lines.length > 0) {
|
|
711
|
+
this.emit('line.destroyed', lines[0]);
|
|
712
|
+
}
|
|
713
|
+
};
|
|
714
|
+
|
|
715
|
+
/**
|
|
716
|
+
* Move a line to a new position.
|
|
717
|
+
*
|
|
718
|
+
* @param {String} lineId The ID of the line to move.
|
|
719
|
+
* @param {Number} position The new position.
|
|
720
|
+
*/
|
|
721
|
+
Peaks.prototype.moveLine = function(lineId, position) {
|
|
722
|
+
this.lineHandler.moveById(lineId, position);
|
|
723
|
+
};
|
|
724
|
+
|
|
725
|
+
Peaks.prototype.showSegments = function(lineId, lineOptions) {
|
|
726
|
+
this.segmentHandler.addSegmentsToPosition(lineId, lineOptions);
|
|
690
727
|
};
|
|
691
728
|
|
|
692
729
|
/**
|
|
@@ -696,15 +733,15 @@ define([
|
|
|
696
733
|
*/
|
|
697
734
|
|
|
698
735
|
Peaks.prototype.destroySegment = function(segmentId) {
|
|
699
|
-
this.
|
|
736
|
+
this.segmentHandler.removeById(segmentId);
|
|
700
737
|
};
|
|
701
738
|
|
|
702
739
|
Peaks.prototype.setDefaultMode = function() {
|
|
703
|
-
this.emit('
|
|
740
|
+
this.emit('handler.view.defaultmode');
|
|
704
741
|
};
|
|
705
742
|
|
|
706
743
|
Peaks.prototype.setCutMode = function() {
|
|
707
|
-
this.emit('
|
|
744
|
+
this.emit('handler.view.cutmode');
|
|
708
745
|
};
|
|
709
746
|
|
|
710
747
|
Peaks.prototype.setIndicatorType = function(linePosition, type) {
|
|
@@ -730,13 +767,11 @@ define([
|
|
|
730
767
|
};
|
|
731
768
|
|
|
732
769
|
Peaks.prototype.overrideInteractions = function(bool, areInteractionsAllowed) {
|
|
733
|
-
|
|
734
|
-
.overrideInteractions(bool, areInteractionsAllowed);
|
|
770
|
+
this.emit('main.overrideInteractions', bool, areInteractionsAllowed);
|
|
735
771
|
};
|
|
736
772
|
|
|
737
773
|
Peaks.prototype.allowInteractions = function(forSources, forSegments) {
|
|
738
|
-
|
|
739
|
-
.allowInteractions(forSources, forSegments);
|
|
774
|
+
this.emit('main.allowInteractions', forSources, forSegments);
|
|
740
775
|
};
|
|
741
776
|
|
|
742
777
|
Peaks.prototype.getSelectedElements = function() {
|
|
@@ -777,13 +812,6 @@ define([
|
|
|
777
812
|
window.removeEventListener('resize', this._onResize);
|
|
778
813
|
};
|
|
779
814
|
|
|
780
|
-
Peaks.prototype.setLineHeight = function(newLineHeight) {
|
|
781
|
-
var oldHeight = this.options.lineHeight;
|
|
782
|
-
|
|
783
|
-
this.options.lineHeight = newLineHeight;
|
|
784
|
-
this.emit('options.set.line_height', oldHeight);
|
|
785
|
-
};
|
|
786
|
-
|
|
787
815
|
Peaks.prototype.zoomIn = function() {
|
|
788
816
|
this.view.setZoom(
|
|
789
817
|
this.view.getTimeToPixelsScale() + Math.floor(this.view.getTimeToPixelsScale() / 10) + 1
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file
|
|
3
|
+
*
|
|
4
|
+
* Defines the {@link Line} class.
|
|
5
|
+
*
|
|
6
|
+
* @module line
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
define([
|
|
10
|
+
'../utils'
|
|
11
|
+
], function(Utils) {
|
|
12
|
+
'use strict';
|
|
13
|
+
|
|
14
|
+
function validateLine(options, context) {
|
|
15
|
+
if (!Utils.isInteger(options.position) || options.position < 0) {
|
|
16
|
+
throw new TypeError('peaks.lines.' + context + ': position must be a non-negative integer');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (Utils.isNullOrUndefined(options.indicatorType)) {
|
|
20
|
+
options.indicatorType = 'default';
|
|
21
|
+
}
|
|
22
|
+
else if (!Utils.isValidIndicatorType(options.indicatorType)) {
|
|
23
|
+
throw new TypeError('peaks.lines.' + context + ': indicatorType must be a valid indicator type');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (Utils.isNullOrUndefined(options.indicatorText)) {
|
|
27
|
+
options.indicatorText = '';
|
|
28
|
+
}
|
|
29
|
+
else if (!Utils.isString(options.indicatorText)) {
|
|
30
|
+
throw new TypeError('peaks.lines.' + context + ': indicatorText must be a string');
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* A line is a horizontal line that can be placed on the timeline.
|
|
36
|
+
* It can contain sources or segments.
|
|
37
|
+
*
|
|
38
|
+
* @class
|
|
39
|
+
* @alias Segment
|
|
40
|
+
* @param {Peaks} peaks The parent {@link Peaks} object.
|
|
41
|
+
* @param {String} id A unique identifier for the line.
|
|
42
|
+
* @param {Number} position Position of the line on the timeline.
|
|
43
|
+
* @param {String} indicatorType Type of the line indicator.
|
|
44
|
+
* @param {String} indicatorText Text to display above the line indicator.
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
function Line(peaks, id, position, indicatorType, indicatorText) {
|
|
48
|
+
var opts = {
|
|
49
|
+
position: position,
|
|
50
|
+
indicatorType: indicatorType,
|
|
51
|
+
indicatorText: indicatorText
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
validateLine(opts, 'add()');
|
|
55
|
+
|
|
56
|
+
this._peaks = peaks;
|
|
57
|
+
this._id = id;
|
|
58
|
+
this._position = opts.position;
|
|
59
|
+
this._indicatorType = opts.indicatorType;
|
|
60
|
+
this._indicatorText = opts.indicatorText;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
Object.defineProperties(Line.prototype, {
|
|
64
|
+
id: {
|
|
65
|
+
enumerable: true,
|
|
66
|
+
get: function() {
|
|
67
|
+
return this._id;
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
position: {
|
|
71
|
+
enumerable: true,
|
|
72
|
+
get: function() {
|
|
73
|
+
return this._position;
|
|
74
|
+
},
|
|
75
|
+
|
|
76
|
+
set: function(pos) {
|
|
77
|
+
if (!Utils.isInteger(pos) || pos < 0) {
|
|
78
|
+
throw new TypeError('peaks.lines.setPosition(): position must be a non-negative integer');
|
|
79
|
+
}
|
|
80
|
+
this._position = pos;
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
indicatorType: {
|
|
84
|
+
enumerable: true,
|
|
85
|
+
get: function() {
|
|
86
|
+
return this._indicatorType;
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
indicatorText: {
|
|
90
|
+
enumerable: true,
|
|
91
|
+
get: function() {
|
|
92
|
+
return this._indicatorText;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
Line.prototype.update = function(options) {
|
|
98
|
+
var opts = {
|
|
99
|
+
position: this.position,
|
|
100
|
+
indicatorType: this.indicatorType,
|
|
101
|
+
indicatorText: this.indicatorText
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
Utils.extend(opts, options);
|
|
105
|
+
|
|
106
|
+
validateLine(this._peaks, opts, 'update()');
|
|
107
|
+
|
|
108
|
+
this._startTime = opts.startTime;
|
|
109
|
+
this._endTime = opts.endTime;
|
|
110
|
+
this._duration = opts.duration;
|
|
111
|
+
this._labelText = opts.labelText;
|
|
112
|
+
this._color = opts.color;
|
|
113
|
+
this._textColor = opts.textColor;
|
|
114
|
+
this._handleTextColor = opts.handleTextColor;
|
|
115
|
+
this._hoverColor = opts.hoverColor;
|
|
116
|
+
this._warningColor = opts.warningColor;
|
|
117
|
+
this._opacity = opts.opacity;
|
|
118
|
+
this._borderColor = opts.borderColor;
|
|
119
|
+
this._borderWidth = opts.borderWidth;
|
|
120
|
+
this._borderRadius = opts.borderRadius;
|
|
121
|
+
this._editable = opts.editable;
|
|
122
|
+
this._allowDeletion = opts.allowDeletion;
|
|
123
|
+
this._line = opts.line;
|
|
124
|
+
this._indicators = opts.indicators;
|
|
125
|
+
|
|
126
|
+
this._peaks.emit('model.line.update', this);
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Returns a serializable object containing only the properties defined with Object.defineProperties.
|
|
131
|
+
* This includes all enumerable properties that can be safely serialized.
|
|
132
|
+
*
|
|
133
|
+
* @returns {Object} A plain object containing the serializable properties of the line.
|
|
134
|
+
*/
|
|
135
|
+
Line.prototype.toSerializable = function() {
|
|
136
|
+
var serializable = {};
|
|
137
|
+
|
|
138
|
+
// Add all the enumerable properties from the prototype
|
|
139
|
+
var proto = Object.getPrototypeOf(this);
|
|
140
|
+
var descriptors = Object.getOwnPropertyDescriptors(proto);
|
|
141
|
+
|
|
142
|
+
for (var prop in descriptors) {
|
|
143
|
+
if (Object.prototype.hasOwnProperty.call(descriptors, prop)) {
|
|
144
|
+
var descriptor = descriptors[prop];
|
|
145
|
+
|
|
146
|
+
if (descriptor.enumerable && descriptor.get && typeof descriptor.get === 'function') {
|
|
147
|
+
serializable[prop] = this[prop];
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return serializable;
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
return Line;
|
|
156
|
+
});
|