@checksub_team/peaks_timeline 1.11.0 → 1.12.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@checksub_team/peaks_timeline",
3
- "version": "1.11.0",
3
+ "version": "1.12.0",
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
@@ -17675,7 +17675,8 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Konva) {
17675
17675
  this._width = this._view.timeToPixels(source.endTime - source.startTime);
17676
17676
  this._unwrappedHeight = source.binaryHeight && source.previewHeight ? source.binaryHeight + source.previewHeight : this._peaks.options.lineHeight;
17677
17677
  this._wrappedHeight = this._peaks.options.wrappedLineHeight;
17678
- this._borderWidth = this._source.borderWidth;
17678
+ this._borderWidth = this._source.borderWidth || 0;
17679
+ this._height = this._unwrappedHeight;
17679
17680
  this._previewList = [];
17680
17681
  this._markersGroup = this._createMarkers();
17681
17682
  this._group = new Konva.Group({
@@ -17688,8 +17689,12 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Konva) {
17688
17689
  });
17689
17690
  this._group.on('dragstart', this._layer.onSourcesGroupDragStart.bind(this._layer));
17690
17691
  this._group.on('dragend', this._layer.onSourcesGroupDragEnd.bind(this._layer));
17692
+ this._cursor = null;
17691
17693
  this._group.on('mouseover', function () {
17692
17694
  self._view.setHoveredElement(self);
17695
+ if (self._source.draggable) {
17696
+ self._view.setCursor(self._cursor || 'pointer');
17697
+ }
17693
17698
  if (self._view.getCurrentMode() === 'cut') {
17694
17699
  self.toggleDragging(false);
17695
17700
  self.toggleResizing(false);
@@ -17697,6 +17702,7 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Konva) {
17697
17702
  });
17698
17703
  this._group.on('mouseout', function () {
17699
17704
  self._view.setHoveredElement(null);
17705
+ self._view.setCursor('default');
17700
17706
  if (self._view.getCurrentMode() === 'cut') {
17701
17707
  self.toggleDragging(true);
17702
17708
  self.toggleResizing(true);
@@ -17752,12 +17758,12 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Konva) {
17752
17758
  SourceGroup.prototype.setWrapping = function (wrap, forceCreate, notify) {
17753
17759
  if (wrap) {
17754
17760
  this._removeUnwrap();
17755
- this._addWrap(forceCreate);
17756
17761
  this._height = this._wrappedHeight;
17762
+ this._addWrap(forceCreate);
17757
17763
  } else {
17758
17764
  this._removeWrap();
17759
- this._addUnwrap(forceCreate);
17760
17765
  this._height = this._unwrappedHeight;
17766
+ this._addUnwrap(forceCreate);
17761
17767
  }
17762
17768
  this.setHandlesWrapping(wrap);
17763
17769
  if (notify) {
@@ -17789,10 +17795,10 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Konva) {
17789
17795
  });
17790
17796
  if (this._source.resizable) {
17791
17797
  this._leftHandle.on('mouseover', function () {
17792
- self._view.setCursor('ew-resize');
17798
+ self._cursor = 'ew-resize';
17793
17799
  });
17794
17800
  this._leftHandle.on('mouseout', function () {
17795
- self._view.setCursor('default');
17801
+ self._cursor = null;
17796
17802
  });
17797
17803
  }
17798
17804
  }
@@ -17809,10 +17815,10 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Konva) {
17809
17815
  });
17810
17816
  if (this._source.resizable) {
17811
17817
  this._rightHandle.on('mouseover', function () {
17812
- self._view.setCursor('ew-resize');
17818
+ self._cursor = 'ew-resize';
17813
17819
  });
17814
17820
  this._rightHandle.on('mouseout', function () {
17815
- self._view.setCursor('default');
17821
+ self._cursor = null;
17816
17822
  });
17817
17823
  }
17818
17824
  }
@@ -17847,7 +17853,7 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Konva) {
17847
17853
  }
17848
17854
  };
17849
17855
  SourceGroup.prototype.drawSourceShape = function (ctx, shape, addBorderWidth) {
17850
- var offset = addBorderWidth && this._borderWidth ? this._borderWidth : 0;
17856
+ var offset = addBorderWidth ? this._borderWidth : 0;
17851
17857
  var radius = this._source.borderRadius !== undefined && this._source.borderRadius !== null ? this._source.borderRadius : Math.max(1, Math.min(this._width / 2, Math.min(CORNER_RADIUS, this._height / 2)));
17852
17858
  var x = Math.max(0, this._view.getFrameOffset() - this._x - radius);
17853
17859
  var width = Math.min(this._width - x, this._view.getOriginalWidth() + radius - Math.max(0, this._x - this._view.getFrameOffset()));
@@ -17882,14 +17888,6 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Konva) {
17882
17888
  self.drawSourceShape(ctx, null, true);
17883
17889
  }
17884
17890
  });
17885
- if (this._source.draggable) {
17886
- unwrap.on('mouseenter', function () {
17887
- self._view.setCursor('pointer');
17888
- });
17889
- unwrap.on('mouseout', function () {
17890
- self._view.setCursor('default');
17891
- });
17892
- }
17893
17891
  var background = new Konva.Group();
17894
17892
  background.add(new Konva.Shape({
17895
17893
  fill: this._source.backgroundColor,
@@ -17899,6 +17897,9 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Konva) {
17899
17897
  }));
17900
17898
  unwrap.add(background);
17901
17899
  unwrap.add(this._markersGroup);
17900
+ if (this._source.volumeRange && this._source.volume !== undefined) {
17901
+ unwrap.add(this._getVolumeSlider());
17902
+ }
17902
17903
  unwrap.add(this._createTitle(false));
17903
17904
  return unwrap;
17904
17905
  };
@@ -17929,14 +17930,6 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Konva) {
17929
17930
  self.drawSourceShape(ctx, null, true);
17930
17931
  }
17931
17932
  });
17932
- if (this._source.draggable) {
17933
- wrap.on('mouseenter', function () {
17934
- self._view.setCursor('pointer');
17935
- });
17936
- wrap.on('mouseout', function () {
17937
- self._view.setCursor('default');
17938
- });
17939
- }
17940
17933
  var background = new Konva.Group();
17941
17934
  background.add(new Konva.Shape({
17942
17935
  fill: this._source.backgroundColor,
@@ -17946,6 +17939,9 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Konva) {
17946
17939
  }));
17947
17940
  wrap.add(background);
17948
17941
  wrap.add(this._markersGroup);
17942
+ if (this._source.volumeRange && this._source.volume !== undefined) {
17943
+ wrap.add(this._getVolumeSlider());
17944
+ }
17949
17945
  wrap.add(this._createTitle(true));
17950
17946
  return wrap;
17951
17947
  };
@@ -18397,6 +18393,97 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Konva) {
18397
18393
  }.bind(this));
18398
18394
  return markersGroup;
18399
18395
  };
18396
+ SourceGroup.prototype._getYFromVolume = function (volume) {
18397
+ return this._borderWidth + (this._height - 2 * this._borderWidth) * (this._source.volumeRange[1] - volume) / (this._source.volumeRange[1] - this._source.volumeRange[0]);
18398
+ };
18399
+ SourceGroup.prototype._getVolumeFromY = function (y) {
18400
+ return this._source.volumeRange[1] - (y - this._borderWidth) / (this._height - 2 * this._borderWidth) * (this._source.volumeRange[1] - this._source.volumeRange[0]);
18401
+ };
18402
+ SourceGroup.prototype._getVolumeSlider = function () {
18403
+ if (!this._volumeSliderGroup) {
18404
+ this._volumeSliderGroup = this._createVolumeSlider();
18405
+ }
18406
+ return this._volumeSliderGroup;
18407
+ };
18408
+ SourceGroup.prototype._createVolumeSlider = function () {
18409
+ var self = this;
18410
+ var volumeY = this._getYFromVolume(this._source.volume);
18411
+ var volumeGroup = new Konva.Group({
18412
+ x: 0,
18413
+ y: 0,
18414
+ width: this._width,
18415
+ height: this._height
18416
+ });
18417
+ var volumeText = new Konva.Text({
18418
+ x: 0,
18419
+ y: volumeY - 20,
18420
+ text: '100%',
18421
+ fontSize: 12,
18422
+ fill: this._source.volumeSliderColor,
18423
+ visible: false
18424
+ });
18425
+ var maxTextWidth = volumeText.width();
18426
+ var maxTextHeight = volumeText.height();
18427
+ var volumeSliderGroup = new Konva.Group({
18428
+ x: 0,
18429
+ y: volumeY,
18430
+ draggable: true,
18431
+ dragBoundFunc: function (pos) {
18432
+ var y = Math.min(volumeGroup.absolutePosition().y + self._height - self._borderWidth, Math.max(volumeGroup.absolutePosition().y + self._borderWidth, pos.y));
18433
+ var textX = Math.min(volumeGroup.absolutePosition().x + self._width - maxTextWidth - self._borderWidth, Math.max(volumeGroup.absolutePosition().x + self._borderWidth, self._view.getPointerPosition().x - maxTextWidth));
18434
+ var textY = y - self._source.volumeSliderWidth / 2 - maxTextHeight;
18435
+ volumeText.absolutePosition({
18436
+ x: textX,
18437
+ y: textY < volumeGroup.absolutePosition().y + self._borderWidth ? y + self._source.volumeSliderWidth : textY
18438
+ });
18439
+ return {
18440
+ x: this.absolutePosition().x,
18441
+ y: y
18442
+ };
18443
+ }
18444
+ });
18445
+ var volumeSliderLine = new Konva.Line({
18446
+ points: [
18447
+ 0,
18448
+ 0,
18449
+ this._width,
18450
+ 0
18451
+ ],
18452
+ stroke: this._source.volumeSliderColor,
18453
+ strokeWidth: this._source.volumeSliderWidth
18454
+ });
18455
+ var volumeSliderRect = new Konva.Rect({
18456
+ x: 0,
18457
+ y: -this._source.volumeSliderDraggingWidth / 2,
18458
+ width: this._width,
18459
+ height: this._source.volumeSliderDraggingWidth,
18460
+ opacity: 0
18461
+ });
18462
+ volumeSliderGroup.add(volumeSliderRect);
18463
+ volumeSliderGroup.add(volumeSliderLine);
18464
+ volumeSliderGroup.on('dragstart', function () {
18465
+ volumeText.visible(true);
18466
+ });
18467
+ volumeSliderGroup.on('dragmove', function () {
18468
+ var volume = self._getVolumeFromY(volumeSliderGroup.y());
18469
+ volumeText.text((volume * 100).toFixed(0) + '%');
18470
+ self._source.volume = Math.max(self._source.volumeRange[0], Math.min(volume, self._source.volumeRange[1]));
18471
+ self._peaks.emit('source.volumeChanged', self._source);
18472
+ self._group.draw();
18473
+ });
18474
+ volumeSliderGroup.on('dragend', function () {
18475
+ volumeText.visible(false);
18476
+ });
18477
+ volumeSliderGroup.on('mouseover', function () {
18478
+ self._cursor = 'ns-resize';
18479
+ });
18480
+ volumeSliderGroup.on('mouseout', function () {
18481
+ self._cursor = null;
18482
+ });
18483
+ volumeGroup.add(volumeSliderGroup);
18484
+ volumeGroup.add(volumeText);
18485
+ return volumeGroup;
18486
+ };
18400
18487
  return SourceGroup;
18401
18488
  }(_dereq_('./waveform-builder'), _dereq_('./waveform-shape'), _dereq_('./utils'), _dereq_('konva'));
18402
18489
  },{"./utils":112,"./waveform-builder":113,"./waveform-shape":114,"konva":43}],105:[function(_dereq_,module,exports){
@@ -18482,6 +18569,21 @@ module.exports = function (Utils) {
18482
18569
  } else if (!Utils.isValidColor(options.selectedColor)) {
18483
18570
  throw new TypeError('peaks.sources.' + context + ': selectedColor should be a valid CSS color');
18484
18571
  }
18572
+ if (Utils.isNullOrUndefined(options.volumeSliderColor)) {
18573
+ options.volumeSliderColor = '#000000';
18574
+ } else if (!Utils.isValidColor(options.volumeSliderColor)) {
18575
+ throw new TypeError('peaks.sources.' + context + ': volumeSliderColor should be a valid CSS color');
18576
+ }
18577
+ if (Utils.isNullOrUndefined(options.volumeSliderWidth)) {
18578
+ options.volumeSliderWidth = 2;
18579
+ } else if (!Utils.isNumber(options.volumeSliderWidth)) {
18580
+ throw new TypeError('peaks.sources.' + context + ': volumeSliderWidth should be a number');
18581
+ }
18582
+ if (Utils.isNullOrUndefined(options.volumeSliderDraggingWidth)) {
18583
+ options.volumeSliderDraggingWidth = options.volumeSliderWidth;
18584
+ } else if (!Utils.isNumber(options.volumeSliderDraggingWidth)) {
18585
+ throw new TypeError('peaks.sources.' + context + ': volumeSliderDraggingWidth should be a number');
18586
+ }
18485
18587
  if (Utils.isNullOrUndefined(options.textFont)) {
18486
18588
  options.textFont = 'Arial';
18487
18589
  }
@@ -18582,8 +18684,20 @@ module.exports = function (Utils) {
18582
18684
  if (Utils.isNullOrUndefined(options.markerWidth)) {
18583
18685
  options.markerWidth = 2;
18584
18686
  }
18687
+ if (!Utils.isNullOrUndefined(options.volumeRange)) {
18688
+ if (!Array.isArray(options.volumeRange) || options.volumeRange.length !== 2 || !options.volumeRange.every(Utils.isNumber)) {
18689
+ throw new TypeError('peaks.sources.' + context + ': volumeRange must be an array of two numbers');
18690
+ } else if (options.volumeRange[0] > options.volumeRange[1]) {
18691
+ throw new RangeError('peaks.sources.' + context + ': volumeRange[0] should be less than volumeRange[1]');
18692
+ }
18693
+ }
18694
+ if (!Utils.isNullOrUndefined(options.volume) && !Utils.isNumber(options.volume)) {
18695
+ throw new TypeError('peaks.sources.' + context + ': volume must be a number');
18696
+ } else if (!Utils.isNullOrUndefined(options.volumeRange)) {
18697
+ options.volume = Utils.clamp(options.volume, options.volumeRange[0], options.volumeRange[1]);
18698
+ }
18585
18699
  }
18586
- 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, textAutoScroll, borderWidth, borderRadius, wrapped, position, draggable, orderable, resizable, cuttable, deletable, wrapping, previewHeight, binaryHeight, indicators, markers, markerColor, markerWidth) {
18700
+ function Source(peaks, id, originId, elementId, title, url, previewUrl, binaryUrl, kind, subkind, duration, startTime, endTime, mediaStartTime, mediaEndTime, color, backgroundColor, borderColor, selectedColor, volumeSliderColor, volumeSliderWidth, volumeSliderDraggingWidth, textFont, textFontSize, textColor, textBackgroundColor, textPosition, textAutoScroll, borderWidth, borderRadius, wrapped, position, draggable, orderable, resizable, cuttable, deletable, wrapping, previewHeight, binaryHeight, indicators, markers, markerColor, markerWidth, volume, volumeRange) {
18587
18701
  var opts = {
18588
18702
  title: title,
18589
18703
  url: url,
@@ -18604,6 +18718,9 @@ module.exports = function (Utils) {
18604
18718
  textFontSize: textFontSize,
18605
18719
  textColor: textColor,
18606
18720
  textBackgroundColor: textBackgroundColor,
18721
+ volumeSliderColor: volumeSliderColor,
18722
+ volumeSliderWidth: volumeSliderWidth,
18723
+ volumeSliderDraggingWidth: volumeSliderDraggingWidth,
18607
18724
  textPosition: textPosition,
18608
18725
  textAutoScroll: textAutoScroll,
18609
18726
  borderWidth: borderWidth,
@@ -18621,7 +18738,9 @@ module.exports = function (Utils) {
18621
18738
  indicators: indicators,
18622
18739
  markers: markers,
18623
18740
  markerColor: markerColor,
18624
- markerWidth: markerWidth
18741
+ markerWidth: markerWidth,
18742
+ volume: volume,
18743
+ volumeRange: volumeRange
18625
18744
  };
18626
18745
  validateSource(peaks, opts, 'add()');
18627
18746
  this._peaks = peaks;
@@ -18643,6 +18762,9 @@ module.exports = function (Utils) {
18643
18762
  this._backgroundColor = opts.backgroundColor;
18644
18763
  this._borderColor = opts.borderColor;
18645
18764
  this._selectedColor = opts.selectedColor || Utils.shadeColor(opts.backgroundColor, 30);
18765
+ this._volumeSliderColor = opts.volumeSliderColor;
18766
+ this._volumeSliderWidth = opts.volumeSliderWidth;
18767
+ this._volumeSliderDraggingWidth = opts.volumeSliderDraggingWidth;
18646
18768
  this._textFont = opts.textFont;
18647
18769
  this._textFontSize = opts.textFontSize;
18648
18770
  this._textColor = opts.textColor;
@@ -18665,6 +18787,8 @@ module.exports = function (Utils) {
18665
18787
  this._markers = opts.markers;
18666
18788
  this._markerColor = opts.markerColor;
18667
18789
  this._markerWidth = opts.markerWidth;
18790
+ this._volume = opts.volume;
18791
+ this._volumeRange = opts.volumeRange;
18668
18792
  this._minSize = peaks.options.minSourceSize;
18669
18793
  this._selected = false;
18670
18794
  }
@@ -18804,6 +18928,24 @@ module.exports = function (Utils) {
18804
18928
  this._selectedColor = selectedColor;
18805
18929
  }
18806
18930
  },
18931
+ volumeSliderColor: {
18932
+ enumerable: true,
18933
+ get: function () {
18934
+ return this._volumeSliderColor;
18935
+ }
18936
+ },
18937
+ volumeSliderWidth: {
18938
+ enumerable: true,
18939
+ get: function () {
18940
+ return this._volumeSliderWidth;
18941
+ }
18942
+ },
18943
+ volumeSliderDraggingWidth: {
18944
+ enumerable: true,
18945
+ get: function () {
18946
+ return this._volumeSliderDraggingWidth;
18947
+ }
18948
+ },
18807
18949
  textFont: {
18808
18950
  enumerable: true,
18809
18951
  get: function () {
@@ -18981,6 +19123,21 @@ module.exports = function (Utils) {
18981
19123
  return this._markerWidth;
18982
19124
  }
18983
19125
  },
19126
+ volume: {
19127
+ enumerable: true,
19128
+ get: function () {
19129
+ return this._volume;
19130
+ },
19131
+ set: function (volume) {
19132
+ this._volume = volume;
19133
+ }
19134
+ },
19135
+ volumeRange: {
19136
+ enumerable: true,
19137
+ get: function () {
19138
+ return this._volumeRange;
19139
+ }
19140
+ },
18984
19141
  minSize: {
18985
19142
  enumerable: true,
18986
19143
  get: function () {
@@ -19098,6 +19255,9 @@ module.exports = function (Utils) {
19098
19255
  backgroundColor: this.backgroundColor,
19099
19256
  borderColor: this.borderColor,
19100
19257
  selectedColor: this.selectedColor,
19258
+ volumeSliderColor: this.volumeSliderColor,
19259
+ volumeSliderWidth: this.volumeSliderWidth,
19260
+ volumeSliderDraggingWidth: this.volumeSliderDraggingWidth,
19101
19261
  textFont: this.textFont,
19102
19262
  textFontSize: this.textFontSize,
19103
19263
  textColor: this.textColor,
@@ -19119,7 +19279,9 @@ module.exports = function (Utils) {
19119
19279
  indicators: this.indicators,
19120
19280
  markers: this.markers,
19121
19281
  markerColor: this.markerColor,
19122
- markerWidth: this.markerWidth
19282
+ markerWidth: this.markerWidth,
19283
+ volume: this.volume,
19284
+ volumeRange: this.volumeRange
19123
19285
  };
19124
19286
  Utils.extend(opts, options);
19125
19287
  validateSource(this._peaks, opts, 'update()');
@@ -19138,6 +19300,9 @@ module.exports = function (Utils) {
19138
19300
  this._backgroundColor = opts.backgroundColor;
19139
19301
  this._borderColor = opts.borderColor;
19140
19302
  this._selectedColor = opts.selectedColor || Utils.shadeColor(opts.backgroundColor, 30);
19303
+ this._volumeSliderColor = opts.volumeSliderColor;
19304
+ this._volumeSliderWidth = opts.volumeSliderWidth;
19305
+ this._volumeSliderDraggingWidth = opts.volumeSliderDraggingWidth;
19141
19306
  this._textFont = opts.textFont;
19142
19307
  this._textFontSize = opts.textFontSize;
19143
19308
  this._textColor = opts.textColor;
@@ -19160,6 +19325,8 @@ module.exports = function (Utils) {
19160
19325
  this._markers = opts.markers;
19161
19326
  this._markerColor = opts.markerColor;
19162
19327
  this._markerWidth = opts.markerWidth;
19328
+ this._volume = opts.volume;
19329
+ this._volumeRange = opts.volumeRange;
19163
19330
  this._peaks.emit('source.update', this);
19164
19331
  };
19165
19332
  Source.prototype.isVisible = function (startTime, endTime) {
@@ -19968,6 +20135,9 @@ module.exports = function (Source, Utils) {
19968
20135
  backgroundColor: sourceToCut.backgroundColor,
19969
20136
  borderColor: sourceToCut.borderColor,
19970
20137
  selectedColor: sourceToCut.selectedColor,
20138
+ volumeSliderColor: sourceToCut.volumeSliderColor,
20139
+ volumeSliderWidth: sourceToCut.volumeSliderWidth,
20140
+ volumeSliderDraggingWidth: sourceToCut.volumeSliderDraggingWidth,
19971
20141
  textFont: sourceToCut.textFont,
19972
20142
  textFontSize: sourceToCut.textFontSize,
19973
20143
  textColor: sourceToCut.textColor,
@@ -19988,7 +20158,9 @@ module.exports = function (Source, Utils) {
19988
20158
  binaryHeight: sourceToCut.binaryHeight,
19989
20159
  markers: sourceToCut.markers,
19990
20160
  markerColor: sourceToCut.markerColor,
19991
- markerWidth: sourceToCut.markerWidth
20161
+ markerWidth: sourceToCut.markerWidth,
20162
+ volume: sourceToCut.volume,
20163
+ volumeRange: sourceToCut.volumeRange
19992
20164
  }])[0];
19993
20165
  this._peaks.emit('sources.updated', [
19994
20166
  sourceToCut,
@@ -20006,7 +20178,7 @@ module.exports = function (Source, Utils) {
20006
20178
  if (!Utils.isObject(options)) {
20007
20179
  throw new TypeError('peaks.sources.add(): expected a Source object parameter');
20008
20180
  }
20009
- 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.textAutoScroll, 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, options.markers, options.markerColor, options.markerWidth);
20181
+ 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.volumeSliderColor, options.volumeSliderWidth, options.volumeSliderDraggingWidth, options.textFont, options.textFontSize, options.textColor, options.textBackgroundColor, options.textPosition, options.textAutoScroll, 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, options.markers, options.markerColor, options.markerWidth, options.volume, options.volumeRange);
20010
20182
  return source;
20011
20183
  };
20012
20184
  TimelineSources.prototype.getSources = function () {
@@ -52,7 +52,8 @@ define([
52
52
  source.binaryHeight + source.previewHeight :
53
53
  this._peaks.options.lineHeight;
54
54
  this._wrappedHeight = this._peaks.options.wrappedLineHeight;
55
- this._borderWidth = this._source.borderWidth;
55
+ this._borderWidth = this._source.borderWidth || 0;
56
+ this._height = this._unwrappedHeight;
56
57
 
57
58
  this._previewList = [];
58
59
 
@@ -70,8 +71,12 @@ define([
70
71
  this._group.on('dragstart', this._layer.onSourcesGroupDragStart.bind(this._layer));
71
72
  this._group.on('dragend', this._layer.onSourcesGroupDragEnd.bind(this._layer));
72
73
 
74
+ this._cursor = null;
73
75
  this._group.on('mouseover', function() {
74
76
  self._view.setHoveredElement(self);
77
+ if (self._source.draggable) {
78
+ self._view.setCursor(self._cursor || 'pointer');
79
+ }
75
80
  if (self._view.getCurrentMode() === 'cut') {
76
81
  self.toggleDragging(false);
77
82
  self.toggleResizing(false);
@@ -79,6 +84,7 @@ define([
79
84
  });
80
85
  this._group.on('mouseout', function() {
81
86
  self._view.setHoveredElement(null);
87
+ self._view.setCursor('default');
82
88
  if (self._view.getCurrentMode() === 'cut') {
83
89
  self.toggleDragging(true);
84
90
  self.toggleResizing(true);
@@ -179,13 +185,13 @@ define([
179
185
  SourceGroup.prototype.setWrapping = function(wrap, forceCreate, notify) {
180
186
  if (wrap) {
181
187
  this._removeUnwrap();
182
- this._addWrap(forceCreate);
183
188
  this._height = this._wrappedHeight;
189
+ this._addWrap(forceCreate);
184
190
  }
185
191
  else {
186
192
  this._removeWrap();
187
- this._addUnwrap(forceCreate);
188
193
  this._height = this._unwrappedHeight;
194
+ this._addUnwrap(forceCreate);
189
195
  }
190
196
 
191
197
  this.setHandlesWrapping(wrap);
@@ -224,11 +230,11 @@ define([
224
230
 
225
231
  if (this._source.resizable) {
226
232
  this._leftHandle.on('mouseover', function() {
227
- self._view.setCursor('ew-resize');
233
+ self._cursor = 'ew-resize';
228
234
  });
229
235
 
230
236
  this._leftHandle.on('mouseout', function() {
231
- self._view.setCursor('default');
237
+ self._cursor = null;
232
238
  });
233
239
  }
234
240
  }
@@ -247,11 +253,11 @@ define([
247
253
 
248
254
  if (this._source.resizable) {
249
255
  this._rightHandle.on('mouseover', function() {
250
- self._view.setCursor('ew-resize');
256
+ self._cursor = 'ew-resize';
251
257
  });
252
258
 
253
259
  this._rightHandle.on('mouseout', function() {
254
- self._view.setCursor('default');
260
+ self._cursor = null;
255
261
  });
256
262
  }
257
263
  }
@@ -293,7 +299,7 @@ define([
293
299
  };
294
300
 
295
301
  SourceGroup.prototype.drawSourceShape = function(ctx, shape, addBorderWidth) {
296
- var offset = addBorderWidth && this._borderWidth ? this._borderWidth : 0;
302
+ var offset = addBorderWidth ? this._borderWidth : 0;
297
303
  var radius = this._source.borderRadius !== undefined && this._source.borderRadius !== null ?
298
304
  this._source.borderRadius :
299
305
  Math.max(
@@ -360,15 +366,6 @@ define([
360
366
  }
361
367
  });
362
368
 
363
- if (this._source.draggable) {
364
- unwrap.on('mouseenter', function() {
365
- self._view.setCursor('pointer');
366
- });
367
- unwrap.on('mouseout', function() {
368
- self._view.setCursor('default');
369
- });
370
- }
371
-
372
369
  var background = new Konva.Group();
373
370
 
374
371
  background.add(new Konva.Shape({
@@ -380,6 +377,9 @@ define([
380
377
 
381
378
  unwrap.add(background);
382
379
  unwrap.add(this._markersGroup);
380
+ if (this._source.volumeRange && this._source.volume !== undefined) {
381
+ unwrap.add(this._getVolumeSlider());
382
+ }
383
383
  unwrap.add(this._createTitle(false));
384
384
 
385
385
  return unwrap;
@@ -419,15 +419,6 @@ define([
419
419
  }
420
420
  });
421
421
 
422
- if (this._source.draggable) {
423
- wrap.on('mouseenter', function() {
424
- self._view.setCursor('pointer');
425
- });
426
- wrap.on('mouseout', function() {
427
- self._view.setCursor('default');
428
- });
429
- }
430
-
431
422
  var background = new Konva.Group();
432
423
 
433
424
  background.add(new Konva.Shape({
@@ -439,6 +430,9 @@ define([
439
430
 
440
431
  wrap.add(background);
441
432
  wrap.add(this._markersGroup);
433
+ if (this._source.volumeRange && this._source.volume !== undefined) {
434
+ wrap.add(this._getVolumeSlider());
435
+ }
442
436
  wrap.add(this._createTitle(true));
443
437
 
444
438
  return wrap;
@@ -1031,5 +1025,136 @@ define([
1031
1025
  return markersGroup;
1032
1026
  };
1033
1027
 
1028
+ SourceGroup.prototype._getYFromVolume = function(volume) {
1029
+ return this._borderWidth + (this._height - 2 * this._borderWidth) * (
1030
+ this._source.volumeRange[1] - volume
1031
+ ) / (
1032
+ this._source.volumeRange[1] - this._source.volumeRange[0]
1033
+ );
1034
+ };
1035
+
1036
+ SourceGroup.prototype._getVolumeFromY = function(y) {
1037
+ return this._source.volumeRange[1] - (
1038
+ (y - this._borderWidth) / (this._height - 2 * this._borderWidth)
1039
+ ) * (
1040
+ this._source.volumeRange[1] - this._source.volumeRange[0]
1041
+ );
1042
+ };
1043
+
1044
+ SourceGroup.prototype._getVolumeSlider = function() {
1045
+ if (!this._volumeSliderGroup) {
1046
+ this._volumeSliderGroup = this._createVolumeSlider();
1047
+ }
1048
+
1049
+ return this._volumeSliderGroup;
1050
+ };
1051
+
1052
+ SourceGroup.prototype._createVolumeSlider = function() {
1053
+ var self = this;
1054
+
1055
+ var volumeY = this._getYFromVolume(this._source.volume);
1056
+
1057
+ var volumeGroup = new Konva.Group({
1058
+ x: 0,
1059
+ y: 0,
1060
+ width: this._width,
1061
+ height: this._height
1062
+ });
1063
+
1064
+ var volumeText = new Konva.Text({
1065
+ x: 0,
1066
+ y: volumeY - 20,
1067
+ text: '100%',
1068
+ fontSize: 12,
1069
+ fill: this._source.volumeSliderColor,
1070
+ visible: false
1071
+ });
1072
+
1073
+ var maxTextWidth = volumeText.width();
1074
+ var maxTextHeight = volumeText.height();
1075
+
1076
+ var volumeSliderGroup = new Konva.Group({
1077
+ x: 0,
1078
+ y: volumeY,
1079
+ draggable: true,
1080
+ dragBoundFunc: function(pos) {
1081
+ var y = Math.min(
1082
+ volumeGroup.absolutePosition().y + self._height - self._borderWidth,
1083
+ Math.max(
1084
+ volumeGroup.absolutePosition().y + self._borderWidth,
1085
+ pos.y
1086
+ )
1087
+ );
1088
+
1089
+ var textX = Math.min(
1090
+ volumeGroup.absolutePosition().x + self._width - maxTextWidth - self._borderWidth,
1091
+ Math.max(
1092
+ volumeGroup.absolutePosition().x + self._borderWidth,
1093
+ self._view.getPointerPosition().x - maxTextWidth
1094
+ )
1095
+ );
1096
+ var textY = y - (self._source.volumeSliderWidth / 2) - maxTextHeight;
1097
+
1098
+ volumeText.absolutePosition({
1099
+ x: textX,
1100
+ y: textY < volumeGroup.absolutePosition().y + self._borderWidth ?
1101
+ y + self._source.volumeSliderWidth :
1102
+ textY
1103
+ });
1104
+
1105
+ return { x: this.absolutePosition().x, y: y };
1106
+ }
1107
+ });
1108
+
1109
+ var volumeSliderLine = new Konva.Line({
1110
+ points: [0, 0, this._width, 0],
1111
+ stroke: this._source.volumeSliderColor,
1112
+ strokeWidth: this._source.volumeSliderWidth
1113
+ });
1114
+
1115
+ var volumeSliderRect = new Konva.Rect({
1116
+ x: 0,
1117
+ y: -this._source.volumeSliderDraggingWidth / 2,
1118
+ width: this._width,
1119
+ height: this._source.volumeSliderDraggingWidth,
1120
+ opacity: 0
1121
+ });
1122
+
1123
+ volumeSliderGroup.add(volumeSliderRect);
1124
+ volumeSliderGroup.add(volumeSliderLine);
1125
+
1126
+ volumeSliderGroup.on('dragstart', function() {
1127
+ volumeText.visible(true);
1128
+ });
1129
+
1130
+ volumeSliderGroup.on('dragmove', function() {
1131
+ var volume = self._getVolumeFromY(volumeSliderGroup.y());
1132
+
1133
+ volumeText.text((volume * 100).toFixed(0) + '%');
1134
+
1135
+ self._source.volume = Math.max(self._source.volumeRange[0], Math.min(volume, self._source.volumeRange[1]));
1136
+ self._peaks.emit('source.volumeChanged', self._source);
1137
+
1138
+ self._group.draw();
1139
+ });
1140
+
1141
+ volumeSliderGroup.on('dragend', function() {
1142
+ volumeText.visible(false);
1143
+ });
1144
+
1145
+ volumeSliderGroup.on('mouseover', function() {
1146
+ self._cursor = 'ns-resize';
1147
+ });
1148
+
1149
+ volumeSliderGroup.on('mouseout', function() {
1150
+ self._cursor = null;
1151
+ });
1152
+
1153
+ volumeGroup.add(volumeSliderGroup);
1154
+ volumeGroup.add(volumeText);
1155
+
1156
+ return volumeGroup;
1157
+ };
1158
+
1034
1159
  return SourceGroup;
1035
1160
  });
package/src/source.js CHANGED
@@ -127,6 +127,31 @@ define([
127
127
  );
128
128
  }
129
129
 
130
+ if (Utils.isNullOrUndefined(options.volumeSliderColor)) {
131
+ options.volumeSliderColor = '#000000';
132
+ }
133
+ else if (!Utils.isValidColor(options.volumeSliderColor)) {
134
+ throw new TypeError(
135
+ 'peaks.sources.' + context + ': volumeSliderColor should be a valid CSS color'
136
+ );
137
+ }
138
+
139
+ if (Utils.isNullOrUndefined(options.volumeSliderWidth)) {
140
+ options.volumeSliderWidth = 2;
141
+ }
142
+ else if (!Utils.isNumber(options.volumeSliderWidth)) {
143
+ throw new TypeError('peaks.sources.' + context + ': volumeSliderWidth should be a number');
144
+ }
145
+
146
+ if (Utils.isNullOrUndefined(options.volumeSliderDraggingWidth)) {
147
+ options.volumeSliderDraggingWidth = options.volumeSliderWidth;
148
+ }
149
+ else if (!Utils.isNumber(options.volumeSliderDraggingWidth)) {
150
+ throw new TypeError(
151
+ 'peaks.sources.' + context + ': volumeSliderDraggingWidth should be a number'
152
+ );
153
+ }
154
+
130
155
  if (Utils.isNullOrUndefined(options.textFont)) {
131
156
  options.textFont = 'Arial';
132
157
  }
@@ -267,6 +292,24 @@ define([
267
292
  if (Utils.isNullOrUndefined(options.markerWidth)) {
268
293
  options.markerWidth = 2;
269
294
  }
295
+
296
+ if (!Utils.isNullOrUndefined(options.volumeRange)) {
297
+ if (!Array.isArray(options.volumeRange)
298
+ || options.volumeRange.length !== 2
299
+ || !options.volumeRange.every(Utils.isNumber)) {
300
+ throw new TypeError('peaks.sources.' + context + ': volumeRange must be an array of two numbers');
301
+ }
302
+ else if (options.volumeRange[0] > options.volumeRange[1]) {
303
+ throw new RangeError('peaks.sources.' + context + ': volumeRange[0] should be less than volumeRange[1]');
304
+ }
305
+ }
306
+
307
+ if (!Utils.isNullOrUndefined(options.volume) && !Utils.isNumber(options.volume)) {
308
+ throw new TypeError('peaks.sources.' + context + ': volume must be a number');
309
+ }
310
+ else if (!Utils.isNullOrUndefined(options.volumeRange)) {
311
+ options.volume = Utils.clamp(options.volume, options.volumeRange[0], options.volumeRange[1]);
312
+ }
270
313
  }
271
314
 
272
315
  /**
@@ -292,10 +335,10 @@ define([
292
335
 
293
336
  function Source(peaks, id, originId, elementId, title, url, previewUrl, binaryUrl, kind,
294
337
  subkind, duration, startTime, endTime, mediaStartTime, mediaEndTime, color, backgroundColor,
295
- borderColor, selectedColor, textFont, textFontSize, textColor, textBackgroundColor,
296
- textPosition, textAutoScroll, borderWidth, borderRadius, wrapped, position, draggable, orderable,
297
- resizable, cuttable, deletable, wrapping, previewHeight, binaryHeight, indicators, markers,
298
- markerColor, markerWidth) {
338
+ borderColor, selectedColor, volumeSliderColor, volumeSliderWidth, volumeSliderDraggingWidth,
339
+ textFont, textFontSize, textColor, textBackgroundColor, textPosition, textAutoScroll, borderWidth,
340
+ borderRadius, wrapped, position, draggable, orderable, resizable, cuttable, deletable, wrapping,
341
+ previewHeight, binaryHeight, indicators, markers, markerColor, markerWidth, volume, volumeRange) {
299
342
  var opts = {
300
343
  title: title,
301
344
  url: url,
@@ -316,6 +359,9 @@ define([
316
359
  textFontSize: textFontSize,
317
360
  textColor: textColor,
318
361
  textBackgroundColor: textBackgroundColor,
362
+ volumeSliderColor: volumeSliderColor,
363
+ volumeSliderWidth: volumeSliderWidth,
364
+ volumeSliderDraggingWidth: volumeSliderDraggingWidth,
319
365
  textPosition: textPosition,
320
366
  textAutoScroll: textAutoScroll,
321
367
  borderWidth: borderWidth,
@@ -333,7 +379,9 @@ define([
333
379
  indicators: indicators,
334
380
  markers: markers,
335
381
  markerColor: markerColor,
336
- markerWidth: markerWidth
382
+ markerWidth: markerWidth,
383
+ volume: volume,
384
+ volumeRange: volumeRange
337
385
  };
338
386
 
339
387
  validateSource(peaks, opts, 'add()');
@@ -357,6 +405,9 @@ define([
357
405
  this._backgroundColor = opts.backgroundColor;
358
406
  this._borderColor = opts.borderColor;
359
407
  this._selectedColor = opts.selectedColor || Utils.shadeColor(opts.backgroundColor, 30);
408
+ this._volumeSliderColor = opts.volumeSliderColor;
409
+ this._volumeSliderWidth = opts.volumeSliderWidth;
410
+ this._volumeSliderDraggingWidth = opts.volumeSliderDraggingWidth;
360
411
  this._textFont = opts.textFont;
361
412
  this._textFontSize = opts.textFontSize;
362
413
  this._textColor = opts.textColor;
@@ -379,6 +430,8 @@ define([
379
430
  this._markers = opts.markers;
380
431
  this._markerColor = opts.markerColor;
381
432
  this._markerWidth = opts.markerWidth;
433
+ this._volume = opts.volume;
434
+ this._volumeRange = opts.volumeRange;
382
435
  this._minSize = peaks.options.minSourceSize;
383
436
  this._selected = false;
384
437
  }
@@ -528,6 +581,24 @@ define([
528
581
  this._selectedColor = selectedColor;
529
582
  }
530
583
  },
584
+ volumeSliderColor: {
585
+ enumerable: true,
586
+ get: function() {
587
+ return this._volumeSliderColor;
588
+ }
589
+ },
590
+ volumeSliderWidth: {
591
+ enumerable: true,
592
+ get: function() {
593
+ return this._volumeSliderWidth;
594
+ }
595
+ },
596
+ volumeSliderDraggingWidth: {
597
+ enumerable: true,
598
+ get: function() {
599
+ return this._volumeSliderDraggingWidth;
600
+ }
601
+ },
531
602
  textFont: {
532
603
  enumerable: true,
533
604
  get: function() {
@@ -718,6 +789,22 @@ define([
718
789
  return this._markerWidth;
719
790
  }
720
791
  },
792
+ volume: {
793
+ enumerable: true,
794
+ get: function() {
795
+ return this._volume;
796
+ },
797
+
798
+ set: function(volume) {
799
+ this._volume = volume;
800
+ }
801
+ },
802
+ volumeRange: {
803
+ enumerable: true,
804
+ get: function() {
805
+ return this._volumeRange;
806
+ }
807
+ },
721
808
  minSize: {
722
809
  enumerable: true,
723
810
  get: function() {
@@ -868,6 +955,9 @@ define([
868
955
  backgroundColor: this.backgroundColor,
869
956
  borderColor: this.borderColor,
870
957
  selectedColor: this.selectedColor,
958
+ volumeSliderColor: this.volumeSliderColor,
959
+ volumeSliderWidth: this.volumeSliderWidth,
960
+ volumeSliderDraggingWidth: this.volumeSliderDraggingWidth,
871
961
  textFont: this.textFont,
872
962
  textFontSize: this.textFontSize,
873
963
  textColor: this.textColor,
@@ -889,7 +979,9 @@ define([
889
979
  indicators: this.indicators,
890
980
  markers: this.markers,
891
981
  markerColor: this.markerColor,
892
- markerWidth: this.markerWidth
982
+ markerWidth: this.markerWidth,
983
+ volume: this.volume,
984
+ volumeRange: this.volumeRange
893
985
  };
894
986
 
895
987
  Utils.extend(opts, options);
@@ -911,6 +1003,9 @@ define([
911
1003
  this._backgroundColor = opts.backgroundColor;
912
1004
  this._borderColor = opts.borderColor;
913
1005
  this._selectedColor = opts.selectedColor || Utils.shadeColor(opts.backgroundColor, 30);
1006
+ this._volumeSliderColor = opts.volumeSliderColor;
1007
+ this._volumeSliderWidth = opts.volumeSliderWidth;
1008
+ this._volumeSliderDraggingWidth = opts.volumeSliderDraggingWidth;
914
1009
  this._textFont = opts.textFont;
915
1010
  this._textFontSize = opts.textFontSize;
916
1011
  this._textColor = opts.textColor;
@@ -933,6 +1028,8 @@ define([
933
1028
  this._markers = opts.markers;
934
1029
  this._markerColor = opts.markerColor;
935
1030
  this._markerWidth = opts.markerWidth;
1031
+ this._volume = opts.volume;
1032
+ this._volumeRange = opts.volumeRange;
936
1033
 
937
1034
  this._peaks.emit('source.update', this);
938
1035
  };
@@ -81,6 +81,9 @@ define([
81
81
  backgroundColor: sourceToCut.backgroundColor,
82
82
  borderColor: sourceToCut.borderColor,
83
83
  selectedColor: sourceToCut.selectedColor,
84
+ volumeSliderColor: sourceToCut.volumeSliderColor,
85
+ volumeSliderWidth: sourceToCut.volumeSliderWidth,
86
+ volumeSliderDraggingWidth: sourceToCut.volumeSliderDraggingWidth,
84
87
  textFont: sourceToCut.textFont,
85
88
  textFontSize: sourceToCut.textFontSize,
86
89
  textColor: sourceToCut.textColor,
@@ -101,7 +104,9 @@ define([
101
104
  binaryHeight: sourceToCut.binaryHeight,
102
105
  markers: sourceToCut.markers,
103
106
  markerColor: sourceToCut.markerColor,
104
- markerWidth: sourceToCut.markerWidth
107
+ markerWidth: sourceToCut.markerWidth,
108
+ volume: sourceToCut.volume,
109
+ volumeRange: sourceToCut.volumeRange
105
110
  }])[0];
106
111
 
107
112
  this._peaks.emit('sources.updated', [sourceToCut, newSource]);
@@ -167,6 +172,9 @@ define([
167
172
  options.backgroundColor,
168
173
  options.borderColor,
169
174
  options.selectedColor,
175
+ options.volumeSliderColor,
176
+ options.volumeSliderWidth,
177
+ options.volumeSliderDraggingWidth,
170
178
  options.textFont,
171
179
  options.textFontSize,
172
180
  options.textColor,
@@ -188,7 +196,9 @@ define([
188
196
  options.indicators,
189
197
  options.markers,
190
198
  options.markerColor,
191
- options.markerWidth
199
+ options.markerWidth,
200
+ options.volume,
201
+ options.volumeRange
192
202
  );
193
203
 
194
204
  return source;