@checksub_team/peaks_timeline 2.1.0-alpha.0 → 2.1.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.1.0-alpha.0",
3
+ "version": "2.1.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
@@ -16723,7 +16723,7 @@ module.exports = function (Utils, Konva) {
16723
16723
  PlayheadLayer.prototype._createPlayheadText = function (color) {
16724
16724
  this._playheadText = new Konva.Text({
16725
16725
  x: 13,
16726
- y: 3,
16726
+ y: 10,
16727
16727
  text: '00:00:00',
16728
16728
  fontSize: 11,
16729
16729
  fontFamily: 'sans-serif',
@@ -16737,21 +16737,28 @@ module.exports = function (Utils, Konva) {
16737
16737
  this._syncPlayhead(time);
16738
16738
  };
16739
16739
  PlayheadLayer.prototype._syncPlayhead = function (time) {
16740
- if (this._time === time) {
16741
- return;
16740
+ const pixelHasChanged = this._updatePlayheadPixel(time);
16741
+ const timeHasChanged = this._time !== time;
16742
+ if (timeHasChanged) {
16743
+ this._updateActiveSegmentsAndSources(time);
16744
+ this._updatePlayheadText(time);
16742
16745
  }
16743
16746
  this._time = time;
16744
- this._updatePlayheadPixel(time);
16745
- this._updateActiveSegmentsAndSources(time);
16746
- this._updatePlayheadText(time);
16747
- this._playheadLayer.batchDraw();
16747
+ if (pixelHasChanged || timeHasChanged) {
16748
+ this._playheadLayer.batchDraw();
16749
+ }
16748
16750
  };
16749
16751
  PlayheadLayer.prototype._updatePlayheadPixel = function (time) {
16750
16752
  const pixelIndex = this._view.timeToPixels(time);
16751
16753
  const frameOffset = this._view.timeToPixels(this._view.getTimeOffset());
16752
16754
  this._playheadPixel = pixelIndex;
16753
16755
  const playheadX = this._playheadPixel - frameOffset;
16754
- this._playheadGroup.setAttr('x', playheadX);
16756
+ const oldX = this._playheadGroup.getAttr('x');
16757
+ const shouldUpdateX = oldX !== playheadX;
16758
+ if (shouldUpdateX) {
16759
+ this._playheadGroup.setAttr('x', playheadX);
16760
+ }
16761
+ return shouldUpdateX;
16755
16762
  };
16756
16763
  PlayheadLayer.prototype._updateActiveSegmentsAndSources = function (time) {
16757
16764
  const lineGroups = this._lines.getLineGroupsById();
@@ -16795,7 +16802,6 @@ module.exports = function (Utils, Konva) {
16795
16802
  PlayheadLayer.prototype._updatePlayheadText = function (time) {
16796
16803
  var text = Utils.formatTime(time, false);
16797
16804
  this._playheadText.setText(text);
16798
- this._peaks.emit('playhead.moved', this._playheadText.getAbsolutePosition().x, this._playheadText.width());
16799
16805
  };
16800
16806
  PlayheadLayer.prototype.getPlayheadOffset = function () {
16801
16807
  return this._playheadPixel - this._view.getFrameOffset();
@@ -705,7 +705,7 @@ define([
705
705
 
706
706
  if (currentSource) {
707
707
  if (currentSource.source.startTime > time) {
708
- // We didn't find an active source and will not in the remainings sources
708
+ // We didn't find an active source and will not in the remaining sources
709
709
  if (previousSource) {
710
710
  this._cachedStartSourceForActive = previousSource.source;
711
711
  }
@@ -196,7 +196,7 @@ define([
196
196
  // Create with default y, the real value is set in fitToView().
197
197
  this._playheadText = new Konva.Text({
198
198
  x: 13,
199
- y: 3,
199
+ y: 10,
200
200
  text: '00:00:00',
201
201
  fontSize: 11,
202
202
  fontFamily: 'sans-serif',
@@ -226,15 +226,18 @@ define([
226
226
  */
227
227
 
228
228
  PlayheadLayer.prototype._syncPlayhead = function(time) {
229
- if (this._time === time) {
230
- return;
229
+ const pixelHasChanged = this._updatePlayheadPixel(time);
230
+ const timeHasChanged = this._time !== time;
231
+
232
+ if (timeHasChanged) {
233
+ this._updateActiveSegmentsAndSources(time);
234
+ this._updatePlayheadText(time);
231
235
  }
232
236
 
233
237
  this._time = time;
234
- this._updatePlayheadPixel(time);
235
- this._updateActiveSegmentsAndSources(time);
236
- this._updatePlayheadText(time);
237
- this._playheadLayer.batchDraw();
238
+ if (pixelHasChanged || timeHasChanged) {
239
+ this._playheadLayer.batchDraw();
240
+ }
238
241
  };
239
242
 
240
243
  /**
@@ -249,8 +252,15 @@ define([
249
252
 
250
253
  this._playheadPixel = pixelIndex;
251
254
  const playheadX = this._playheadPixel - frameOffset;
255
+ const oldX = this._playheadGroup.getAttr('x');
256
+
257
+ const shouldUpdateX = oldX !== playheadX;
258
+
259
+ if (shouldUpdateX) {
260
+ this._playheadGroup.setAttr('x', playheadX);
261
+ }
252
262
 
253
- this._playheadGroup.setAttr('x', playheadX);
263
+ return shouldUpdateX;
254
264
  };
255
265
 
256
266
  /**
@@ -328,11 +338,6 @@ define([
328
338
  var text = Utils.formatTime(time, false);
329
339
 
330
340
  this._playheadText.setText(text);
331
- this._peaks.emit(
332
- 'playhead.moved',
333
- this._playheadText.getAbsolutePosition().x,
334
- this._playheadText.width()
335
- );
336
341
  };
337
342
 
338
343
  /**