@checksub_team/peaks_timeline 2.3.0-alpha.0 → 2.3.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/peaks.js CHANGED
@@ -14418,44 +14418,47 @@ WaveformData.createFromAudio = _dereq_("./lib/builders/webaudio");
14418
14418
  module.exports = WaveformData;
14419
14419
 
14420
14420
  },{"./lib/builders/webaudio":81,"./lib/core":83}],86:[function(_dereq_,module,exports){
14421
- module.exports = function (Utils, Konva) {
14421
+ module.exports = function (Utils, Invoker, Konva) {
14422
14422
  'use strict';
14423
14423
  var LEFT_PADDING = 4;
14424
14424
  function Axis(peaks, view, options) {
14425
14425
  this._view = view;
14426
+ this._invoker = new Invoker();
14426
14427
  var self = this;
14427
14428
  peaks.on('playhead.moved', this._onPlayheadMoved.bind(this));
14428
14429
  peaks.on('playhead.hidden', this._onPlayheadHidden.bind(this));
14429
- self._axisGridlineColor = options.axisGridlineColor;
14430
- self._axisLabelColor = options.axisLabelColor;
14431
- self._backLayer = new Konva.Layer({ listening: false });
14432
- self._frontLayer = new Konva.Layer({ listening: false });
14433
- self._axisShape = new Konva.Shape({
14430
+ this._axisGridlineColor = options.axisGridlineColor;
14431
+ this._axisLabelColor = options.axisLabelColor;
14432
+ this._backLayer = new Konva.Layer({ listening: false });
14433
+ this._frontLayer = new Konva.Layer({ listening: false });
14434
+ this._axisShape = new Konva.Shape({
14434
14435
  sceneFunc: function (context) {
14435
14436
  self.drawAxis(context, view);
14436
14437
  }
14437
14438
  });
14438
- self._backLayer.add(self._axisShape);
14439
- self._timesShape = new Konva.Shape({
14439
+ this._backLayer.add(this._axisShape);
14440
+ this._timesShape = new Konva.Shape({
14440
14441
  sceneFunc: function (context) {
14441
14442
  self.drawTimes(context, view);
14442
14443
  }
14443
14444
  });
14444
- self._frontLayer.add(self._timesShape);
14445
+ this._frontLayer.add(this._timesShape);
14446
+ this._throttledBackDraw = this._invoker.throttleTrailing(this._backLayer.batchDraw.bind(this._backLayer));
14447
+ this._throttledFrontDraw = this._invoker.throttleTrailing(this._frontLayer.batchDraw.bind(this._frontLayer));
14445
14448
  }
14446
14449
  Axis.prototype._onPlayheadMoved = function (playheadX, playheadWidth) {
14447
14450
  this._maskStart = playheadX + this._view.getFrameOffset();
14448
14451
  this._maskEnd = playheadX + this._view.getFrameOffset() + playheadWidth;
14449
- this._frontLayer.batchDraw();
14452
+ this._throttledFrontDraw();
14450
14453
  };
14451
14454
  Axis.prototype._onPlayheadHidden = function () {
14452
14455
  this._maskStart = null;
14453
14456
  this._maskEnd = null;
14454
- this._frontLayer.batchDraw();
14457
+ this._throttledFrontDraw();
14455
14458
  };
14456
14459
  Axis.prototype.batchDraw = function () {
14457
- this._backLayer.batchDraw();
14458
- this._frontLayer.batchDraw();
14460
+ this._throttledBackDraw();
14461
+ this._throttledFrontDraw();
14459
14462
  };
14460
14463
  Axis.prototype.addBackToStage = function (stage) {
14461
14464
  stage.add(this._backLayer);
@@ -14559,8 +14562,8 @@ module.exports = function (Utils, Konva) {
14559
14562
  return false;
14560
14563
  };
14561
14564
  return Axis;
14562
- }(_dereq_('../utils'), _dereq_('konva'));
14563
- },{"../utils":116,"konva":43}],87:[function(_dereq_,module,exports){
14565
+ }(_dereq_('../utils'), _dereq_('./invoker'), _dereq_('konva'));
14566
+ },{"../utils":116,"./invoker":90,"konva":43}],87:[function(_dereq_,module,exports){
14564
14567
  module.exports = function (Data, Utils) {
14565
14568
  'use strict';
14566
14569
  function DataRetriever(peaks) {
@@ -15082,7 +15085,7 @@ module.exports = function (SourceGroup, Utils, Konva) {
15082
15085
  LineGroup.prototype.addSource = function (source, sourceGroup, sourcesAround) {
15083
15086
  if (sourceGroup) {
15084
15087
  this._sourcesGroup[source.id] = sourceGroup;
15085
- if (!sourceGroup.isActive()) {
15088
+ if (!sourceGroup.isDragged()) {
15086
15089
  if (!sourceGroup.getParent() || !sourceGroup.isDescendantOf(this._group)) {
15087
15090
  sourceGroup.moveTo(this._group);
15088
15091
  }
@@ -15732,30 +15735,9 @@ module.exports = function (SegmentsGroup, LineGroup, LineIndicator, Utils) {
15732
15735
  }
15733
15736
  this._automaticallyCreatedLineId = automaticallyCreatedLineGroup.getId();
15734
15737
  this._moveSourcesToPositionIfPossible(sources, newLinePosition);
15735
- this._nudgeFrameOffsetYToLineCenter(newLinePosition, this._automaticLineCreationMouseY);
15736
15738
  this._peaks.emit('sources.delayedLineChange', sources);
15737
15739
  }.bind(this), this._peaks.options.automaticLineCreationDelay);
15738
15740
  };
15739
- LineGroups.prototype._nudgeFrameOffsetYToLineCenter = function (linePosition, mouseY) {
15740
- if (!this._peaks.options.enableVerticalScrolling) {
15741
- return;
15742
- }
15743
- if (Utils.isNullOrUndefined(mouseY)) {
15744
- return;
15745
- }
15746
- const lineGroup = this._lineGroupsByPosition[linePosition];
15747
- if (!lineGroup) {
15748
- return;
15749
- }
15750
- const targetCenterY = lineGroup.y() + lineGroup.lineHeight() / 2;
15751
- const deltaY = targetCenterY - mouseY;
15752
- if (deltaY === 0) {
15753
- return;
15754
- }
15755
- const maxOffsetY = Math.max(0, this._view.getFullHeight() - this._view.getHeight());
15756
- const nextOffsetY = Utils.clamp(this._view.getFrameOffsetY() + deltaY, 0, maxOffsetY);
15757
- this._view.updateTimeline(null, nextOffsetY);
15758
- };
15759
15741
  LineGroups.prototype.manageVerticalPosition = function (sources, startTime, endTime, mouseX, mouseY) {
15760
15742
  if (Utils.isNullOrUndefined(mouseX)) {
15761
15743
  return;
@@ -15983,12 +15965,13 @@ module.exports = function (SegmentsGroup, LineGroup, LineIndicator, Utils) {
15983
15965
  return LineGroups;
15984
15966
  }(_dereq_('./segments-group'), _dereq_('./line-group'), _dereq_('./line-indicator'), _dereq_('../utils'));
15985
15967
  },{"../utils":116,"./line-group":91,"./line-indicator":93,"./segments-group":101}],93:[function(_dereq_,module,exports){
15986
- module.exports = function (Konva, SVGs, Utils) {
15968
+ module.exports = function (Konva, SVGs, Invoker, Utils) {
15987
15969
  'use strict';
15988
15970
  function LineIndicator(peaks, view, container) {
15989
15971
  this._peaks = peaks;
15990
15972
  this._view = view;
15991
15973
  this._container = container;
15974
+ this._invoker = new Invoker();
15992
15975
  this._width = this._peaks.options.lineIndicatorWidth;
15993
15976
  this._height = this._view.getHeight();
15994
15977
  this._sizes = {
@@ -16012,6 +15995,7 @@ module.exports = function (Konva, SVGs, Utils) {
16012
15995
  });
16013
15996
  this._layer = new Konva.Layer();
16014
15997
  this._stage.add(this._layer);
15998
+ this._throttledBatchDraw = this._invoker.throttleTrailing(this._layer.batchDraw.bind(this._layer));
16015
15999
  this._indicators = {};
16016
16000
  this._separatingLine = new Konva.Line({
16017
16001
  points: [
@@ -16025,7 +16009,7 @@ module.exports = function (Konva, SVGs, Utils) {
16025
16009
  listening: false
16026
16010
  });
16027
16011
  this._layer.add(this._separatingLine);
16028
- this._layer.batchDraw();
16012
+ this.batchDraw();
16029
16013
  this._isDragging = false;
16030
16014
  this._dragLineId = null;
16031
16015
  this._dragContainerRect = null;
@@ -16043,24 +16027,24 @@ module.exports = function (Konva, SVGs, Utils) {
16043
16027
  ]);
16044
16028
  this.refreshIndicators();
16045
16029
  };
16046
- LineIndicator.prototype._createIndicator = function (lineGroup, type, text, subText) {
16030
+ LineIndicator.prototype._createIndicator = function (lineGroup, type, text, subText, defaultStyle = {}) {
16047
16031
  const indicator = new Konva.Group();
16048
16032
  let indicatorHeight = 0;
16049
16033
  var self = this;
16050
16034
  var textGroup, iconGroup, subTextGroup;
16051
16035
  var textNode, iconNode, subTextNode;
16052
16036
  if (text) {
16053
- [textGroup, textNode] = this._createIndicatorText(text);
16037
+ [textGroup, textNode] = this._createIndicatorText(text, 'line-indicator-text', defaultStyle);
16054
16038
  indicator.add(textGroup);
16055
16039
  indicatorHeight += textGroup.getAttr('trueHeight') + this._topPadding;
16056
16040
  }
16057
- [iconGroup, iconNode] = this._createIndicatorIcon(type);
16041
+ [iconGroup, iconNode] = this._createIndicatorIcon(type, 'line-indicator-icon', defaultStyle);
16058
16042
  iconGroup.y(indicatorHeight);
16059
16043
  indicator.add(iconGroup);
16060
16044
  indicatorHeight += iconGroup.getAttr('trueHeight');
16061
16045
  if (subText) {
16062
16046
  indicatorHeight += this._bottomPadding;
16063
- [subTextGroup, subTextNode] = this._createIndicatorText(subText);
16047
+ [subTextGroup, subTextNode] = this._createIndicatorText(subText, 'line-indicator-subText', defaultStyle);
16064
16048
  subTextGroup.y(indicatorHeight);
16065
16049
  indicator.add(subTextGroup);
16066
16050
  indicatorHeight += subTextGroup.getAttr('trueHeight');
@@ -16141,16 +16125,18 @@ module.exports = function (Konva, SVGs, Utils) {
16141
16125
  indicator.y(lineGroup.y() + (lineGroup.lineHeight() - indicatorHeight) / 2);
16142
16126
  return indicator;
16143
16127
  };
16144
- LineIndicator.prototype._createIndicatorText = function (text) {
16128
+ LineIndicator.prototype._createIndicatorText = function (text, role, defaultStyle = {}) {
16129
+ defaultStyle = defaultStyle[role] || {};
16145
16130
  const textGroup = new Konva.Group();
16146
16131
  const textNode = new Konva.Text({
16147
16132
  text: text,
16148
16133
  fontSize: this._sizes.font,
16149
16134
  fontFamily: this._peaks.options.lineIndicatorFont,
16150
- fill: this._peaks.options.lineIndicatorTextColor,
16135
+ fill: defaultStyle.fill || this._peaks.options.lineIndicatorTextColor,
16151
16136
  align: 'center',
16152
16137
  width: this._width,
16153
- listening: false
16138
+ listening: false,
16139
+ name: role
16154
16140
  });
16155
16141
  textNode.setAttr('defaultColor', this._peaks.options.lineIndicatorTextColor);
16156
16142
  textNode.setAttr('selectedColor', this._peaks.options.lineIndicatorSelectedTextColor);
@@ -16171,7 +16157,8 @@ module.exports = function (Konva, SVGs, Utils) {
16171
16157
  textNode
16172
16158
  ];
16173
16159
  };
16174
- LineIndicator.prototype._createIndicatorIcon = function (type) {
16160
+ LineIndicator.prototype._createIndicatorIcon = function (type, role, defaultStyle = {}) {
16161
+ defaultStyle = defaultStyle[role] || {};
16175
16162
  type = this._types.includes(type) ? type : 'default';
16176
16163
  const iconGroup = new Konva.Group();
16177
16164
  var iconHeight = this._sizes.icon[type];
@@ -16181,21 +16168,23 @@ module.exports = function (Konva, SVGs, Utils) {
16181
16168
  x: this._width / 2,
16182
16169
  y: this._sizes.icon.default / 2,
16183
16170
  radius: this._sizes.icon.default / 2,
16184
- fill: this._peaks.options.lineIndicatorIconColor,
16171
+ fill: defaultStyle.fill || this._peaks.options.lineIndicatorIconColor,
16185
16172
  strokeWidth: 0,
16186
- listening: false
16173
+ listening: false,
16174
+ name: role
16187
16175
  });
16188
16176
  } else {
16189
16177
  iconNode = new Konva.Path({
16190
16178
  x: (this._width - this._sizes.icon[type]) / 2,
16191
16179
  y: 0,
16192
16180
  data: SVGs[type].path,
16193
- fill: this._peaks.options.lineIndicatorIconColor,
16181
+ fill: defaultStyle.fill || this._peaks.options.lineIndicatorIconColor,
16194
16182
  scale: {
16195
16183
  x: this._sizes.icon[type] / SVGs[type].width,
16196
16184
  y: this._sizes.icon[type] / SVGs[type].height
16197
16185
  },
16198
- listening: false
16186
+ listening: false,
16187
+ name: role
16199
16188
  });
16200
16189
  }
16201
16190
  iconNode.setAttr('defaultColor', this._peaks.options.lineIndicatorIconColor);
@@ -16237,11 +16226,11 @@ module.exports = function (Konva, SVGs, Utils) {
16237
16226
  this._peaks.logger('peaks.line-indicator.update(): line indicator not found: ' + line.id);
16238
16227
  return;
16239
16228
  }
16240
- if (indicatorData.type === line.indicatorType && indicatorData.text === line.indicatorText) {
16229
+ if (indicatorData.type === line.indicatorType && indicatorData.text === line.indicatorText && indicatorData.subText === line.indicatorSubText) {
16241
16230
  return;
16242
16231
  }
16243
- this.removeIndicator(line.id, true);
16244
- var indicator = this._createIndicator(indicatorData.lineGroup, line.indicatorType, line.indicatorText, line.indicatorSubText);
16232
+ const styleData = this.removeIndicator(line.id, true);
16233
+ var indicator = this._createIndicator(indicatorData.lineGroup, line.indicatorType, line.indicatorText, line.indicatorSubText, styleData);
16245
16234
  this._layer.add(indicator);
16246
16235
  indicatorData.indicator = indicator;
16247
16236
  indicatorData.type = line.indicatorType;
@@ -16249,17 +16238,40 @@ module.exports = function (Konva, SVGs, Utils) {
16249
16238
  indicatorData.subText = line.indicatorSubText;
16250
16239
  this.batchDraw();
16251
16240
  };
16241
+ LineIndicator.prototype._getStyleData = function (konvaItem) {
16242
+ if (!konvaItem) {
16243
+ return {};
16244
+ }
16245
+ var styleData = {};
16246
+ const name = konvaItem.name();
16247
+ if (name) {
16248
+ styleData[name] = { fill: konvaItem.fill() };
16249
+ }
16250
+ if (typeof konvaItem.getChildren === 'function') {
16251
+ const children = konvaItem.getChildren();
16252
+ if (children && children.length > 0) {
16253
+ children.forEach(function (child) {
16254
+ styleData = Object.assign(styleData, this._getStyleData(child));
16255
+ }.bind(this));
16256
+ }
16257
+ }
16258
+ return styleData;
16259
+ };
16252
16260
  LineIndicator.prototype.removeIndicator = function (lineId, keepInList) {
16261
+ var styleData = {};
16253
16262
  if (this._indicators[lineId]) {
16254
- if (this._indicators[lineId].indicator) {
16255
- this._indicators[lineId].indicator.destroy();
16256
- }
16263
+ const indicator = this._indicators[lineId].indicator;
16257
16264
  if (!keepInList) {
16258
16265
  delete this._indicators[lineId];
16259
16266
  } else {
16260
16267
  this._indicators[lineId].indicator = null;
16268
+ styleData = this._getStyleData(indicator);
16269
+ }
16270
+ if (indicator) {
16271
+ indicator.destroy();
16261
16272
  }
16262
16273
  }
16274
+ return styleData;
16263
16275
  };
16264
16276
  LineIndicator.prototype.refreshIndicator = function (lineId) {
16265
16277
  var anyChange = false;
@@ -16301,7 +16313,7 @@ module.exports = function (Konva, SVGs, Utils) {
16301
16313
  return anyChange;
16302
16314
  };
16303
16315
  LineIndicator.prototype.batchDraw = function () {
16304
- this._layer.batchDraw();
16316
+ this._throttledBatchDraw();
16305
16317
  };
16306
16318
  LineIndicator.prototype._onWindowMove = function (event) {
16307
16319
  if (!this._dragContainerRect) {
@@ -16331,8 +16343,8 @@ module.exports = function (Konva, SVGs, Utils) {
16331
16343
  this._stage.container().style.cursor = 'pointer';
16332
16344
  };
16333
16345
  return LineIndicator;
16334
- }(_dereq_('konva'), _dereq_('./svgs'), _dereq_('../utils'));
16335
- },{"../utils":116,"./svgs":104,"konva":43}],94:[function(_dereq_,module,exports){
16346
+ }(_dereq_('konva'), _dereq_('./svgs'), _dereq_('./invoker'), _dereq_('../utils'));
16347
+ },{"../utils":116,"./invoker":90,"./svgs":104,"konva":43}],94:[function(_dereq_,module,exports){
16336
16348
  module.exports = function (Konva) {
16337
16349
  'use strict';
16338
16350
  var RADIUS = 5;
@@ -16414,7 +16426,7 @@ module.exports = function (DefaultSegmentMarker, Utils, Konva) {
16414
16426
  };
16415
16427
  }(_dereq_('./default-segment-marker'), _dereq_('../utils'), _dereq_('konva'));
16416
16428
  },{"../utils":116,"./default-segment-marker":89,"konva":43}],96:[function(_dereq_,module,exports){
16417
- module.exports = function (SourceGroup, Source, Utils, Konva) {
16429
+ module.exports = function (SourceGroup, Invoker, Source, Utils, Konva) {
16418
16430
  'use strict';
16419
16431
  var TIME_X_OFFSET = 20;
16420
16432
  var TIME_Y_OFFSET = 10;
@@ -16424,9 +16436,11 @@ module.exports = function (SourceGroup, Source, Utils, Konva) {
16424
16436
  this._view = view;
16425
16437
  this._playheadLayer = playheadLayer;
16426
16438
  this._stage = stage;
16439
+ this._invoker = new Invoker();
16427
16440
  this._selectedElements = {};
16428
16441
  this._currentLine = null;
16429
16442
  this._layer = new Konva.Layer({ listening: this._mode !== 'default' });
16443
+ this._throttledBatchDraw = this._invoker.throttleTrailing(this._layer.batchDraw.bind(this._layer));
16430
16444
  this._prepareDefaultMode();
16431
16445
  this._onMouseClickInDefaultMode = this._onMouseClickInDefaultMode.bind(this);
16432
16446
  this._onKeyboardDelete = this._onKeyboardDelete.bind(this);
@@ -16438,6 +16452,9 @@ module.exports = function (SourceGroup, Source, Utils, Konva) {
16438
16452
  this.setMode(initialMode);
16439
16453
  this._peaks.on('handler.sources.destroy', this._onSourcesDestroy.bind(this));
16440
16454
  }
16455
+ ModeLayer.prototype.batchDraw = function () {
16456
+ this._throttledBatchDraw();
16457
+ };
16441
16458
  ModeLayer.prototype._onSourcesDestroy = function (sources) {
16442
16459
  const selectedElementsToDeselect = {};
16443
16460
  sources.forEach(function (source) {
@@ -16599,7 +16616,7 @@ module.exports = function (SourceGroup, Source, Utils, Konva) {
16599
16616
  };
16600
16617
  ModeLayer.prototype._onMouseEnterInCutMode = function () {
16601
16618
  this._cutGroup.visible(true);
16602
- this._layer.batchDraw();
16619
+ this.batchDraw();
16603
16620
  };
16604
16621
  ModeLayer.prototype._updateCursorTime = function (position) {
16605
16622
  var hoveredElement = this._view.getHoveredElement();
@@ -16659,6 +16676,10 @@ module.exports = function (SourceGroup, Source, Utils, Konva) {
16659
16676
  };
16660
16677
  ModeLayer.prototype._onMouseMoveInCutMode = function () {
16661
16678
  var mousePosition = this._stage.getPointerPosition();
16679
+ if (!mousePosition) {
16680
+ return;
16681
+ }
16682
+ this._syncHoveredElementFromPointer();
16662
16683
  mousePosition.x = this._view.timeToPixels(this._view.pixelsToTime(mousePosition.x));
16663
16684
  var cuttingPosition = mousePosition;
16664
16685
  var hoveredElement = this._view.getHoveredElement();
@@ -16671,11 +16692,11 @@ module.exports = function (SourceGroup, Source, Utils, Konva) {
16671
16692
  }
16672
16693
  this._updateCursorTime(cuttingPosition);
16673
16694
  this._updateCuttingLine(cuttingPosition);
16674
- this._layer.batchDraw();
16695
+ this.batchDraw();
16675
16696
  };
16676
16697
  ModeLayer.prototype._onMouseLeaveInCutMode = function () {
16677
16698
  this._cutGroup.visible(false);
16678
- this._layer.batchDraw();
16699
+ this.batchDraw();
16679
16700
  };
16680
16701
  ModeLayer.prototype._onMouseClickInCutMode = function () {
16681
16702
  var mousePosition = this._stage.getPointerPosition();
@@ -16700,14 +16721,36 @@ module.exports = function (SourceGroup, Source, Utils, Konva) {
16700
16721
  }
16701
16722
  cuttingPixel -= hoveredElement.x();
16702
16723
  this._cuttingLine.visible(false);
16703
- this._peaks.cutSource(hoveredElement.getSource(), this._view.pixelsToTime(cuttingPixel));
16704
16724
  this._view.setHoveredElement(null);
16725
+ this._peaks.cutSource(hoveredElement.getSource(), this._view.pixelsToTime(cuttingPixel));
16726
+ this._syncHoveredElementFromPointer();
16705
16727
  this._updateCursorTime(cuttingPosition);
16706
16728
  this._updateCuttingLine(cuttingPosition);
16707
- this._layer.batchDraw();
16729
+ this.batchDraw();
16708
16730
  }
16709
16731
  }
16710
16732
  };
16733
+ ModeLayer.prototype._syncHoveredElementFromPointer = function () {
16734
+ var pointerPos = this._stage.getPointerPosition();
16735
+ if (!pointerPos) {
16736
+ return;
16737
+ }
16738
+ var node = this._stage.getIntersection(pointerPos);
16739
+ while (node) {
16740
+ if (node.attrs && node.attrs.sourceId) {
16741
+ var sourceGroup = this._view.getSourceGroupById(node.attrs.sourceId);
16742
+ if (sourceGroup) {
16743
+ this._view.setHoveredElement(sourceGroup);
16744
+ if (!sourceGroup.isHovered()) {
16745
+ sourceGroup.startHover();
16746
+ }
16747
+ }
16748
+ return;
16749
+ }
16750
+ node = node.getParent ? node.getParent() : null;
16751
+ }
16752
+ this._view.setHoveredElement(null);
16753
+ };
16711
16754
  ModeLayer.prototype.setMode = function (mode) {
16712
16755
  if (this._mode === mode) {
16713
16756
  return;
@@ -16761,15 +16804,15 @@ module.exports = function (SourceGroup, Source, Utils, Konva) {
16761
16804
  return;
16762
16805
  }
16763
16806
  this._mode = mode;
16764
- this._layer.batchDraw();
16807
+ this.batchDraw();
16765
16808
  this._view.batchDrawSourcesLayer();
16766
16809
  };
16767
16810
  ModeLayer.prototype.getCurrentMode = function () {
16768
16811
  return this._mode;
16769
16812
  };
16770
16813
  return ModeLayer;
16771
- }(_dereq_('./source-group'), _dereq_('../models/source'), _dereq_('../utils'), _dereq_('konva'));
16772
- },{"../models/source":112,"../utils":116,"./source-group":102,"konva":43}],97:[function(_dereq_,module,exports){
16814
+ }(_dereq_('./source-group'), _dereq_('./invoker'), _dereq_('../models/source'), _dereq_('../utils'), _dereq_('konva'));
16815
+ },{"../models/source":112,"../utils":116,"./invoker":90,"./source-group":102,"konva":43}],97:[function(_dereq_,module,exports){
16773
16816
  module.exports = function (Konva) {
16774
16817
  'use strict';
16775
16818
  function getMarkerObject(obj) {
@@ -16866,7 +16909,7 @@ module.exports = function (Konva) {
16866
16909
  return MouseDragHandler;
16867
16910
  }(_dereq_('konva'));
16868
16911
  },{"konva":43}],98:[function(_dereq_,module,exports){
16869
- module.exports = function (Utils, Konva) {
16912
+ module.exports = function (Utils, Invoker, Konva) {
16870
16913
  'use strict';
16871
16914
  var HANDLE_RADIUS = 10;
16872
16915
  function PlayheadLayer(peaks, view, lines, showTime) {
@@ -16879,6 +16922,8 @@ module.exports = function (Utils, Konva) {
16879
16922
  this._playheadTextColor = peaks.options.playheadTextColor;
16880
16923
  this._time = null;
16881
16924
  this._playheadLayer = new Konva.Layer();
16925
+ this._invoker = new Invoker();
16926
+ this._throttledBatchDraw = this._invoker.throttleTrailing(this._playheadLayer.batchDraw.bind(this._playheadLayer));
16882
16927
  this._activeSegments = {};
16883
16928
  this._activeSources = {};
16884
16929
  this._createPlayhead(this._playheadColor);
@@ -17001,9 +17046,12 @@ module.exports = function (Utils, Konva) {
17001
17046
  }
17002
17047
  this._time = time;
17003
17048
  if (pixelHasChanged || timeHasChanged) {
17004
- this._playheadLayer.batchDraw();
17049
+ this.batchDraw();
17005
17050
  }
17006
17051
  };
17052
+ PlayheadLayer.prototype.batchDraw = function () {
17053
+ this._throttledBatchDraw();
17054
+ };
17007
17055
  PlayheadLayer.prototype._updatePlayheadPixel = function (time) {
17008
17056
  const pixelIndex = this._view.timeToPixels(time);
17009
17057
  const frameOffset = this._view.timeToPixels(this._view.getTimeOffset());
@@ -17081,12 +17129,12 @@ module.exports = function (Utils, Konva) {
17081
17129
  }
17082
17130
  }
17083
17131
  if (updated) {
17084
- this._playheadLayer.batchDraw();
17132
+ this.batchDraw();
17085
17133
  }
17086
17134
  };
17087
17135
  return PlayheadLayer;
17088
- }(_dereq_('../utils'), _dereq_('konva'));
17089
- },{"../utils":116,"konva":43}],99:[function(_dereq_,module,exports){
17136
+ }(_dereq_('../utils'), _dereq_('./invoker'), _dereq_('konva'));
17137
+ },{"../utils":116,"./invoker":90,"konva":43}],99:[function(_dereq_,module,exports){
17090
17138
  module.exports = function (Konva) {
17091
17139
  'use strict';
17092
17140
  function SegmentMarker(options) {
@@ -18103,8 +18151,9 @@ module.exports = function (WaveformBuilder, WaveformShape, Loader, Invoker, Util
18103
18151
  this._selected = this._source.selected;
18104
18152
  this._hovered = false;
18105
18153
  this._isDragged = false;
18106
- this._isHandleDragging = false;
18154
+ this._isHandleDragged = false;
18107
18155
  this._destroyed = false;
18156
+ this._dragGhost = null;
18108
18157
  this._drawScheduled = false;
18109
18158
  this._previewList = [];
18110
18159
  this._previewBuildQueue = new Set();
@@ -18171,10 +18220,42 @@ module.exports = function (WaveformBuilder, WaveformShape, Loader, Invoker, Util
18171
18220
  SourceGroup.prototype._onHoverEnd = function () {
18172
18221
  this._hovered = false;
18173
18222
  this._manualHover = false;
18223
+ this._disableManualHoverTracking();
18174
18224
  this._view.setHoveredElement(null);
18175
18225
  this._hideButtons();
18176
18226
  this._scheduleBatchDraw();
18177
18227
  };
18228
+ SourceGroup.prototype._enableManualHoverTracking = function () {
18229
+ if (this._manualHoverTrackingEnabled) {
18230
+ return;
18231
+ }
18232
+ if (!this._group || this._destroyed) {
18233
+ return;
18234
+ }
18235
+ var stage = this._group.getStage && this._group.getStage();
18236
+ if (!stage) {
18237
+ return;
18238
+ }
18239
+ this._manualHoverTrackingEnabled = true;
18240
+ this._manualHoverNamespace = '.manualHover.' + this._source.id;
18241
+ this._manualHoverMoveHandler = function () {
18242
+ this._manageManualHoverStop();
18243
+ }.bind(this);
18244
+ stage.on('mousemove' + this._manualHoverNamespace, this._manualHoverMoveHandler);
18245
+ stage.on('touchmove' + this._manualHoverNamespace, this._manualHoverMoveHandler);
18246
+ };
18247
+ SourceGroup.prototype._disableManualHoverTracking = function () {
18248
+ if (!this._manualHoverTrackingEnabled) {
18249
+ return;
18250
+ }
18251
+ var stage = this._group && this._group.getStage && this._group.getStage();
18252
+ if (stage && this._manualHoverNamespace) {
18253
+ stage.off(this._manualHoverNamespace);
18254
+ }
18255
+ this._manualHoverTrackingEnabled = false;
18256
+ this._manualHoverMoveHandler = null;
18257
+ this._manualHoverNamespace = null;
18258
+ };
18178
18259
  SourceGroup.prototype._onDragStart = function (element) {
18179
18260
  this._isDragged = true;
18180
18261
  this._layer.onSourcesGroupDragStart(element);
@@ -18201,7 +18282,10 @@ module.exports = function (WaveformBuilder, WaveformShape, Loader, Invoker, Util
18201
18282
  return this._hovered;
18202
18283
  };
18203
18284
  SourceGroup.prototype.isActive = function () {
18204
- return this._isDragged || this._isHandleDragging;
18285
+ return this._isDragged || this._isHandleDragged;
18286
+ };
18287
+ SourceGroup.prototype.isDragged = function () {
18288
+ return this._isDragged;
18205
18289
  };
18206
18290
  SourceGroup.prototype.addToContent = function (newChild) {
18207
18291
  if (this._source.wrapped) {
@@ -18210,7 +18294,7 @@ module.exports = function (WaveformBuilder, WaveformShape, Loader, Invoker, Util
18210
18294
  this._unwrap.add(newChild);
18211
18295
  }
18212
18296
  };
18213
- SourceGroup.prototype.prepareDragEnd = function () {
18297
+ SourceGroup.prototype._updateHandles = function () {
18214
18298
  var handleWidth = Math.min(this._peaks.options.sourceHandleWidth, this._width / 2);
18215
18299
  this._leftHandle.width(handleWidth);
18216
18300
  this._rightHandle.width(handleWidth);
@@ -18226,7 +18310,7 @@ module.exports = function (WaveformBuilder, WaveformShape, Loader, Invoker, Util
18226
18310
  if (this._layer.manageSourceMovements([this._source], leftHandle ? start + diff + timeOffsetDiff : null, leftHandle ? null : end + diff + timeOffsetDiff)) {
18227
18311
  this._layer.batchDraw();
18228
18312
  }
18229
- }.bind(this));
18313
+ }.bind(this), null, false);
18230
18314
  return {
18231
18315
  x: draggedElement.absolutePosition().x,
18232
18316
  y: draggedElement.absolutePosition().y
@@ -18246,7 +18330,6 @@ module.exports = function (WaveformBuilder, WaveformShape, Loader, Invoker, Util
18246
18330
  if (newTimeToPixelsScale !== this._currentTimeToPixelsScaleUsed) {
18247
18331
  this._currentTimeToPixelsScaleUsed = newTimeToPixelsScale;
18248
18332
  this._updateMarkers();
18249
- this._rightHandle.x(this._width - this._rightHandle.width());
18250
18333
  } else {
18251
18334
  const newTitle = Utils.removeLineBreaks(this._source.getVisibleTitle());
18252
18335
  if (this._wrappedTitle && this._wrappedTitle.text() !== newTitle) {
@@ -18256,11 +18339,16 @@ module.exports = function (WaveformBuilder, WaveformShape, Loader, Invoker, Util
18256
18339
  this._unwrap.add(this._createTitle(false));
18257
18340
  }
18258
18341
  }
18342
+ this._updateHandles();
18259
18343
  this._updateVolumeSlider();
18260
18344
  this._updateButtons();
18261
18345
  this._updateLoadingOverlay();
18262
18346
  this.updatePreviews();
18263
18347
  }
18348
+ if (this._isDragged) {
18349
+ this.createDragGhost();
18350
+ this.updateDragGhost();
18351
+ }
18264
18352
  };
18265
18353
  SourceGroup.prototype.setWrapping = function (wrap, forceCreate, notify) {
18266
18354
  if (wrap) {
@@ -18293,14 +18381,13 @@ module.exports = function (WaveformBuilder, WaveformShape, Loader, Invoker, Util
18293
18381
  start: this._source.startTime,
18294
18382
  end: this._source.endTime
18295
18383
  };
18296
- this._isHandleDragging = true;
18384
+ this._isHandleDragged = true;
18297
18385
  this._hideButtons();
18298
18386
  };
18299
18387
  SourceGroup.prototype._onHandleDragEnd = function () {
18300
- this._isHandleDragging = false;
18388
+ this._isHandleDragged = false;
18301
18389
  this._showButtons();
18302
- this.update();
18303
- this.prepareDragEnd();
18390
+ this._layer.processSourceUpdates([this._source]);
18304
18391
  };
18305
18392
  SourceGroup.prototype._addHandles = function (forceCreate) {
18306
18393
  var self = this;
@@ -18394,9 +18481,8 @@ module.exports = function (WaveformBuilder, WaveformShape, Loader, Invoker, Util
18394
18481
  SourceGroup.prototype.drawSourceShape = function (ctx, shape, addBorderWidth, fill) {
18395
18482
  var offset = addBorderWidth ? this._borderWidth : 0;
18396
18483
  var radius = !Utils.isNullOrUndefined(this._source.borderRadius) ? this._source.borderRadius : Math.max(1, Math.min(this._width / 2, Math.min(CORNER_RADIUS, this._height / 2)));
18397
- var actualX = this._group.x() + this._view.getFrameOffset();
18398
- var x = Math.max(0, this._view.getFrameOffset() - actualX - 2 * radius);
18399
- var width = Math.min(this._width - x, this._view.getWidth() + 4 * radius - Math.max(0, actualX - this._view.getFrameOffset()));
18484
+ var x = Math.max(0, -(this._group.x() + 2 * radius));
18485
+ var width = Math.min(this._width - x, this._view.getWidth() + 4 * radius - Math.max(0, this._group.x()));
18400
18486
  var xWidth = x + width;
18401
18487
  if (width > 0) {
18402
18488
  ctx.beginPath();
@@ -18414,7 +18500,7 @@ module.exports = function (WaveformBuilder, WaveformShape, Loader, Invoker, Util
18414
18500
  var backgroundColor;
18415
18501
  if (this._selected) {
18416
18502
  backgroundColor = this._source.selectedBackgroundColor;
18417
- } else if (this._hovered) {
18503
+ } else if (this._hovered && this._view.getCurrentMode() !== 'cut') {
18418
18504
  backgroundColor = this._source.hoverBackgroundColor;
18419
18505
  } else {
18420
18506
  backgroundColor = this._source.backgroundColor;
@@ -18610,6 +18696,7 @@ module.exports = function (WaveformBuilder, WaveformShape, Loader, Invoker, Util
18610
18696
  };
18611
18697
  SourceGroup.prototype.startHover = function () {
18612
18698
  this._manualHover = true;
18699
+ this._enableManualHoverTracking();
18613
18700
  this._group.fire('mouseenter', { evt: new MouseEvent('mouseenter') }, true);
18614
18701
  };
18615
18702
  SourceGroup.prototype.stopHover = function () {
@@ -18617,6 +18704,11 @@ module.exports = function (WaveformBuilder, WaveformShape, Loader, Invoker, Util
18617
18704
  };
18618
18705
  SourceGroup.prototype.setDragging = function (isDragging) {
18619
18706
  this._isDragged = isDragging;
18707
+ if (isDragging) {
18708
+ this.createDragGhost();
18709
+ } else {
18710
+ this.destroyDragGhost();
18711
+ }
18620
18712
  };
18621
18713
  SourceGroup.prototype.startDrag = function () {
18622
18714
  return this._group.startDrag();
@@ -18754,12 +18846,14 @@ module.exports = function (WaveformBuilder, WaveformShape, Loader, Invoker, Util
18754
18846
  });
18755
18847
  }
18756
18848
  }
18849
+ var self = this;
18757
18850
  var waveform = new WaveformShape({
18758
- layer: this._layer,
18759
18851
  view: this._view,
18760
- source: this._source,
18852
+ color: this._source.color,
18761
18853
  height: preview.group.height(),
18762
- url: url
18854
+ waveformDataFunc: function () {
18855
+ return self._createWaveformPointsIterator(url);
18856
+ }
18763
18857
  });
18764
18858
  preview.group.add(waveform);
18765
18859
  this._addToUnwrap(preview.group);
@@ -18768,6 +18862,69 @@ module.exports = function (WaveformBuilder, WaveformShape, Loader, Invoker, Util
18768
18862
  }
18769
18863
  this._previewList.push(preview);
18770
18864
  };
18865
+ SourceGroup.prototype._createWaveformPointsIterator = function (url) {
18866
+ var loaded = this._layer.getLoadedData(url + '-scaled');
18867
+ var waveformData = loaded && loaded.data;
18868
+ if (!waveformData) {
18869
+ return {
18870
+ next: function () {
18871
+ return { done: true };
18872
+ }
18873
+ };
18874
+ }
18875
+ var view = this._view;
18876
+ var source = this._source;
18877
+ var groupX = this._group && typeof this._group.x === 'function' ? this._group.x() : 0;
18878
+ var groupWidth = this._width;
18879
+ var viewWidth = view.getWidth();
18880
+ var startPixel = 0;
18881
+ var startOffset = 0;
18882
+ var endPixel = Math.min(viewWidth, waveformData.length);
18883
+ var targetSpeed = 1;
18884
+ if (source) {
18885
+ targetSpeed = source.targetSpeed || 1;
18886
+ var hiddenLeftPixels = Math.max(-groupX, 0);
18887
+ var hiddenRightPixels = Math.max(groupX + groupWidth - viewWidth, 0);
18888
+ startPixel = Math.floor((view.timeToPixels(source.mediaStartTime) + hiddenLeftPixels) * targetSpeed);
18889
+ startOffset = view.timeToPixels(source.mediaStartTime);
18890
+ endPixel = Math.min(Math.ceil((view.timeToPixels(source.mediaEndTime) - hiddenRightPixels) * targetSpeed), waveformData.length);
18891
+ }
18892
+ if (startPixel < 0) {
18893
+ startPixel = 0;
18894
+ }
18895
+ if (endPixel < startPixel) {
18896
+ endPixel = startPixel;
18897
+ }
18898
+ var channels = waveformData.channels;
18899
+ var channelData = new Array(channels);
18900
+ for (var c = 0; c < channels; c++) {
18901
+ channelData[c] = waveformData.channel(c);
18902
+ }
18903
+ var x = startPixel;
18904
+ return {
18905
+ next: function () {
18906
+ if (x >= endPixel) {
18907
+ return { done: true };
18908
+ }
18909
+ var min = new Array(channels);
18910
+ var max = new Array(channels);
18911
+ for (var i = 0; i < channels; i++) {
18912
+ min[i] = channelData[i].min_sample(x);
18913
+ max[i] = channelData[i].max_sample(x);
18914
+ }
18915
+ var value = {
18916
+ x: x / targetSpeed - startOffset + 0.5,
18917
+ min: min,
18918
+ max: max
18919
+ };
18920
+ x++;
18921
+ return {
18922
+ done: false,
18923
+ value: value
18924
+ };
18925
+ }
18926
+ };
18927
+ };
18771
18928
  SourceGroup.prototype.getAudioPreview = function () {
18772
18929
  return this._previewList.filter(function (preview) {
18773
18930
  return preview.type === 'audio';
@@ -18998,6 +19155,65 @@ module.exports = function (WaveformBuilder, WaveformShape, Loader, Invoker, Util
18998
19155
  SourceGroup.prototype.getCurrentHeight = function () {
18999
19156
  return this._height;
19000
19157
  };
19158
+ SourceGroup.prototype.createDragGhost = function () {
19159
+ if (this._dragGhost) {
19160
+ return this._dragGhost;
19161
+ }
19162
+ var frameOffset = this._view.getFrameOffset();
19163
+ var x = this._view.timeToPixels(this._source.startTime) - frameOffset;
19164
+ var width = this._view.timeToPixels(this._source.endTime - this._source.startTime);
19165
+ var height = this.getCurrentHeight();
19166
+ var y = this.getAbsoluteY();
19167
+ this._dragGhost = new Konva.Rect({
19168
+ x: x,
19169
+ y: y,
19170
+ width: width,
19171
+ height: height,
19172
+ fill: this._source.backgroundColor,
19173
+ opacity: 0.4,
19174
+ stroke: this._source.selectedBorderColor,
19175
+ strokeWidth: 2,
19176
+ dash: [
19177
+ 8,
19178
+ 4
19179
+ ],
19180
+ cornerRadius: 8,
19181
+ listening: false
19182
+ });
19183
+ this._layer.add(this._dragGhost);
19184
+ this._dragGhost.moveToBottom();
19185
+ this.updateDragGhost();
19186
+ return this._dragGhost;
19187
+ };
19188
+ SourceGroup.prototype.updateDragGhost = function (lineGroupsById) {
19189
+ if (!this._dragGhost) {
19190
+ return;
19191
+ }
19192
+ if (!lineGroupsById && this._layer && typeof this._layer.getLineGroups === 'function') {
19193
+ var lineGroups = this._layer.getLineGroups();
19194
+ if (lineGroups && typeof lineGroups.getLineGroupsById === 'function') {
19195
+ lineGroupsById = lineGroups.getLineGroupsById();
19196
+ }
19197
+ }
19198
+ var frameOffset = this._view.getFrameOffset();
19199
+ var x = this._view.timeToPixels(this._source.startTime) - frameOffset;
19200
+ var width = this._view.timeToPixels(this._source.endTime - this._source.startTime);
19201
+ this._dragGhost.x(x);
19202
+ this._dragGhost.width(width);
19203
+ this._dragGhost.height(this.getCurrentHeight());
19204
+ if (lineGroupsById) {
19205
+ var lineGroup = lineGroupsById[this._source.lineId];
19206
+ if (lineGroup) {
19207
+ this._dragGhost.y(lineGroup.y());
19208
+ }
19209
+ }
19210
+ };
19211
+ SourceGroup.prototype.destroyDragGhost = function () {
19212
+ if (this._dragGhost) {
19213
+ this._dragGhost.destroy();
19214
+ this._dragGhost = null;
19215
+ }
19216
+ };
19001
19217
  SourceGroup.prototype.getHeights = function () {
19002
19218
  return {
19003
19219
  unwrapped: this._unwrappedHeight,
@@ -19365,18 +19581,21 @@ module.exports = function (WaveformBuilder, WaveformShape, Loader, Invoker, Util
19365
19581
  });
19366
19582
  volumeSliderGroup.add(volumeSliderRect);
19367
19583
  volumeSliderGroup.add(volumeSliderLine);
19368
- volumeSliderGroup.on('dragstart', function () {
19584
+ volumeSliderGroup.on('dragstart', function (evt) {
19585
+ evt.cancelBubble = true;
19369
19586
  volumeText.visible(true);
19370
19587
  self._peaks.emit('source.startVolumeChange', self._source);
19371
19588
  });
19372
- volumeSliderGroup.on('dragmove', function () {
19589
+ volumeSliderGroup.on('dragmove', function (evt) {
19590
+ evt.cancelBubble = true;
19373
19591
  var volume = self._getVolumeFromY(volumeSliderGroup.y());
19374
19592
  volumeText.text((volume * 100).toFixed(0) + '%');
19375
19593
  self._source.volume = Math.max(self._source.volumeRange[0], Math.min(volume, self._source.volumeRange[1]));
19376
19594
  self._peaks.emit('source.volumeChanged', self._source);
19377
19595
  self._scheduleBatchDraw();
19378
19596
  });
19379
- volumeSliderGroup.on('dragend', function () {
19597
+ volumeSliderGroup.on('dragend', function (evt) {
19598
+ evt.cancelBubble = true;
19380
19599
  volumeText.visible(false);
19381
19600
  self._peaks.emit('source.endVolumeChange', self._source);
19382
19601
  });
@@ -19391,6 +19610,8 @@ module.exports = function (WaveformBuilder, WaveformShape, Loader, Invoker, Util
19391
19610
  return volumeGroup;
19392
19611
  };
19393
19612
  SourceGroup.prototype.destroy = function () {
19613
+ this.destroyDragGhost();
19614
+ this._disableManualHoverTracking();
19394
19615
  if (this._pendingIdleCallbacks) {
19395
19616
  this._pendingIdleCallbacks.forEach(function (id) {
19396
19617
  Utils.cancelIdle(id);
@@ -19432,10 +19653,11 @@ module.exports = function (SourceGroup, LineGroups, DataRetriever, Invoker, Util
19432
19653
  this._allowEditing = allowEditing;
19433
19654
  this._sourcesGroup = {};
19434
19655
  this._layer = new Konva.Layer();
19435
- this._dragLayer = new Konva.Layer();
19436
19656
  this._dataRetriever = new DataRetriever(peaks);
19437
19657
  this._lineGroups = new LineGroups(peaks, view, this);
19438
19658
  this._lineGroups.addToLayer(this);
19659
+ this._dragGroup = new Konva.Group({ listening: false });
19660
+ this._layer.add(this._dragGroup);
19439
19661
  this._loadedData = {};
19440
19662
  this._invoker = new Invoker();
19441
19663
  this._rescaleVersion = 0;
@@ -19454,7 +19676,7 @@ module.exports = function (SourceGroup, LineGroups, DataRetriever, Invoker, Util
19454
19676
  this._peaks.on('sources.delayedLineChange', this._onSourcesDelayedLineChanged.bind(this));
19455
19677
  }
19456
19678
  SourcesLayer.prototype._onSourcesDelayedLineChanged = function () {
19457
- if (this._dragGhosts && this._draggedElements && this._draggedElements.length > 0) {
19679
+ if (this._draggedElements && this._draggedElements.length > 0) {
19458
19680
  this._dragSourcesGroup();
19459
19681
  }
19460
19682
  };
@@ -19478,10 +19700,12 @@ module.exports = function (SourceGroup, LineGroups, DataRetriever, Invoker, Util
19478
19700
  };
19479
19701
  SourcesLayer.prototype.add = function (element) {
19480
19702
  this._layer.add(element);
19703
+ if (this._dragGroup) {
19704
+ this._dragGroup.moveToTop();
19705
+ }
19481
19706
  };
19482
19707
  SourcesLayer.prototype.addToStage = function (stage) {
19483
19708
  stage.add(this._layer);
19484
- stage.add(this._dragLayer);
19485
19709
  };
19486
19710
  SourcesLayer.prototype.enableEditing = function (enable) {
19487
19711
  this._allowEditing = enable;
@@ -19502,19 +19726,19 @@ module.exports = function (SourceGroup, LineGroups, DataRetriever, Invoker, Util
19502
19726
  const frameEndTime = this._view.pixelsToTime(frameOffset + width);
19503
19727
  var redraw = false;
19504
19728
  var isSourceGroupHovered = false;
19505
- var isSourceGroupActive = false;
19729
+ var isSourceGroupDragged = false;
19506
19730
  if (sourceGroup) {
19507
19731
  isSourceGroupHovered = sourceGroup.isHovered();
19508
- isSourceGroupActive = sourceGroup.isActive();
19732
+ isSourceGroupDragged = sourceGroup.isDragged();
19509
19733
  this._destroySourceGroup(source);
19510
19734
  redraw = true;
19511
19735
  }
19512
- if (source.isVisible(frameStartTime, frameEndTime) || isSourceGroupActive) {
19736
+ if (source.isVisible(frameStartTime, frameEndTime) || isSourceGroupDragged) {
19513
19737
  const newSourceGroup = this._addSourceGroup(source);
19514
19738
  if (isSourceGroupHovered) {
19515
19739
  newSourceGroup.startHover();
19516
19740
  }
19517
- if (isSourceGroupActive) {
19741
+ if (isSourceGroupDragged) {
19518
19742
  newSourceGroup.startDrag();
19519
19743
  }
19520
19744
  redraw = true;
@@ -19651,7 +19875,6 @@ module.exports = function (SourceGroup, LineGroups, DataRetriever, Invoker, Util
19651
19875
  draggable: true
19652
19876
  });
19653
19877
  var self = this;
19654
- this._dragGhosts = [];
19655
19878
  this._initialSourcePositions = {};
19656
19879
  this._draggedElements.forEach(function (source) {
19657
19880
  self._initialSourcePositions[source.id] = {
@@ -19663,34 +19886,20 @@ module.exports = function (SourceGroup, LineGroups, DataRetriever, Invoker, Util
19663
19886
  if (sourceGroup) {
19664
19887
  sourceGroup.setDragging(true);
19665
19888
  var absoluteY = sourceGroup.getAbsoluteY();
19666
- sourceGroup.moveTo(self._dragLayer);
19889
+ sourceGroup.moveTo(self._dragGroup);
19667
19890
  sourceGroup.y(absoluteY);
19668
- var ghost = self._createDragGhost(sourceGroup);
19669
- self._dragGhosts.push({
19670
- ghost: ghost,
19671
- sourceId: source.id
19672
- });
19673
19891
  }
19674
19892
  });
19675
19893
  };
19676
19894
  SourcesLayer.prototype.onSourcesGroupDragEnd = function () {
19677
- if (this._dragGhosts) {
19678
- this._dragGhosts.forEach(function (item) {
19679
- if (item.ghost) {
19680
- item.ghost.destroy();
19681
- }
19682
- });
19683
- this._dragGhosts = null;
19684
- }
19895
+ var self = this;
19685
19896
  this._initialSourcePositions = null;
19686
19897
  this._dragOffsetX = undefined;
19687
19898
  this._dragOffsetY = undefined;
19688
- var self = this;
19689
19899
  const updatedSources = this._draggedElements.map(function (source) {
19690
19900
  const sourceGroup = self._sourcesGroup[source.id];
19691
19901
  if (sourceGroup) {
19692
19902
  sourceGroup.setDragging(false);
19693
- sourceGroup.prepareDragEnd();
19694
19903
  self._lineGroups.addSource(source, sourceGroup);
19695
19904
  sourceGroup.y(0);
19696
19905
  }
@@ -19698,13 +19907,11 @@ module.exports = function (SourceGroup, LineGroups, DataRetriever, Invoker, Util
19698
19907
  });
19699
19908
  this._draggedElementId = null;
19700
19909
  this.refresh();
19701
- this._view.batchDrawSourcesLayer();
19702
- this._view.updateTimelineLength();
19703
- this._peaks.emit('sources.updated', updatedSources);
19910
+ this.processSourceUpdates(updatedSources);
19704
19911
  };
19705
19912
  SourcesLayer.prototype.onSourcesGroupDrag = function (draggedElement) {
19706
19913
  var pointerPos = this._view.getPointerPosition();
19707
- this._view.updateWithAutoScroll(this._dragSourcesGroup.bind(this));
19914
+ this._view.updateWithAutoScroll(this._dragSourcesGroup.bind(this), null, true);
19708
19915
  var clickedSourceGroup = this._sourcesGroup[this._draggedElementId];
19709
19916
  if (clickedSourceGroup) {
19710
19917
  var mouseX = pointerPos.x;
@@ -19766,12 +19973,15 @@ module.exports = function (SourceGroup, LineGroups, DataRetriever, Invoker, Util
19766
19973
  var newStartTime = Utils.roundTime(initialStartTime + timeOffsetDiff + timeDiff);
19767
19974
  var newEndTime = Utils.roundTime(initialEndTime + timeOffsetDiff + timeDiff);
19768
19975
  const shouldRedraw = this.manageSourceMovements(this._draggedElements, newStartTime, newEndTime, orderable, mousePosX, mousePosY);
19769
- this._updateDragGhosts();
19770
19976
  if (shouldRedraw) {
19771
19977
  this.batchDraw();
19772
- this._dragLayer.batchDraw();
19773
19978
  }
19774
19979
  };
19980
+ SourcesLayer.prototype.processSourceUpdates = function (updatedSources) {
19981
+ this._view.batchDrawSourcesLayer();
19982
+ this._view.updateTimelineLength();
19983
+ this._peaks.emit('sources.updated', updatedSources);
19984
+ };
19775
19985
  SourcesLayer.prototype.findSources = function (startTime, endTime) {
19776
19986
  var sources = this._peaks.sourceHandler.find(startTime, endTime);
19777
19987
  var lineIds = this._lineGroups.getVisibleLines();
@@ -19779,54 +19989,6 @@ module.exports = function (SourceGroup, LineGroups, DataRetriever, Invoker, Util
19779
19989
  return lineIds[source.lineId];
19780
19990
  });
19781
19991
  };
19782
- SourcesLayer.prototype._createDragGhost = function (sourceGroup) {
19783
- var source = sourceGroup.getSource();
19784
- var frameOffset = this._view.getFrameOffset();
19785
- var x = this._view.timeToPixels(source.startTime) - frameOffset;
19786
- var width = this._view.timeToPixels(source.endTime - source.startTime);
19787
- var height = sourceGroup.getCurrentHeight();
19788
- var y = sourceGroup.getAbsoluteY();
19789
- var ghost = new Konva.Rect({
19790
- x: x,
19791
- y: y,
19792
- width: width,
19793
- height: height,
19794
- fill: source.backgroundColor,
19795
- opacity: 0.4,
19796
- stroke: source.selectedBorderColor,
19797
- strokeWidth: 2,
19798
- dash: [
19799
- 8,
19800
- 4
19801
- ],
19802
- cornerRadius: 8,
19803
- listening: false
19804
- });
19805
- this._layer.add(ghost);
19806
- ghost.moveToBottom();
19807
- return ghost;
19808
- };
19809
- SourcesLayer.prototype._updateDragGhosts = function () {
19810
- if (!this._dragGhosts) {
19811
- return;
19812
- }
19813
- var self = this;
19814
- var frameOffset = this._view.getFrameOffset();
19815
- var lineGroupsById = this._lineGroups.getLineGroupsById();
19816
- this._dragGhosts.forEach(function (item) {
19817
- var sourceGroup = self._sourcesGroup[item.sourceId];
19818
- if (!sourceGroup || !item.ghost) {
19819
- return;
19820
- }
19821
- var sourceData = sourceGroup.getSource();
19822
- var x = self._view.timeToPixels(sourceData.startTime) - frameOffset;
19823
- item.ghost.x(x);
19824
- var lineGroup = lineGroupsById[sourceData.lineId];
19825
- if (lineGroup) {
19826
- item.ghost.y(lineGroup.y());
19827
- }
19828
- });
19829
- };
19830
19992
  SourcesLayer.prototype._updateSourceTimesDuringDrag = function (newStartTime) {
19831
19993
  if (!this._initialSourcePositions || !this._draggedElements) {
19832
19994
  return;
@@ -19919,13 +20081,8 @@ module.exports = function (SourceGroup, LineGroups, DataRetriever, Invoker, Util
19919
20081
  if (isDraggedSource) {
19920
20082
  sourceGroup.setDragging(true);
19921
20083
  var absoluteY = sourceGroup.getAbsoluteY();
19922
- sourceGroup.moveTo(this._dragLayer);
20084
+ sourceGroup.moveTo(this._dragGroup);
19923
20085
  sourceGroup.y(absoluteY);
19924
- var ghost = this._createDragGhost(sourceGroup);
19925
- this._dragGhosts.push({
19926
- ghost: ghost,
19927
- sourceId: source.id
19928
- });
19929
20086
  }
19930
20087
  }
19931
20088
  return sourceGroup;
@@ -19935,7 +20092,9 @@ module.exports = function (SourceGroup, LineGroups, DataRetriever, Invoker, Util
19935
20092
  for (var sourceId in this._sourcesGroup) {
19936
20093
  if (Utils.objectHasProperty(this._sourcesGroup, sourceId)) {
19937
20094
  var sourceGroup = this._sourcesGroup[sourceId];
19938
- if (!sourceGroup.isActive()) {
20095
+ if (sourceGroup.isActive()) {
20096
+ sourceGroup.update();
20097
+ } else {
19939
20098
  var source = this._sourcesGroup[sourceId].getSource();
19940
20099
  if (!this._isSourceVisible(source, startTime, endTime)) {
19941
20100
  this._destroySourceGroup(source);
@@ -20342,83 +20501,104 @@ module.exports = function (Utils, Konva) {
20342
20501
  return height - Utils.clamp(height - scaledAmplitude, 0, height);
20343
20502
  }
20344
20503
  function WaveformShape(options) {
20345
- const shape = new Konva.Shape({ fill: options.source.color });
20504
+ const shape = new Konva.Shape({
20505
+ fill: options.color,
20506
+ listening: false
20507
+ });
20346
20508
  Object.assign(this, shape);
20347
- this._layer = options.layer;
20348
20509
  this._view = options.view;
20349
- this._source = options.source;
20350
20510
  this._height = options.height;
20351
- this._url = options.url + '-scaled';
20352
- this.sceneFunc(this._sceneFunc);
20353
- this.hitFunc(this._waveformShapeHitFunc);
20511
+ this._waveformDataFunc = options.waveformDataFunc;
20512
+ this.sceneFunc(function (context) {
20513
+ var waveformPoints = this._waveformDataFunc ? this._waveformDataFunc() : null;
20514
+ this._sceneFunc(context, waveformPoints);
20515
+ });
20354
20516
  }
20355
20517
  WaveformShape.prototype = Object.create(Konva.Shape.prototype);
20356
- WaveformShape.prototype._sceneFunc = function (context) {
20357
- var width = this._view.getWidth();
20358
- var waveformData = this._layer.getLoadedData(this._url).data;
20359
- var startPixel = 0, startOffset = 0, endPixel = width, targetSpeed = 1;
20360
- if (this._source) {
20361
- targetSpeed = this._source.targetSpeed || 1;
20362
- startPixel = Math.floor((this._view.timeToPixels(this._source.mediaStartTime) + Math.max(this._view.getFrameOffset() - this._view.timeToPixels(this._source.startTime), 0)) * targetSpeed);
20363
- startOffset = this._view.timeToPixels(this._source.mediaStartTime);
20364
- endPixel = Math.min(Math.ceil((this._view.timeToPixels(this._source.mediaEndTime) - Math.max(this._view.timeToPixels(this._source.endTime) - this._view.getFrameOffset() - this._view.getWidth(), 0)) * targetSpeed), waveformData.length);
20518
+ WaveformShape.prototype._sceneFunc = function (context, waveformPoints) {
20519
+ if (!waveformPoints) {
20520
+ return;
20521
+ }
20522
+ var xPoints = [];
20523
+ var minByChannel = [];
20524
+ var maxByChannel = [];
20525
+ var channels = 0;
20526
+ this._forEachWaveformPoint(waveformPoints, function (point) {
20527
+ if (!point || !point.min || !point.max) {
20528
+ return;
20529
+ }
20530
+ if (channels === 0) {
20531
+ channels = point.min.length;
20532
+ for (var c = 0; c < channels; c++) {
20533
+ minByChannel[c] = [];
20534
+ maxByChannel[c] = [];
20535
+ }
20536
+ }
20537
+ xPoints.push(point.x);
20538
+ for (var i = 0; i < channels; i++) {
20539
+ minByChannel[i].push(point.min[i]);
20540
+ maxByChannel[i].push(point.max[i]);
20541
+ }
20542
+ });
20543
+ if (channels === 0 || xPoints.length === 0) {
20544
+ return;
20365
20545
  }
20366
- this._drawWaveform(context, waveformData, startPixel, startOffset, endPixel, targetSpeed, this._height);
20546
+ this._drawWaveformFromPoints(context, xPoints, minByChannel, maxByChannel, channels, this._height);
20367
20547
  };
20368
- WaveformShape.prototype._drawWaveform = function (context, waveformData, startPixel, startOffset, endPixel, targetSpeed, height) {
20369
- var channels = waveformData.channels;
20548
+ WaveformShape.prototype._forEachWaveformPoint = function (waveformPoints, callback) {
20549
+ if (!waveformPoints) {
20550
+ return;
20551
+ }
20552
+ if (typeof waveformPoints.next === 'function') {
20553
+ while (true) {
20554
+ var result = waveformPoints.next();
20555
+ if (!result || result.done) {
20556
+ break;
20557
+ }
20558
+ callback(result.value);
20559
+ }
20560
+ return;
20561
+ }
20562
+ if (typeof Symbol !== 'undefined' && waveformPoints[Symbol.iterator]) {
20563
+ var iterator = waveformPoints[Symbol.iterator]();
20564
+ while (true) {
20565
+ var iterResult = iterator.next();
20566
+ if (iterResult.done) {
20567
+ break;
20568
+ }
20569
+ callback(iterResult.value);
20570
+ }
20571
+ return;
20572
+ }
20573
+ if (Array.isArray(waveformPoints)) {
20574
+ for (var i = 0; i < waveformPoints.length; i++) {
20575
+ callback(waveformPoints[i]);
20576
+ }
20577
+ }
20578
+ };
20579
+ WaveformShape.prototype._drawWaveformFromPoints = function (context, xPoints, minByChannel, maxByChannel, channels, height) {
20370
20580
  var waveformTop = 0;
20371
20581
  var waveformHeight = Math.floor(height / channels);
20372
20582
  for (var i = 0; i < channels; i++) {
20373
20583
  if (i === channels - 1) {
20374
20584
  waveformHeight = height - (channels - 1) * waveformHeight;
20375
20585
  }
20376
- this._drawChannel(context, waveformData.channel(i), startPixel, startOffset, endPixel, waveformTop, waveformHeight, targetSpeed);
20586
+ this._drawChannelFromPoints(context, xPoints, minByChannel[i], maxByChannel[i], waveformTop, waveformHeight);
20377
20587
  waveformTop += waveformHeight;
20378
20588
  }
20379
20589
  };
20380
- WaveformShape.prototype._drawChannel = function (context, channel, startPixel, startOffset, endPixel, top, height, targetSpeed) {
20381
- var x, val;
20590
+ WaveformShape.prototype._drawChannelFromPoints = function (context, xPoints, minValues, maxValues, top, height) {
20382
20591
  var amplitudeScale = this._view.getAmplitudeScale();
20383
20592
  context.beginPath();
20384
- for (x = startPixel; x < endPixel; x++) {
20385
- val = channel.min_sample(x);
20386
- context.lineTo(x / targetSpeed - startOffset + 0.5, top + scaleY(val, height, amplitudeScale) + 0.5);
20593
+ for (var i = 0; i < xPoints.length; i++) {
20594
+ context.lineTo(xPoints[i], top + scaleY(minValues[i], height, amplitudeScale) + 0.5);
20387
20595
  }
20388
- for (x = endPixel - 1; x >= startPixel; x--) {
20389
- val = channel.max_sample(x);
20390
- context.lineTo(x / targetSpeed - startOffset + 0.5, top + scaleY(val, height, amplitudeScale) + 0.5);
20596
+ for (var j = xPoints.length - 1; j >= 0; j--) {
20597
+ context.lineTo(xPoints[j], top + scaleY(maxValues[j], height, amplitudeScale) + 0.5);
20391
20598
  }
20392
20599
  context.closePath();
20393
20600
  context.fillShape(this);
20394
20601
  };
20395
- WaveformShape.prototype._waveformShapeHitFunc = function (context) {
20396
- if (!this._source) {
20397
- return;
20398
- }
20399
- var frameOffset = this._view.getFrameOffset();
20400
- var viewWidth = this._view.getWidth();
20401
- var startPixels = this._view.timeToPixels(this._source.startTime);
20402
- var endPixels = this._view.timeToPixels(this._source.endTime);
20403
- var offsetY = 10;
20404
- var hitRectHeight = this._height;
20405
- if (hitRectHeight < 0) {
20406
- hitRectHeight = 0;
20407
- }
20408
- var hitRectLeft = startPixels - frameOffset;
20409
- var hitRectWidth = endPixels - startPixels;
20410
- if (hitRectLeft < 0) {
20411
- hitRectWidth -= -hitRectLeft;
20412
- hitRectLeft = 0;
20413
- }
20414
- if (hitRectLeft + hitRectWidth > viewWidth) {
20415
- hitRectWidth -= hitRectLeft + hitRectWidth - viewWidth;
20416
- }
20417
- context.beginPath();
20418
- context.rect(hitRectLeft, offsetY, hitRectWidth, hitRectHeight);
20419
- context.closePath();
20420
- context.fillStrokeShape(this);
20421
- };
20422
20602
  return WaveformShape;
20423
20603
  }(_dereq_('../utils'), _dereq_('konva'));
20424
20604
  },{"../utils":116,"konva":43}],107:[function(_dereq_,module,exports){
@@ -23153,48 +23333,90 @@ module.exports = function (MouseDragHandler, PlayheadLayer, SourcesLayer, ModeLa
23153
23333
  View.prototype.getSelectedElements = function () {
23154
23334
  return Object.values(this._modeLayer.getSelectedElements());
23155
23335
  };
23156
- View.prototype.updateWithAutoScroll = function (updateWhileScrolling, updateWhileNotScrolling) {
23336
+ View.prototype.updateWithAutoScroll = function (updateWhileScrolling, updateWhileNotScrolling, enableVerticalAutoScroll) {
23157
23337
  var self = this;
23158
23338
  var pointer = this.getPointerPosition();
23159
23339
  var pointerX = pointer ? pointer.x : null;
23340
+ var pointerY = pointer ? pointer.y : null;
23160
23341
  var viewWidth = this.getWidth();
23342
+ var viewHeight = this.getHeight();
23161
23343
  var thresholdPx = Math.round(this._peaks.options.autoScrollThreshold * viewWidth);
23344
+ var thresholdPy = Math.round(this._peaks.options.autoScrollThreshold * viewHeight);
23162
23345
  var MAX_AUTO_SCROLL_PX_PER_FRAME = 30;
23163
23346
  var NOMINAL_FRAME_MS = 16.67;
23164
- function getAutoScrollVelocity(pointerXValue) {
23165
- if (typeof pointerXValue !== 'number' || thresholdPx <= 0) {
23347
+ function getAutoScrollVelocity(pointerValue, threshold, size) {
23348
+ if (typeof pointerValue !== 'number' || threshold <= 0 || size <= 0) {
23166
23349
  return 0;
23167
23350
  }
23168
- if (pointerXValue < thresholdPx) {
23169
- return Math.round(-MAX_AUTO_SCROLL_PX_PER_FRAME * Math.min(1, (thresholdPx - pointerXValue) / thresholdPx));
23351
+ if (pointerValue < threshold) {
23352
+ return Math.round(-MAX_AUTO_SCROLL_PX_PER_FRAME * Math.min(1, (threshold - pointerValue) / threshold));
23170
23353
  }
23171
- if (pointerXValue > viewWidth - thresholdPx) {
23172
- return Math.round(MAX_AUTO_SCROLL_PX_PER_FRAME * Math.min(1, (pointerXValue - (viewWidth - thresholdPx)) / thresholdPx));
23354
+ if (pointerValue > size - threshold) {
23355
+ return Math.round(MAX_AUTO_SCROLL_PX_PER_FRAME * Math.min(1, (pointerValue - (size - threshold)) / threshold));
23173
23356
  }
23174
23357
  return 0;
23175
23358
  }
23176
- var velocityPxPerFrame = getAutoScrollVelocity(pointerX);
23177
- var canScroll = velocityPxPerFrame > 0 || velocityPxPerFrame < 0 && self.getFrameOffset() > 0;
23178
- this._limited = velocityPxPerFrame;
23179
- if (velocityPxPerFrame !== 0 && canScroll) {
23359
+ var velocityXPerFrame = getAutoScrollVelocity(pointerX, thresholdPx, viewWidth);
23360
+ var verticalScrollingEnabled = Boolean(enableVerticalAutoScroll && this._peaks.options.enableVerticalScrolling);
23361
+ var maxFrameOffsetY = 0;
23362
+ if (verticalScrollingEnabled) {
23363
+ maxFrameOffsetY = this.getFullHeight() - viewHeight;
23364
+ if (!Number.isFinite(maxFrameOffsetY) || maxFrameOffsetY < 0) {
23365
+ maxFrameOffsetY = 0;
23366
+ }
23367
+ }
23368
+ var velocityYPerFrame = verticalScrollingEnabled && maxFrameOffsetY > 0 ? getAutoScrollVelocity(pointerY, thresholdPy, viewHeight) : 0;
23369
+ var canScrollX = velocityXPerFrame > 0 || velocityXPerFrame < 0 && self.getFrameOffset() > 0;
23370
+ var canScrollY = verticalScrollingEnabled && maxFrameOffsetY > 0 && (velocityYPerFrame > 0 && self.getFrameOffsetY() < maxFrameOffsetY || velocityYPerFrame < 0 && self.getFrameOffsetY() > 0);
23371
+ this._autoScrollVelocityX = velocityXPerFrame;
23372
+ this._autoScrollVelocityY = velocityYPerFrame;
23373
+ if (velocityXPerFrame !== 0 && canScrollX || velocityYPerFrame !== 0 && canScrollY) {
23180
23374
  if (!this._scrollingRafId) {
23181
23375
  var lastTime = performance.now();
23182
23376
  function scrollFrame(currentTime) {
23183
23377
  if (!self._scrollingRafId) {
23184
23378
  return;
23185
23379
  }
23380
+ var xVel = self._autoScrollVelocityX || 0;
23381
+ var yVel = self._autoScrollVelocityY || 0;
23382
+ var canContinueX = xVel > 0 || xVel < 0 && self.getFrameOffset() > 0;
23383
+ var maxY = 0;
23384
+ var canContinueY = false;
23385
+ if (verticalScrollingEnabled) {
23386
+ maxY = self.getFullHeight() - self.getHeight();
23387
+ if (!Number.isFinite(maxY) || maxY < 0) {
23388
+ maxY = 0;
23389
+ }
23390
+ canContinueY = maxY > 0 && (yVel > 0 && self.getFrameOffsetY() < maxY || yVel < 0 && self.getFrameOffsetY() > 0);
23391
+ }
23392
+ if ((xVel === 0 || !canContinueX) && (yVel === 0 || !canContinueY)) {
23393
+ self.stopAutoScroll();
23394
+ updateWhileScrolling();
23395
+ return;
23396
+ }
23186
23397
  var deltaTime = currentTime - lastTime;
23187
- var scrollAmount = Math.round(self._limited * deltaTime / NOMINAL_FRAME_MS);
23398
+ var scrollAmountX = Math.round(xVel * deltaTime / NOMINAL_FRAME_MS);
23399
+ var scrollAmountY = Math.round(yVel * deltaTime / NOMINAL_FRAME_MS);
23188
23400
  lastTime = currentTime;
23189
- var newOffset = self.getFrameOffset() + scrollAmount;
23190
- if (newOffset < 0) {
23191
- self.updateTimeline(0);
23192
- self._scrollingRafId = null;
23401
+ var newOffsetX = self.getFrameOffset() + scrollAmountX;
23402
+ var newOffsetY = self.getFrameOffsetY() + scrollAmountY;
23403
+ if (newOffsetX < 0) {
23404
+ newOffsetX = 0;
23405
+ }
23406
+ if (verticalScrollingEnabled) {
23407
+ if (newOffsetY < 0) {
23408
+ newOffsetY = 0;
23409
+ } else if (newOffsetY > maxY) {
23410
+ newOffsetY = maxY;
23411
+ }
23412
+ }
23413
+ if (!verticalScrollingEnabled) {
23414
+ self.updateTimeline(newOffsetX);
23193
23415
  } else {
23194
- self.updateTimeline(newOffset);
23195
- updateWhileScrolling();
23196
- self._scrollingRafId = requestAnimationFrame(scrollFrame);
23416
+ self.updateTimeline(newOffsetX, newOffsetY);
23197
23417
  }
23418
+ updateWhileScrolling();
23419
+ self._scrollingRafId = requestAnimationFrame(scrollFrame);
23198
23420
  }
23199
23421
  self._scrollingRafId = requestAnimationFrame(scrollFrame);
23200
23422
  }