@checksub_team/peaks_timeline 2.2.0-alpha.0 → 2.2.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@checksub_team/peaks_timeline",
3
- "version": "2.2.0-alpha.0",
3
+ "version": "2.2.0-alpha.1",
4
4
  "description": "JavaScript UI component for displaying audio waveforms",
5
5
  "main": "./peaks.js",
6
6
  "types": "./peaks.js.d.ts",
package/peaks.js CHANGED
@@ -19828,21 +19828,16 @@ module.exports = function (Utils, Konva) {
19828
19828
  WaveformShape.prototype._sceneFunc = function (context) {
19829
19829
  var width = this._view.getWidth();
19830
19830
  var waveformData = this._layer.getLoadedData(this._url).data;
19831
- var targetSpeed = this._source.targetSpeed || 1;
19832
- var startPixel = 0, startOffset = 0;
19831
+ var startPixel = 0, startOffset = 0, endPixel = width, targetSpeed = 1;
19833
19832
  if (this._source) {
19834
- startPixel = this._view.timeToPixels(this._source.mediaStartTime) + Math.max(this._view.getFrameOffset() - this._view.timeToPixels(this._source.startTime), 0);
19833
+ targetSpeed = this._source.targetSpeed || 1;
19834
+ startPixel = Math.floor((this._view.timeToPixels(this._source.mediaStartTime) + Math.max(this._view.getFrameOffset() - this._view.timeToPixels(this._source.startTime), 0)) * targetSpeed);
19835
19835
  startOffset = this._view.timeToPixels(this._source.mediaStartTime);
19836
+ endPixel = Math.min(Math.ceil((this._view.timeToPixels(this._source.mediaEndTime) - Math.max(this._view.timeToPixels(this._source.endTime) - this._view.getFrameOffset() - this._view.getWidth(), 0)) * targetSpeed), waveformData.length);
19836
19837
  }
19837
- var endPixel = width;
19838
- if (this._source) {
19839
- var effectiveMediaDuration = (this._source.endTime - this._source.startTime) * targetSpeed;
19840
- var effectiveMediaEndTime = Math.min(this._source.mediaStartTime + effectiveMediaDuration, this._source.duration || Infinity);
19841
- endPixel = Math.min(this._view.timeToPixels(effectiveMediaEndTime) - Math.max(this._view.timeToPixels(this._source.endTime) - this._view.getFrameOffset() - this._view.getWidth(), 0), waveformData.length);
19842
- }
19843
- this._drawWaveform(context, waveformData, startPixel, startOffset, endPixel, this._height);
19838
+ this._drawWaveform(context, waveformData, startPixel, startOffset, endPixel, targetSpeed, this._height);
19844
19839
  };
19845
- WaveformShape.prototype._drawWaveform = function (context, waveformData, startPixel, startOffset, endPixel, height) {
19840
+ WaveformShape.prototype._drawWaveform = function (context, waveformData, startPixel, startOffset, endPixel, targetSpeed, height) {
19846
19841
  var channels = waveformData.channels;
19847
19842
  var waveformTop = 0;
19848
19843
  var waveformHeight = Math.floor(height / channels);
@@ -19850,24 +19845,21 @@ module.exports = function (Utils, Konva) {
19850
19845
  if (i === channels - 1) {
19851
19846
  waveformHeight = height - (channels - 1) * waveformHeight;
19852
19847
  }
19853
- this._drawChannel(context, waveformData.channel(i), startPixel, startOffset, endPixel, waveformTop, waveformHeight);
19848
+ this._drawChannel(context, waveformData.channel(i), startPixel, startOffset, endPixel, waveformTop, waveformHeight, targetSpeed);
19854
19849
  waveformTop += waveformHeight;
19855
19850
  }
19856
19851
  };
19857
- WaveformShape.prototype._drawChannel = function (context, channel, startPixel, startOffset, endPixel, top, height) {
19858
- var x, val, displayX;
19852
+ WaveformShape.prototype._drawChannel = function (context, channel, startPixel, startOffset, endPixel, top, height, targetSpeed) {
19853
+ var x, val;
19859
19854
  var amplitudeScale = this._view.getAmplitudeScale();
19860
- var targetSpeed = this._source && this._source.targetSpeed ? this._source.targetSpeed : 1;
19861
19855
  context.beginPath();
19862
- for (x = Math.floor(startPixel); x < Math.ceil(endPixel); x++) {
19856
+ for (x = startPixel; x < endPixel; x++) {
19863
19857
  val = channel.min_sample(x);
19864
- displayX = (x - startPixel) / targetSpeed + startPixel;
19865
- context.lineTo(displayX - startOffset + 0.5, top + scaleY(val, height, amplitudeScale) + 0.5);
19858
+ context.lineTo(x / targetSpeed - startOffset + 0.5, top + scaleY(val, height, amplitudeScale) + 0.5);
19866
19859
  }
19867
- for (x = Math.ceil(endPixel) - 1; x >= Math.floor(startPixel); x--) {
19860
+ for (x = endPixel - 1; x >= startPixel; x--) {
19868
19861
  val = channel.max_sample(x);
19869
- displayX = (x - startPixel) / targetSpeed + startPixel;
19870
- context.lineTo(displayX - startOffset + 0.5, top + scaleY(val, height, amplitudeScale) + 0.5);
19862
+ context.lineTo(x / targetSpeed - startOffset + 0.5, top + scaleY(val, height, amplitudeScale) + 0.5);
19871
19863
  }
19872
19864
  context.closePath();
19873
19865
  context.fillShape(this);
@@ -72,36 +72,29 @@ define(['../utils', 'konva'], function(Utils, Konva) {
72
72
  WaveformShape.prototype._sceneFunc = function(context) {
73
73
  var width = this._view.getWidth();
74
74
  var waveformData = this._layer.getLoadedData(this._url).data;
75
- var targetSpeed = this._source.targetSpeed || 1.0;
76
75
 
77
- var startPixel = 0, startOffset = 0;
76
+ var startPixel = 0, startOffset = 0, endPixel = width, targetSpeed = 1.0;
78
77
 
79
78
  if (this._source) {
80
- startPixel = this._view.timeToPixels(this._source.mediaStartTime) + Math.max(
81
- this._view.getFrameOffset() - this._view.timeToPixels(this._source.startTime),
82
- 0
79
+ targetSpeed = this._source.targetSpeed || 1.0;
80
+
81
+ startPixel = Math.floor(
82
+ (this._view.timeToPixels(this._source.mediaStartTime) + Math.max(
83
+ this._view.getFrameOffset() - this._view.timeToPixels(this._source.startTime),
84
+ 0
85
+ )) * targetSpeed
83
86
  );
84
87
 
85
88
  startOffset = this._view.timeToPixels(this._source.mediaStartTime);
86
- }
87
-
88
- var endPixel = width;
89
-
90
- if (this._source) {
91
- // Calculate the effective media end time based on targetSpeed
92
- // If speed is 2.0, we can fit 2x more audio in the same visual space
93
- var effectiveMediaDuration = (this._source.endTime - this._source.startTime) * targetSpeed;
94
- var effectiveMediaEndTime = Math.min(
95
- this._source.mediaStartTime + effectiveMediaDuration,
96
- this._source.duration || Infinity
97
- );
98
89
 
99
90
  endPixel = Math.min(
100
- this._view.timeToPixels(effectiveMediaEndTime) - Math.max(
101
- this._view.timeToPixels(this._source.endTime)
102
- - this._view.getFrameOffset()
103
- - this._view.getWidth(),
104
- 0
91
+ Math.ceil(
92
+ (this._view.timeToPixels(this._source.mediaEndTime) - Math.max(
93
+ this._view.timeToPixels(this._source.endTime)
94
+ - this._view.getFrameOffset()
95
+ - this._view.getWidth(),
96
+ 0
97
+ )) * targetSpeed
105
98
  ),
106
99
  waveformData.length
107
100
  );
@@ -113,6 +106,7 @@ define(['../utils', 'konva'], function(Utils, Konva) {
113
106
  startPixel,
114
107
  startOffset,
115
108
  endPixel,
109
+ targetSpeed,
116
110
  this._height
117
111
  );
118
112
  };
@@ -133,7 +127,7 @@ define(['../utils', 'konva'], function(Utils, Konva) {
133
127
  */
134
128
 
135
129
  WaveformShape.prototype._drawWaveform = function(context, waveformData,
136
- startPixel, startOffset, endPixel, height) {
130
+ startPixel, startOffset, endPixel, targetSpeed, height) {
137
131
  var channels = waveformData.channels;
138
132
 
139
133
  var waveformTop = 0;
@@ -151,7 +145,8 @@ define(['../utils', 'konva'], function(Utils, Konva) {
151
145
  startOffset,
152
146
  endPixel,
153
147
  waveformTop,
154
- waveformHeight
148
+ waveformHeight,
149
+ targetSpeed
155
150
  );
156
151
 
157
152
  waveformTop += waveformHeight;
@@ -159,31 +154,23 @@ define(['../utils', 'konva'], function(Utils, Konva) {
159
154
  };
160
155
 
161
156
  WaveformShape.prototype._drawChannel = function(context, channel,
162
- startPixel, startOffset, endPixel, top, height) {
163
- var x, val, displayX;
157
+ startPixel, startOffset, endPixel, top, height, targetSpeed) {
158
+ var x, val;
164
159
 
165
160
  var amplitudeScale = this._view.getAmplitudeScale();
166
- var targetSpeed = this._source && this._source.targetSpeed ? this._source.targetSpeed : 1.0;
167
161
 
168
162
  context.beginPath();
169
163
 
170
- for (x = Math.floor(startPixel); x < Math.ceil(endPixel); x++) {
164
+ for (x = startPixel; x < endPixel; x++) {
171
165
  val = channel.min_sample(x);
172
166
 
173
- // Scale the x position by dividing by targetSpeed to compress/expand the waveform
174
- // targetSpeed = 2.0 means the waveform is drawn at half width (compressed)
175
- // targetSpeed = 0.5 means the waveform is drawn at double width (expanded)
176
- displayX = (x - startPixel) / targetSpeed + startPixel;
177
-
178
- context.lineTo(displayX - startOffset + 0.5, top + scaleY(val, height, amplitudeScale) + 0.5);
167
+ context.lineTo(x / targetSpeed - startOffset + 0.5, top + scaleY(val, height, amplitudeScale) + 0.5);
179
168
  }
180
169
 
181
- for (x = Math.ceil(endPixel) - 1; x >= Math.floor(startPixel); x--) {
170
+ for (x = endPixel - 1; x >= startPixel; x--) {
182
171
  val = channel.max_sample(x);
183
172
 
184
- displayX = (x - startPixel) / targetSpeed + startPixel;
185
-
186
- context.lineTo(displayX - startOffset + 0.5, top + scaleY(val, height, amplitudeScale) + 0.5);
173
+ context.lineTo(x / targetSpeed - startOffset + 0.5, top + scaleY(val, height, amplitudeScale) + 0.5);
187
174
  }
188
175
 
189
176
  context.closePath();