@checksub_team/peaks_timeline 1.8.1 → 1.8.3

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@checksub_team/peaks_timeline",
3
- "version": "1.8.1",
3
+ "version": "1.8.3",
4
4
  "description": "JavaScript UI component for displaying audio waveforms",
5
5
  "main": "./peaks.js",
6
6
  "types": "./peaks.js.d.ts",
package/peaks.js CHANGED
@@ -17565,11 +17565,15 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Konva) {
17565
17565
  var SPACING_BETWEEN_PREVIEW_AND_BORDER_RATIO = 0.15;
17566
17566
  var SPACING_BETWEEN_PREVIEWS = 1.5;
17567
17567
  var CORNER_RADIUS = 8;
17568
+ var INDICATOR_RADIUS = 4;
17569
+ var INDICATORS_MARGIN_LEFT = 8;
17570
+ var INDICATORS_MARGIN_TOP = 12;
17568
17571
  function SourceGroup(source, peaks, layer, view) {
17569
17572
  this._source = source;
17570
17573
  this._peaks = peaks;
17571
17574
  this._layer = layer;
17572
17575
  this._view = view;
17576
+ this._indicators = {};
17573
17577
  var self = this;
17574
17578
  this._x = this._view.timeToPixels(source.startTime);
17575
17579
  this._width = this._view.timeToPixels(source.endTime - source.startTime);
@@ -17615,6 +17619,9 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Konva) {
17615
17619
  }
17616
17620
  this._addHandles();
17617
17621
  this.setWrapping(source.wrapped);
17622
+ this._indicatorsGroup = new Konva.Group();
17623
+ this._group.add(this._indicatorsGroup);
17624
+ this.createIndicators();
17618
17625
  }
17619
17626
  SourceGroup.prototype._onSourceGroupDragStart = function () {
17620
17627
  this._dragged = true;
@@ -18298,6 +18305,54 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Konva) {
18298
18305
  SourceGroup.prototype.destroy = function () {
18299
18306
  this._group.destroy();
18300
18307
  };
18308
+ SourceGroup.prototype.createIndicators = function () {
18309
+ var newIndicatorsColors = this._source.indicators;
18310
+ var oldIndicators = this._indicators;
18311
+ var newIndicators = {};
18312
+ if (newIndicatorsColors) {
18313
+ newIndicatorsColors.forEach(function (indicatorColor) {
18314
+ var oldIndicator = oldIndicators[indicatorColor];
18315
+ if (oldIndicator) {
18316
+ newIndicators[indicatorColor] = oldIndicator;
18317
+ delete oldIndicators[indicatorColor];
18318
+ } else {
18319
+ newIndicators[indicatorColor] = null;
18320
+ }
18321
+ });
18322
+ for (var color in oldIndicators) {
18323
+ if (Utils.objectHasProperty(oldIndicators, color)) {
18324
+ oldIndicators[color].destroy();
18325
+ }
18326
+ }
18327
+ }
18328
+ this._indicators = Object.keys(newIndicators).sort().reverse().reduce(function (objEntries, key) {
18329
+ objEntries[key] = newIndicators[key];
18330
+ return objEntries;
18331
+ }, {});
18332
+ this._createIndicators();
18333
+ };
18334
+ SourceGroup.prototype._createIndicators = function () {
18335
+ var currentX = 0;
18336
+ var zIndex = 0;
18337
+ for (var color in this._indicators) {
18338
+ if (Utils.objectHasProperty(this._indicators, color)) {
18339
+ if (!this._indicators[color]) {
18340
+ this._indicators[color] = new Konva.Circle({
18341
+ radius: INDICATOR_RADIUS,
18342
+ fill: color,
18343
+ strokeEnabled: false
18344
+ });
18345
+ this._indicatorsGroup.add(this._indicators[color]);
18346
+ }
18347
+ this._indicators[color].x(currentX);
18348
+ this._indicators[color].zIndex(zIndex);
18349
+ currentX -= INDICATOR_RADIUS;
18350
+ zIndex += 1;
18351
+ }
18352
+ }
18353
+ this._indicatorsGroup.offsetX(currentX - INDICATORS_MARGIN_LEFT);
18354
+ this._indicatorsGroup.offsetY(-INDICATORS_MARGIN_TOP);
18355
+ };
18301
18356
  return SourceGroup;
18302
18357
  }(_dereq_('./waveform-builder'), _dereq_('./waveform-shape'), _dereq_('./utils'), _dereq_('konva'));
18303
18358
  },{"./utils":112,"./waveform-builder":113,"./waveform-shape":114,"konva":43}],105:[function(_dereq_,module,exports){
@@ -18468,8 +18523,11 @@ module.exports = function (Utils) {
18468
18523
  } else if (options.wrapping === 'complete') {
18469
18524
  options.wrapped = false;
18470
18525
  }
18526
+ if (Utils.isNullOrUndefined(options.indicators)) {
18527
+ options.indicators = [];
18528
+ }
18471
18529
  }
18472
- function Source(peaks, id, originId, elementId, title, url, previewUrl, binaryUrl, kind, subkind, duration, startTime, endTime, mediaStartTime, mediaEndTime, color, backgroundColor, borderColor, selectedColor, textFont, textFontSize, textColor, textBackgroundColor, textPosition, borderWidth, borderRadius, wrapped, position, draggable, orderable, resizable, cuttable, deletable, wrapping, previewHeight, binaryHeight) {
18530
+ function Source(peaks, id, originId, elementId, title, url, previewUrl, binaryUrl, kind, subkind, duration, startTime, endTime, mediaStartTime, mediaEndTime, color, backgroundColor, borderColor, selectedColor, textFont, textFontSize, textColor, textBackgroundColor, textPosition, borderWidth, borderRadius, wrapped, position, draggable, orderable, resizable, cuttable, deletable, wrapping, previewHeight, binaryHeight, indicators) {
18473
18531
  var opts = {
18474
18532
  title: title,
18475
18533
  url: url,
@@ -18502,7 +18560,8 @@ module.exports = function (Utils) {
18502
18560
  deletable: deletable,
18503
18561
  wrapping: wrapping,
18504
18562
  previewHeight: previewHeight,
18505
- binaryHeight: binaryHeight
18563
+ binaryHeight: binaryHeight,
18564
+ indicators: indicators
18506
18565
  };
18507
18566
  validateSource(peaks, opts, 'add()');
18508
18567
  this._peaks = peaks;
@@ -18541,6 +18600,7 @@ module.exports = function (Utils) {
18541
18600
  this._wrapping = opts.wrapping;
18542
18601
  this._previewHeight = opts.previewHeight;
18543
18602
  this._binaryHeight = opts.binaryHeight;
18603
+ this._indicators = opts.indicators;
18544
18604
  this._minSize = peaks.options.minSourceSize;
18545
18605
  }
18546
18606
  Object.defineProperties(Source.prototype, {
@@ -18823,6 +18883,12 @@ module.exports = function (Utils) {
18823
18883
  this._binaryHeight = binaryHeight;
18824
18884
  }
18825
18885
  },
18886
+ indicators: {
18887
+ enumerable: true,
18888
+ get: function () {
18889
+ return this._indicators;
18890
+ }
18891
+ },
18826
18892
  minSize: {
18827
18893
  enumerable: true,
18828
18894
  get: function () {
@@ -18947,7 +19013,8 @@ module.exports = function (Utils) {
18947
19013
  deletable: this.deletable,
18948
19014
  wrapping: this.wrapping,
18949
19015
  previewHeight: this.previewHeight,
18950
- binaryHeight: this.binaryHeight
19016
+ binaryHeight: this.binaryHeight,
19017
+ indicators: this.indicators
18951
19018
  };
18952
19019
  Utils.extend(opts, options);
18953
19020
  validateSource(this._peaks, opts, 'update()');
@@ -18983,11 +19050,16 @@ module.exports = function (Utils) {
18983
19050
  this._wrapping = opts.wrapping;
18984
19051
  this._previewHeight = opts.previewHeight;
18985
19052
  this._binaryHeight = opts.binaryHeight;
19053
+ this._indicators = opts.indicators;
18986
19054
  this._peaks.emit('source.update', this);
18987
19055
  };
18988
19056
  Source.prototype.isVisible = function (startTime, endTime) {
18989
19057
  return this._startTime < endTime && startTime < this._endTime;
18990
19058
  };
19059
+ Source.prototype.setIndicators = function (newIndicators) {
19060
+ this._indicators = newIndicators;
19061
+ this._peaks.emit('source.setIndicators', this);
19062
+ };
18991
19063
  return Source;
18992
19064
  }(_dereq_('./utils'));
18993
19065
  },{"./utils":112}],106:[function(_dereq_,module,exports){
@@ -19013,6 +19085,7 @@ module.exports = function (SourceGroup, Lines, DataRetriever, Utils, Invoker, Ko
19013
19085
  this._peaks.on('sources.refresh', this._onSourcesRefresh.bind(this));
19014
19086
  this._peaks.on('segments.show', this._onSegmentsShow.bind(this));
19015
19087
  this._peaks.on('options.set.line_height', this._onOptionsLineHeightChange.bind(this));
19088
+ this._peaks.on('source.setIndicators', this.setIndicators.bind(this));
19016
19089
  }
19017
19090
  SourcesLayer.prototype.fitToView = function () {
19018
19091
  this._lines.fitToView();
@@ -19159,6 +19232,13 @@ module.exports = function (SourceGroup, Lines, DataRetriever, Utils, Invoker, Ko
19159
19232
  this._dataRetriever.retrieveData(source);
19160
19233
  return sourceGroup;
19161
19234
  };
19235
+ SourcesLayer.prototype.setIndicators = function (source) {
19236
+ var sourceGroup = this._sourcesGroup[source.id];
19237
+ if (sourceGroup) {
19238
+ sourceGroup.createIndicators();
19239
+ this._layer.draw();
19240
+ }
19241
+ };
19162
19242
  SourcesLayer.prototype.updateSources = function (startTime, endTime) {
19163
19243
  this._lines.updateSegments(startTime, endTime);
19164
19244
  var sources = this.findSources(startTime, endTime);
@@ -19330,6 +19410,7 @@ module.exports = function (SourceGroup, Lines, DataRetriever, Utils, Invoker, Ko
19330
19410
  this._peaks.off('data.retrieved', this._onDataRetrieved);
19331
19411
  this._peaks.off('sources.refresh', this._onSourcesRefresh);
19332
19412
  this._peaks.off('segments.show', this._onSegmentsShow);
19413
+ this._peaks.off('source.setIndicators', this.setIndicators);
19333
19414
  };
19334
19415
  SourcesLayer.prototype.getHeight = function () {
19335
19416
  return this._layer.getHeight();
@@ -19728,7 +19809,7 @@ module.exports = function (Source, Utils) {
19728
19809
  wrapping: sourceToCut.wrapping,
19729
19810
  previewHeight: sourceToCut.previewHeight,
19730
19811
  binaryHeight: sourceToCut.binaryHeight
19731
- }]);
19812
+ }])[0];
19732
19813
  this._peaks.emit('sources.updated', [
19733
19814
  sourceToCut,
19734
19815
  newSource
@@ -19745,7 +19826,7 @@ module.exports = function (Source, Utils) {
19745
19826
  if (!Utils.isObject(options)) {
19746
19827
  throw new TypeError('peaks.sources.add(): expected a Source object parameter');
19747
19828
  }
19748
- var source = new Source(this._peaks, options.id || this._getNextSourceId(), options.originId, options.elementId, options.title, options.url, options.previewUrl, options.binaryUrl, options.kind, options.subkind, options.duration, options.startTime, options.endTime, options.mediaStartTime, options.mediaEndTime, options.color, options.backgroundColor, options.borderColor, options.selectedColor, options.textFont, options.textFontSize, options.textColor, options.textBackgroundColor, options.textPosition, options.borderWidth, options.borderRadius, options.wrapped, options.position, options.draggable, options.orderable, options.resizable, options.cuttable, options.deletable, options.wrapping, options.previewHeight, options.binaryHeight);
19829
+ var source = new Source(this._peaks, options.id || this._getNextSourceId(), options.originId, options.elementId, options.title, options.url, options.previewUrl, options.binaryUrl, options.kind, options.subkind, options.duration, options.startTime, options.endTime, options.mediaStartTime, options.mediaEndTime, options.color, options.backgroundColor, options.borderColor, options.selectedColor, options.textFont, options.textFontSize, options.textColor, options.textBackgroundColor, options.textPosition, options.borderWidth, options.borderRadius, options.wrapped, options.position, options.draggable, options.orderable, options.resizable, options.cuttable, options.deletable, options.wrapping, options.previewHeight, options.binaryHeight, options.indicators);
19749
19830
  return source;
19750
19831
  };
19751
19832
  TimelineSources.prototype.getSources = function () {
@@ -19790,6 +19871,7 @@ module.exports = function (Source, Utils) {
19790
19871
  self._addSource(source);
19791
19872
  });
19792
19873
  this._peaks.emit('sources.add', sources);
19874
+ return sources;
19793
19875
  };
19794
19876
  TimelineSources.prototype._findSource = function (predicate) {
19795
19877
  var indexes = [];
@@ -21,6 +21,9 @@ define([
21
21
  var SPACING_BETWEEN_PREVIEW_AND_BORDER_RATIO = 0.15;
22
22
  var SPACING_BETWEEN_PREVIEWS = 1.5;
23
23
  var CORNER_RADIUS = 8;
24
+ var INDICATOR_RADIUS = 4; // px
25
+ var INDICATORS_MARGIN_LEFT = 8; // px
26
+ var INDICATORS_MARGIN_TOP = 12; // px
24
27
 
25
28
  /**
26
29
  * Creates a source group for the given source.
@@ -39,6 +42,7 @@ define([
39
42
  this._peaks = peaks;
40
43
  this._layer = layer;
41
44
  this._view = view;
45
+ this._indicators = {};
42
46
 
43
47
  var self = this;
44
48
 
@@ -94,6 +98,11 @@ define([
94
98
  this._addHandles();
95
99
 
96
100
  this.setWrapping(source.wrapped);
101
+
102
+ this._indicatorsGroup = new Konva.Group();
103
+ this._group.add(this._indicatorsGroup);
104
+
105
+ this.createIndicators();
97
106
  }
98
107
 
99
108
  // SourceGroup.prototype.rescale = function() {
@@ -1039,5 +1048,69 @@ define([
1039
1048
  this._group.destroy();
1040
1049
  };
1041
1050
 
1051
+ SourceGroup.prototype.createIndicators = function() {
1052
+ var newIndicatorsColors = this._source.indicators;
1053
+
1054
+ var oldIndicators = this._indicators;
1055
+ var newIndicators = {};
1056
+
1057
+ if (newIndicatorsColors) {
1058
+ newIndicatorsColors.forEach(function(indicatorColor) {
1059
+ var oldIndicator = oldIndicators[indicatorColor];
1060
+
1061
+ if (oldIndicator) {
1062
+ newIndicators[indicatorColor] = oldIndicator;
1063
+ delete oldIndicators[indicatorColor];
1064
+ }
1065
+ else {
1066
+ newIndicators[indicatorColor] = null;
1067
+ }
1068
+ });
1069
+
1070
+ for (var color in oldIndicators) {
1071
+ if (Utils.objectHasProperty(oldIndicators, color)) {
1072
+ oldIndicators[color].destroy();
1073
+ }
1074
+ }
1075
+ }
1076
+
1077
+ this._indicators = Object.keys(newIndicators)
1078
+ .sort()
1079
+ .reverse()
1080
+ .reduce(function(objEntries, key) {
1081
+ objEntries[key] = newIndicators[key];
1082
+ return objEntries;
1083
+ }, {}
1084
+ );
1085
+
1086
+ this._createIndicators();
1087
+ };
1088
+
1089
+ SourceGroup.prototype._createIndicators = function() {
1090
+ var currentX = 0;
1091
+ var zIndex = 0;
1092
+
1093
+ for (var color in this._indicators) {
1094
+ if (Utils.objectHasProperty(this._indicators, color)) {
1095
+ if (!this._indicators[color]) {
1096
+ this._indicators[color] = new Konva.Circle({
1097
+ radius: INDICATOR_RADIUS,
1098
+ fill: color,
1099
+ strokeEnabled: false
1100
+ });
1101
+ this._indicatorsGroup.add(this._indicators[color]);
1102
+ }
1103
+
1104
+ this._indicators[color].x(currentX);
1105
+ this._indicators[color].zIndex(zIndex);
1106
+ currentX -= INDICATOR_RADIUS;
1107
+ zIndex += 1;
1108
+ }
1109
+ }
1110
+
1111
+ this._indicatorsGroup.offsetX(currentX - INDICATORS_MARGIN_LEFT);
1112
+ this._indicatorsGroup.offsetY(-INDICATORS_MARGIN_TOP);
1113
+ };
1114
+
1042
1115
  return SourceGroup;
1043
1116
  });
package/src/source.js CHANGED
@@ -246,6 +246,10 @@ define([
246
246
  else if (options.wrapping === 'complete') {
247
247
  options.wrapped = false;
248
248
  }
249
+
250
+ if (Utils.isNullOrUndefined(options.indicators)) {
251
+ options.indicators = [];
252
+ }
249
253
  }
250
254
 
251
255
  /**
@@ -266,13 +270,14 @@ define([
266
270
  * @param {Number} position Position of the source on the timeline.
267
271
  * Correspond to the index of the line.
268
272
  * @param {Boolean} segments If <code>true</code> this source will integrate the segments.
273
+ * @param {Array<String>} indicators Array containing the colors of all indicators.
269
274
  */
270
275
 
271
276
  function Source(peaks, id, originId, elementId, title, url, previewUrl, binaryUrl, kind,
272
277
  subkind, duration, startTime, endTime, mediaStartTime, mediaEndTime, color, backgroundColor,
273
278
  borderColor, selectedColor, textFont, textFontSize, textColor, textBackgroundColor,
274
279
  textPosition, borderWidth, borderRadius, wrapped, position, draggable, orderable, resizable,
275
- cuttable, deletable, wrapping, previewHeight, binaryHeight) {
280
+ cuttable, deletable, wrapping, previewHeight, binaryHeight, indicators) {
276
281
  var opts = {
277
282
  title: title,
278
283
  url: url,
@@ -305,7 +310,8 @@ define([
305
310
  deletable: deletable,
306
311
  wrapping: wrapping,
307
312
  previewHeight: previewHeight,
308
- binaryHeight: binaryHeight
313
+ binaryHeight: binaryHeight,
314
+ indicators: indicators
309
315
  };
310
316
 
311
317
  validateSource(peaks, opts, 'add()');
@@ -346,6 +352,7 @@ define([
346
352
  this._wrapping = opts.wrapping;
347
353
  this._previewHeight = opts.previewHeight;
348
354
  this._binaryHeight = opts.binaryHeight;
355
+ this._indicators = opts.indicators;
349
356
  this._minSize = peaks.options.minSourceSize;
350
357
  }
351
358
 
@@ -650,6 +657,12 @@ define([
650
657
  this._binaryHeight = binaryHeight;
651
658
  }
652
659
  },
660
+ indicators: {
661
+ enumerable: true,
662
+ get: function() {
663
+ return this._indicators;
664
+ }
665
+ },
653
666
  minSize: {
654
667
  enumerable: true,
655
668
  get: function() {
@@ -806,7 +819,8 @@ define([
806
819
  deletable: this.deletable,
807
820
  wrapping: this.wrapping,
808
821
  previewHeight: this.previewHeight,
809
- binaryHeight: this.binaryHeight
822
+ binaryHeight: this.binaryHeight,
823
+ indicators: this.indicators
810
824
  };
811
825
 
812
826
  Utils.extend(opts, options);
@@ -845,6 +859,7 @@ define([
845
859
  this._wrapping = opts.wrapping;
846
860
  this._previewHeight = opts.previewHeight;
847
861
  this._binaryHeight = opts.binaryHeight;
862
+ this._indicators = opts.indicators;
848
863
 
849
864
  this._peaks.emit('source.update', this);
850
865
  };
@@ -862,5 +877,16 @@ define([
862
877
  return this._startTime < endTime && startTime < this._endTime;
863
878
  };
864
879
 
880
+ /**
881
+ * Update the indicators of this source.
882
+ *
883
+ * @param {Array<String>} newIndicators The new indicators.
884
+ */
885
+
886
+ Source.prototype.setIndicators = function(newIndicators) {
887
+ this._indicators = newIndicators;
888
+ this._peaks.emit('source.setIndicators', this);
889
+ };
890
+
865
891
  return Source;
866
892
  });
@@ -58,6 +58,7 @@ define([
58
58
  this._peaks.on('sources.refresh', this._onSourcesRefresh.bind(this));
59
59
  this._peaks.on('segments.show', this._onSegmentsShow.bind(this));
60
60
  this._peaks.on('options.set.line_height', this._onOptionsLineHeightChange.bind(this));
61
+ this._peaks.on('source.setIndicators', this.setIndicators.bind(this));
61
62
  }
62
63
 
63
64
  SourcesLayer.prototype.fitToView = function() {
@@ -280,6 +281,15 @@ define([
280
281
  return sourceGroup;
281
282
  };
282
283
 
284
+ SourcesLayer.prototype.setIndicators = function(source) {
285
+ var sourceGroup = this._sourcesGroup[source.id];
286
+
287
+ if (sourceGroup) {
288
+ sourceGroup.createIndicators();
289
+ this._layer.draw();
290
+ }
291
+ };
292
+
283
293
  /**
284
294
  * Updates the positions of all displayed sources in the view.
285
295
  *
@@ -568,6 +578,7 @@ define([
568
578
  this._peaks.off('data.retrieved', this._onDataRetrieved);
569
579
  this._peaks.off('sources.refresh', this._onSourcesRefresh);
570
580
  this._peaks.off('segments.show', this._onSegmentsShow);
581
+ this._peaks.off('source.setIndicators', this.setIndicators);
571
582
  };
572
583
 
573
584
  SourcesLayer.prototype.getHeight = function() {
@@ -98,7 +98,7 @@ define([
98
98
  wrapping: sourceToCut.wrapping,
99
99
  previewHeight: sourceToCut.previewHeight,
100
100
  binaryHeight: sourceToCut.binaryHeight
101
- }]);
101
+ }])[0];
102
102
 
103
103
  this._peaks.emit('sources.updated', [sourceToCut, newSource]);
104
104
  };
@@ -179,7 +179,8 @@ define([
179
179
  options.deletable,
180
180
  options.wrapping,
181
181
  options.previewHeight,
182
- options.binaryHeight
182
+ options.binaryHeight,
183
+ options.indicators
183
184
  );
184
185
 
185
186
  return source;
@@ -283,6 +284,8 @@ define([
283
284
  });
284
285
 
285
286
  this._peaks.emit('sources.add', sources);
287
+
288
+ return sources;
286
289
  };
287
290
 
288
291
  /**