@checksub_team/peaks_timeline 1.4.23 → 1.4.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@checksub_team/peaks_timeline",
3
- "version": "1.4.23",
3
+ "version": "1.4.26",
4
4
  "description": "JavaScript UI component for displaying audio waveforms",
5
5
  "main": "./peaks.js",
6
6
  "types": "./peaks.js.d.ts",
package/peaks.js CHANGED
@@ -14754,6 +14754,35 @@ module.exports = function (Konva, Utils) {
14754
14754
  Line.prototype.lineHeight = function () {
14755
14755
  return this._height;
14756
14756
  };
14757
+ Line.prototype.changeHeight = function (from, to) {
14758
+ if (this._sourceHeights[from]) {
14759
+ var oldHeight = this._height;
14760
+ if (this._sourceHeights[to]) {
14761
+ this._sourceHeights[to] += this._sourceHeights[from];
14762
+ } else {
14763
+ this._sourceHeights[to] = this._sourceHeights[from];
14764
+ }
14765
+ if (to > this._height) {
14766
+ this._height = to;
14767
+ } else if (from === this._height) {
14768
+ this._height = 0;
14769
+ for (var height in this._sourceHeights) {
14770
+ if (Utils.objectHasProperty(this._sourceHeights, height)) {
14771
+ var parsedHeight = parseInt(height, 10);
14772
+ if (parsedHeight !== from) {
14773
+ if (parsedHeight > this._height) {
14774
+ this._height = parsedHeight;
14775
+ }
14776
+ }
14777
+ }
14778
+ }
14779
+ }
14780
+ if (this._height !== oldHeight) {
14781
+ this._peaks.emit('line.heightChanged', this._position);
14782
+ }
14783
+ delete this._sourceHeights[from];
14784
+ }
14785
+ };
14757
14786
  Line.prototype.updateLineHeight = function (sourceGroup, action) {
14758
14787
  var oldHeight = this._height;
14759
14788
  var sourceGroupHeight;
@@ -14782,7 +14811,7 @@ module.exports = function (Konva, Utils) {
14782
14811
  for (var height in this._sourceHeights) {
14783
14812
  if (Utils.objectHasProperty(this._sourceHeights, height)) {
14784
14813
  var parsedHeight = parseInt(height, 10);
14785
- if (parseInt(height, 10) > this._height) {
14814
+ if (parsedHeight > this._height) {
14786
14815
  this._height = parsedHeight;
14787
14816
  }
14788
14817
  }
@@ -15148,6 +15177,15 @@ module.exports = function (Line, LineIndicator, Utils) {
15148
15177
  var lineNewY = oldLine.getY();
15149
15178
  this._updateLinesPosition(position, lineNewY);
15150
15179
  };
15180
+ Lines.prototype.changeLineHeight = function (from, to) {
15181
+ for (var position in this._linesByPosition) {
15182
+ if (Utils.objectHasProperty(this._linesByPosition, position)) {
15183
+ if (!this._linesByPosition[position].isSegmentsLine()) {
15184
+ this._linesByPosition[position].changeHeight(from, to);
15185
+ }
15186
+ }
15187
+ }
15188
+ };
15151
15189
  Lines.prototype.addSourceGroup = function (sourceGroup, position) {
15152
15190
  if (!this._linesByPosition[position]) {
15153
15191
  this._createLine(position);
@@ -15419,7 +15457,8 @@ module.exports = function (Colors, EventEmitter, TimelineSegments, TimelineSourc
15419
15457
  autoScrollThreshold: 0.05,
15420
15458
  enableLineIndicatorContextMenu: true,
15421
15459
  minSourceSize: 0.05,
15422
- minSegmentSize: 0.2
15460
+ minSegmentSize: 0.2,
15461
+ canMoveSourcesBetweenLines: true
15423
15462
  };
15424
15463
  this.logger = console.error.bind(console);
15425
15464
  return this;
@@ -15571,6 +15610,11 @@ module.exports = function (Colors, EventEmitter, TimelineSegments, TimelineSourc
15571
15610
  Peaks.prototype._removeWindowResizeHandler = function () {
15572
15611
  window.removeEventListener('resize', this._onResize);
15573
15612
  };
15613
+ Peaks.prototype.setLineHeight = function (newLineHeight) {
15614
+ var oldHeight = this.options.lineHeight;
15615
+ this.options.lineHeight = newLineHeight;
15616
+ this.emit('options.set.line_height', oldHeight);
15617
+ };
15574
15618
  Peaks.prototype.destroy = function () {
15575
15619
  this._removeWindowResizeHandler();
15576
15620
  if (this.keyboardHandler) {
@@ -15696,12 +15740,15 @@ module.exports = function (Utils, SourceGroup, Konva) {
15696
15740
  if (hoveredElement) {
15697
15741
  if (this._selectedElement) {
15698
15742
  this._selectedElement.setSelected(false);
15743
+ this._peaks.emit('source.deselected', this._selectedElement.getSource());
15699
15744
  }
15700
15745
  this._selectedElement = hoveredElement;
15701
15746
  this._selectedElement.setSelected(true);
15747
+ this._peaks.emit('source.selected', this._selectedElement.getSource());
15702
15748
  } else {
15703
15749
  if (this._selectedElement) {
15704
15750
  this._selectedElement.setSelected(false);
15751
+ this._peaks.emit('source.deselected', this._selectedElement.getSource());
15705
15752
  this._selectedElement = null;
15706
15753
  }
15707
15754
  }
@@ -18076,8 +18123,11 @@ module.exports = function (Utils) {
18076
18123
  } else if (options.wrapping === 'complete') {
18077
18124
  options.wrapped = false;
18078
18125
  }
18126
+ if (!Utils.isNullOrUndefined(options.tts) && !Utils.isBoolean(options.tts)) {
18127
+ throw new TypeError('peaks.sources.' + context + ': tts must be a boolean or undefined');
18128
+ }
18079
18129
  }
18080
- function Source(peaks, id, originId, elementId, title, url, previewUrl, binaryUrl, kind, duration, startTime, endTime, mediaStartTime, mediaEndTime, color, borderColor, selectedColor, textColor, borderWidth, wrapped, position, draggable, resizable, wrapping, previewHeight, binaryHeight) {
18130
+ function Source(peaks, id, originId, elementId, title, url, previewUrl, binaryUrl, kind, duration, startTime, endTime, mediaStartTime, mediaEndTime, color, borderColor, selectedColor, textColor, borderWidth, wrapped, position, draggable, resizable, wrapping, previewHeight, binaryHeight, tts) {
18081
18131
  var opts = {
18082
18132
  title: title,
18083
18133
  url: url,
@@ -18100,7 +18150,8 @@ module.exports = function (Utils) {
18100
18150
  resizable: resizable,
18101
18151
  wrapping: wrapping,
18102
18152
  previewHeight: previewHeight,
18103
- binaryHeight: binaryHeight
18153
+ binaryHeight: binaryHeight,
18154
+ tts: tts
18104
18155
  };
18105
18156
  validateSource(peaks, opts, 'add()');
18106
18157
  this._peaks = peaks;
@@ -18130,6 +18181,7 @@ module.exports = function (Utils) {
18130
18181
  this._previewHeight = opts.previewHeight;
18131
18182
  this._binaryHeight = opts.binaryHeight;
18132
18183
  this._minSize = peaks.options.minSourceSize;
18184
+ this._tts = opts.tts;
18133
18185
  }
18134
18186
  Object.defineProperties(Source.prototype, {
18135
18187
  id: {
@@ -18335,6 +18387,14 @@ module.exports = function (Utils) {
18335
18387
  get: function () {
18336
18388
  return this._minSize;
18337
18389
  }
18390
+ },
18391
+ tts: {
18392
+ get: function () {
18393
+ return this._tts;
18394
+ },
18395
+ set: function (tts) {
18396
+ this._tts = tts;
18397
+ }
18338
18398
  }
18339
18399
  });
18340
18400
  Source.prototype.updateTimes = function (newStartTime, newEndTime) {
@@ -18444,7 +18504,8 @@ module.exports = function (Utils) {
18444
18504
  resizable: this.resizable,
18445
18505
  wrapping: this.wrapping,
18446
18506
  previewHeight: this.previewHeight,
18447
- binaryHeight: this.binaryHeight
18507
+ binaryHeight: this.binaryHeight,
18508
+ tts: this._tts
18448
18509
  };
18449
18510
  Utils.extend(opts, options);
18450
18511
  validateSource(this._peaks, opts, 'update()');
@@ -18470,6 +18531,7 @@ module.exports = function (Utils) {
18470
18531
  this._wrapping = opts.wrapping;
18471
18532
  this._previewHeight = opts.previewHeight;
18472
18533
  this._binaryHeight = opts.binaryHeight;
18534
+ this._tts = opts.tts;
18473
18535
  this._peaks.emit('source.update', this);
18474
18536
  };
18475
18537
  Source.prototype.isVisible = function (startTime, endTime) {
@@ -18500,6 +18562,7 @@ module.exports = function (SourceGroup, SegmentsGroup, Lines, DataRetriever, Uti
18500
18562
  this._peaks.on('data.retrieved', this._onDataRetrieved.bind(this));
18501
18563
  this._peaks.on('sources.refresh', this._onSourcesRefresh.bind(this));
18502
18564
  this._peaks.on('segments.show', this._onSegmentsShow.bind(this));
18565
+ this._peaks.on('options.set.line_height', this._onOptionsLineHeightChange.bind(this));
18503
18566
  }
18504
18567
  SourcesLayer.prototype.getLoadedData = function (id) {
18505
18568
  return this._loadedData[id];
@@ -18522,6 +18585,25 @@ module.exports = function (SourceGroup, SegmentsGroup, Lines, DataRetriever, Uti
18522
18585
  SourcesLayer.prototype.isEditingEnabled = function () {
18523
18586
  return this._allowEditing;
18524
18587
  };
18588
+ SourcesLayer.prototype._onOptionsLineHeightChange = function (oldHeight) {
18589
+ var positions = [];
18590
+ for (var sourceId in this._sourcesGroup) {
18591
+ if (Utils.objectHasProperty(this._sourcesGroup, sourceId)) {
18592
+ var source = this._sourcesGroup[sourceId].getSource();
18593
+ if (!positions.includes(source.position)) {
18594
+ this._lines.changeLineHeight(oldHeight, this._peaks.options.lineHeight);
18595
+ positions.push(source.position);
18596
+ }
18597
+ this._removeSource(source);
18598
+ this._addSourceGroup(source);
18599
+ }
18600
+ }
18601
+ if (positions) {
18602
+ var frameOffset = this._view.getFrameOffset();
18603
+ var width = this._view.getWidth();
18604
+ this.updateSources(this._view.pixelsToTime(frameOffset), this._view.pixelsToTime(frameOffset + width));
18605
+ }
18606
+ };
18525
18607
  SourcesLayer.prototype._onSourceUpdate = function (source) {
18526
18608
  var redraw = false;
18527
18609
  var sourceGroup = this._sourcesGroup[source.id];
@@ -18648,7 +18730,9 @@ module.exports = function (SourceGroup, SegmentsGroup, Lines, DataRetriever, Uti
18648
18730
  endX: newEndX,
18649
18731
  updateWidth: false
18650
18732
  };
18651
- this.manageVerticalPosition(source, newY);
18733
+ if (this._peaks.options.canMoveSourcesBetweenLines) {
18734
+ this.manageVerticalPosition(source, newY);
18735
+ }
18652
18736
  newXs = this.manageSourceOrder(source, newStartX, newEndX);
18653
18737
  newXs = this.manageCollision(source, newXs.startX, newXs.endX);
18654
18738
  source.updateTimes(newXs.startX !== null ? this._view.pixelsToTime(newXs.startX) : null, newXs.endX !== null ? this._view.pixelsToTime(newXs.endX) : null);
@@ -19132,7 +19216,8 @@ module.exports = function (Source, Utils) {
19132
19216
  resizable: sourceToCut.resizable,
19133
19217
  wrapping: sourceToCut.wrapping,
19134
19218
  previewHeight: sourceToCut.previewHeight,
19135
- binaryHeight: sourceToCut.binaryHeight
19219
+ binaryHeight: sourceToCut.binaryHeight,
19220
+ tts: sourceToCut.tts
19136
19221
  }]);
19137
19222
  this._peaks.emit('sources.updated');
19138
19223
  };
@@ -19147,7 +19232,7 @@ module.exports = function (Source, Utils) {
19147
19232
  if (!Utils.isObject(options)) {
19148
19233
  throw new TypeError('peaks.sources.add(): expected a Source object parameter');
19149
19234
  }
19150
- var source = new Source(this._peaks, options.id || this._getNextSourceId(), options.originId, options.elementId, options.title, options.url, options.previewUrl, options.binaryUrl, options.kind, options.duration, options.startTime, options.endTime, options.mediaStartTime, options.mediaEndTime, options.color, options.borderColor, options.selectedColor, options.textColor, options.borderWidth, options.wrapped, options.position, options.draggable, options.resizable, options.wrapping, options.previewHeight, options.binaryHeight);
19235
+ var source = new Source(this._peaks, options.id || this._getNextSourceId(), options.originId, options.elementId, options.title, options.url, options.previewUrl, options.binaryUrl, options.kind, options.duration, options.startTime, options.endTime, options.mediaStartTime, options.mediaEndTime, options.color, options.borderColor, options.selectedColor, options.textColor, options.borderWidth, options.wrapped, options.position, options.draggable, options.resizable, options.wrapping, options.previewHeight, options.binaryHeight, options.tts);
19151
19236
  return source;
19152
19237
  };
19153
19238
  TimelineSources.prototype.getSources = function () {
package/src/line.js CHANGED
@@ -91,6 +91,43 @@ define([
91
91
  return this._height;
92
92
  };
93
93
 
94
+ Line.prototype.changeHeight = function(from, to) {
95
+ if (this._sourceHeights[from]) {
96
+ var oldHeight = this._height;
97
+
98
+ if (this._sourceHeights[to]) {
99
+ this._sourceHeights[to] += this._sourceHeights[from];
100
+ }
101
+ else {
102
+ this._sourceHeights[to] = this._sourceHeights[from];
103
+ }
104
+
105
+ if (to > this._height) {
106
+ this._height = to;
107
+ }
108
+ else if (from === this._height) {
109
+ this._height = 0;
110
+ for (var height in this._sourceHeights) {
111
+ if (Utils.objectHasProperty(this._sourceHeights, height)) {
112
+ var parsedHeight = parseInt(height, 10);
113
+
114
+ if (parsedHeight !== from) {
115
+ if (parsedHeight > this._height) {
116
+ this._height = parsedHeight;
117
+ }
118
+ }
119
+ }
120
+ }
121
+ }
122
+
123
+ if (this._height !== oldHeight) {
124
+ this._peaks.emit('line.heightChanged', this._position);
125
+ }
126
+
127
+ delete this._sourceHeights[from];
128
+ }
129
+ };
130
+
94
131
  Line.prototype.updateLineHeight = function(sourceGroup, action) {
95
132
  var oldHeight = this._height;
96
133
  var sourceGroupHeight;
@@ -127,7 +164,7 @@ define([
127
164
  if (Utils.objectHasProperty(this._sourceHeights, height)) {
128
165
  var parsedHeight = parseInt(height, 10);
129
166
 
130
- if (parseInt(height, 10) > this._height) {
167
+ if (parsedHeight > this._height) {
131
168
  this._height = parsedHeight;
132
169
  }
133
170
  }
package/src/lines.js CHANGED
@@ -57,6 +57,16 @@ define([
57
57
  this._updateLinesPosition(position, lineNewY);
58
58
  };
59
59
 
60
+ Lines.prototype.changeLineHeight = function(from, to) {
61
+ for (var position in this._linesByPosition) {
62
+ if (Utils.objectHasProperty(this._linesByPosition, position)) {
63
+ if (!this._linesByPosition[position].isSegmentsLine()) {
64
+ this._linesByPosition[position].changeHeight(from, to);
65
+ }
66
+ }
67
+ }
68
+ };
69
+
60
70
  Lines.prototype.addSourceGroup = function(sourceGroup, position) {
61
71
  if (!this._linesByPosition[position]) {
62
72
  this._createLine(position);
package/src/main.js CHANGED
@@ -233,7 +233,7 @@ define([
233
233
  lineHeight: 80,
234
234
 
235
235
  /**
236
- * Ratio by which lineHeight must be multiplied to obtain the segment's line height.
236
+ * Height of a segment, in pixels.
237
237
  */
238
238
  segmentHeight: 32,
239
239
 
@@ -310,7 +310,13 @@ define([
310
310
  /**
311
311
  * The minimal size of a segment, in seconds
312
312
  */
313
- minSegmentSize: 0.2
313
+ minSegmentSize: 0.2,
314
+
315
+ /**
316
+ * Indicates whether or not sources can be dragged
317
+ * from one line to another
318
+ */
319
+ canMoveSourcesBetweenLines: true
314
320
  };
315
321
 
316
322
  /**
@@ -635,6 +641,13 @@ define([
635
641
  window.removeEventListener('resize', this._onResize);
636
642
  };
637
643
 
644
+ Peaks.prototype.setLineHeight = function(newLineHeight) {
645
+ var oldHeight = this.options.lineHeight;
646
+
647
+ this.options.lineHeight = newLineHeight;
648
+ this.emit('options.set.line_height', oldHeight);
649
+ };
650
+
638
651
  /**
639
652
  * Cleans up a Peaks instance after use.
640
653
  */
package/src/mode-layer.js CHANGED
@@ -121,15 +121,19 @@ define([
121
121
  if (hoveredElement) {
122
122
  if (this._selectedElement) {
123
123
  this._selectedElement.setSelected(false);
124
+ this._peaks.emit('source.deselected', this._selectedElement.getSource());
124
125
  }
125
126
 
126
127
  this._selectedElement = hoveredElement;
127
128
 
128
129
  this._selectedElement.setSelected(true);
130
+
131
+ this._peaks.emit('source.selected', this._selectedElement.getSource());
129
132
  }
130
133
  else {
131
134
  if (this._selectedElement) {
132
135
  this._selectedElement.setSelected(false);
136
+ this._peaks.emit('source.deselected', this._selectedElement.getSource());
133
137
  this._selectedElement = null;
134
138
  }
135
139
  }
package/src/source.js CHANGED
@@ -197,6 +197,10 @@ define([
197
197
  else if (options.wrapping === 'complete') {
198
198
  options.wrapped = false;
199
199
  }
200
+
201
+ if (!Utils.isNullOrUndefined(options.tts) && !Utils.isBoolean(options.tts)) {
202
+ throw new TypeError('peaks.sources.' + context + ': tts must be a boolean or undefined');
203
+ }
200
204
  }
201
205
 
202
206
  /**
@@ -222,7 +226,7 @@ define([
222
226
  function Source(peaks, id, originId, elementId, title, url, previewUrl, binaryUrl, kind,
223
227
  duration, startTime, endTime, mediaStartTime, mediaEndTime, color, borderColor,
224
228
  selectedColor, textColor, borderWidth, wrapped, position, draggable, resizable, wrapping,
225
- previewHeight, binaryHeight) {
229
+ previewHeight, binaryHeight, tts) {
226
230
  var opts = {
227
231
  title: title,
228
232
  url: url,
@@ -245,7 +249,8 @@ define([
245
249
  resizable: resizable,
246
250
  wrapping: wrapping,
247
251
  previewHeight: previewHeight,
248
- binaryHeight: binaryHeight
252
+ binaryHeight: binaryHeight,
253
+ tts: tts
249
254
  };
250
255
 
251
256
  validateSource(peaks, opts, 'add()');
@@ -277,6 +282,7 @@ define([
277
282
  this._previewHeight = opts.previewHeight;
278
283
  this._binaryHeight = opts.binaryHeight;
279
284
  this._minSize = peaks.options.minSourceSize;
285
+ this._tts = opts.tts;
280
286
  }
281
287
 
282
288
  Object.defineProperties(Source.prototype, {
@@ -497,6 +503,15 @@ define([
497
503
  get: function() {
498
504
  return this._minSize;
499
505
  }
506
+ },
507
+ tts: {
508
+ get: function() {
509
+ return this._tts;
510
+ },
511
+
512
+ set: function(tts) {
513
+ this._tts = tts;
514
+ }
500
515
  }
501
516
  });
502
517
 
@@ -638,7 +653,8 @@ define([
638
653
  resizable: this.resizable,
639
654
  wrapping: this.wrapping,
640
655
  previewHeight: this.previewHeight,
641
- binaryHeight: this.binaryHeight
656
+ binaryHeight: this.binaryHeight,
657
+ tts: this._tts
642
658
  };
643
659
 
644
660
  Utils.extend(opts, options);
@@ -667,6 +683,7 @@ define([
667
683
  this._wrapping = opts.wrapping;
668
684
  this._previewHeight = opts.previewHeight;
669
685
  this._binaryHeight = opts.binaryHeight;
686
+ this._tts = opts.tts;
670
687
 
671
688
  this._peaks.emit('source.update', this);
672
689
  };
@@ -61,6 +61,7 @@ define([
61
61
  this._peaks.on('data.retrieved', this._onDataRetrieved.bind(this));
62
62
  this._peaks.on('sources.refresh', this._onSourcesRefresh.bind(this));
63
63
  this._peaks.on('segments.show', this._onSegmentsShow.bind(this));
64
+ this._peaks.on('options.set.line_height', this._onOptionsLineHeightChange.bind(this));
64
65
  }
65
66
 
66
67
  SourcesLayer.prototype.getLoadedData = function(id) {
@@ -97,6 +98,36 @@ define([
97
98
  return this._allowEditing;
98
99
  };
99
100
 
101
+ SourcesLayer.prototype._onOptionsLineHeightChange = function(oldHeight) {
102
+ var positions = [];
103
+
104
+ for (var sourceId in this._sourcesGroup) {
105
+ if (Utils.objectHasProperty(this._sourcesGroup, sourceId)) {
106
+ var source = this._sourcesGroup[sourceId].getSource();
107
+
108
+ if (!positions.includes(source.position)) {
109
+ this._lines.changeLineHeight(
110
+ oldHeight,
111
+ this._peaks.options.lineHeight
112
+ );
113
+ positions.push(source.position);
114
+ }
115
+ this._removeSource(source);
116
+ this._addSourceGroup(source);
117
+ }
118
+ }
119
+
120
+ if (positions) {
121
+ var frameOffset = this._view.getFrameOffset();
122
+ var width = this._view.getWidth();
123
+
124
+ this.updateSources(
125
+ this._view.pixelsToTime(frameOffset),
126
+ this._view.pixelsToTime(frameOffset + width)
127
+ );
128
+ }
129
+ };
130
+
100
131
  SourcesLayer.prototype._onSourceUpdate = function(source) {
101
132
  var redraw = false;
102
133
  var sourceGroup = this._sourcesGroup[source.id];
@@ -297,7 +328,9 @@ define([
297
328
  updateWidth: false
298
329
  };
299
330
 
300
- this.manageVerticalPosition(source, newY);
331
+ if (this._peaks.options.canMoveSourcesBetweenLines) {
332
+ this.manageVerticalPosition(source, newY);
333
+ }
301
334
 
302
335
  newXs = this.manageSourceOrder(source, newStartX, newEndX);
303
336
 
@@ -87,7 +87,8 @@ define([
87
87
  resizable: sourceToCut.resizable,
88
88
  wrapping: sourceToCut.wrapping,
89
89
  previewHeight: sourceToCut.previewHeight,
90
- binaryHeight: sourceToCut.binaryHeight
90
+ binaryHeight: sourceToCut.binaryHeight,
91
+ tts: sourceToCut.tts
91
92
  }]);
92
93
 
93
94
  this._peaks.emit('sources.updated');
@@ -159,7 +160,8 @@ define([
159
160
  options.resizable,
160
161
  options.wrapping,
161
162
  options.previewHeight,
162
- options.binaryHeight
163
+ options.binaryHeight,
164
+ options.tts
163
165
  );
164
166
 
165
167
  return source;