@checksub_team/peaks_timeline 1.4.39 → 1.4.41

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.39",
3
+ "version": "1.4.41",
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
@@ -16242,9 +16242,9 @@ module.exports = function (Utils, Konva) {
16242
16242
  this._playheadVisible = false;
16243
16243
  this._playheadColor = peaks.options.playheadColor;
16244
16244
  this._playheadTextColor = peaks.options.playheadTextColor;
16245
+ this._time = null;
16245
16246
  this._playheadLayer = new Konva.Layer();
16246
16247
  this._activeSegments = {};
16247
- this._lastActiveSegments = {};
16248
16248
  this._createPlayhead(this._playheadColor);
16249
16249
  if (showTime) {
16250
16250
  this._createPlayheadText(this._playheadTextColor);
@@ -16256,20 +16256,15 @@ module.exports = function (Utils, Konva) {
16256
16256
  }
16257
16257
  PlayheadLayer.prototype._onSegmentsRemoveAll = function () {
16258
16258
  this._activeSegments = {};
16259
- this._lastActiveSegments = {};
16260
16259
  };
16261
16260
  PlayheadLayer.prototype._onSegmentsRemove = function (segments) {
16262
- if (this._activeSegments || this._lastActiveSegments) {
16261
+ if (this._activeSegments) {
16263
16262
  for (var id in segments) {
16264
16263
  if (Utils.objectHasProperty(segments, id)) {
16265
16264
  var activeSegmentId = this._activeSegments[segments[id].line] ? this._activeSegments[segments[id].line].id : null;
16266
- var lastActiveSegmentId = this._lastActiveSegments[segments[id].line] ? this._lastActiveSegments[segments[id].line].id : null;
16267
16265
  if (segments[id].id === activeSegmentId) {
16268
16266
  delete this._activeSegments[segments[id].line];
16269
16267
  }
16270
- if (segments[id].id === lastActiveSegmentId) {
16271
- delete this._lastActiveSegments[segments[id].line];
16272
- }
16273
16268
  }
16274
16269
  }
16275
16270
  }
@@ -16375,50 +16370,34 @@ module.exports = function (Utils, Konva) {
16375
16370
  PlayheadLayer.prototype._syncPlayhead = function (time) {
16376
16371
  var pixelIndex = this._view.timeToPixels(time);
16377
16372
  var frameOffset = this._view.timeToPixels(this._view.getTimeOffset());
16378
- var width = this._view.getWidth();
16379
- var isVisible = pixelIndex + HANDLE_RADIUS >= frameOffset && pixelIndex - HANDLE_RADIUS < frameOffset + width;
16380
16373
  this._playheadPixel = pixelIndex;
16381
- if (isVisible) {
16382
- var playheadX = this._playheadPixel - frameOffset;
16383
- if (!this._playheadVisible) {
16384
- this._playheadVisible = true;
16385
- this._playheadGroup.show();
16386
- }
16387
- var playheadPositionDiff = this._playheadGroup.x() - playheadX;
16388
- if (playheadPositionDiff) {
16389
- var segmentsGroup = this._lines.getSegmentsGroups();
16390
- for (var lineId in segmentsGroup) {
16391
- if (Utils.objectHasProperty(segmentsGroup, lineId)) {
16392
- var newActiveSegment = segmentsGroup[lineId].getActiveSegment(this._view.pixelsToTime(playheadX + frameOffset), null, true);
16393
- if (newActiveSegment !== this._activeSegments[lineId]) {
16394
- if (this._activeSegments[lineId]) {
16395
- this._peaks.emit('segments.exit', this._activeSegments[lineId]);
16396
- delete this._activeSegments[lineId];
16397
- }
16398
- if (newActiveSegment) {
16399
- this._peaks.emit('segments.enter', newActiveSegment);
16400
- this._activeSegments[lineId] = newActiveSegment;
16401
- this._lastActiveSegments[lineId] = this._activeSegments[lineId];
16402
- }
16374
+ var playheadX = this._playheadPixel - frameOffset;
16375
+ var segmentsGroup = this._lines.getSegmentsGroups();
16376
+ this._playheadGroup.setAttr('x', playheadX);
16377
+ if (this._time !== time) {
16378
+ for (var lineId in segmentsGroup) {
16379
+ if (Utils.objectHasProperty(segmentsGroup, lineId)) {
16380
+ var newActiveSegment = segmentsGroup[lineId].getActiveSegment(this._view.pixelsToTime(playheadX + frameOffset));
16381
+ if (newActiveSegment !== this._activeSegments[lineId]) {
16382
+ if (this._activeSegments[lineId]) {
16383
+ this._peaks.emit('segments.exit', this._activeSegments[lineId]);
16384
+ delete this._activeSegments[lineId];
16385
+ }
16386
+ if (newActiveSegment) {
16387
+ this._peaks.emit('segments.enter', newActiveSegment);
16388
+ this._activeSegments[lineId] = newActiveSegment;
16403
16389
  }
16404
16390
  }
16405
16391
  }
16406
16392
  }
16407
- this._playheadGroup.setAttr('x', playheadX);
16408
16393
  if (this._playheadText) {
16409
16394
  var text = Utils.formatTime(time, false);
16410
16395
  this._playheadText.setText(text);
16411
16396
  this._peaks.emit('playhead.moved', this._playheadText.getAbsolutePosition().x, this._playheadText.width());
16412
16397
  }
16413
- this._playheadLayer.draw();
16414
- } else {
16415
- if (this._playheadVisible) {
16416
- this._playheadVisible = false;
16417
- this._playheadGroup.hide();
16418
- this._playheadLayer.draw();
16419
- this._peaks.emit('playhead.hidden');
16420
- }
16421
16398
  }
16399
+ this._time = time;
16400
+ this._playheadLayer.draw();
16422
16401
  };
16423
16402
  PlayheadLayer.prototype._start = function () {
16424
16403
  var self = this;
@@ -18832,10 +18811,10 @@ module.exports = function (SourceGroup, Lines, DataRetriever, Utils, Invoker, Ko
18832
18811
  this._view.updateTimelineLength();
18833
18812
  this.updateSources(frameStartTime, frameEndTime);
18834
18813
  };
18835
- SourcesLayer.prototype._onSourcesDestroy = function (sources) {
18814
+ SourcesLayer.prototype._onSourcesDestroy = function (sources, shouldBlockEvent) {
18836
18815
  var self = this;
18837
18816
  sources.forEach(function (source) {
18838
- self._removeSource(source, true);
18817
+ self._removeSource(source, true, shouldBlockEvent);
18839
18818
  });
18840
18819
  this._view.updateTimelineLength();
18841
18820
  this._layer.draw();
@@ -18997,14 +18976,14 @@ module.exports = function (SourceGroup, Lines, DataRetriever, Utils, Invoker, Ko
18997
18976
  return result;
18998
18977
  }, []);
18999
18978
  };
19000
- SourcesLayer.prototype._removeSource = function (source, isPermanent) {
18979
+ SourcesLayer.prototype._removeSource = function (source, isPermanent, shouldBlockEvent) {
19001
18980
  var sourceGroup = this._sourcesGroup[source.id];
19002
18981
  if (sourceGroup) {
19003
18982
  delete this._sourcesGroup[source.id];
19004
18983
  this._lines.removeSourceGroup(source, isPermanent);
19005
18984
  sourceGroup.destroy();
19006
18985
  }
19007
- if (isPermanent) {
18986
+ if (isPermanent && !shouldBlockEvent) {
19008
18987
  this._peaks.emit('source.destroyed', source);
19009
18988
  }
19010
18989
  };
@@ -19494,23 +19473,23 @@ module.exports = function (Source, Utils) {
19494
19473
  }
19495
19474
  return destroyed;
19496
19475
  };
19497
- TimelineSources.prototype._destroySources = function (predicate) {
19476
+ TimelineSources.prototype._destroySources = function (predicate, shouldBlockEvent) {
19498
19477
  var indexes = this._findSource(predicate);
19499
19478
  var destroyed = this._destroyIndexes(indexes);
19500
- this._peaks.emit('sources.destroy', destroyed);
19479
+ this._peaks.emit('sources.destroy', destroyed, shouldBlockEvent);
19501
19480
  return destroyed;
19502
19481
  };
19503
- TimelineSources.prototype.destroy = function (source) {
19482
+ TimelineSources.prototype.destroy = function (source, shouldBlockEvent) {
19504
19483
  return this._destroySources(function (s) {
19505
19484
  return s === source;
19506
- });
19485
+ }, shouldBlockEvent);
19507
19486
  };
19508
- TimelineSources.prototype.destroyById = function (sourceId) {
19487
+ TimelineSources.prototype.destroyById = function (sourceId, shouldBlockEvent) {
19509
19488
  return this._destroySources(function (source) {
19510
19489
  return source.id === sourceId;
19511
- });
19490
+ }, shouldBlockEvent);
19512
19491
  };
19513
- TimelineSources.prototype.destroyByTime = function (startTime, endTime) {
19492
+ TimelineSources.prototype.destroyByTime = function (startTime, endTime, shouldBlockEvent) {
19514
19493
  var fnFilter;
19515
19494
  if (endTime > 0) {
19516
19495
  fnFilter = function (source) {
@@ -19521,12 +19500,12 @@ module.exports = function (Source, Utils) {
19521
19500
  return source.startTime === startTime;
19522
19501
  };
19523
19502
  }
19524
- return this._destroySources(fnFilter);
19503
+ return this._destroySources(fnFilter, shouldBlockEvent);
19525
19504
  };
19526
- TimelineSources.prototype.destroyAll = function () {
19505
+ TimelineSources.prototype.destroyAll = function (shouldBlockEvent) {
19527
19506
  this._destroySources(function () {
19528
19507
  return true;
19529
- });
19508
+ }, shouldBlockEvent);
19530
19509
  };
19531
19510
  TimelineSources.prototype.showById = function (sourceId) {
19532
19511
  this._sourcesById[sourceId].wrapped = false;
@@ -35,11 +35,11 @@ define([
35
35
  this._playheadVisible = false;
36
36
  this._playheadColor = peaks.options.playheadColor;
37
37
  this._playheadTextColor = peaks.options.playheadTextColor;
38
+ this._time = null;
38
39
 
39
40
  this._playheadLayer = new Konva.Layer();
40
41
 
41
42
  this._activeSegments = {};
42
- this._lastActiveSegments = {};
43
43
 
44
44
  this._createPlayhead(this._playheadColor);
45
45
 
@@ -57,26 +57,19 @@ define([
57
57
 
58
58
  PlayheadLayer.prototype._onSegmentsRemoveAll = function() {
59
59
  this._activeSegments = {};
60
- this._lastActiveSegments = {};
61
60
  };
62
61
 
63
62
  PlayheadLayer.prototype._onSegmentsRemove = function(segments) {
64
- if (this._activeSegments || this._lastActiveSegments) {
63
+ if (this._activeSegments) {
65
64
  for (var id in segments) {
66
65
  if (Utils.objectHasProperty(segments, id)) {
67
66
  var activeSegmentId = this._activeSegments[segments[id].line] ?
68
67
  this._activeSegments[segments[id].line].id :
69
68
  null;
70
- var lastActiveSegmentId = this._lastActiveSegments[segments[id].line] ?
71
- this._lastActiveSegments[segments[id].line].id :
72
- null;
73
69
 
74
70
  if (segments[id].id === activeSegmentId) {
75
71
  delete this._activeSegments[segments[id].line];
76
72
  }
77
- if (segments[id].id === lastActiveSegmentId) {
78
- delete this._lastActiveSegments[segments[id].line];
79
- }
80
73
  }
81
74
  }
82
75
  }
@@ -263,53 +256,35 @@ define([
263
256
 
264
257
  PlayheadLayer.prototype._syncPlayhead = function(time) {
265
258
  var pixelIndex = this._view.timeToPixels(time);
266
-
267
259
  var frameOffset = this._view.timeToPixels(this._view.getTimeOffset());
268
- var width = this._view.getWidth();
269
-
270
- var isVisible = (pixelIndex + HANDLE_RADIUS >= frameOffset) &&
271
- (pixelIndex - HANDLE_RADIUS < frameOffset + width);
272
260
 
273
261
  this._playheadPixel = pixelIndex;
274
262
 
275
- if (isVisible) {
276
- var playheadX = this._playheadPixel - frameOffset;
263
+ var playheadX = this._playheadPixel - frameOffset;
264
+ var segmentsGroup = this._lines.getSegmentsGroups();
277
265
 
278
- if (!this._playheadVisible) {
279
- this._playheadVisible = true;
280
- this._playheadGroup.show();
281
- }
266
+ this._playheadGroup.setAttr('x', playheadX);
282
267
 
283
- var playheadPositionDiff = this._playheadGroup.x() - playheadX;
268
+ if (this._time !== time) {
269
+ for (var lineId in segmentsGroup) {
270
+ if (Utils.objectHasProperty(segmentsGroup, lineId)) {
271
+ var newActiveSegment = segmentsGroup[lineId].getActiveSegment(
272
+ this._view.pixelsToTime(playheadX + frameOffset)
273
+ );
284
274
 
285
- if (playheadPositionDiff) {
286
- var segmentsGroup = this._lines.getSegmentsGroups();
287
-
288
- for (var lineId in segmentsGroup) {
289
- if (Utils.objectHasProperty(segmentsGroup, lineId)) {
290
- var newActiveSegment = segmentsGroup[lineId].getActiveSegment(
291
- this._view.pixelsToTime(playheadX + frameOffset),
292
- null,
293
- true
294
- );
295
-
296
- if (newActiveSegment !== this._activeSegments[lineId]) {
297
- if (this._activeSegments[lineId]) {
298
- this._peaks.emit('segments.exit', this._activeSegments[lineId]);
299
- delete this._activeSegments[lineId];
300
- }
301
- if (newActiveSegment) {
302
- this._peaks.emit('segments.enter', newActiveSegment);
303
- this._activeSegments[lineId] = newActiveSegment;
304
- this._lastActiveSegments[lineId] = this._activeSegments[lineId];
305
- }
275
+ if (newActiveSegment !== this._activeSegments[lineId]) {
276
+ if (this._activeSegments[lineId]) {
277
+ this._peaks.emit('segments.exit', this._activeSegments[lineId]);
278
+ delete this._activeSegments[lineId];
279
+ }
280
+ if (newActiveSegment) {
281
+ this._peaks.emit('segments.enter', newActiveSegment);
282
+ this._activeSegments[lineId] = newActiveSegment;
306
283
  }
307
284
  }
308
285
  }
309
286
  }
310
287
 
311
- this._playheadGroup.setAttr('x', playheadX);
312
-
313
288
  if (this._playheadText) {
314
289
  var text = Utils.formatTime(time, false);
315
290
 
@@ -321,21 +296,10 @@ define([
321
296
  this._playheadText.width()
322
297
  );
323
298
  }
324
-
325
- this._playheadLayer.draw();
326
299
  }
327
- else {
328
- if (this._playheadVisible) {
329
- this._playheadVisible = false;
330
- this._playheadGroup.hide();
331
-
332
- this._playheadLayer.draw();
333
300
 
334
- this._peaks.emit(
335
- 'playhead.hidden'
336
- );
337
- }
338
- }
301
+ this._time = time;
302
+ this._playheadLayer.draw();
339
303
  };
340
304
 
341
305
  /**