@checksub_team/peaks_timeline 1.11.0 → 1.12.1

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.1",
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,22 @@ 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)) {
18695
+ if (!Utils.isNumber(options.volume)) {
18696
+ throw new TypeError('peaks.sources.' + context + ': volume must be a number');
18697
+ } else {
18698
+ options.volume = Utils.clamp(options.volume, options.volumeRange[0], options.volumeRange[1]);
18699
+ }
18700
+ }
18585
18701
  }
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) {
18702
+ 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
18703
  var opts = {
18588
18704
  title: title,
18589
18705
  url: url,
@@ -18604,6 +18720,9 @@ module.exports = function (Utils) {
18604
18720
  textFontSize: textFontSize,
18605
18721
  textColor: textColor,
18606
18722
  textBackgroundColor: textBackgroundColor,
18723
+ volumeSliderColor: volumeSliderColor,
18724
+ volumeSliderWidth: volumeSliderWidth,
18725
+ volumeSliderDraggingWidth: volumeSliderDraggingWidth,
18607
18726
  textPosition: textPosition,
18608
18727
  textAutoScroll: textAutoScroll,
18609
18728
  borderWidth: borderWidth,
@@ -18621,7 +18740,9 @@ module.exports = function (Utils) {
18621
18740
  indicators: indicators,
18622
18741
  markers: markers,
18623
18742
  markerColor: markerColor,
18624
- markerWidth: markerWidth
18743
+ markerWidth: markerWidth,
18744
+ volume: volume,
18745
+ volumeRange: volumeRange
18625
18746
  };
18626
18747
  validateSource(peaks, opts, 'add()');
18627
18748
  this._peaks = peaks;
@@ -18643,6 +18764,9 @@ module.exports = function (Utils) {
18643
18764
  this._backgroundColor = opts.backgroundColor;
18644
18765
  this._borderColor = opts.borderColor;
18645
18766
  this._selectedColor = opts.selectedColor || Utils.shadeColor(opts.backgroundColor, 30);
18767
+ this._volumeSliderColor = opts.volumeSliderColor;
18768
+ this._volumeSliderWidth = opts.volumeSliderWidth;
18769
+ this._volumeSliderDraggingWidth = opts.volumeSliderDraggingWidth;
18646
18770
  this._textFont = opts.textFont;
18647
18771
  this._textFontSize = opts.textFontSize;
18648
18772
  this._textColor = opts.textColor;
@@ -18665,6 +18789,8 @@ module.exports = function (Utils) {
18665
18789
  this._markers = opts.markers;
18666
18790
  this._markerColor = opts.markerColor;
18667
18791
  this._markerWidth = opts.markerWidth;
18792
+ this._volume = opts.volume;
18793
+ this._volumeRange = opts.volumeRange;
18668
18794
  this._minSize = peaks.options.minSourceSize;
18669
18795
  this._selected = false;
18670
18796
  }
@@ -18804,6 +18930,24 @@ module.exports = function (Utils) {
18804
18930
  this._selectedColor = selectedColor;
18805
18931
  }
18806
18932
  },
18933
+ volumeSliderColor: {
18934
+ enumerable: true,
18935
+ get: function () {
18936
+ return this._volumeSliderColor;
18937
+ }
18938
+ },
18939
+ volumeSliderWidth: {
18940
+ enumerable: true,
18941
+ get: function () {
18942
+ return this._volumeSliderWidth;
18943
+ }
18944
+ },
18945
+ volumeSliderDraggingWidth: {
18946
+ enumerable: true,
18947
+ get: function () {
18948
+ return this._volumeSliderDraggingWidth;
18949
+ }
18950
+ },
18807
18951
  textFont: {
18808
18952
  enumerable: true,
18809
18953
  get: function () {
@@ -18981,6 +19125,21 @@ module.exports = function (Utils) {
18981
19125
  return this._markerWidth;
18982
19126
  }
18983
19127
  },
19128
+ volume: {
19129
+ enumerable: true,
19130
+ get: function () {
19131
+ return this._volume;
19132
+ },
19133
+ set: function (volume) {
19134
+ this._volume = volume;
19135
+ }
19136
+ },
19137
+ volumeRange: {
19138
+ enumerable: true,
19139
+ get: function () {
19140
+ return this._volumeRange;
19141
+ }
19142
+ },
18984
19143
  minSize: {
18985
19144
  enumerable: true,
18986
19145
  get: function () {
@@ -19098,6 +19257,9 @@ module.exports = function (Utils) {
19098
19257
  backgroundColor: this.backgroundColor,
19099
19258
  borderColor: this.borderColor,
19100
19259
  selectedColor: this.selectedColor,
19260
+ volumeSliderColor: this.volumeSliderColor,
19261
+ volumeSliderWidth: this.volumeSliderWidth,
19262
+ volumeSliderDraggingWidth: this.volumeSliderDraggingWidth,
19101
19263
  textFont: this.textFont,
19102
19264
  textFontSize: this.textFontSize,
19103
19265
  textColor: this.textColor,
@@ -19119,7 +19281,9 @@ module.exports = function (Utils) {
19119
19281
  indicators: this.indicators,
19120
19282
  markers: this.markers,
19121
19283
  markerColor: this.markerColor,
19122
- markerWidth: this.markerWidth
19284
+ markerWidth: this.markerWidth,
19285
+ volume: this.volume,
19286
+ volumeRange: this.volumeRange
19123
19287
  };
19124
19288
  Utils.extend(opts, options);
19125
19289
  validateSource(this._peaks, opts, 'update()');
@@ -19138,6 +19302,9 @@ module.exports = function (Utils) {
19138
19302
  this._backgroundColor = opts.backgroundColor;
19139
19303
  this._borderColor = opts.borderColor;
19140
19304
  this._selectedColor = opts.selectedColor || Utils.shadeColor(opts.backgroundColor, 30);
19305
+ this._volumeSliderColor = opts.volumeSliderColor;
19306
+ this._volumeSliderWidth = opts.volumeSliderWidth;
19307
+ this._volumeSliderDraggingWidth = opts.volumeSliderDraggingWidth;
19141
19308
  this._textFont = opts.textFont;
19142
19309
  this._textFontSize = opts.textFontSize;
19143
19310
  this._textColor = opts.textColor;
@@ -19160,6 +19327,8 @@ module.exports = function (Utils) {
19160
19327
  this._markers = opts.markers;
19161
19328
  this._markerColor = opts.markerColor;
19162
19329
  this._markerWidth = opts.markerWidth;
19330
+ this._volume = opts.volume;
19331
+ this._volumeRange = opts.volumeRange;
19163
19332
  this._peaks.emit('source.update', this);
19164
19333
  };
19165
19334
  Source.prototype.isVisible = function (startTime, endTime) {
@@ -19968,6 +20137,9 @@ module.exports = function (Source, Utils) {
19968
20137
  backgroundColor: sourceToCut.backgroundColor,
19969
20138
  borderColor: sourceToCut.borderColor,
19970
20139
  selectedColor: sourceToCut.selectedColor,
20140
+ volumeSliderColor: sourceToCut.volumeSliderColor,
20141
+ volumeSliderWidth: sourceToCut.volumeSliderWidth,
20142
+ volumeSliderDraggingWidth: sourceToCut.volumeSliderDraggingWidth,
19971
20143
  textFont: sourceToCut.textFont,
19972
20144
  textFontSize: sourceToCut.textFontSize,
19973
20145
  textColor: sourceToCut.textColor,
@@ -19988,7 +20160,9 @@ module.exports = function (Source, Utils) {
19988
20160
  binaryHeight: sourceToCut.binaryHeight,
19989
20161
  markers: sourceToCut.markers,
19990
20162
  markerColor: sourceToCut.markerColor,
19991
- markerWidth: sourceToCut.markerWidth
20163
+ markerWidth: sourceToCut.markerWidth,
20164
+ volume: sourceToCut.volume,
20165
+ volumeRange: sourceToCut.volumeRange
19992
20166
  }])[0];
19993
20167
  this._peaks.emit('sources.updated', [
19994
20168
  sourceToCut,
@@ -20006,7 +20180,7 @@ module.exports = function (Source, Utils) {
20006
20180
  if (!Utils.isObject(options)) {
20007
20181
  throw new TypeError('peaks.sources.add(): expected a Source object parameter');
20008
20182
  }
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);
20183
+ 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
20184
  return source;
20011
20185
  };
20012
20186
  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,26 @@ 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)) {
308
+ if (!Utils.isNumber(options.volume)) {
309
+ throw new TypeError('peaks.sources.' + context + ': volume must be a number');
310
+ }
311
+ else {
312
+ options.volume = Utils.clamp(options.volume, options.volumeRange[0], options.volumeRange[1]);
313
+ }
314
+ }
270
315
  }
271
316
 
272
317
  /**
@@ -292,10 +337,10 @@ define([
292
337
 
293
338
  function Source(peaks, id, originId, elementId, title, url, previewUrl, binaryUrl, kind,
294
339
  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) {
340
+ borderColor, selectedColor, volumeSliderColor, volumeSliderWidth, volumeSliderDraggingWidth,
341
+ textFont, textFontSize, textColor, textBackgroundColor, textPosition, textAutoScroll, borderWidth,
342
+ borderRadius, wrapped, position, draggable, orderable, resizable, cuttable, deletable, wrapping,
343
+ previewHeight, binaryHeight, indicators, markers, markerColor, markerWidth, volume, volumeRange) {
299
344
  var opts = {
300
345
  title: title,
301
346
  url: url,
@@ -316,6 +361,9 @@ define([
316
361
  textFontSize: textFontSize,
317
362
  textColor: textColor,
318
363
  textBackgroundColor: textBackgroundColor,
364
+ volumeSliderColor: volumeSliderColor,
365
+ volumeSliderWidth: volumeSliderWidth,
366
+ volumeSliderDraggingWidth: volumeSliderDraggingWidth,
319
367
  textPosition: textPosition,
320
368
  textAutoScroll: textAutoScroll,
321
369
  borderWidth: borderWidth,
@@ -333,7 +381,9 @@ define([
333
381
  indicators: indicators,
334
382
  markers: markers,
335
383
  markerColor: markerColor,
336
- markerWidth: markerWidth
384
+ markerWidth: markerWidth,
385
+ volume: volume,
386
+ volumeRange: volumeRange
337
387
  };
338
388
 
339
389
  validateSource(peaks, opts, 'add()');
@@ -357,6 +407,9 @@ define([
357
407
  this._backgroundColor = opts.backgroundColor;
358
408
  this._borderColor = opts.borderColor;
359
409
  this._selectedColor = opts.selectedColor || Utils.shadeColor(opts.backgroundColor, 30);
410
+ this._volumeSliderColor = opts.volumeSliderColor;
411
+ this._volumeSliderWidth = opts.volumeSliderWidth;
412
+ this._volumeSliderDraggingWidth = opts.volumeSliderDraggingWidth;
360
413
  this._textFont = opts.textFont;
361
414
  this._textFontSize = opts.textFontSize;
362
415
  this._textColor = opts.textColor;
@@ -379,6 +432,8 @@ define([
379
432
  this._markers = opts.markers;
380
433
  this._markerColor = opts.markerColor;
381
434
  this._markerWidth = opts.markerWidth;
435
+ this._volume = opts.volume;
436
+ this._volumeRange = opts.volumeRange;
382
437
  this._minSize = peaks.options.minSourceSize;
383
438
  this._selected = false;
384
439
  }
@@ -528,6 +583,24 @@ define([
528
583
  this._selectedColor = selectedColor;
529
584
  }
530
585
  },
586
+ volumeSliderColor: {
587
+ enumerable: true,
588
+ get: function() {
589
+ return this._volumeSliderColor;
590
+ }
591
+ },
592
+ volumeSliderWidth: {
593
+ enumerable: true,
594
+ get: function() {
595
+ return this._volumeSliderWidth;
596
+ }
597
+ },
598
+ volumeSliderDraggingWidth: {
599
+ enumerable: true,
600
+ get: function() {
601
+ return this._volumeSliderDraggingWidth;
602
+ }
603
+ },
531
604
  textFont: {
532
605
  enumerable: true,
533
606
  get: function() {
@@ -718,6 +791,22 @@ define([
718
791
  return this._markerWidth;
719
792
  }
720
793
  },
794
+ volume: {
795
+ enumerable: true,
796
+ get: function() {
797
+ return this._volume;
798
+ },
799
+
800
+ set: function(volume) {
801
+ this._volume = volume;
802
+ }
803
+ },
804
+ volumeRange: {
805
+ enumerable: true,
806
+ get: function() {
807
+ return this._volumeRange;
808
+ }
809
+ },
721
810
  minSize: {
722
811
  enumerable: true,
723
812
  get: function() {
@@ -868,6 +957,9 @@ define([
868
957
  backgroundColor: this.backgroundColor,
869
958
  borderColor: this.borderColor,
870
959
  selectedColor: this.selectedColor,
960
+ volumeSliderColor: this.volumeSliderColor,
961
+ volumeSliderWidth: this.volumeSliderWidth,
962
+ volumeSliderDraggingWidth: this.volumeSliderDraggingWidth,
871
963
  textFont: this.textFont,
872
964
  textFontSize: this.textFontSize,
873
965
  textColor: this.textColor,
@@ -889,7 +981,9 @@ define([
889
981
  indicators: this.indicators,
890
982
  markers: this.markers,
891
983
  markerColor: this.markerColor,
892
- markerWidth: this.markerWidth
984
+ markerWidth: this.markerWidth,
985
+ volume: this.volume,
986
+ volumeRange: this.volumeRange
893
987
  };
894
988
 
895
989
  Utils.extend(opts, options);
@@ -911,6 +1005,9 @@ define([
911
1005
  this._backgroundColor = opts.backgroundColor;
912
1006
  this._borderColor = opts.borderColor;
913
1007
  this._selectedColor = opts.selectedColor || Utils.shadeColor(opts.backgroundColor, 30);
1008
+ this._volumeSliderColor = opts.volumeSliderColor;
1009
+ this._volumeSliderWidth = opts.volumeSliderWidth;
1010
+ this._volumeSliderDraggingWidth = opts.volumeSliderDraggingWidth;
914
1011
  this._textFont = opts.textFont;
915
1012
  this._textFontSize = opts.textFontSize;
916
1013
  this._textColor = opts.textColor;
@@ -933,6 +1030,8 @@ define([
933
1030
  this._markers = opts.markers;
934
1031
  this._markerColor = opts.markerColor;
935
1032
  this._markerWidth = opts.markerWidth;
1033
+ this._volume = opts.volume;
1034
+ this._volumeRange = opts.volumeRange;
936
1035
 
937
1036
  this._peaks.emit('source.update', this);
938
1037
  };
@@ -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;