@checksub_team/peaks_timeline 1.5.2 → 1.5.3

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.5.2",
3
+ "version": "1.5.3",
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
@@ -16208,10 +16208,9 @@ module.exports = function (Konva) {
16208
16208
  this._onDragStart = options.onDragStart;
16209
16209
  this._onDragEnd = options.onDragEnd;
16210
16210
  this._view = options.view;
16211
- this._dragBoundFunc = this._dragBoundFunc.bind(this);
16212
16211
  this._group = new Konva.Group({
16213
16212
  draggable: this._draggable,
16214
- dragBoundFunc: this._dragBoundFunc
16213
+ dragBoundFunc: this._dragBoundFunc.bind(this)
16215
16214
  });
16216
16215
  this._bindDefaultEventHandlers();
16217
16216
  this._marker.init(this._group);
@@ -16237,9 +16236,21 @@ module.exports = function (Konva) {
16237
16236
  };
16238
16237
  SegmentMarker.prototype._dragBoundFunc = function (pos) {
16239
16238
  if (this._startMarker) {
16240
- this._segmentShape.getSegmentsGroup().updateSegment(this._segment, pos.x + this._view.getFrameOffset(), null);
16239
+ var newStartX;
16240
+ if (this._segment.duration) {
16241
+ newStartX = Math.max(pos.x + this._view.getFrameOffset(), this._view.timeToPixels(this._segment.endTime - this._segment.duration) + this._view.getFrameOffset());
16242
+ } else {
16243
+ newStartX = pos.x + this._view.getFrameOffset();
16244
+ }
16245
+ this._segmentShape.getSegmentsGroup().updateSegment(this._segment, newStartX, null);
16241
16246
  } else {
16242
- this._segmentShape.getSegmentsGroup().updateSegment(this._segment, null, pos.x + this._view.getFrameOffset() + this._marker.getHandleWidth());
16247
+ var newEndX;
16248
+ if (this._segment.duration) {
16249
+ newEndX = Math.min(pos.x + this._view.getFrameOffset() + this._marker.getHandleWidth(), this._view.timeToPixels(this._segment.startTime + this._segment.duration) + this._view.getFrameOffset());
16250
+ } else {
16251
+ newEndX = pos.x + this._view.getFrameOffset() + this._marker.getHandleWidth();
16252
+ }
16253
+ this._segmentShape.getSegmentsGroup().updateSegment(this._segment, null, newEndX);
16243
16254
  }
16244
16255
  return {
16245
16256
  x: this._group.getAbsolutePosition().x,
@@ -16315,13 +16326,24 @@ module.exports = function (Konva, SegmentMarker, Utils) {
16315
16326
  self._drawRect(ctx);
16316
16327
  }
16317
16328
  });
16329
+ var width = this._view.timeToPixels(this._segment.endTime - this._segment.startTime);
16330
+ var fillColor = segment.color + Math.round(segment.opacity * 255).toString(16);
16318
16331
  this._rectangle = new Konva.Rect({
16319
- width: this._view.timeToPixels(this._segment.endTime - this._segment.startTime),
16332
+ width: width,
16320
16333
  height: this._segmentHeight,
16321
16334
  cornerRadius: SEGMENT_CORNER_RADIUS,
16322
- fill: segment.color + Math.round(segment.opacity * 255).toString(16),
16323
16335
  stroke: segment.textColor + 'FF',
16324
- strokeWidth: 2
16336
+ strokeWidth: 2,
16337
+ fillPriority: segment.shouldShowWarning() ? 'linear-gradient' : 'color',
16338
+ fill: fillColor,
16339
+ fillLinearGradientColorStops: [
16340
+ 0,
16341
+ fillColor,
16342
+ 0.65,
16343
+ segment.warningColor
16344
+ ],
16345
+ fillLinearGradientStartPointX: Math.max(width - 20, width / 2),
16346
+ fillLinearGradientEndPointX: width
16325
16347
  });
16326
16348
  this._shapeGroup.add(this._rectangle);
16327
16349
  this._shapeGroup.dragBoundFunc(function () {
@@ -16365,6 +16387,13 @@ module.exports = function (Konva, SegmentMarker, Utils) {
16365
16387
  this._segmentWidth = endPixel - startPixel;
16366
16388
  this._shapeGroup.width(this._segmentWidth);
16367
16389
  this._rectangle.width(this._segmentWidth);
16390
+ if (this._segment.shouldShowWarning()) {
16391
+ this._rectangle.fillPriority('linear-gradient');
16392
+ this._rectangle.fillLinearGradientStartPointX(Math.max(this._segmentWidth - 20, this._segmentWidth / 2));
16393
+ this._rectangle.fillLinearGradientEndPointX(this._segmentWidth);
16394
+ } else {
16395
+ this._rectangle.fillPriority('color');
16396
+ }
16368
16397
  this._indicatorsGroup.x(this._segmentWidth);
16369
16398
  var newWidth = Math.floor(this._segmentWidth / 2);
16370
16399
  if (this._segmentWidth < this._startMarker.getHandleWidth() + this._endMarker.getHandleWidth()) {
@@ -16524,14 +16553,28 @@ module.exports = function (Konva, SegmentMarker, Utils) {
16524
16553
  SegmentShape.prototype._onMouseEnter = function () {
16525
16554
  this._view.setCursor('pointer');
16526
16555
  this._view.setHoveredElement(this);
16527
- this._rectangle.fill(this._segment.hoverColor + Math.round(this._segment.opacity * 255).toString(16));
16556
+ var fillColor = this._segment.hoverColor + Math.round(this._segment.opacity * 255).toString(16);
16557
+ this._rectangle.fill(fillColor);
16558
+ this._rectangle.fillLinearGradientColorStops([
16559
+ 0,
16560
+ fillColor,
16561
+ 0.65,
16562
+ this._segment.warningColor
16563
+ ]);
16528
16564
  this._view.drawSourcesLayer();
16529
16565
  this._peaks.emit('segments.mouseenter', this._segment);
16530
16566
  };
16531
16567
  SegmentShape.prototype._onMouseLeave = function () {
16532
16568
  this._view.setCursor('default');
16533
16569
  this._view.setHoveredElement(null);
16534
- this._rectangle.fill(this._segment.color + Math.round(this._segment.opacity * 255).toString(16));
16570
+ var fillColor = this._segment.color + Math.round(this._segment.opacity * 255).toString(16);
16571
+ this._rectangle.fill(fillColor);
16572
+ this._rectangle.fillLinearGradientColorStops([
16573
+ 0,
16574
+ fillColor,
16575
+ 0.65,
16576
+ this._segment.warningColor
16577
+ ]);
16535
16578
  this._view.drawSourcesLayer();
16536
16579
  this._peaks.emit('segments.mouseleave', this._segment);
16537
16580
  };
@@ -16648,17 +16691,24 @@ module.exports = function (Utils) {
16648
16691
  } else if (!Utils.isValidColor(options.hoverColor)) {
16649
16692
  throw new TypeError('peaks.segments.' + context + ': hoverColor must be a boolean');
16650
16693
  }
16694
+ if (Utils.isNullOrUndefined(options.warningColor)) {
16695
+ options.warningColor = '#E48023';
16696
+ } else if (!Utils.isValidColor(options.warningColor)) {
16697
+ throw new TypeError('peaks.segments.' + context + ': warningColor must be a boolean');
16698
+ }
16651
16699
  return shouldNotifyUpdate;
16652
16700
  }
16653
- function Segment(peaks, id, startTime, endTime, labelText, color, textColor, handleTextColor, hoverColor, opacity, editable, allowDeletion, line, indicators) {
16701
+ function Segment(peaks, id, startTime, endTime, duration, labelText, color, textColor, handleTextColor, hoverColor, warningColor, opacity, editable, allowDeletion, line, indicators) {
16654
16702
  var opts = {
16655
16703
  startTime: startTime,
16656
16704
  endTime: endTime,
16705
+ duration: duration,
16657
16706
  labelText: labelText,
16658
16707
  color: color,
16659
16708
  textColor: textColor,
16660
16709
  handleTextColor: handleTextColor,
16661
16710
  hoverColor: hoverColor,
16711
+ warningColor: warningColor,
16662
16712
  opacity: opacity,
16663
16713
  editable: editable,
16664
16714
  allowDeletion: allowDeletion,
@@ -16670,11 +16720,13 @@ module.exports = function (Utils) {
16670
16720
  this._id = id;
16671
16721
  this._startTime = opts.startTime;
16672
16722
  this._endTime = opts.endTime;
16723
+ this._duration = opts.duration;
16673
16724
  this._labelText = opts.labelText;
16674
16725
  this._color = opts.color;
16675
16726
  this._hoverColor = opts.hoverColor;
16676
16727
  this._textColor = opts.textColor;
16677
16728
  this._handleTextColor = opts.handleTextColor;
16729
+ this._warningColor = opts.warningColor;
16678
16730
  this._opacity = opts.opacity;
16679
16731
  this._editable = opts.editable;
16680
16732
  this._allowDeletion = opts.allowDeletion;
@@ -16711,6 +16763,15 @@ module.exports = function (Utils) {
16711
16763
  this._endTime = Utils.roundTime(time);
16712
16764
  }
16713
16765
  },
16766
+ duration: {
16767
+ enumerable: true,
16768
+ get: function () {
16769
+ return this._duration;
16770
+ },
16771
+ set: function (duration) {
16772
+ this._duration = Utils.roundTime(duration);
16773
+ }
16774
+ },
16714
16775
  labelText: {
16715
16776
  enumerable: true,
16716
16777
  get: function () {
@@ -16741,6 +16802,12 @@ module.exports = function (Utils) {
16741
16802
  return this._handleTextColor;
16742
16803
  }
16743
16804
  },
16805
+ warningColor: {
16806
+ enumerable: true,
16807
+ get: function () {
16808
+ return this._warningColor;
16809
+ }
16810
+ },
16744
16811
  opacity: {
16745
16812
  enumerable: true,
16746
16813
  get: function () {
@@ -16791,11 +16858,13 @@ module.exports = function (Utils) {
16791
16858
  var opts = {
16792
16859
  startTime: this.startTime,
16793
16860
  endTime: this.endTime,
16861
+ duration: this.duration,
16794
16862
  labelText: this.labelText,
16795
16863
  color: this.color,
16796
16864
  textColor: this.textColor,
16797
16865
  handleTextColor: this.handleTextColor,
16798
16866
  hoverColor: this.hoverColor,
16867
+ warningColor: this.warningColor,
16799
16868
  opacity: this.opacity,
16800
16869
  editable: this.editable,
16801
16870
  allowDeletion: this.allowDeletion,
@@ -16806,11 +16875,13 @@ module.exports = function (Utils) {
16806
16875
  validateSegment(this._peaks, opts, 'update()');
16807
16876
  this._startTime = opts.startTime;
16808
16877
  this._endTime = opts.endTime;
16878
+ this._duration = opts.duration;
16809
16879
  this._labelText = opts.labelText;
16810
16880
  this._color = opts.color;
16811
16881
  this._textColor = opts.textColor;
16812
16882
  this._handleTextColor = opts.handleTextColor;
16813
16883
  this._hoverColor = opts.hoverColor;
16884
+ this._warningColor = opts.warningColor;
16814
16885
  this._opacity = opts.opacity;
16815
16886
  this._editable = opts.editable;
16816
16887
  this._allowDeletion = opts.allowDeletion;
@@ -16825,6 +16896,9 @@ module.exports = function (Utils) {
16825
16896
  this._indicators = newIndicators;
16826
16897
  this._peaks.emit('segment.setIndicators', this);
16827
16898
  };
16899
+ Segment.prototype.shouldShowWarning = function () {
16900
+ return this.duration > Utils.roundTime(this.endTime - this.startTime);
16901
+ };
16828
16902
  return Segment;
16829
16903
  }(_dereq_('./utils'));
16830
16904
  },{"./utils":111}],103:[function(_dereq_,module,exports){
@@ -19159,7 +19233,7 @@ module.exports = function (Colors, Segment, Utils) {
19159
19233
  if (!Utils.isObject(options)) {
19160
19234
  throw new TypeError('peaks.segments.add(): expected a Segment object parameter');
19161
19235
  }
19162
- var segment = new Segment(this._peaks, Utils.isNullOrUndefined(options.id) ? this._getNextSegmentId() : options.id, options.startTime, options.endTime, options.labelText, options.color || this._getSegmentColor(), options.textColor || '#000000', options.handleTextColor || '#000000', options.hoverColor, options.opacity || 1, options.editable, options.allowDeletion || false, options.line, options.indicators);
19236
+ var segment = new Segment(this._peaks, Utils.isNullOrUndefined(options.id) ? this._getNextSegmentId() : options.id, options.startTime, options.endTime, options.duration, options.labelText, options.color || this._getSegmentColor(), options.textColor || '#000000', options.handleTextColor || '#000000', options.hoverColor, options.warningColor, options.opacity || 1, options.editable, options.allowDeletion || false, options.line, options.indicators);
19163
19237
  return segment;
19164
19238
  };
19165
19239
  TimelineSegments.prototype.getSegments = function () {
@@ -49,11 +49,9 @@ define([
49
49
 
50
50
  this._view = options.view;
51
51
 
52
- this._dragBoundFunc = this._dragBoundFunc.bind(this);
53
-
54
52
  this._group = new Konva.Group({
55
53
  draggable: this._draggable,
56
- dragBoundFunc: this._dragBoundFunc
54
+ dragBoundFunc: this._dragBoundFunc.bind(this)
57
55
  });
58
56
 
59
57
  this._bindDefaultEventHandlers();
@@ -88,17 +86,43 @@ define([
88
86
 
89
87
  SegmentMarker.prototype._dragBoundFunc = function(pos) {
90
88
  if (this._startMarker) {
89
+ var newStartX;
90
+
91
+ if (this._segment.duration) {
92
+ newStartX = Math.max(
93
+ pos.x + this._view.getFrameOffset(),
94
+ this._view.timeToPixels(this._segment.endTime - this._segment.duration)
95
+ + this._view.getFrameOffset()
96
+ );
97
+ }
98
+ else {
99
+ newStartX = pos.x + this._view.getFrameOffset();
100
+ }
101
+
91
102
  this._segmentShape.getSegmentsGroup().updateSegment(
92
103
  this._segment,
93
- pos.x + this._view.getFrameOffset(),
104
+ newStartX,
94
105
  null
95
106
  );
96
107
  }
97
108
  else {
109
+ var newEndX;
110
+
111
+ if (this._segment.duration) {
112
+ newEndX = Math.min(
113
+ pos.x + this._view.getFrameOffset() + this._marker.getHandleWidth(),
114
+ this._view.timeToPixels(this._segment.startTime + this._segment.duration)
115
+ + this._view.getFrameOffset()
116
+ );
117
+ }
118
+ else {
119
+ newEndX = pos.x + this._view.getFrameOffset() + this._marker.getHandleWidth();
120
+ }
121
+
98
122
  this._segmentShape.getSegmentsGroup().updateSegment(
99
123
  this._segment,
100
124
  null,
101
- pos.x + this._view.getFrameOffset() + this._marker.getHandleWidth()
125
+ newEndX
102
126
  );
103
127
  }
104
128
 
@@ -65,13 +65,23 @@ define([
65
65
  }
66
66
  });
67
67
 
68
+ var width = this._view.timeToPixels(this._segment.endTime - this._segment.startTime);
69
+ var fillColor = segment.color + Math.round(segment.opacity * 255).toString(16);
70
+
68
71
  this._rectangle = new Konva.Rect({
69
- width: this._view.timeToPixels(this._segment.endTime - this._segment.startTime),
72
+ width: width,
70
73
  height: this._segmentHeight,
71
74
  cornerRadius: SEGMENT_CORNER_RADIUS,
72
- fill: segment.color + Math.round(segment.opacity * 255).toString(16),
73
75
  stroke: segment.textColor + 'FF',
74
- strokeWidth: 2
76
+ strokeWidth: 2,
77
+ fillPriority: segment.shouldShowWarning() ? 'linear-gradient' : 'color',
78
+ fill: fillColor,
79
+ fillLinearGradientColorStops: [
80
+ 0, fillColor,
81
+ 0.65, segment.warningColor
82
+ ],
83
+ fillLinearGradientStartPointX: Math.max(width - 20, width / 2),
84
+ fillLinearGradientEndPointX: width
75
85
  });
76
86
 
77
87
  this._shapeGroup.add(this._rectangle);
@@ -137,6 +147,17 @@ define([
137
147
 
138
148
  this._shapeGroup.width(this._segmentWidth);
139
149
  this._rectangle.width(this._segmentWidth);
150
+ if (this._segment.shouldShowWarning()) {
151
+ this._rectangle.fillPriority('linear-gradient');
152
+ this._rectangle.fillLinearGradientStartPointX(
153
+ Math.max(this._segmentWidth - 20, this._segmentWidth / 2)
154
+ );
155
+ this._rectangle.fillLinearGradientEndPointX(this._segmentWidth);
156
+ }
157
+ else {
158
+ this._rectangle.fillPriority('color');
159
+ }
160
+
140
161
  this._indicatorsGroup.x(this._segmentWidth);
141
162
 
142
163
  var newWidth = Math.floor(this._segmentWidth / 2);
@@ -338,9 +359,15 @@ define([
338
359
 
339
360
  this._view.setHoveredElement(this);
340
361
 
341
- this._rectangle.fill(this._segment.hoverColor + Math.round(
362
+ var fillColor = this._segment.hoverColor + Math.round(
342
363
  this._segment.opacity * 255
343
- ).toString(16));
364
+ ).toString(16);
365
+
366
+ this._rectangle.fill(fillColor);
367
+ this._rectangle.fillLinearGradientColorStops([
368
+ 0, fillColor,
369
+ 0.65, this._segment.warningColor
370
+ ]);
344
371
 
345
372
  this._view.drawSourcesLayer();
346
373
 
@@ -352,9 +379,15 @@ define([
352
379
 
353
380
  this._view.setHoveredElement(null);
354
381
 
355
- this._rectangle.fill(this._segment.color + Math.round(
382
+ var fillColor = this._segment.color + Math.round(
356
383
  this._segment.opacity * 255
357
- ).toString(16));
384
+ ).toString(16);
385
+
386
+ this._rectangle.fill(fillColor);
387
+ this._rectangle.fillLinearGradientColorStops([
388
+ 0, fillColor,
389
+ 0.65, this._segment.warningColor
390
+ ]);
358
391
 
359
392
  this._view.drawSourcesLayer();
360
393
 
package/src/segment.js CHANGED
@@ -71,6 +71,13 @@ define([
71
71
  throw new TypeError('peaks.segments.' + context + ': hoverColor must be a boolean');
72
72
  }
73
73
 
74
+ if (Utils.isNullOrUndefined(options.warningColor)) {
75
+ options.warningColor = '#E48023';
76
+ }
77
+ else if (!Utils.isValidColor(options.warningColor)) {
78
+ throw new TypeError('peaks.segments.' + context + ': warningColor must be a boolean');
79
+ }
80
+
74
81
  return shouldNotifyUpdate;
75
82
  }
76
83
 
@@ -96,17 +103,19 @@ define([
96
103
  * of all indicators.
97
104
  */
98
105
 
99
- function Segment(peaks, id, startTime, endTime, labelText, color,
100
- textColor, handleTextColor, hoverColor, opacity, editable,
101
- allowDeletion, line, indicators) {
106
+ function Segment(peaks, id, startTime, endTime, duration, labelText,
107
+ color, textColor, handleTextColor, hoverColor, warningColor, opacity,
108
+ editable, allowDeletion, line, indicators) {
102
109
  var opts = {
103
110
  startTime: startTime,
104
111
  endTime: endTime,
112
+ duration: duration,
105
113
  labelText: labelText,
106
114
  color: color,
107
115
  textColor: textColor,
108
116
  handleTextColor: handleTextColor,
109
117
  hoverColor: hoverColor,
118
+ warningColor: warningColor,
110
119
  opacity: opacity,
111
120
  editable: editable,
112
121
  allowDeletion: allowDeletion,
@@ -120,11 +129,13 @@ define([
120
129
  this._id = id;
121
130
  this._startTime = opts.startTime;
122
131
  this._endTime = opts.endTime;
132
+ this._duration = opts.duration;
123
133
  this._labelText = opts.labelText;
124
134
  this._color = opts.color;
125
135
  this._hoverColor = opts.hoverColor;
126
136
  this._textColor = opts.textColor;
127
137
  this._handleTextColor = opts.handleTextColor;
138
+ this._warningColor = opts.warningColor;
128
139
  this._opacity = opts.opacity;
129
140
  this._editable = opts.editable;
130
141
  this._allowDeletion = opts.allowDeletion;
@@ -165,6 +176,16 @@ define([
165
176
  this._endTime = Utils.roundTime(time);
166
177
  }
167
178
  },
179
+ duration: {
180
+ enumerable: true,
181
+ get: function() {
182
+ return this._duration;
183
+ },
184
+
185
+ set: function(duration) {
186
+ this._duration = Utils.roundTime(duration);
187
+ }
188
+ },
168
189
  labelText: {
169
190
  enumerable: true,
170
191
  get: function() {
@@ -195,6 +216,12 @@ define([
195
216
  return this._handleTextColor;
196
217
  }
197
218
  },
219
+ warningColor: {
220
+ enumerable: true,
221
+ get: function() {
222
+ return this._warningColor;
223
+ }
224
+ },
198
225
  opacity: {
199
226
  enumerable: true,
200
227
  get: function() {
@@ -246,11 +273,13 @@ define([
246
273
  var opts = {
247
274
  startTime: this.startTime,
248
275
  endTime: this.endTime,
276
+ duration: this.duration,
249
277
  labelText: this.labelText,
250
278
  color: this.color,
251
279
  textColor: this.textColor,
252
280
  handleTextColor: this.handleTextColor,
253
281
  hoverColor: this.hoverColor,
282
+ warningColor: this.warningColor,
254
283
  opacity: this.opacity,
255
284
  editable: this.editable,
256
285
  allowDeletion: this.allowDeletion,
@@ -264,11 +293,13 @@ define([
264
293
 
265
294
  this._startTime = opts.startTime;
266
295
  this._endTime = opts.endTime;
296
+ this._duration = opts.duration;
267
297
  this._labelText = opts.labelText;
268
298
  this._color = opts.color;
269
299
  this._textColor = opts.textColor;
270
300
  this._handleTextColor = opts.handleTextColor;
271
301
  this._hoverColor = opts.hoverColor;
302
+ this._warningColor = opts.warningColor;
272
303
  this._opacity = opts.opacity;
273
304
  this._editable = opts.editable;
274
305
  this._allowDeletion = opts.allowDeletion;
@@ -303,5 +334,13 @@ define([
303
334
  this._peaks.emit('segment.setIndicators', this);
304
335
  };
305
336
 
337
+ /**
338
+ * Returns <code>true</code> if a warning should be shown
339
+ */
340
+
341
+ Segment.prototype.shouldShowWarning = function() {
342
+ return this.duration > Utils.roundTime(this.endTime - this.startTime);
343
+ };
344
+
306
345
  return Segment;
307
346
  });
@@ -131,11 +131,13 @@ define([
131
131
  Utils.isNullOrUndefined(options.id) ? this._getNextSegmentId() : options.id,
132
132
  options.startTime,
133
133
  options.endTime,
134
+ options.duration,
134
135
  options.labelText,
135
136
  options.color || this._getSegmentColor(),
136
137
  options.textColor || '#000000',
137
138
  options.handleTextColor || '#000000',
138
139
  options.hoverColor,
140
+ options.warningColor,
139
141
  options.opacity || 1,
140
142
  options.editable,
141
143
  options.allowDeletion || false,