@checksub_team/peaks_timeline 1.15.4-alpha.1 → 1.15.5

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.15.4-alpha.1",
3
+ "version": "1.15.5",
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
@@ -15425,20 +15425,19 @@ module.exports = function (Konva, Utils) {
15425
15425
  this._sources[source.id] = sourceObj;
15426
15426
  };
15427
15427
  Line.prototype.manageCollision = function (source, newStartX, newEndX) {
15428
- var originalStartTime = null;
15429
- var originalEndTime = null;
15430
15428
  var newStartTime = null;
15431
15429
  var newEndTime = null;
15432
15430
  var startLimited = false;
15433
15431
  var endLimited = false;
15432
+ var timeWidth = this._view.pixelsToTime(newEndX - newStartX);
15434
15433
  var newXs = {
15435
15434
  startX: newStartX,
15436
15435
  endX: newEndX,
15436
+ updateWidth: false,
15437
15437
  updateTimelineLength: false
15438
15438
  };
15439
15439
  if (newStartX !== null) {
15440
- originalStartTime = this._view.pixelsToTime(newStartX);
15441
- newStartTime = originalStartTime;
15440
+ newStartTime = this._view.pixelsToTime(newStartX);
15442
15441
  if (source.startTime > newStartTime) {
15443
15442
  if (this._sources[source.id].prevSourceId) {
15444
15443
  var previousSource = this._sources[this._sources[source.id].prevSourceId].source;
@@ -15455,8 +15454,7 @@ module.exports = function (Konva, Utils) {
15455
15454
  }
15456
15455
  }
15457
15456
  if (newEndX !== null) {
15458
- originalEndTime = this._view.pixelsToTime(newEndX);
15459
- newEndTime = originalEndTime;
15457
+ newEndTime = this._view.pixelsToTime(newEndX);
15460
15458
  if (source.endTime < newEndTime) {
15461
15459
  if (this._sources[source.id].nextSourceId) {
15462
15460
  var nextSource = this._sources[this._sources[source.id].nextSourceId].source;
@@ -15468,7 +15466,6 @@ module.exports = function (Konva, Utils) {
15468
15466
  }
15469
15467
  }
15470
15468
  if (newStartTime !== null && newEndTime !== null) {
15471
- var timeWidth = Utils.roundTime(originalEndTime - originalStartTime);
15472
15469
  if (startLimited) {
15473
15470
  newEndTime = newStartTime + timeWidth;
15474
15471
  }
@@ -15494,15 +15491,18 @@ module.exports = function (Konva, Utils) {
15494
15491
  }
15495
15492
  }
15496
15493
  }
15497
- if (newStartTime !== null && newStartTime !== originalStartTime) {
15494
+ if (newStartTime !== null) {
15498
15495
  newXs.startX = this._view.timeToPixels(newStartTime);
15499
15496
  }
15500
- if (newEndTime !== null && newEndTime !== originalEndTime) {
15497
+ if (newEndTime !== null) {
15501
15498
  newXs.endX = this._view.timeToPixels(newEndTime);
15502
15499
  if (this._sources[source.id].nextSourceId === null) {
15503
15500
  newXs.updateTimelineLength = true;
15504
15501
  }
15505
15502
  }
15503
+ if (newXs.startX !== null && newXs.endX === null || newXs.startX === null && newXs.endX !== null) {
15504
+ newXs.updateWidth = true;
15505
+ }
15506
15506
  return newXs;
15507
15507
  };
15508
15508
  Line.prototype.getSourcesAfter = function (time) {
@@ -17632,6 +17632,20 @@ module.exports = function (Utils) {
17632
17632
  Segment.prototype.shouldShowWarning = function () {
17633
17633
  return this.duration > Utils.roundTime(this.endTime - this.startTime);
17634
17634
  };
17635
+ Segment.prototype.toSerializable = function () {
17636
+ var serializable = {};
17637
+ var proto = Object.getPrototypeOf(this);
17638
+ var descriptors = Object.getOwnPropertyDescriptors(proto);
17639
+ for (var prop in descriptors) {
17640
+ if (Object.prototype.hasOwnProperty.call(descriptors, prop)) {
17641
+ var descriptor = descriptors[prop];
17642
+ if (descriptor.enumerable && descriptor.get && typeof descriptor.get === 'function') {
17643
+ serializable[prop] = this[prop];
17644
+ }
17645
+ }
17646
+ }
17647
+ return serializable;
17648
+ };
17635
17649
  return Segment;
17636
17650
  }(_dereq_('./utils'));
17637
17651
  },{"./utils":113}],104:[function(_dereq_,module,exports){
@@ -20299,6 +20313,25 @@ module.exports = function (Utils) {
20299
20313
  return visibleTitle;
20300
20314
  }.bind(this), []).join(' ');
20301
20315
  };
20316
+ Source.prototype.toSerializable = function () {
20317
+ var serializable = {};
20318
+ for (var key in this) {
20319
+ if (Object.prototype.hasOwnProperty.call(this, key) && key.startsWith('custom_')) {
20320
+ serializable[key] = this[key];
20321
+ }
20322
+ }
20323
+ var proto = Object.getPrototypeOf(this);
20324
+ var descriptors = Object.getOwnPropertyDescriptors(proto);
20325
+ for (var prop in descriptors) {
20326
+ if (Object.prototype.hasOwnProperty.call(descriptors, prop)) {
20327
+ var descriptor = descriptors[prop];
20328
+ if (descriptor.enumerable && descriptor.get && typeof descriptor.get === 'function') {
20329
+ serializable[prop] = this[prop];
20330
+ }
20331
+ }
20332
+ }
20333
+ return serializable;
20334
+ };
20302
20335
  return Source;
20303
20336
  }(_dereq_('./utils'));
20304
20337
  },{"./utils":113}],107:[function(_dereq_,module,exports){
@@ -20562,7 +20595,8 @@ module.exports = function (SourceGroup, Lines, DataRetriever, Utils, Invoker, Ko
20562
20595
  SourcesLayer.prototype.updateSource = function (source, newStartX, newEndX, newY) {
20563
20596
  var newXs = {
20564
20597
  startX: newStartX,
20565
- endX: newEndX
20598
+ endX: newEndX,
20599
+ updateWidth: false
20566
20600
  };
20567
20601
  if (this._peaks.options.canMoveSourcesBetweenLines) {
20568
20602
  this.manageVerticalPosition(source, newY);
@@ -20571,7 +20605,7 @@ module.exports = function (SourceGroup, Lines, DataRetriever, Utils, Invoker, Ko
20571
20605
  newXs = this.manageCollision(source, newXs.startX, newXs.endX);
20572
20606
  source.updateTimes(newXs.startX !== null ? this._view.pixelsToTime(newXs.startX) : null, newXs.endX !== null ? this._view.pixelsToTime(newXs.endX) : null);
20573
20607
  if (newXs) {
20574
- this._updateSource(source);
20608
+ this._updateSource(source, newXs.updateWidth);
20575
20609
  return true;
20576
20610
  }
20577
20611
  return false;
@@ -20952,6 +20986,11 @@ module.exports = function (Colors, Segment, Utils) {
20952
20986
  TimelineSegments.prototype.getSegments = function () {
20953
20987
  return this._segments;
20954
20988
  };
20989
+ TimelineSegments.prototype.getSegmentsSerialized = function () {
20990
+ return this._segments.map(function (segment) {
20991
+ return segment.toSerializable();
20992
+ });
20993
+ };
20955
20994
  TimelineSegments.prototype.addSegmentsToPosition = function (lineId, position) {
20956
20995
  this._peaks.emit('segments.show', lineId, position);
20957
20996
  };
@@ -21168,6 +21207,11 @@ module.exports = function (Source, Utils) {
21168
21207
  TimelineSources.prototype.getSources = function () {
21169
21208
  return this._sources;
21170
21209
  };
21210
+ TimelineSources.prototype.getSourcesSerialized = function () {
21211
+ return this._sources.map(function (source) {
21212
+ return source.toSerializable();
21213
+ });
21214
+ };
21171
21215
  TimelineSources.prototype.getSource = function (id) {
21172
21216
  return this._sourcesById[id] || null;
21173
21217
  };
package/src/line.js CHANGED
@@ -535,23 +535,22 @@ define([
535
535
  };
536
536
 
537
537
  Line.prototype.manageCollision = function(source, newStartX, newEndX) {
538
- var originalStartTime = null;
539
- var originalEndTime = null;
540
538
  var newStartTime = null;
541
539
  var newEndTime = null;
542
540
  var startLimited = false;
543
541
  var endLimited = false;
542
+ var timeWidth = this._view.pixelsToTime(newEndX - newStartX);
544
543
 
545
544
  var newXs = {
546
545
  startX: newStartX,
547
546
  endX: newEndX,
547
+ updateWidth: false,
548
548
  updateTimelineLength: false
549
549
  };
550
550
 
551
551
  if (newStartX !== null) {
552
552
  // startMarker changed
553
- originalStartTime = this._view.pixelsToTime(newStartX);
554
- newStartTime = originalStartTime;
553
+ newStartTime = this._view.pixelsToTime(newStartX);
555
554
 
556
555
  if (source.startTime > newStartTime) {
557
556
  // startMarker moved to the left
@@ -577,8 +576,7 @@ define([
577
576
 
578
577
  if (newEndX !== null) {
579
578
  // endMarker changed
580
- originalEndTime = this._view.pixelsToTime(newEndX);
581
- newEndTime = originalEndTime;
579
+ newEndTime = this._view.pixelsToTime(newEndX);
582
580
 
583
581
  if (source.endTime < newEndTime) {
584
582
  // endMarker moved to the right
@@ -598,8 +596,6 @@ define([
598
596
 
599
597
  // Update the other edge if dragging and collision
600
598
  if (newStartTime !== null && newEndTime !== null) {
601
- var timeWidth = Utils.roundTime(originalEndTime - originalStartTime);
602
-
603
599
  if (startLimited) {
604
600
  newEndTime = newStartTime + timeWidth;
605
601
  }
@@ -631,11 +627,11 @@ define([
631
627
  }
632
628
  }
633
629
 
634
- if (newStartTime !== null && newStartTime !== originalStartTime) {
630
+ if (newStartTime !== null) {
635
631
  newXs.startX = this._view.timeToPixels(newStartTime);
636
632
  }
637
633
 
638
- if (newEndTime !== null && newEndTime !== originalEndTime) {
634
+ if (newEndTime !== null) {
639
635
  newXs.endX = this._view.timeToPixels(newEndTime);
640
636
 
641
637
  if (this._sources[source.id].nextSourceId === null) {
@@ -643,6 +639,11 @@ define([
643
639
  }
644
640
  }
645
641
 
642
+ if ((newXs.startX !== null && newXs.endX === null)
643
+ || (newXs.startX === null && newXs.endX !== null)) {
644
+ newXs.updateWidth = true;
645
+ }
646
+
646
647
  return newXs;
647
648
  };
648
649
 
package/src/segment.js CHANGED
@@ -389,5 +389,31 @@ define([
389
389
  return this.duration > Utils.roundTime(this.endTime - this.startTime);
390
390
  };
391
391
 
392
+ /**
393
+ * Returns a serializable object containing only the properties defined with Object.defineProperties.
394
+ * This includes all enumerable properties that can be safely serialized.
395
+ *
396
+ * @returns {Object} A plain object containing the serializable properties of the segment.
397
+ */
398
+ Segment.prototype.toSerializable = function() {
399
+ var serializable = {};
400
+
401
+ // Add all the enumerable properties from the prototype
402
+ var proto = Object.getPrototypeOf(this);
403
+ var descriptors = Object.getOwnPropertyDescriptors(proto);
404
+
405
+ for (var prop in descriptors) {
406
+ if (Object.prototype.hasOwnProperty.call(descriptors, prop)) {
407
+ var descriptor = descriptors[prop];
408
+
409
+ if (descriptor.enumerable && descriptor.get && typeof descriptor.get === 'function') {
410
+ serializable[prop] = this[prop];
411
+ }
412
+ }
413
+ }
414
+
415
+ return serializable;
416
+ };
417
+
392
418
  return Segment;
393
419
  });
package/src/source.js CHANGED
@@ -1232,5 +1232,38 @@ define([
1232
1232
  }.bind(this), []).join(' ');
1233
1233
  };
1234
1234
 
1235
+ /**
1236
+ * Returns a serializable object containing only the properties defined with Object.defineProperties.
1237
+ * This includes all enumerable properties that can be safely serialized.
1238
+ *
1239
+ * @returns {Object} A plain object containing the serializable properties of the source.
1240
+ */
1241
+ Source.prototype.toSerializable = function() {
1242
+ var serializable = {};
1243
+
1244
+ // Get all custom properties
1245
+ for (var key in this) {
1246
+ if (Object.prototype.hasOwnProperty.call(this, key) && key.startsWith('custom_')) {
1247
+ serializable[key] = this[key];
1248
+ }
1249
+ }
1250
+
1251
+ // Add all the enumerable properties from the prototype
1252
+ var proto = Object.getPrototypeOf(this);
1253
+ var descriptors = Object.getOwnPropertyDescriptors(proto);
1254
+
1255
+ for (var prop in descriptors) {
1256
+ if (Object.prototype.hasOwnProperty.call(descriptors, prop)) {
1257
+ var descriptor = descriptors[prop];
1258
+
1259
+ if (descriptor.enumerable && descriptor.get && typeof descriptor.get === 'function') {
1260
+ serializable[prop] = this[prop];
1261
+ }
1262
+ }
1263
+ }
1264
+
1265
+ return serializable;
1266
+ };
1267
+
1235
1268
  return Source;
1236
1269
  });
@@ -438,7 +438,8 @@ define([
438
438
  SourcesLayer.prototype.updateSource = function(source, newStartX, newEndX, newY) {
439
439
  var newXs = {
440
440
  startX: newStartX,
441
- endX: newEndX
441
+ endX: newEndX,
442
+ updateWidth: false
442
443
  };
443
444
 
444
445
  if (this._peaks.options.canMoveSourcesBetweenLines) {
@@ -456,7 +457,8 @@ define([
456
457
 
457
458
  if (newXs) {
458
459
  this._updateSource(
459
- source
460
+ source,
461
+ newXs.updateWidth
460
462
  );
461
463
 
462
464
  return true;
@@ -160,6 +160,18 @@ define([
160
160
  return this._segments;
161
161
  };
162
162
 
163
+ /**
164
+ * Returns all segments, serialized to a plain object.
165
+ *
166
+ * @returns {Array<Object>}
167
+ */
168
+
169
+ TimelineSegments.prototype.getSegmentsSerialized = function() {
170
+ return this._segments.map(function(segment) {
171
+ return segment.toSerializable();
172
+ });
173
+ };
174
+
163
175
  /**
164
176
  * Add segments to the given line so they can be displayed.
165
177
  */
@@ -240,6 +240,18 @@ define([
240
240
  return this._sources;
241
241
  };
242
242
 
243
+ /**
244
+ * Returns all sources, serialized to a plain object.
245
+ *
246
+ * @returns {Array<Object>}
247
+ */
248
+
249
+ TimelineSources.prototype.getSourcesSerialized = function() {
250
+ return this._sources.map(function(source) {
251
+ return source.toSerializable();
252
+ });
253
+ };
254
+
243
255
  /**
244
256
  * Returns the Source with the given id, or <code>null</code> if not found.
245
257
  *