@checksub_team/peaks_timeline 1.16.0-alpha.2 → 1.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/peaks.js CHANGED
@@ -14809,6 +14809,12 @@ module.exports = function (Konva, Utils, SVGs) {
14809
14809
  this._indicators[lineId].text = text;
14810
14810
  this.draw();
14811
14811
  };
14812
+ LineIndicator.prototype._showMenu = function (menu) {
14813
+ menu.style.display = 'block';
14814
+ var containerRect = this._stage.container().getBoundingClientRect();
14815
+ menu.style.top = containerRect.top + this._stage.getPointerPosition().y - menu.offsetHeight + 'px';
14816
+ menu.style.left = containerRect.left + this._stage.getPointerPosition().x + 6 + 'px';
14817
+ };
14812
14818
  LineIndicator.prototype._createIndicator = function (line, type, text) {
14813
14819
  var indicator = new Konva.Group();
14814
14820
  var indicatorHeight = 0;
@@ -14943,7 +14949,7 @@ module.exports = function (Konva, Utils, SVGs) {
14943
14949
  return LineIndicator;
14944
14950
  }(_dereq_('konva'), _dereq_('./utils'), _dereq_('./svgs'));
14945
14951
  },{"./svgs":108,"./utils":113,"konva":43}],92:[function(_dereq_,module,exports){
14946
- module.exports = function (SourceGroup, Konva, Utils) {
14952
+ module.exports = function (Konva, Utils) {
14947
14953
  'use strict';
14948
14954
  function Line(peaks, view, y, id, position) {
14949
14955
  this._peaks = peaks;
@@ -14976,8 +14982,8 @@ module.exports = function (SourceGroup, Konva, Utils) {
14976
14982
  Line.prototype.getId = function () {
14977
14983
  return this._id;
14978
14984
  };
14979
- Line.prototype.countRemainingElements = function () {
14980
- return this.isSegmentsLine() ? this._segmentsGroup.countRemainingElements() : Object.keys(this._sources).length;
14985
+ Line.prototype.isEmpty = function () {
14986
+ return this.isSegmentsLine() ? this._segmentsGroup.isEmpty() : Object.keys(this._sources).length === 0;
14981
14987
  };
14982
14988
  Line.prototype.isSegmentsLine = function () {
14983
14989
  return Boolean(this._segmentsGroup);
@@ -15005,53 +15011,71 @@ module.exports = function (SourceGroup, Konva, Utils) {
15005
15011
  Line.prototype.lineHeight = function () {
15006
15012
  return this._height;
15007
15013
  };
15008
- Line.prototype._addHeight = function (height) {
15009
- if (this._sourceHeights[height]) {
15010
- this._sourceHeights[height]++;
15011
- } else {
15012
- this._sourceHeights[height] = 1;
15013
- if (height > this._height) {
15014
- this._height = height;
15014
+ Line.prototype.changeHeight = function (from, to) {
15015
+ if (this._sourceHeights[from]) {
15016
+ var oldHeight = this._height;
15017
+ if (this._sourceHeights[to]) {
15018
+ this._sourceHeights[to] += this._sourceHeights[from];
15019
+ } else {
15020
+ this._sourceHeights[to] = this._sourceHeights[from];
15015
15021
  }
15016
- }
15017
- };
15018
- Line.prototype._subtractHeight = function (height) {
15019
- if (Object.keys(this._sources).length === 0) {
15020
- this._height = this._peaks.options.emptyLineHeight;
15021
- this._sourceHeights = {};
15022
- } else {
15023
- this._sourceHeights[height]--;
15024
- if (this._sourceHeights[height] === 0 && height === this._height) {
15025
- delete this._sourceHeights[height];
15022
+ if (to > this._height) {
15023
+ this._height = to;
15024
+ } else if (from === this._height) {
15026
15025
  this._height = 0;
15027
- for (var sourceHeight in this._sourceHeights) {
15028
- if (Utils.objectHasProperty(this._sourceHeights, sourceHeight)) {
15029
- var parsedHeight = parseInt(sourceHeight, 10);
15030
- if (parsedHeight > this._height) {
15031
- this._height = parsedHeight;
15026
+ for (var height in this._sourceHeights) {
15027
+ if (Utils.objectHasProperty(this._sourceHeights, height)) {
15028
+ var parsedHeight = parseInt(height, 10);
15029
+ if (parsedHeight !== from) {
15030
+ if (parsedHeight > this._height) {
15031
+ this._height = parsedHeight;
15032
+ }
15032
15033
  }
15033
15034
  }
15034
15035
  }
15035
15036
  }
15037
+ if (this._height !== oldHeight) {
15038
+ this._peaks.emit('line.heightChanged', this._position);
15039
+ }
15040
+ delete this._sourceHeights[from];
15036
15041
  }
15037
15042
  };
15038
- Line.prototype.updateLineHeight = function (source, action) {
15043
+ Line.prototype.updateLineHeight = function (sourceGroup, action) {
15039
15044
  var oldHeight = this._height;
15040
- var sourceGroup = this._sourcesGroup[source.id];
15041
15045
  var sourceGroupHeight;
15042
15046
  switch (action) {
15043
15047
  case 'add':
15044
- sourceGroupHeight = sourceGroup ? sourceGroup.getCurrentHeight() : SourceGroup.getHeights(source, this._peaks).current;
15045
- this._addHeight(sourceGroupHeight);
15048
+ sourceGroupHeight = sourceGroup.getCurrentHeight();
15049
+ if (this._sourceHeights[sourceGroupHeight]) {
15050
+ this._sourceHeights[sourceGroupHeight]++;
15051
+ } else {
15052
+ this._sourceHeights[sourceGroupHeight] = 1;
15053
+ if (sourceGroupHeight > this._height) {
15054
+ this._height = sourceGroupHeight;
15055
+ }
15056
+ }
15046
15057
  break;
15047
15058
  case 'remove':
15048
- sourceGroupHeight = sourceGroup ? sourceGroup.getCurrentHeight() : SourceGroup.getHeights(source, this._peaks).current;
15049
- this._subtractHeight(sourceGroupHeight);
15059
+ if (Object.keys(this._sources).length === 0) {
15060
+ this._height = this._peaks.options.emptyLineHeight;
15061
+ this._sourceHeights = {};
15062
+ } else {
15063
+ sourceGroupHeight = sourceGroup.getCurrentHeight();
15064
+ this._sourceHeights[sourceGroupHeight]--;
15065
+ if (this._sourceHeights[sourceGroupHeight] === 0 && sourceGroupHeight === this._height) {
15066
+ delete this._sourceHeights[sourceGroupHeight];
15067
+ this._height = 0;
15068
+ for (var height in this._sourceHeights) {
15069
+ if (Utils.objectHasProperty(this._sourceHeights, height)) {
15070
+ var parsedHeight = parseInt(height, 10);
15071
+ if (parsedHeight > this._height) {
15072
+ this._height = parsedHeight;
15073
+ }
15074
+ }
15075
+ }
15076
+ }
15077
+ }
15050
15078
  break;
15051
- default:
15052
- var {unwrapped, wrapped} = sourceGroup ? sourceGroup.getHeights() : SourceGroup.getHeights(source, this._peaks);
15053
- this._addHeight(source.wrapped ? wrapped : unwrapped);
15054
- this._subtractHeight(source.wrapped ? unwrapped : wrapped);
15055
15079
  }
15056
15080
  if (this._height !== oldHeight) {
15057
15081
  this._peaks.emit('line.heightChanged', this._position);
@@ -15063,10 +15087,9 @@ module.exports = function (SourceGroup, Konva, Utils) {
15063
15087
  Line.prototype.addToLayer = function (layer) {
15064
15088
  layer.add(this._group);
15065
15089
  };
15066
- Line.prototype.addSourceGroup = function (source, sourceGroup) {
15067
- if (sourceGroup) {
15068
- this._sourcesGroup[source.id] = sourceGroup;
15069
- }
15090
+ Line.prototype.addSourceGroup = function (sourceGroup) {
15091
+ var source = sourceGroup.getSource();
15092
+ this._sourcesGroup[source.id] = sourceGroup;
15070
15093
  if (!this._sources[source.id]) {
15071
15094
  var newSource = {
15072
15095
  source: source,
@@ -15083,9 +15106,9 @@ module.exports = function (SourceGroup, Konva, Utils) {
15083
15106
  }
15084
15107
  if (source.endTime <= currentSource.source.startTime) {
15085
15108
  var startLimit = currentSource.prevSourceId ? this._sources[currentSource.prevSourceId].source.endTime : 0;
15086
- const {newStartTime, newEndTime} = this._canBePlacedBetween(source.startTime, source.endTime, startLimit, currentSource.source.startTime);
15087
- if (newStartTime !== null && newEndTime !== null) {
15088
- source.updateTimes(newStartTime, newEndTime);
15109
+ var newTimes = this._canBePlacedBetween(source.startTime, source.endTime, startLimit, currentSource.source.startTime);
15110
+ if (newTimes) {
15111
+ source.updateTimes(newTimes.start, newTimes.end);
15089
15112
  if (currentSource.prevSourceId) {
15090
15113
  this._sources[currentSource.prevSourceId].nextSourceId = source.id;
15091
15114
  newSource.prevSourceId = currentSource.prevSourceId;
@@ -15112,9 +15135,9 @@ module.exports = function (SourceGroup, Konva, Utils) {
15112
15135
  this._firstSourceId = source.id;
15113
15136
  this._sources[source.id] = newSource;
15114
15137
  }
15115
- this.updateLineHeight(source, 'add');
15138
+ this.updateLineHeight(sourceGroup, 'add');
15116
15139
  }
15117
- if (sourceGroup && (!sourceGroup.getParent() || !sourceGroup.isDescendantOf(this._group))) {
15140
+ if (!sourceGroup.getParent() || !sourceGroup.isDescendantOf(this._group)) {
15118
15141
  sourceGroup.addToGroup(this._group);
15119
15142
  }
15120
15143
  };
@@ -15134,46 +15157,42 @@ module.exports = function (SourceGroup, Konva, Utils) {
15134
15157
  };
15135
15158
  Line.prototype._canBePlacedBetween = function (startTime, endTime, startLimit, endLimit) {
15136
15159
  var timeWidth = Utils.roundTime(endTime - startTime);
15137
- var newStartTime, newEndTime;
15160
+ var newTimes = null;
15138
15161
  if (!endLimit && startTime > startLimit || startTime > startLimit && endTime < endLimit) {
15139
- newStartTime = startTime;
15140
- newEndTime = endTime;
15162
+ newTimes = {
15163
+ start: startTime,
15164
+ end: endTime
15165
+ };
15141
15166
  } else if (Utils.roundTime(endLimit - startLimit) >= timeWidth) {
15142
15167
  if (startTime > startLimit) {
15143
- newStartTime = Utils.roundTime(endLimit - timeWidth);
15144
- newEndTime = endLimit;
15168
+ newTimes = {
15169
+ start: Utils.roundTime(endLimit - timeWidth),
15170
+ end: endLimit
15171
+ };
15145
15172
  } else {
15146
- newStartTime = startLimit;
15147
- newEndTime = Utils.roundTime(startLimit + timeWidth);
15173
+ newTimes = {
15174
+ start: startLimit,
15175
+ end: Utils.roundTime(startLimit + timeWidth)
15176
+ };
15148
15177
  }
15149
15178
  }
15150
- return {
15151
- newStartTime,
15152
- newEndTime
15153
- };
15179
+ return newTimes;
15154
15180
  };
15155
15181
  Line.prototype.removeSourceGroup = function (source, isPermanent) {
15156
15182
  var sourceGroup = this._sourcesGroup[source.id];
15157
15183
  delete this._sourcesGroup[source.id];
15158
15184
  if (isPermanent) {
15159
- var sourceData = this._sources[source.id];
15160
- delete this._sources[source.id];
15161
- if (Object.keys(this._sources).length === 0) {
15162
- setTimeout(function () {
15163
- this._peaks.emit('line.remove', this._position);
15164
- }.bind(this), 0);
15165
- return sourceGroup;
15166
- }
15167
- if (sourceData.prevSourceId) {
15168
- this._sources[sourceData.prevSourceId].nextSourceId = sourceData.nextSourceId;
15185
+ if (this._sources[source.id].prevSourceId) {
15186
+ this._sources[this._sources[source.id].prevSourceId].nextSourceId = this._sources[source.id].nextSourceId;
15169
15187
  }
15170
- if (sourceData.nextSourceId) {
15171
- this._sources[sourceData.nextSourceId].prevSourceId = sourceData.prevSourceId;
15188
+ if (this._sources[source.id].nextSourceId) {
15189
+ this._sources[this._sources[source.id].nextSourceId].prevSourceId = this._sources[source.id].prevSourceId;
15172
15190
  }
15173
15191
  if (this._firstSourceId === source.id) {
15174
- this._firstSourceId = sourceData.nextSourceId;
15192
+ this._firstSourceId = this._sources[source.id].nextSourceId;
15175
15193
  }
15176
- this.updateLineHeight(source, 'remove');
15194
+ delete this._sources[source.id];
15195
+ this.updateLineHeight(sourceGroup, 'remove');
15177
15196
  }
15178
15197
  return sourceGroup;
15179
15198
  };
@@ -15196,85 +15215,83 @@ module.exports = function (SourceGroup, Konva, Utils) {
15196
15215
  this._y += dy;
15197
15216
  this._group.y(this._group.y() + dy);
15198
15217
  };
15199
- Line.prototype.manageOrder = function (sources, startTime, endTime) {
15200
- const firstSource = sources[0];
15201
- const lastSource = sources[sources.length - 1];
15202
- const cursorTime = this._view.pixelsToTime(this._view.getPointerPosition().x);
15203
- var newStartTime = startTime;
15204
- var newEndTime = endTime;
15218
+ Line.prototype.manageSourceOrder = function (source, newTimes) {
15219
+ var cursorTime = this._view.pixelsToTime(this._view.getPointerPosition().x);
15205
15220
  var tmpTimes;
15206
- var sourceDuration = Utils.roundTime(endTime - startTime);
15207
- if (typeof newStartTime === 'number' && typeof newEndTime === 'number') {
15208
- if (this._sources[firstSource.id].prevSourceId) {
15209
- var previousStartTime = this._sources[this._sources[firstSource.id].prevSourceId].source.startTime;
15210
- if (Utils.roundTime(cursorTime + this._view.getTimeOffset()) < previousStartTime) {
15211
- tmpTimes = this._changeSourcesPosition(sources, sourceDuration, cursorTime + this._view.getTimeOffset());
15212
- if (typeof tmpTimes.newStartTime === 'number' && typeof tmpTimes.newEndTime === 'number') {
15213
- newStartTime = tmpTimes.newStartTime;
15214
- newEndTime = tmpTimes.newEndTime;
15221
+ var sourceDuration = source.endTime - source.startTime;
15222
+ if (newTimes.start !== null && newTimes.end !== null) {
15223
+ if (this._sources[source.id].prevSourceId) {
15224
+ var previousStartTime = this._sources[this._sources[source.id].prevSourceId].source.startTime;
15225
+ if (cursorTime + this._view.getTimeOffset() < previousStartTime) {
15226
+ tmpTimes = this._changeSourcePosition(source, sourceDuration, cursorTime + this._view.getTimeOffset());
15227
+ if (tmpTimes) {
15228
+ newTimes.start = tmpTimes.start;
15229
+ newTimes.end = tmpTimes.end;
15215
15230
  }
15216
15231
  }
15217
15232
  }
15218
- if (this._sources[lastSource.id].nextSourceId) {
15219
- var nextEndTime = this._sources[this._sources[lastSource.id].nextSourceId].source.endTime;
15220
- if (Utils.roundTime(cursorTime + this._view.getTimeOffset()) > nextEndTime) {
15221
- tmpTimes = this._changeSourcesPosition(sources, sourceDuration, cursorTime + this._view.getTimeOffset());
15222
- if (typeof tmpTimes.newStartTime === 'number' && typeof tmpTimes.newEndTime === 'number') {
15223
- newStartTime = tmpTimes.newStartTime;
15224
- newEndTime = tmpTimes.newEndTime;
15233
+ if (this._sources[source.id].nextSourceId) {
15234
+ var nextEndTime = this._sources[this._sources[source.id].nextSourceId].source.endTime;
15235
+ if (cursorTime + this._view.getTimeOffset() > nextEndTime) {
15236
+ tmpTimes = this._changeSourcePosition(source, sourceDuration, cursorTime + this._view.getTimeOffset());
15237
+ if (tmpTimes) {
15238
+ newTimes.start = tmpTimes.start;
15239
+ newTimes.end = tmpTimes.end;
15225
15240
  }
15226
15241
  }
15227
15242
  }
15228
15243
  }
15229
- return {
15230
- newStartTime,
15231
- newEndTime
15232
- };
15244
+ if (newTimes.start) {
15245
+ newTimes.start = Utils.roundTime(newTimes.start);
15246
+ }
15247
+ if (newTimes.end) {
15248
+ newTimes.end = Utils.roundTime(newTimes.end);
15249
+ }
15250
+ return newTimes;
15233
15251
  };
15234
- Line.prototype._changeSourcesPosition = function (sources, sourceDuration, time) {
15235
- var currentRange = {
15236
- start: null,
15237
- end: null
15238
- };
15239
- var startLimit = null;
15240
- var endLimit = null;
15241
- let newStartTime, newEndTime;
15242
- do {
15243
- if (!currentRange.end) {
15244
- currentRange.end = this._sources[this._firstSourceId];
15245
- } else {
15246
- currentRange.start = currentRange.end;
15247
- currentRange.end = this._sources[currentRange.start.nextSourceId];
15248
- }
15249
- if (currentRange.start) {
15250
- startLimit = currentRange.start.source.endTime;
15251
- } else {
15252
- startLimit = 0;
15253
- }
15254
- if (currentRange.end) {
15255
- endLimit = currentRange.end.source.startTime;
15256
- } else {
15257
- endLimit = null;
15258
- }
15259
- if (time > startLimit && (endLimit === null || time < endLimit)) {
15260
- ({newStartTime, newEndTime} = this._canBePlacedBetween(time, time + sourceDuration, startLimit, endLimit));
15261
- if (typeof newStartTime === 'number' && typeof newEndTime === 'number') {
15262
- let prevSourceId = currentRange.start ? currentRange.start.source.id : null;
15263
- sources.forEach(function (source) {
15252
+ Line.prototype._changeSourcePosition = function (source, sourceDuration, time) {
15253
+ if (source.orderable && this._firstSourceId) {
15254
+ var currentRange = {
15255
+ start: null,
15256
+ end: null
15257
+ };
15258
+ var startLimit = null;
15259
+ var endLimit = null;
15260
+ do {
15261
+ if (!currentRange.end) {
15262
+ currentRange.end = this._sources[this._firstSourceId];
15263
+ } else {
15264
+ currentRange.start = currentRange.end;
15265
+ currentRange.end = this._sources[currentRange.start.nextSourceId];
15266
+ }
15267
+ if (currentRange.start) {
15268
+ startLimit = currentRange.start.source.endTime;
15269
+ } else {
15270
+ startLimit = 0;
15271
+ }
15272
+ if (currentRange.end) {
15273
+ endLimit = currentRange.end.source.startTime;
15274
+ } else {
15275
+ endLimit = null;
15276
+ }
15277
+ if (time > startLimit && (endLimit === null || time < endLimit)) {
15278
+ var newTimes = this._canBePlacedBetween(time, time + sourceDuration, startLimit, endLimit);
15279
+ if (newTimes) {
15280
+ if (newTimes.start) {
15281
+ newTimes.start = Utils.roundTime(newTimes.start);
15282
+ }
15283
+ if (newTimes.end) {
15284
+ newTimes.end = Utils.roundTime(newTimes.end);
15285
+ }
15286
+ source.updateTimes(newTimes.start, newTimes.end);
15287
+ var prevSourceId = currentRange.start ? currentRange.start.source.id : null;
15264
15288
  this._moveSource(this._sources[source.id].source, prevSourceId);
15265
- prevSourceId = source.id;
15266
- }.bind(this));
15289
+ return newTimes;
15290
+ }
15267
15291
  }
15268
- return {
15269
- newStartTime,
15270
- newEndTime
15271
- };
15272
- }
15273
- } while (currentRange.end);
15274
- return {
15275
- newStartTime,
15276
- newEndTime
15277
- };
15292
+ } while (currentRange.end);
15293
+ }
15294
+ return null;
15278
15295
  };
15279
15296
  Line.prototype._moveSource = function (source, prevSourceId) {
15280
15297
  var sourceObj = this._sources[source.id];
@@ -15302,17 +15319,20 @@ module.exports = function (SourceGroup, Konva, Utils) {
15302
15319
  }
15303
15320
  this._sources[source.id] = sourceObj;
15304
15321
  };
15305
- Line.prototype.manageCollision = function (sources, newStartTime, newEndTime) {
15306
- var originalStartTime = newStartTime;
15307
- var originalEndTime = newEndTime;
15322
+ Line.prototype.manageCollision = function (source, newTimes) {
15323
+ var originalStartTime = null;
15324
+ var originalEndTime = null;
15325
+ var newStartTime = null;
15326
+ var newEndTime = null;
15308
15327
  var startLimited = false;
15309
15328
  var endLimited = false;
15310
- const firstSource = sources[0];
15311
- const lastSource = sources[sources.length - 1];
15312
- if (typeof newStartTime === 'number') {
15313
- if (firstSource.startTime > newStartTime) {
15314
- if (this._sources[firstSource.id].prevSourceId) {
15315
- var previousSource = this._sources[this._sources[firstSource.id].prevSourceId].source;
15329
+ newTimes.updateTimelineLength = false;
15330
+ if (newTimes.start !== null) {
15331
+ originalStartTime = newTimes.start;
15332
+ newStartTime = originalStartTime;
15333
+ if (source.startTime > newStartTime) {
15334
+ if (this._sources[source.id].prevSourceId) {
15335
+ var previousSource = this._sources[this._sources[source.id].prevSourceId].source;
15316
15336
  if (newStartTime < previousSource.endTime) {
15317
15337
  newStartTime = previousSource.endTime;
15318
15338
  startLimited = true;
@@ -15325,10 +15345,12 @@ module.exports = function (SourceGroup, Konva, Utils) {
15325
15345
  }
15326
15346
  }
15327
15347
  }
15328
- if (typeof newEndTime === 'number') {
15329
- if (lastSource.endTime < newEndTime) {
15330
- if (this._sources[lastSource.id].nextSourceId) {
15331
- var nextSource = this._sources[this._sources[lastSource.id].nextSourceId].source;
15348
+ if (newTimes.end !== null) {
15349
+ originalEndTime = newTimes.end;
15350
+ newEndTime = originalEndTime;
15351
+ if (source.endTime < newEndTime) {
15352
+ if (this._sources[source.id].nextSourceId) {
15353
+ var nextSource = this._sources[this._sources[source.id].nextSourceId].source;
15332
15354
  if (newEndTime > nextSource.startTime) {
15333
15355
  newEndTime = nextSource.startTime;
15334
15356
  endLimited = true;
@@ -15336,7 +15358,7 @@ module.exports = function (SourceGroup, Konva, Utils) {
15336
15358
  }
15337
15359
  }
15338
15360
  }
15339
- if (typeof newStartTime === 'number' && typeof newEndTime === 'number') {
15361
+ if (newStartTime !== null && newEndTime !== null) {
15340
15362
  var timeWidth = originalEndTime - originalStartTime;
15341
15363
  if (startLimited) {
15342
15364
  newEndTime = Utils.roundTime(newStartTime + timeWidth);
@@ -15345,28 +15367,34 @@ module.exports = function (SourceGroup, Konva, Utils) {
15345
15367
  newStartTime = Utils.roundTime(newEndTime - timeWidth);
15346
15368
  }
15347
15369
  }
15348
- if (typeof newStartTime === 'number' && typeof newEndTime !== 'number') {
15349
- if (Utils.roundTime(sources[0].endTime - newStartTime) < sources[0].minSize) {
15350
- newStartTime = Utils.roundTime(sources[0].endTime - sources[0].minSize);
15370
+ if (newStartTime !== null && newEndTime === null) {
15371
+ if (Utils.roundTime(source.endTime - newStartTime) < source.minSize) {
15372
+ newStartTime = Utils.roundTime(source.endTime - source.minSize);
15351
15373
  }
15352
- } else if (typeof newEndTime === 'number' && typeof newStartTime !== 'number') {
15353
- if (Utils.roundTime(newEndTime - sources[0].startTime) < sources[0].minSize) {
15354
- newEndTime = Utils.roundTime(sources[0].startTime + sources[0].minSize);
15374
+ } else if (newEndTime !== null && newStartTime === null) {
15375
+ if (Utils.roundTime(newEndTime - source.startTime) < source.minSize) {
15376
+ newEndTime = Utils.roundTime(source.startTime + source.minSize);
15355
15377
  }
15356
15378
  } else {
15357
- if (Utils.roundTime(newEndTime - newStartTime) < sources[0].minSize) {
15358
- if (sources[0].endTime !== newEndTime) {
15359
- newEndTime = Utils.roundTime(newStartTime + sources[0].minSize);
15379
+ if (Utils.roundTime(newEndTime - newStartTime) < source.minSize) {
15380
+ if (source.endTime !== newEndTime) {
15381
+ newEndTime = Utils.roundTime(newStartTime + source.minSize);
15360
15382
  }
15361
- if (sources[0].startTime !== newStartTime) {
15362
- newStartTime = Utils.roundTime(newEndTime - sources[0].minSize);
15383
+ if (source.startTime !== newStartTime) {
15384
+ newStartTime = Utils.roundTime(newEndTime - source.minSize);
15363
15385
  }
15364
15386
  }
15365
15387
  }
15366
- return {
15367
- newStartTime,
15368
- newEndTime
15369
- };
15388
+ if (newStartTime !== null && newStartTime !== originalStartTime) {
15389
+ newTimes.start = newStartTime;
15390
+ }
15391
+ if (newEndTime !== null && newEndTime !== originalEndTime) {
15392
+ newTimes.end = newEndTime;
15393
+ if (this._sources[source.id].nextSourceId === null) {
15394
+ newTimes.updateTimelineLength = true;
15395
+ }
15396
+ }
15397
+ return newTimes;
15370
15398
  };
15371
15399
  Line.prototype.getSourcesAfter = function (time) {
15372
15400
  const sources = [];
@@ -15385,34 +15413,6 @@ module.exports = function (SourceGroup, Konva, Utils) {
15385
15413
  }
15386
15414
  return sources;
15387
15415
  };
15388
- Line.prototype.getSourcesAround = function (time) {
15389
- var left = null;
15390
- var right = null;
15391
- var overlapping = null;
15392
- var currentId = this._firstSourceId;
15393
- while (currentId) {
15394
- var lineSource = this._sources[currentId];
15395
- var source = lineSource.source;
15396
- if (time < source.startTime) {
15397
- right = source;
15398
- break;
15399
- } else if (time >= source.startTime && time <= source.endTime) {
15400
- overlapping = source;
15401
- break;
15402
- } else {
15403
- left = source;
15404
- }
15405
- currentId = lineSource.nextSourceId;
15406
- }
15407
- if (overlapping) {
15408
- return { overlapping: overlapping };
15409
- } else {
15410
- return {
15411
- left: left,
15412
- right: right
15413
- };
15414
- }
15415
- };
15416
15416
  Line.prototype.updatePosition = function (pos) {
15417
15417
  for (var sourceId in this._sources) {
15418
15418
  if (Utils.objectHasProperty(this._sources, sourceId)) {
@@ -15431,29 +15431,26 @@ module.exports = function (SourceGroup, Konva, Utils) {
15431
15431
  this._group.listening(bool);
15432
15432
  };
15433
15433
  return Line;
15434
- }(_dereq_('./source-group'), _dereq_('konva'), _dereq_('./utils'));
15435
- },{"./source-group":105,"./utils":113,"konva":43}],93:[function(_dereq_,module,exports){
15434
+ }(_dereq_('konva'), _dereq_('./utils'));
15435
+ },{"./utils":113,"konva":43}],93:[function(_dereq_,module,exports){
15436
15436
  module.exports = function (SegmentsGroup, Line, LineIndicator, Utils) {
15437
15437
  'use strict';
15438
15438
  function Lines(peaks, view, layer) {
15439
15439
  this._peaks = peaks;
15440
15440
  this._view = view;
15441
15441
  this._layer = layer;
15442
+ this._linesBySourceId = {};
15442
15443
  this._linesByPosition = {};
15443
15444
  this._autoAddToLayer = false;
15444
15445
  this._areSourceInteractionsAllowed = true;
15445
15446
  this._areSegmentInteractionsAllowed = true;
15446
- this._automaticallyCreatedLineId = null;
15447
- this._automaticLineCreationPosition = null;
15448
- this._automaticLineCreationTimeout = null;
15449
15447
  this._segmentsGroups = {};
15450
15448
  this._segmentsGroupToLine = {};
15451
15449
  this._lineId = 0;
15452
15450
  this._lineIndicator = new LineIndicator(peaks, view, document.getElementById('line-indicator-container'));
15453
15451
  this._peaks.on('line.heightChanged', this._onLineHeightChanged.bind(this));
15452
+ this._peaks.on('line.add', this._onLineAdd.bind(this));
15454
15453
  this._peaks.on('line.remove', this._onLineRemove.bind(this));
15455
- this._peaks.on('sources.show', this._onSourcesWrappingChanged.bind(this));
15456
- this._peaks.on('sources.hide', this._onSourcesWrappingChanged.bind(this));
15457
15454
  this._peaks.on('segment.updated', this._onSegmentsUpdate.bind(this));
15458
15455
  this._peaks.on('segments.add', this._onSegmentsAdd.bind(this));
15459
15456
  this._peaks.on('segments.remove', this._onSegmentsRemove.bind(this));
@@ -15497,24 +15494,33 @@ module.exports = function (SegmentsGroup, Line, LineIndicator, Utils) {
15497
15494
  this._updateLinesPosition(position);
15498
15495
  this._view.updateTimeline();
15499
15496
  };
15500
- Lines.prototype._onLineRemove = function (position) {
15501
- this._removeLine(position);
15497
+ Lines.prototype._onLineAdd = function (position) {
15498
+ this._createLine(position);
15499
+ this._setInteractions(position);
15502
15500
  this._updateLinesPosition(position);
15503
15501
  };
15504
- Lines.prototype._onSourcesWrappingChanged = function (sources) {
15505
- sources.forEach(function (source) {
15506
- if (this._linesByPosition[source.position]) {
15507
- this._linesByPosition[source.position].updateLineHeight(source, 'wrappingChanged');
15502
+ Lines.prototype._onLineRemove = function (position) {
15503
+ var oldLine = this.removeLine(position);
15504
+ var lineNewY = oldLine.getY();
15505
+ this._updateLinesPosition(position, lineNewY);
15506
+ };
15507
+ Lines.prototype.changeLineHeight = function (from, to) {
15508
+ for (var position in this._linesByPosition) {
15509
+ if (Utils.objectHasProperty(this._linesByPosition, position)) {
15510
+ if (!this._linesByPosition[position].isSegmentsLine()) {
15511
+ this._linesByPosition[position].changeHeight(from, to);
15512
+ }
15508
15513
  }
15509
- }.bind(this));
15514
+ }
15510
15515
  };
15511
- Lines.prototype.addSourceGroup = function (source, sourceGroup, position) {
15516
+ Lines.prototype.addSourceGroup = function (sourceGroup, position) {
15512
15517
  if (!this._linesByPosition[position] || this._linesByPosition[position].isSegmentsLine()) {
15513
15518
  this._createLine(position);
15514
15519
  this._setInteractions(position);
15515
15520
  }
15516
- source.position = position;
15517
- this._linesByPosition[position].addSourceGroup(source, sourceGroup);
15521
+ sourceGroup.getSource().position = position;
15522
+ this._linesByPosition[position].addSourceGroup(sourceGroup);
15523
+ this._linesBySourceId[sourceGroup.getSource().id] = this._linesByPosition[position];
15518
15524
  };
15519
15525
  Lines.prototype.addSegments = function (lineId, position) {
15520
15526
  this._createLine(position);
@@ -15525,28 +15531,22 @@ module.exports = function (SegmentsGroup, Line, LineIndicator, Utils) {
15525
15531
  this._updateLinesPosition(position);
15526
15532
  };
15527
15533
  Lines.prototype.removeSourceGroup = function (source, isPermanent) {
15528
- if (!this._linesByPosition[source.position]) {
15529
- return null;
15530
- }
15531
15534
  var sourceGroup = this._linesByPosition[source.position].removeSourceGroup(source, isPermanent);
15532
15535
  if (isPermanent) {
15536
+ delete this._linesBySourceId[source.id];
15533
15537
  this._updateLinesPosition(source.position);
15534
15538
  }
15535
15539
  return sourceGroup;
15536
15540
  };
15537
- Lines.prototype._removeLine = function (pos) {
15541
+ Lines.prototype.removeLine = function (pos) {
15538
15542
  var oldLine = this._linesByPosition[pos];
15539
- var lineId = oldLine.getId();
15540
- if (this._automaticallyCreatedLineId === lineId) {
15541
- this._automaticallyCreatedLineId = null;
15542
- }
15543
15543
  oldLine.destroy();
15544
15544
  delete this._linesByPosition[pos];
15545
- this._lineIndicator.removeIndicator(lineId, false);
15545
+ this._lineIndicator.removeIndicator(oldLine.getId(), false);
15546
15546
  return oldLine;
15547
15547
  };
15548
15548
  Lines.prototype.isLineVisible = function (position) {
15549
- return this._linesByPosition[position] ? this._linesByPosition[position].isVisible() : false;
15549
+ return this._linesByPosition[position].isVisible();
15550
15550
  };
15551
15551
  Lines.prototype.getVisibleLines = function () {
15552
15552
  var positions = {};
@@ -15576,18 +15576,14 @@ module.exports = function (SegmentsGroup, Line, LineIndicator, Utils) {
15576
15576
  Lines.prototype.updateLines = function (position) {
15577
15577
  this._updateLinesPosition(position);
15578
15578
  };
15579
- Lines.prototype._updateLinesPosition = function (position) {
15579
+ Lines.prototype._updateLinesPosition = function (position, forceNewY) {
15580
15580
  var line = this._linesByPosition[position];
15581
15581
  var dy = null;
15582
15582
  var newY;
15583
- if (line) {
15584
- newY = line.getY() + line.lineHeight() + this._peaks.options.interline;
15583
+ if (forceNewY) {
15584
+ newY = forceNewY;
15585
15585
  } else {
15586
- var previousLine;
15587
- while ((previousLine === undefined || previousLine === null) && position > 0) {
15588
- previousLine = this._linesByPosition[--position];
15589
- }
15590
- newY = previousLine ? previousLine.getY() + previousLine.lineHeight() + this._peaks.options.interline : 0;
15586
+ newY = line.getY() + line.lineHeight() + this._peaks.options.interline;
15591
15587
  }
15592
15588
  for (var pos in this._linesByPosition) {
15593
15589
  if (Utils.objectHasProperty(this._linesByPosition, pos)) {
@@ -15603,7 +15599,7 @@ module.exports = function (SegmentsGroup, Line, LineIndicator, Utils) {
15603
15599
  }
15604
15600
  this._lineIndicator.updateIndicators();
15605
15601
  this._lineIndicator.draw();
15606
- this._view.refresh();
15602
+ this._view.drawSourcesLayer();
15607
15603
  };
15608
15604
  Lines.prototype.setOffsetY = function (frameOffset) {
15609
15605
  for (var position in this._linesByPosition) {
@@ -15637,83 +15633,22 @@ module.exports = function (SegmentsGroup, Line, LineIndicator, Utils) {
15637
15633
  }
15638
15634
  return length;
15639
15635
  };
15640
- Lines.prototype.stopAutomaticLineCreation = function () {
15641
- if (this._automaticLineCreationTimeout) {
15642
- clearTimeout(this._automaticLineCreationTimeout);
15643
- }
15644
- this._automaticLineCreationTimeout = null;
15645
- this._automaticLineCreationPosition = null;
15646
- this._automaticallyCreatedLineId = null;
15647
- };
15648
- Lines.prototype.manageAutomaticLineCreation = function (newLinePosition, initialPosition, sources) {
15649
- if (this._automaticallyCreatedLineId !== null) {
15650
- return;
15651
- } else if (this._automaticLineCreationPosition !== null && this._automaticLineCreationPosition !== newLinePosition) {
15652
- this.stopAutomaticLineCreation();
15653
- }
15654
- if (this._automaticLineCreationTimeout) {
15655
- return;
15656
- }
15657
- this._automaticLineCreationPosition = newLinePosition;
15658
- this._automaticLineCreationTimeout = setTimeout(function () {
15659
- this._automaticLineCreationTimeout = null;
15660
- var currentLine = this._linesByPosition[initialPosition];
15661
- if (currentLine.countRemainingElements() === sources.length) {
15662
- this.stopAutomaticLineCreation();
15663
- return;
15664
- }
15665
- this._automaticallyCreatedLineId = this._createLine(newLinePosition);
15666
- this._setInteractions(newLinePosition);
15667
- this.moveSourcesToPosition(sources, currentLine.getPosition(), newLinePosition);
15668
- }.bind(this), this._peaks.options.automaticLineCreationDelay);
15669
- };
15670
- Lines.prototype.manageVerticalPosition = function (sources, startTime, endTime, mouseX, mouseY) {
15671
- if (mouseX === null || mouseX === undefined) {
15672
- return;
15673
- }
15674
- const position = sources[0].position;
15675
- const linePos = this.getLinesUnderY(mouseY);
15676
- if (linePos[0] !== linePos[1]) {
15677
- this.manageAutomaticLineCreation(linePos[0] + 1, position, sources);
15678
- } else {
15679
- this.stopAutomaticLineCreation();
15680
- if (mouseX !== null && mouseX !== undefined && linePos[0] !== position && !this._linesByPosition[linePos[0]].isSegmentsLine()) {
15681
- var mouseTime = this._view.pixelsToTime(mouseX + this._view.getFrameOffset());
15682
- var sourceDuration = Utils.roundTime(endTime - startTime);
15683
- if (this._hasSpaceForSourceAt(linePos[0], mouseTime, sourceDuration)) {
15684
- this.moveSourcesToPosition(sources, position, linePos[0]);
15685
- }
15636
+ Lines.prototype.manageVerticalPosition = function (source, newY) {
15637
+ if (newY !== null && newY !== undefined) {
15638
+ var pos = this.getLineOnPosition(newY);
15639
+ if (pos[0] === pos[1] && pos[0] !== source.position && !this._linesByPosition[pos[0]].isSegmentsLine()) {
15640
+ this.moveSourceToPosition(source, pos[0]);
15686
15641
  }
15687
15642
  }
15688
15643
  };
15689
- Lines.prototype._hasSpaceForSourceAt = function (linePosition, mouseTime, sourceDuration) {
15690
- var line = this._linesByPosition[linePosition];
15691
- if (!line || line.isSegmentsLine()) {
15692
- return false;
15693
- }
15694
- var sourcesAround = line.getSourcesAround(mouseTime);
15695
- if (sourcesAround.overlapping) {
15696
- return false;
15697
- } else if (!sourcesAround.right) {
15698
- return true;
15699
- } else {
15700
- var leftLimit = sourcesAround.left ? sourcesAround.left.endTime : 0;
15701
- var rightLimit = sourcesAround.right.startTime;
15702
- return sourceDuration <= Utils.roundTime(rightLimit - leftLimit);
15703
- }
15704
- };
15705
15644
  Lines.prototype.getLineByPosition = function (pos) {
15706
15645
  return this._linesByPosition[pos];
15707
15646
  };
15708
- Lines.prototype.getLastPosition = function () {
15709
- var keys = Object.keys(this._linesByPosition);
15710
- return keys.pop();
15711
- };
15712
- Lines.prototype.getLinesUnderY = function (y) {
15647
+ Lines.prototype.getLineOnPosition = function (y) {
15713
15648
  var height;
15714
15649
  var pos = [
15715
15650
  -1,
15716
- this.getLastPosition() + 1
15651
+ Number.MAX_VALUE
15717
15652
  ];
15718
15653
  for (var position in this._linesByPosition) {
15719
15654
  if (Utils.objectHasProperty(this._linesByPosition, position)) {
@@ -15728,15 +15663,12 @@ module.exports = function (SegmentsGroup, Line, LineIndicator, Utils) {
15728
15663
  }
15729
15664
  return pos;
15730
15665
  };
15731
- Lines.prototype.moveSourcesToPosition = function (sources, initialPosition, targetPosition) {
15732
- sources.forEach(function (source) {
15733
- var sourceGroup = this._linesByPosition[initialPosition].removeSourceGroup(source, true);
15734
- if (sourceGroup) {
15735
- sourceGroup.moveTo(this._linesByPosition[targetPosition].getKonvaGroup());
15736
- }
15737
- this.addSourceGroup(source, sourceGroup, targetPosition);
15738
- }.bind(this));
15739
- this._updateLinesPosition(initialPosition);
15666
+ Lines.prototype.moveSourceToPosition = function (source, pos) {
15667
+ var sourceGroup = this._linesByPosition[source.position].removeSourceGroup(source, true);
15668
+ delete this._linesBySourceId[source.id];
15669
+ sourceGroup.moveTo(this._linesByPosition[pos].getKonvaGroup());
15670
+ this._updateLinesPosition(source.position);
15671
+ this.addSourceGroup(sourceGroup, pos);
15740
15672
  };
15741
15673
  Lines.prototype._getNextLineId = function () {
15742
15674
  this._lineId++;
@@ -15752,13 +15684,9 @@ module.exports = function (SegmentsGroup, Line, LineIndicator, Utils) {
15752
15684
  if (currentPos < position) {
15753
15685
  y += this._linesByPosition[pos].lineHeight() + this._peaks.options.interline;
15754
15686
  } else {
15755
- if (Utils.objectHasProperty(this._linesByPosition, position)) {
15756
- var newPosition = currentPos + 1;
15757
- this._linesByPosition[currentPos].updatePosition(newPosition);
15758
- newLinesByPosition[newPosition] = this._linesByPosition[currentPos];
15759
- if (!this._linesByPosition[newPosition]) {
15760
- break;
15761
- }
15687
+ if (this._linesByPosition[position]) {
15688
+ this._linesByPosition[currentPos].updatePosition(currentPos + 1);
15689
+ newLinesByPosition[currentPos + 1] = this._linesByPosition[currentPos];
15762
15690
  }
15763
15691
  }
15764
15692
  }
@@ -15770,7 +15698,6 @@ module.exports = function (SegmentsGroup, Line, LineIndicator, Utils) {
15770
15698
  }
15771
15699
  newLinesByPosition[position] = line;
15772
15700
  this._linesByPosition = newLinesByPosition;
15773
- return line.getId();
15774
15701
  };
15775
15702
  Lines.prototype.updateSegments = function (frameStartTime, frameEndTime) {
15776
15703
  for (var lineId in this._segmentsGroups) {
@@ -15779,11 +15706,11 @@ module.exports = function (SegmentsGroup, Line, LineIndicator, Utils) {
15779
15706
  }
15780
15707
  }
15781
15708
  };
15782
- Lines.prototype.manageCollision = function (sources, newStartTime, newEndTime) {
15783
- return this._linesByPosition[sources[0].position].manageCollision(sources, newStartTime, newEndTime);
15709
+ Lines.prototype.manageCollision = function (source, newTimes) {
15710
+ return this._linesBySourceId[source.id].manageCollision(source, newTimes);
15784
15711
  };
15785
- Lines.prototype.manageOrder = function (sources, startTime, endTime) {
15786
- return this._linesByPosition[sources[0].position].manageOrder(sources, startTime, endTime);
15712
+ Lines.prototype.manageSourceOrder = function (source, newTimes) {
15713
+ return this._linesBySourceId[source.id].manageSourceOrder(source, newTimes);
15787
15714
  };
15788
15715
  Lines.prototype._setInteractions = function (position) {
15789
15716
  var line = this._linesByPosition[position];
@@ -15936,8 +15863,7 @@ module.exports = function (Colors, EventEmitter, TimelineSegments, TimelineSourc
15936
15863
  autoScrollThreshold: 0.05,
15937
15864
  minSourceSize: 0.05,
15938
15865
  minSegmentSize: 0.2,
15939
- canMoveSourcesBetweenLines: true,
15940
- automaticLineCreationDelay: 100
15866
+ canMoveSourcesBetweenLines: true
15941
15867
  };
15942
15868
  this.logger = console.error.bind(console);
15943
15869
  return this;
@@ -16115,6 +16041,11 @@ module.exports = function (Colors, EventEmitter, TimelineSegments, TimelineSourc
16115
16041
  Peaks.prototype._removeWindowResizeHandler = function () {
16116
16042
  window.removeEventListener('resize', this._onResize);
16117
16043
  };
16044
+ Peaks.prototype.setLineHeight = function (newLineHeight) {
16045
+ var oldHeight = this.options.lineHeight;
16046
+ this.options.lineHeight = newLineHeight;
16047
+ this.emit('options.set.line_height', oldHeight);
16048
+ };
16118
16049
  Peaks.prototype.zoomIn = function () {
16119
16050
  this.view.setZoom(this.view.getTimeToPixelsScale() + Math.floor(this.view.getTimeToPixelsScale() / 10) + 1);
16120
16051
  };
@@ -17640,9 +17571,6 @@ module.exports = function (SegmentShape, Utils, Konva) {
17640
17571
  SegmentsGroup.prototype.isEmpty = function () {
17641
17572
  return Object.keys(this._segments).length === 0;
17642
17573
  };
17643
- SegmentsGroup.prototype.countRemainingElements = function () {
17644
- return Object.keys(this._segments).length;
17645
- };
17646
17574
  SegmentsGroup.prototype.addToGroup = function (group) {
17647
17575
  group.add(this._group);
17648
17576
  };
@@ -18148,12 +18076,13 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Loader, Konva)
18148
18076
  this._indicators = {};
18149
18077
  var self = this;
18150
18078
  this._x = this._view.timeToPixels(source.startTime);
18079
+ this._roundedX = Math.round(this._x);
18151
18080
  this._width = this._view.timeToPixels(source.endTime - source.startTime);
18152
- var heights = SourceGroup.getHeights(source, peaks);
18153
- this._unwrappedHeight = heights.unwrapped;
18154
- this._wrappedHeight = heights.wrapped;
18155
- this._height = heights.current;
18081
+ this._roundedWidth = Math.round(this._width);
18082
+ this._unwrappedHeight = source.binaryHeight && source.previewHeight ? source.binaryHeight + source.previewHeight : this._peaks.options.lineHeight;
18083
+ this._wrappedHeight = this._peaks.options.wrappedLineHeight;
18156
18084
  this._borderWidth = this._source.borderWidth || 0;
18085
+ this._height = this._unwrappedHeight;
18157
18086
  this._currentTimeToPixelsScaleUsed = this._view.getTimeToPixelsScale();
18158
18087
  this._selected = this._source.selected;
18159
18088
  this._isDragged = false;
@@ -18174,12 +18103,14 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Loader, Konva)
18174
18103
  this._group.on('dragend', this._onDragEnd.bind(this));
18175
18104
  this._cursor = null;
18176
18105
  this._group.on('mouseenter', function () {
18106
+ self._hovered = true;
18177
18107
  self._view.setHoveredElement(self);
18178
18108
  if (!self._source.loading) {
18179
18109
  self._showButtons();
18180
18110
  }
18181
18111
  });
18182
18112
  this._group.on('mouseleave', function () {
18113
+ self._hovered = false;
18183
18114
  self._view.setHoveredElement(null);
18184
18115
  self._hideButtons();
18185
18116
  });
@@ -18246,10 +18177,11 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Loader, Konva)
18246
18177
  const timeOffsetDiff = this._view.getTimeOffset() - this._initialTimeOffset;
18247
18178
  const {start, end} = this._initialTimes;
18248
18179
  this._view.updateWithAutoScroll(function () {
18249
- if (this._layer.manageSourceMovements([this._source], leftHandle ? start + diff + timeOffsetDiff : null, leftHandle ? null : end + diff + timeOffsetDiff)) {
18180
+ if (this._layer.updateSource(this._source, leftHandle ? start + diff + timeOffsetDiff : null, leftHandle ? null : end + diff + timeOffsetDiff)) {
18250
18181
  this._layer.draw();
18251
18182
  }
18252
18183
  }.bind(this));
18184
+ this._view.setTimelineLength(this._view.timeToPixels(this._source.endTime) + this._view.getWidth());
18253
18185
  return {
18254
18186
  x: draggedElement.absolutePosition().x,
18255
18187
  y: draggedElement.absolutePosition().y
@@ -18262,9 +18194,11 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Loader, Konva)
18262
18194
  const newTimeToPixelsScale = this._view.getTimeToPixelsScale();
18263
18195
  this._group.x(startPixel - frameOffset);
18264
18196
  this._x = startPixel;
18197
+ this._roundedX = Math.round(this._x);
18265
18198
  const newWidth = endPixel - startPixel;
18266
18199
  if (newWidth !== this._width) {
18267
18200
  this._width = newWidth;
18201
+ this._roundedWidth = Math.round(this._width);
18268
18202
  if (newTimeToPixelsScale !== this._currentTimeToPixelsScaleUsed) {
18269
18203
  this._currentTimeToPixelsScaleUsed = newTimeToPixelsScale;
18270
18204
  this._updateMarkers();
@@ -18315,11 +18249,9 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Loader, Konva)
18315
18249
  start: this._source.startTime,
18316
18250
  end: this._source.endTime
18317
18251
  };
18318
- this._isDragged = true;
18319
18252
  this._hideButtons();
18320
18253
  };
18321
18254
  SourceGroup.prototype._onHandleDragEnd = function () {
18322
- this._isDragged = false;
18323
18255
  this._showButtons();
18324
18256
  };
18325
18257
  SourceGroup.prototype._addHandles = function (forceCreate) {
@@ -18401,46 +18333,52 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Loader, Konva)
18401
18333
  };
18402
18334
  SourceGroup.prototype.drawSourceShape = function (ctx, shape, addBorderWidth, fill) {
18403
18335
  var offset = addBorderWidth ? this._borderWidth : 0;
18404
- 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)));
18405
- var x = Math.max(0, this._view.getFrameOffset() - this._x - 2 * radius);
18406
- var width = Math.min(this._width - x, this._view.getWidth() + 4 * radius - Math.max(0, this._x - this._view.getFrameOffset()));
18336
+ var radius = this._source.borderRadius !== undefined && this._source.borderRadius !== null ? this._source.borderRadius : Math.max(1, Math.min(this._roundedWidth / 2, Math.min(CORNER_RADIUS, this._height / 2)));
18337
+ var x = Math.max(0, this._view.getFrameOffset() - this._roundedX - radius);
18338
+ var width = Math.min(this._roundedWidth - x, this._view.getWidth() + radius - Math.max(0, this._roundedX - this._view.getFrameOffset()));
18407
18339
  var xWidth = x + width;
18408
- if (width > 0) {
18409
- ctx.beginPath();
18410
- ctx.moveTo(x + radius, offset);
18411
- ctx.lineTo(xWidth - radius, offset);
18412
- ctx.quadraticCurveTo(xWidth - offset, offset, xWidth - offset, radius);
18413
- ctx.lineTo(xWidth - offset, this._height - radius);
18414
- ctx.quadraticCurveTo(xWidth - offset, this._height - offset, xWidth - radius, this._height - offset);
18415
- ctx.lineTo(x + radius, this._height - offset);
18416
- ctx.quadraticCurveTo(x + offset, this._height - offset, x + offset, this._height - radius);
18417
- ctx.lineTo(x + offset, radius);
18418
- ctx.quadraticCurveTo(x + offset, offset, x + radius, offset);
18419
- ctx.closePath();
18420
- if (fill) {
18421
- if (this._source.shouldShowWarning()) {
18422
- var gradient = ctx.createLinearGradient(0, 0, this._width, 0);
18423
- if (this._source.mediaEndTime < this._source.duration) {
18424
- var rightStopPosition = Math.max(1 - this._source.warningWidth / this._width, 0.5);
18425
- gradient.addColorStop(rightStopPosition, this._source.backgroundColor);
18426
- gradient.addColorStop(1, this._source.warningColor);
18427
- }
18428
- if (this._source.mediaStartTime > 0) {
18429
- var leftStopPosition = Math.min(this._source.warningWidth / this._width, 0.5);
18430
- gradient.addColorStop(0, this._source.warningColor);
18431
- gradient.addColorStop(leftStopPosition, this._source.backgroundColor);
18432
- }
18433
- ctx.fillStyle = gradient;
18434
- ctx.fill();
18435
- } else {
18436
- ctx.fillStyle = this._source.backgroundColor;
18437
- ctx.fill();
18340
+ ctx.beginPath();
18341
+ ctx.moveTo(x + radius, offset);
18342
+ ctx.lineTo(xWidth - radius, offset);
18343
+ ctx.quadraticCurveTo(xWidth - offset, offset, xWidth - offset, radius);
18344
+ ctx.lineTo(xWidth - offset, this._height - radius);
18345
+ ctx.quadraticCurveTo(xWidth - offset, this._height - offset, xWidth - radius, this._height - offset);
18346
+ ctx.lineTo(x + radius, this._height - offset);
18347
+ ctx.quadraticCurveTo(x + offset, this._height - offset, x + offset, this._height - radius);
18348
+ ctx.lineTo(x + offset, radius);
18349
+ ctx.quadraticCurveTo(x + offset, offset, x + radius, offset);
18350
+ ctx.closePath();
18351
+ if (fill) {
18352
+ var backgroundColor;
18353
+ if (this._selected) {
18354
+ backgroundColor = this._source.selectedBackgroundColor;
18355
+ } else if (this._hovered) {
18356
+ backgroundColor = this._source.hoverBackgroundColor;
18357
+ } else {
18358
+ backgroundColor = this._source.backgroundColor;
18359
+ }
18360
+ if (this._source.shouldShowWarning()) {
18361
+ var gradient = ctx.createLinearGradient(0, 0, this._roundedWidth, 0);
18362
+ if (this._source.mediaEndTime < this._source.duration) {
18363
+ var rightStopPosition = Math.max(1 - this._source.warningWidth / this._roundedWidth, 0.5);
18364
+ gradient.addColorStop(rightStopPosition, backgroundColor);
18365
+ gradient.addColorStop(1, this._source.warningColor);
18438
18366
  }
18439
- }
18440
- if (shape) {
18441
- ctx.fillStrokeShape(shape);
18367
+ if (this._source.mediaStartTime > 0) {
18368
+ var leftStopPosition = Math.min(this._source.warningWidth / this._roundedWidth, 0.5);
18369
+ gradient.addColorStop(0, this._source.warningColor);
18370
+ gradient.addColorStop(leftStopPosition, backgroundColor);
18371
+ }
18372
+ ctx.fillStyle = gradient;
18373
+ ctx.fill();
18374
+ } else {
18375
+ ctx.fillStyle = backgroundColor;
18376
+ ctx.fill();
18442
18377
  }
18443
18378
  }
18379
+ if (shape) {
18380
+ ctx.fillStrokeShape(shape);
18381
+ }
18444
18382
  };
18445
18383
  SourceGroup.prototype._addUnwrap = function (forceCreate) {
18446
18384
  if (!this._unwrap || forceCreate) {
@@ -18774,7 +18712,7 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Loader, Konva)
18774
18712
  this._selected = this._source.selected;
18775
18713
  if (this._border) {
18776
18714
  if (this._selected) {
18777
- this._border.fill(this._source.selectedColor);
18715
+ this._border.fill(this._source.selectedBorderColor);
18778
18716
  this._borderWidth = this._peaks.options.sourceSelectedBorderWidth;
18779
18717
  } else {
18780
18718
  this._border.fill(this._source.borderColor);
@@ -18787,7 +18725,7 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Loader, Konva)
18787
18725
  })[0];
18788
18726
  if (unwrap_background) {
18789
18727
  if (this._selected) {
18790
- unwrap_background.stroke(this._source.selectedColor);
18728
+ unwrap_background.stroke(this._source.selectedBorderColor);
18791
18729
  unwrap_background.strokeWidth(this._peaks.options.sourceSelectedBorderWidth);
18792
18730
  } else {
18793
18731
  unwrap_background.strokeWidth(0);
@@ -18800,7 +18738,7 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Loader, Konva)
18800
18738
  })[0];
18801
18739
  if (wrap_background) {
18802
18740
  if (this._selected) {
18803
- wrap_background.stroke(this._source.selectedColor);
18741
+ wrap_background.stroke(this._source.selectedBorderColor);
18804
18742
  wrap_background.strokeWidth(this._peaks.options.sourceSelectedBorderWidth);
18805
18743
  } else {
18806
18744
  wrap_background.strokeWidth(0);
@@ -18953,13 +18891,6 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Loader, Konva)
18953
18891
  SourceGroup.prototype.getCurrentHeight = function () {
18954
18892
  return this._height;
18955
18893
  };
18956
- SourceGroup.prototype.getHeights = function () {
18957
- return {
18958
- unwrapped: this._unwrappedHeight,
18959
- wrapped: this._wrappedHeight,
18960
- current: this._height
18961
- };
18962
- };
18963
18894
  SourceGroup.prototype.setVisible = function (boolean) {
18964
18895
  this._group.visible(boolean);
18965
18896
  };
@@ -19342,16 +19273,6 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Loader, Konva)
19342
19273
  }
19343
19274
  this._group.destroy();
19344
19275
  };
19345
- SourceGroup.getHeights = function (source, peaks) {
19346
- var unwrappedHeight = source.binaryHeight && source.previewHeight ? source.binaryHeight + source.previewHeight : peaks.options.lineHeight;
19347
- var wrappedHeight = peaks.options.wrappedLineHeight;
19348
- var height = source.wrapped ? wrappedHeight : unwrappedHeight;
19349
- return {
19350
- unwrapped: unwrappedHeight,
19351
- wrapped: wrappedHeight,
19352
- current: height
19353
- };
19354
- };
19355
19276
  return SourceGroup;
19356
19277
  }(_dereq_('./waveform-builder'), _dereq_('./waveform-shape'), _dereq_('./utils'), _dereq_('./loader'), _dereq_('konva'));
19357
19278
  },{"./loader":94,"./utils":113,"./waveform-builder":114,"./waveform-shape":115,"konva":43}],106:[function(_dereq_,module,exports){
@@ -19434,13 +19355,23 @@ module.exports = function (Utils) {
19434
19355
  if (!Utils.isValidColor(options.backgroundColor)) {
19435
19356
  throw new TypeError('peaks.sources.' + context + ': backgroundColor should be a valid CSS color');
19436
19357
  }
19358
+ if (Utils.isNullOrUndefined(options.selectedBackgroundColor)) {
19359
+ options.selectedBackgroundColor = options.backgroundColor;
19360
+ } else if (!Utils.isValidColor(options.selectedBackgroundColor)) {
19361
+ throw new TypeError('peaks.sources.' + context + ': selectedBackgroundColor should be a valid CSS color');
19362
+ }
19363
+ if (Utils.isNullOrUndefined(options.hoverBackgroundColor)) {
19364
+ options.hoverBackgroundColor = Utils.shadeColor(options.backgroundColor, 30);
19365
+ } else if (!Utils.isValidColor(options.hoverBackgroundColor)) {
19366
+ throw new TypeError('peaks.sources.' + context + ': hoverBackgroundColor should be a valid CSS color');
19367
+ }
19437
19368
  if (!Utils.isValidColor(options.borderColor)) {
19438
19369
  options.borderColor = options.color;
19439
19370
  }
19440
- if (Utils.isNullOrUndefined(options.selectedColor)) {
19441
- options.selectedColor = null;
19442
- } else if (!Utils.isValidColor(options.selectedColor)) {
19443
- throw new TypeError('peaks.sources.' + context + ': selectedColor should be a valid CSS color');
19371
+ if (Utils.isNullOrUndefined(options.selectedBorderColor)) {
19372
+ options.selectedBorderColor = Utils.shadeColor(options.borderColor, 30);
19373
+ } else if (!Utils.isValidColor(options.selectedBorderColor)) {
19374
+ throw new TypeError('peaks.sources.' + context + ': selectedBorderColor should be a valid CSS color');
19444
19375
  }
19445
19376
  if (Utils.isNullOrUndefined(options.warningColor)) {
19446
19377
  options.warningColor = null;
@@ -19592,7 +19523,7 @@ module.exports = function (Utils) {
19592
19523
  throw new TypeError('peaks.sources.' + context + ': loading must be a boolean');
19593
19524
  }
19594
19525
  }
19595
- function Source(peaks, id, originId, elementId, title, titleAlignments, url, previewUrl, binaryUrl, kind, subkind, duration, startTime, endTime, mediaStartTime, mediaEndTime, color, backgroundColor, borderColor, selectedColor, warningColor, warningWidth, volumeSliderColor, volumeSliderWidth, volumeSliderDraggingWidth, textFont, textFontSize, textColor, textBackgroundColor, textPosition, textAutoScroll, borderWidth, borderRadius, wrapped, position, draggable, orderable, resizable, cuttable, deletable, wrapping, previewHeight, binaryHeight, indicators, markers, buttons, markerColor, markerWidth, volume, volumeRange, loading, ...customParams) {
19526
+ function Source(peaks, id, originId, elementId, title, titleAlignments, url, previewUrl, binaryUrl, kind, subkind, duration, startTime, endTime, mediaStartTime, mediaEndTime, color, backgroundColor, hoverBackgroundColor, selectedBackgroundColor, borderColor, selectedBorderColor, warningColor, warningWidth, volumeSliderColor, volumeSliderWidth, volumeSliderDraggingWidth, textFont, textFontSize, textColor, textBackgroundColor, textPosition, textAutoScroll, borderWidth, borderRadius, wrapped, position, draggable, orderable, resizable, cuttable, deletable, wrapping, previewHeight, binaryHeight, indicators, markers, buttons, markerColor, markerWidth, volume, volumeRange, loading, ...customParams) {
19596
19527
  var opts = {
19597
19528
  title: title,
19598
19529
  titleAlignments: titleAlignments,
@@ -19608,8 +19539,10 @@ module.exports = function (Utils) {
19608
19539
  mediaEndTime: mediaEndTime,
19609
19540
  color: color,
19610
19541
  backgroundColor: backgroundColor,
19542
+ hoverBackgroundColor: hoverBackgroundColor,
19543
+ selectedBackgroundColor: selectedBackgroundColor,
19611
19544
  borderColor: borderColor,
19612
- selectedColor: selectedColor,
19545
+ selectedBorderColor: selectedBorderColor,
19613
19546
  warningColor: warningColor,
19614
19547
  warningWidth: warningWidth,
19615
19548
  textFont: textFont,
@@ -19661,8 +19594,10 @@ module.exports = function (Utils) {
19661
19594
  this._mediaEndTime = opts.mediaEndTime;
19662
19595
  this._color = opts.color;
19663
19596
  this._backgroundColor = opts.backgroundColor;
19597
+ this._hoverBackgroundColor = opts.hoverBackgroundColor;
19598
+ this._selectedBackgroundColor = opts.selectedBackgroundColor;
19664
19599
  this._borderColor = opts.borderColor;
19665
- this._selectedColor = opts.selectedColor || Utils.shadeColor(opts.backgroundColor, 30);
19600
+ this._selectedBorderColor = opts.selectedBorderColor;
19666
19601
  this._warningColor = opts.warningColor;
19667
19602
  this._warningWidth = opts.warningWidth;
19668
19603
  this._volumeSliderColor = opts.volumeSliderColor;
@@ -19828,6 +19763,24 @@ module.exports = function (Utils) {
19828
19763
  this._backgroundColor = backgroundColor;
19829
19764
  }
19830
19765
  },
19766
+ hoverBackgroundColor: {
19767
+ enumerable: true,
19768
+ get: function () {
19769
+ return this._hoverBackgroundColor;
19770
+ },
19771
+ set: function (hoverBackgroundColor) {
19772
+ this._hoverBackgroundColor = hoverBackgroundColor;
19773
+ }
19774
+ },
19775
+ selectedBackgroundColor: {
19776
+ enumerable: true,
19777
+ get: function () {
19778
+ return this._selectedBackgroundColor;
19779
+ },
19780
+ set: function (selectedBackgroundColor) {
19781
+ this._selectedBackgroundColor = selectedBackgroundColor;
19782
+ }
19783
+ },
19831
19784
  borderColor: {
19832
19785
  enumerable: true,
19833
19786
  get: function () {
@@ -19837,13 +19790,13 @@ module.exports = function (Utils) {
19837
19790
  this._borderColor = borderColor;
19838
19791
  }
19839
19792
  },
19840
- selectedColor: {
19793
+ selectedBorderColor: {
19841
19794
  enumerable: true,
19842
19795
  get: function () {
19843
- return this._selectedColor;
19796
+ return this._selectedBorderColor;
19844
19797
  },
19845
- set: function (selectedColor) {
19846
- this._selectedColor = selectedColor;
19798
+ set: function (selectedBorderColor) {
19799
+ this._selectedBorderColor = selectedBorderColor;
19847
19800
  }
19848
19801
  },
19849
19802
  warningColor: {
@@ -20202,8 +20155,10 @@ module.exports = function (Utils) {
20202
20155
  mediaEndTime: this.mediaEndTime,
20203
20156
  color: this.color,
20204
20157
  backgroundColor: this.backgroundColor,
20158
+ hoverBackgroundColor: this.hoverBackgroundColor,
20159
+ selectedBackgroundColor: this.selectedBackgroundColor,
20205
20160
  borderColor: this.borderColor,
20206
- selectedColor: this.selectedColor,
20161
+ selectedBorderColor: this.selectedBorderColor,
20207
20162
  warningColor: this.warningColor,
20208
20163
  warningWidth: this.warningWidth,
20209
20164
  volumeSliderColor: this.volumeSliderColor,
@@ -20252,8 +20207,10 @@ module.exports = function (Utils) {
20252
20207
  this._mediaEndTime = opts.mediaEndTime;
20253
20208
  this._color = opts.color;
20254
20209
  this._backgroundColor = opts.backgroundColor;
20210
+ this._hoverBackgroundColor = opts.hoverBackgroundColor;
20211
+ this._selectedBackgroundColor = opts.selectedBackgroundColor;
20255
20212
  this._borderColor = opts.borderColor;
20256
- this._selectedColor = opts.selectedColor || Utils.shadeColor(opts.backgroundColor, 30);
20213
+ this._selectedBorderColor = opts.selectedBorderColor;
20257
20214
  this._warningColor = opts.warningColor;
20258
20215
  this._warningWidth = opts.warningWidth;
20259
20216
  this._volumeSliderColor = opts.volumeSliderColor;
@@ -20357,7 +20314,9 @@ module.exports = function (SourceGroup, Lines, DataRetriever, Utils, Invoker, Ko
20357
20314
  this._peaks.on('sources.setSelected', this._onSourcesSetSelected.bind(this));
20358
20315
  this._peaks.on('source.update', this._onSourceUpdate.bind(this));
20359
20316
  this._peaks.on('data.retrieved', this._onDataRetrieved.bind(this));
20317
+ this._peaks.on('sources.refresh', this._onSourcesRefresh.bind(this));
20360
20318
  this._peaks.on('segments.show', this._onSegmentsShow.bind(this));
20319
+ this._peaks.on('options.set.line_height', this._onOptionsLineHeightChange.bind(this));
20361
20320
  this._peaks.on('source.setIndicators', this.setIndicators.bind(this));
20362
20321
  }
20363
20322
  SourcesLayer.prototype.fitToView = function () {
@@ -20384,10 +20343,24 @@ module.exports = function (SourceGroup, Lines, DataRetriever, Utils, Invoker, Ko
20384
20343
  SourcesLayer.prototype.isEditingEnabled = function () {
20385
20344
  return this._allowEditing;
20386
20345
  };
20387
- SourcesLayer.prototype.refresh = function () {
20388
- var frameOffset = this._view.getFrameOffset();
20389
- var width = this._view.getWidth();
20390
- this.updateSources(this._view.pixelsToTime(frameOffset), this._view.pixelsToTime(frameOffset + width));
20346
+ SourcesLayer.prototype._onOptionsLineHeightChange = function (oldHeight) {
20347
+ var positions = [];
20348
+ for (var sourceId in this._sourcesGroup) {
20349
+ if (Utils.objectHasProperty(this._sourcesGroup, sourceId)) {
20350
+ var source = this._sourcesGroup[sourceId].getSource();
20351
+ if (!positions.includes(source.position)) {
20352
+ this._lines.changeLineHeight(oldHeight, this._peaks.options.lineHeight);
20353
+ positions.push(source.position);
20354
+ }
20355
+ this._removeSource(source);
20356
+ this._addSourceGroup(source);
20357
+ }
20358
+ }
20359
+ if (positions) {
20360
+ var frameOffset = this._view.getFrameOffset();
20361
+ var width = this._view.getWidth();
20362
+ this.updateSources(this._view.pixelsToTime(frameOffset), this._view.pixelsToTime(frameOffset + width));
20363
+ }
20391
20364
  };
20392
20365
  SourcesLayer.prototype._onSourceUpdate = function (source) {
20393
20366
  var redraw = false;
@@ -20417,6 +20390,13 @@ module.exports = function (SourceGroup, Lines, DataRetriever, Utils, Invoker, Ko
20417
20390
  }.bind(this));
20418
20391
  this.draw();
20419
20392
  };
20393
+ SourcesLayer.prototype._onSourcesShow = function (sources) {
20394
+ var self = this;
20395
+ sources.forEach(function (source) {
20396
+ self._sourcesGroup[source.id].setWrapping(false, true);
20397
+ });
20398
+ this._layer.draw();
20399
+ };
20420
20400
  SourcesLayer.prototype._onSourcesAdd = function (sources) {
20421
20401
  var self = this;
20422
20402
  var frameOffset = self._view.getFrameOffset();
@@ -20475,6 +20455,9 @@ module.exports = function (SourceGroup, Lines, DataRetriever, Utils, Invoker, Ko
20475
20455
  }
20476
20456
  }
20477
20457
  };
20458
+ SourcesLayer.prototype._onSourcesRefresh = function () {
20459
+ this._layer.draw();
20460
+ };
20478
20461
  SourcesLayer.prototype._onSegmentsShow = function (lineId, position) {
20479
20462
  this._lines.addSegments(lineId, position);
20480
20463
  this._view.updateTimelineLength();
@@ -20486,7 +20469,7 @@ module.exports = function (SourceGroup, Lines, DataRetriever, Utils, Invoker, Ko
20486
20469
  SourcesLayer.prototype._addSourceGroup = function (source, startDataRetrieval = true) {
20487
20470
  var sourceGroup = this._createSourceGroup(source);
20488
20471
  this._sourcesGroup[source.id] = sourceGroup;
20489
- this._lines.addSourceGroup(source, sourceGroup, source.position);
20472
+ this._lines.addSourceGroup(sourceGroup, source.position);
20490
20473
  if (startDataRetrieval) {
20491
20474
  this._dataRetriever.retrieveData(source);
20492
20475
  }
@@ -20513,28 +20496,20 @@ module.exports = function (SourceGroup, Lines, DataRetriever, Utils, Invoker, Ko
20513
20496
  SourcesLayer.prototype.onSourcesGroupDragStart = function (element) {
20514
20497
  this._initialTimeOffset = this._view.getTimeOffset();
20515
20498
  this._mouseDownX = this._view.getPointerPosition().x;
20499
+ this._activeElements = {};
20516
20500
  const draggedElementId = element.currentTarget.attrs.sourceId;
20517
- var selectedElements = this._view.getSelectedElements();
20518
- const shouldDragSelectedElements = Object.keys(selectedElements).includes(draggedElementId);
20519
- if (shouldDragSelectedElements) {
20520
- this._draggedElements = Object.values(selectedElements).sort((a, b) => a.startTime - b.startTime);
20521
- } else {
20522
- this._draggedElements = [this._sourcesGroup[draggedElementId].getSource()];
20523
- this._view.deselectAll();
20524
- }
20525
- this._draggedElementsData = this._draggedElements.reduce(function (bounds, source) {
20526
- bounds.initialStartTime = Math.min(source.startTime, bounds.initialStartTime);
20527
- bounds.initialEndTime = Math.max(source.endTime, bounds.initialEndTime);
20528
- bounds.orderable = source.orderable && bounds.orderable;
20529
- return bounds;
20530
- }, {
20531
- initialStartTime: Infinity,
20532
- initialEndTime: -Infinity,
20533
- orderable: true
20534
- });
20501
+ const shouldDragSelectedElements = Object.keys(this._view.getSelectedElements()).includes(draggedElementId);
20502
+ this._nonSelectedElement = shouldDragSelectedElements ? null : [this._sourcesGroup[draggedElementId].getSource()];
20503
+ this._isDraggable = true;
20504
+ (this._nonSelectedElement || Object.values(this._view.getSelectedElements())).forEach(function (source) {
20505
+ if (!source.draggable) {
20506
+ this._isDraggable = false;
20507
+ return;
20508
+ }
20509
+ }.bind(this));
20535
20510
  };
20536
20511
  SourcesLayer.prototype.onSourcesGroupDragEnd = function () {
20537
- const updatedSources = this._draggedElements.map(function (source) {
20512
+ const updatedSources = (this._nonSelectedElement || Object.values(this._view.getSelectedElements())).map(function (source) {
20538
20513
  const sourceGroup = this._sourcesGroup[source.id];
20539
20514
  if (sourceGroup) {
20540
20515
  sourceGroup.prepareDragEnd();
@@ -20543,6 +20518,7 @@ module.exports = function (SourceGroup, Lines, DataRetriever, Utils, Invoker, Ko
20543
20518
  }.bind(this));
20544
20519
  this._view.drawSourcesLayer();
20545
20520
  this._view.updateTimelineLength();
20521
+ this._activeElements = {};
20546
20522
  this._peaks.emit('sources.updated', updatedSources);
20547
20523
  };
20548
20524
  SourcesLayer.prototype.onSourcesGroupDrag = function (draggedElement) {
@@ -20554,15 +20530,28 @@ module.exports = function (SourceGroup, Lines, DataRetriever, Utils, Invoker, Ko
20554
20530
  };
20555
20531
  SourcesLayer.prototype._dragSourcesGroup = function () {
20556
20532
  var mousePos = Math.min(this._view.getWidth() - this._peaks.options.autoScrollThreshold * this._view.getWidth(), Math.max(0, this._view.getPointerPosition().x));
20557
- const timeDiff = this._view.pixelsToTime(mousePos - this._mouseDownX);
20533
+ const diff = this._view.pixelsToTime(mousePos - this._mouseDownX);
20558
20534
  const timeOffsetDiff = this._view.getTimeOffset() - this._initialTimeOffset;
20559
- const mousePosX = this._view.getPointerPosition().x;
20560
20535
  const mousePosY = this._view.getPointerPosition().y;
20561
- const {initialStartTime, initialEndTime, orderable} = this._draggedElementsData;
20562
- const shouldRedraw = this.manageSourceMovements(this._draggedElements, initialStartTime + timeOffsetDiff + timeDiff, initialEndTime + timeOffsetDiff + timeDiff, orderable, mousePosX, mousePosY);
20536
+ var newEnd = 0;
20537
+ var shouldRedraw = false;
20538
+ (this._nonSelectedElement || Object.values(this._view.getSelectedElements())).forEach(function (source) {
20539
+ if (!this._activeElements[source.id]) {
20540
+ this._activeElements[source.id] = {
20541
+ initialStartTime: source.startTime,
20542
+ initialEndTime: source.endTime
20543
+ };
20544
+ }
20545
+ const {initialStartTime, initialEndTime} = this._activeElements[source.id];
20546
+ newEnd = Math.max(newEnd, source.endTime);
20547
+ if (this._isDraggable) {
20548
+ shouldRedraw = this.updateSource(source, initialStartTime + diff + timeOffsetDiff, initialEndTime + diff + timeOffsetDiff, mousePosY) || shouldRedraw;
20549
+ }
20550
+ }.bind(this));
20563
20551
  if (shouldRedraw) {
20564
20552
  this.draw();
20565
20553
  }
20554
+ this._view.setTimelineLength(this._view.timeToPixels(newEnd) + this._view.getWidth());
20566
20555
  };
20567
20556
  SourcesLayer.prototype.findSources = function (startTime, endTime) {
20568
20557
  var sources = this._peaks.sources.find(startTime, endTime);
@@ -20571,41 +20560,31 @@ module.exports = function (SourceGroup, Lines, DataRetriever, Utils, Invoker, Ko
20571
20560
  return positions[source.position];
20572
20561
  });
20573
20562
  };
20574
- SourcesLayer.prototype._applyTimeChangesToSources = function (sources, initialStartTime, newStartTime, newEndTime) {
20575
- if (sources.length === 1) {
20576
- sources[0].updateTimes(newStartTime, newEndTime);
20577
- } else {
20578
- const timeDiff = Utils.roundTime(newStartTime - initialStartTime);
20579
- if (timeDiff !== 0) {
20580
- sources.forEach(function (source) {
20581
- source.updateTimes(Utils.roundTime(source.startTime + timeDiff), Utils.roundTime(source.endTime + timeDiff));
20582
- });
20583
- }
20584
- }
20585
- this.refresh();
20586
- };
20587
- SourcesLayer.prototype.manageSourceMovements = function (sources, newStartTime, newEndTime, orderable, mouseX, mouseY) {
20588
- newStartTime = typeof newStartTime === 'number' ? Utils.roundTime(newStartTime) : newStartTime;
20589
- newEndTime = typeof newEndTime === 'number' ? Utils.roundTime(newEndTime) : newEndTime;
20590
- if (this._peaks.options.canMoveSourcesBetweenLines && typeof mouseY === 'number') {
20591
- this.manageVerticalPosition(sources, newStartTime, newEndTime, mouseX, mouseY);
20592
- }
20593
- if (orderable) {
20594
- ({newStartTime, newEndTime} = this.manageOrder(sources, newStartTime, newEndTime));
20563
+ SourcesLayer.prototype.updateSource = function (source, startTime, endTime, newY) {
20564
+ var newTimes = {
20565
+ start: startTime,
20566
+ end: endTime
20567
+ };
20568
+ if (this._peaks.options.canMoveSourcesBetweenLines) {
20569
+ this.manageVerticalPosition(source, newY);
20570
+ }
20571
+ newTimes = this.manageSourceOrder(source, newTimes);
20572
+ newTimes = this.manageCollision(source, newTimes);
20573
+ source.updateTimes(newTimes.start, newTimes.end);
20574
+ if (newTimes) {
20575
+ this._updateSource(source);
20576
+ return true;
20595
20577
  }
20596
- ({newStartTime, newEndTime} = this.manageCollision(sources, newStartTime, newEndTime));
20597
- this._applyTimeChangesToSources(sources, sources[0].startTime, newStartTime, newEndTime);
20598
- this._view.setTimelineLength(this._view.timeToPixels(sources[sources.length - 1].endTime) + this._view.getWidth());
20599
- return true;
20578
+ return false;
20600
20579
  };
20601
- SourcesLayer.prototype.manageVerticalPosition = function (sources, startTime, endTime, mouseX, mouseY) {
20602
- return this._lines.manageVerticalPosition(sources, startTime, endTime, mouseX, mouseY);
20580
+ SourcesLayer.prototype.manageVerticalPosition = function (source, newY) {
20581
+ return this._lines.manageVerticalPosition(source, newY);
20603
20582
  };
20604
- SourcesLayer.prototype.manageOrder = function (sources, startTime, endTime) {
20605
- return this._lines.manageOrder(sources, startTime, endTime);
20583
+ SourcesLayer.prototype.manageSourceOrder = function (source, newTimes) {
20584
+ return this._lines.manageSourceOrder(source, newTimes);
20606
20585
  };
20607
- SourcesLayer.prototype.manageCollision = function (sources, newStartTime, newEndTime) {
20608
- return this._lines.manageCollision(sources, newStartTime, newEndTime);
20586
+ SourcesLayer.prototype.manageCollision = function (source, newTimes) {
20587
+ return this._lines.manageCollision(source, newTimes);
20609
20588
  };
20610
20589
  SourcesLayer.prototype._updateSource = function (source) {
20611
20590
  var sourceGroup = this._findOrAddSourceGroup(source);
@@ -20739,7 +20718,9 @@ module.exports = function (SourceGroup, Lines, DataRetriever, Utils, Invoker, Ko
20739
20718
  this._peaks.off('sources.hide', this._onSourcesHide);
20740
20719
  this._peaks.off('source.update', this._onSourceUpdate);
20741
20720
  this._peaks.off('data.retrieved', this._onDataRetrieved);
20721
+ this._peaks.off('sources.refresh', this._onSourcesRefresh);
20742
20722
  this._peaks.off('segments.show', this._onSegmentsShow);
20723
+ this._peaks.off('options.set.line_height', this._onOptionsLineHeightChange);
20743
20724
  this._peaks.off('source.setIndicators', this.setIndicators);
20744
20725
  };
20745
20726
  SourcesLayer.prototype.getHeight = function () {
@@ -21129,8 +21110,10 @@ module.exports = function (Source, Utils) {
21129
21110
  mediaEndTime: originalMediaEndTime,
21130
21111
  color: sourceToCut.color,
21131
21112
  backgroundColor: sourceToCut.backgroundColor,
21113
+ hoverBackgroundColor: sourceToCut.hoverBackgroundColor,
21114
+ selectedBackgroundColor: sourceToCut.selectedBackgroundColor,
21132
21115
  borderColor: sourceToCut.borderColor,
21133
- selectedColor: sourceToCut.selectedColor,
21116
+ selectedBorderColor: sourceToCut.selectedBorderColor,
21134
21117
  warningColor: sourceToCut.warningColor,
21135
21118
  warningWidth: sourceToCut.warningWidth,
21136
21119
  volumeSliderColor: sourceToCut.volumeSliderColor,
@@ -21190,7 +21173,7 @@ module.exports = function (Source, Utils) {
21190
21173
  customParams.push(key, value);
21191
21174
  }
21192
21175
  });
21193
- var source = new Source(this._peaks, options.id || this._getNextSourceId(), options.originId, options.elementId, options.title, options.titleAlignments, 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.warningColor, options.warningWidth, 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.buttons, options.markerColor, options.markerWidth, options.volume, options.volumeRange, options.loading, ...customParams);
21176
+ var source = new Source(this._peaks, options.id || this._getNextSourceId(), options.originId, options.elementId, options.title, options.titleAlignments, 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.hoverBackgroundColor, options.selectedBackgroundColor, options.borderColor, options.selectedBorderColor, options.warningColor, options.warningWidth, 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.buttons, options.markerColor, options.markerWidth, options.volume, options.volumeRange, options.loading, ...customParams);
21194
21177
  return source;
21195
21178
  };
21196
21179
  TimelineSources.prototype.getSources = function () {
@@ -21296,16 +21279,10 @@ module.exports = function (Source, Utils) {
21296
21279
  }, shouldBlockEvent);
21297
21280
  };
21298
21281
  TimelineSources.prototype.showById = function (sourceId) {
21299
- if (this._sourcesById[sourceId].wrapped === false) {
21300
- return;
21301
- }
21302
21282
  this._sourcesById[sourceId].wrapped = false;
21303
21283
  this._peaks.emit('sources.show', [this._sourcesById[sourceId]]);
21304
21284
  };
21305
21285
  TimelineSources.prototype.hideById = function (sourceId) {
21306
- if (this._sourcesById[sourceId].wrapped === true) {
21307
- return;
21308
- }
21309
21286
  this._sourcesById[sourceId].wrapped = true;
21310
21287
  this._peaks.emit('sources.hide', [this._sourcesById[sourceId]]);
21311
21288
  };
@@ -21580,9 +21557,6 @@ module.exports = function (MouseDragHandler, PlayheadLayer, SourcesLayer, ModeLa
21580
21557
  TimelineZoomView.prototype.drawSourcesLayer = function () {
21581
21558
  this._sourcesLayer.draw();
21582
21559
  };
21583
- TimelineZoomView.prototype.refresh = function () {
21584
- this._sourcesLayer.refresh();
21585
- };
21586
21560
  TimelineZoomView.prototype.getSegmentsGroup = function () {
21587
21561
  return this._sourcesLayer.getSegmentsGroup();
21588
21562
  };