@checksub_team/peaks_timeline 1.6.5 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@checksub_team/peaks_timeline",
3
- "version": "1.6.5",
3
+ "version": "1.7.0",
4
4
  "description": "JavaScript UI component for displaying audio waveforms",
5
5
  "main": "./peaks.js",
6
6
  "types": "./peaks.js.d.ts",
package/peaks.js CHANGED
@@ -15631,6 +15631,12 @@ module.exports = function (Colors, EventEmitter, TimelineSegments, TimelineSourc
15631
15631
  this.options.lineHeight = newLineHeight;
15632
15632
  this.emit('options.set.line_height', oldHeight);
15633
15633
  };
15634
+ Peaks.prototype.zoomIn = function () {
15635
+ this.view.setZoom(this.view.getTimeToPixelsScale() + Math.floor(this.view.getTimeToPixelsScale() / 10) + 1);
15636
+ };
15637
+ Peaks.prototype.zoomOut = function () {
15638
+ this.view.setZoom(this.view.getTimeToPixelsScale() - Math.floor(this.view.getTimeToPixelsScale() / 10) + 1);
15639
+ };
15634
15640
  Peaks.prototype.destroy = function () {
15635
15641
  this._removeWindowResizeHandler();
15636
15642
  if (this.keyboardHandler) {
@@ -20770,18 +20776,18 @@ module.exports = function (Utils, Konva) {
20770
20776
  WaveformShape.prototype._sceneFunc = function (context) {
20771
20777
  var width = this._view.getWidth();
20772
20778
  var waveformData = this._layer.getLoadedData(this._url).data;
20773
- var startPixels = 0, startOffset = 0;
20779
+ var startPixel = 0, startOffset = 0;
20774
20780
  if (this._source) {
20775
- startPixels = this._view.timeToPixels(this._source.mediaStartTime) + Math.max(this._view.getFrameOffset() - this._view.timeToPixels(this._source.startTime), 0);
20781
+ startPixel = this._view.timeToPixels(this._source.mediaStartTime) + Math.max(this._view.getFrameOffset() - this._view.timeToPixels(this._source.startTime), 0);
20776
20782
  startOffset = this._view.timeToPixels(this._source.mediaStartTime);
20777
20783
  }
20778
- var endPixels = width;
20784
+ var endPixel = width;
20779
20785
  if (this._source) {
20780
- endPixels = Math.min(this._view.timeToPixels(this._source.mediaEndTime) - Math.max(this._view.timeToPixels(this._source.endTime) - this._view.getFrameOffset() - this._view.getWidth(), 0), waveformData.length);
20786
+ endPixel = Math.min(this._view.timeToPixels(this._source.mediaEndTime) - Math.max(this._view.timeToPixels(this._source.endTime) - this._view.getFrameOffset() - this._view.getWidth(), 0), waveformData.length);
20781
20787
  }
20782
- this._drawWaveform(context, waveformData, startPixels, startOffset, endPixels, this._height);
20788
+ this._drawWaveform(context, waveformData, startPixel, startOffset, endPixel, this._height);
20783
20789
  };
20784
- WaveformShape.prototype._drawWaveform = function (context, waveformData, startPixels, startOffset, endPixels, height) {
20790
+ WaveformShape.prototype._drawWaveform = function (context, waveformData, startPixel, startOffset, endPixel, height) {
20785
20791
  var channels = waveformData.channels;
20786
20792
  var waveformTop = 0;
20787
20793
  var waveformHeight = Math.floor(height / channels);
@@ -20789,19 +20795,19 @@ module.exports = function (Utils, Konva) {
20789
20795
  if (i === channels - 1) {
20790
20796
  waveformHeight = height - (channels - 1) * waveformHeight;
20791
20797
  }
20792
- this._drawChannel(context, waveformData.channel(i), startPixels, startOffset, endPixels, waveformTop, waveformHeight);
20798
+ this._drawChannel(context, waveformData.channel(i), startPixel, startOffset, endPixel, waveformTop, waveformHeight);
20793
20799
  waveformTop += waveformHeight;
20794
20800
  }
20795
20801
  };
20796
- WaveformShape.prototype._drawChannel = function (context, channel, startPixels, startOffset, endPixels, top, height) {
20802
+ WaveformShape.prototype._drawChannel = function (context, channel, startPixel, startOffset, endPixel, top, height) {
20797
20803
  var x, val;
20798
20804
  var amplitudeScale = this._view.getAmplitudeScale();
20799
20805
  context.beginPath();
20800
- for (x = startPixels; x < endPixels; x++) {
20806
+ for (x = Math.floor(startPixel); x < Math.ceil(endPixel); x++) {
20801
20807
  val = channel.min_sample(x);
20802
20808
  context.lineTo(x - startOffset + 0.5, top + scaleY(val, height, amplitudeScale) + 0.5);
20803
20809
  }
20804
- for (x = endPixels - 1; x >= startPixels; x--) {
20810
+ for (x = Math.ceil(endPixel) - 1; x >= Math.floor(startPixel); x--) {
20805
20811
  val = channel.max_sample(x);
20806
20812
  context.lineTo(x - startOffset + 0.5, top + scaleY(val, height, amplitudeScale) + 0.5);
20807
20813
  }
package/src/main.js CHANGED
@@ -745,6 +745,18 @@ define([
745
745
  this.emit('options.set.line_height', oldHeight);
746
746
  };
747
747
 
748
+ Peaks.prototype.zoomIn = function() {
749
+ this.view.setZoom(
750
+ this.view.getTimeToPixelsScale() + Math.floor(this.view.getTimeToPixelsScale() / 10) + 1
751
+ );
752
+ };
753
+
754
+ Peaks.prototype.zoomOut = function() {
755
+ this.view.setZoom(
756
+ this.view.getTimeToPixelsScale() - Math.floor(this.view.getTimeToPixelsScale() / 10) + 1
757
+ );
758
+ };
759
+
748
760
  /**
749
761
  * Cleans up a Peaks instance after use.
750
762
  */
@@ -71,10 +71,10 @@ define(['./utils', 'konva'], function(Utils, Konva) {
71
71
  var width = this._view.getWidth();
72
72
  var waveformData = this._layer.getLoadedData(this._url).data;
73
73
 
74
- var startPixels = 0, startOffset = 0;
74
+ var startPixel = 0, startOffset = 0;
75
75
 
76
76
  if (this._source) {
77
- startPixels = this._view.timeToPixels(this._source.mediaStartTime) + Math.max(
77
+ startPixel = this._view.timeToPixels(this._source.mediaStartTime) + Math.max(
78
78
  this._view.getFrameOffset() - this._view.timeToPixels(this._source.startTime),
79
79
  0
80
80
  );
@@ -82,10 +82,10 @@ define(['./utils', 'konva'], function(Utils, Konva) {
82
82
  startOffset = this._view.timeToPixels(this._source.mediaStartTime);
83
83
  }
84
84
 
85
- var endPixels = width;
85
+ var endPixel = width;
86
86
 
87
87
  if (this._source) {
88
- endPixels = Math.min(
88
+ endPixel = Math.min(
89
89
  this._view.timeToPixels(this._source.mediaEndTime) - Math.max(
90
90
  this._view.timeToPixels(this._source.endTime)
91
91
  - this._view.getFrameOffset()
@@ -99,9 +99,9 @@ define(['./utils', 'konva'], function(Utils, Konva) {
99
99
  this._drawWaveform(
100
100
  context,
101
101
  waveformData,
102
- startPixels,
102
+ startPixel,
103
103
  startOffset,
104
- endPixels,
104
+ endPixel,
105
105
  this._height
106
106
  );
107
107
  };
@@ -122,7 +122,7 @@ define(['./utils', 'konva'], function(Utils, Konva) {
122
122
  */
123
123
 
124
124
  WaveformShape.prototype._drawWaveform = function(context, waveformData,
125
- startPixels, startOffset, endPixels, height) {
125
+ startPixel, startOffset, endPixel, height) {
126
126
  var channels = waveformData.channels;
127
127
 
128
128
  var waveformTop = 0;
@@ -136,9 +136,9 @@ define(['./utils', 'konva'], function(Utils, Konva) {
136
136
  this._drawChannel(
137
137
  context,
138
138
  waveformData.channel(i),
139
- startPixels,
139
+ startPixel,
140
140
  startOffset,
141
- endPixels,
141
+ endPixel,
142
142
  waveformTop,
143
143
  waveformHeight
144
144
  );
@@ -148,20 +148,20 @@ define(['./utils', 'konva'], function(Utils, Konva) {
148
148
  };
149
149
 
150
150
  WaveformShape.prototype._drawChannel = function(context, channel,
151
- startPixels, startOffset, endPixels, top, height) {
151
+ startPixel, startOffset, endPixel, top, height) {
152
152
  var x, val;
153
153
 
154
154
  var amplitudeScale = this._view.getAmplitudeScale();
155
155
 
156
156
  context.beginPath();
157
157
 
158
- for (x = startPixels; x < endPixels; x++) {
158
+ for (x = Math.floor(startPixel); x < Math.ceil(endPixel); x++) {
159
159
  val = channel.min_sample(x);
160
160
 
161
161
  context.lineTo(x - startOffset + 0.5, top + scaleY(val, height, amplitudeScale) + 0.5);
162
162
  }
163
163
 
164
- for (x = endPixels - 1; x >= startPixels; x--) {
164
+ for (x = Math.ceil(endPixel) - 1; x >= Math.floor(startPixel); x--) {
165
165
  val = channel.max_sample(x);
166
166
 
167
167
  context.lineTo(x - startOffset + 0.5, top + scaleY(val, height, amplitudeScale) + 0.5);