@checksub_team/peaks_timeline 1.5.11 → 1.5.12

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.11",
3
+ "version": "1.5.12",
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
@@ -14376,7 +14376,7 @@ module.exports = function (Konva, Utils, SVGs) {
14376
14376
  var textNode = new Konva.Text({
14377
14377
  text: text,
14378
14378
  fontSize: this._sizes.font,
14379
- fontFamily: 'Arial',
14379
+ fontFamily: this._peaks.options.lineIndicatorFont,
14380
14380
  fill: this._peaks.options.lineIndicatorTextColor,
14381
14381
  align: 'center',
14382
14382
  width: this._width
@@ -15421,6 +15421,7 @@ module.exports = function (Colors, EventEmitter, TimelineSegments, TimelineSourc
15421
15421
  lineIndicatorNoVolumeIconSize: 24,
15422
15422
  lineIndicatorVisibilityIconSize: 24,
15423
15423
  lineIndicatorNoVisibilityIconSize: 24,
15424
+ lineIndicatorFont: 'Arial',
15424
15425
  lineIndicatorFontSize: 10,
15425
15426
  lineIndicatorTextColor: '#8A8F98',
15426
15427
  lineIndicatorIconColor: '#8A8F98',
@@ -15764,7 +15765,9 @@ module.exports = function (Utils, SourceGroup, Konva) {
15764
15765
  var selectedElement = this._selectedElement;
15765
15766
  this.deselectElement(true);
15766
15767
  if (selectedElement instanceof SourceGroup) {
15767
- this._peaks.destroySource(selectedElement.getSource().id);
15768
+ if (selectedElement.isDeletable()) {
15769
+ this._peaks.destroySource(selectedElement.getSource().id);
15770
+ }
15768
15771
  } else {
15769
15772
  if (selectedElement.getSegment().allowDeletion) {
15770
15773
  this._peaks.destroySegment(selectedElement.getSegment().id);
@@ -15778,7 +15781,7 @@ module.exports = function (Utils, SourceGroup, Konva) {
15778
15781
  };
15779
15782
  ModeLayer.prototype._updateCursorTime = function (mousePosition) {
15780
15783
  var hoveredElement = this._view.getHoveredElement();
15781
- if (hoveredElement && hoveredElement instanceof SourceGroup) {
15784
+ if (hoveredElement && hoveredElement instanceof SourceGroup && hoveredElement.isCuttable()) {
15782
15785
  this._timeLabel.text(Utils.formatTime(this._view.pixelsToTime(mousePosition.x + this._view.getFrameOffset()), false));
15783
15786
  this._timeBackground.width(this._timeLabel.width() + 8);
15784
15787
  this._cursorTime.x(mousePosition.x + TIME_X_OFFSET);
@@ -15794,7 +15797,7 @@ module.exports = function (Utils, SourceGroup, Konva) {
15794
15797
  };
15795
15798
  ModeLayer.prototype._updateCuttingLine = function (mousePosition) {
15796
15799
  var hoveredElement = this._view.getHoveredElement();
15797
- if (hoveredElement && hoveredElement instanceof SourceGroup) {
15800
+ if (hoveredElement && hoveredElement instanceof SourceGroup && hoveredElement.isCuttable()) {
15798
15801
  var minSize = this._view.timeToPixels(hoveredElement.getSource().minSize);
15799
15802
  if (hoveredElement.getWidth() >= 2 * minSize) {
15800
15803
  var height = hoveredElement.getCurrentHeight();
@@ -15847,7 +15850,7 @@ module.exports = function (Utils, SourceGroup, Konva) {
15847
15850
  var mousePosition = this._stage.getPointerPosition();
15848
15851
  mousePosition.x = this._view.timeToPixels(this._view.pixelsToTime(mousePosition.x));
15849
15852
  var hoveredElement = this._view.getHoveredElement();
15850
- if (hoveredElement && hoveredElement instanceof SourceGroup) {
15853
+ if (hoveredElement && hoveredElement instanceof SourceGroup && hoveredElement.isCuttable()) {
15851
15854
  var minSize = this._view.timeToPixels(hoveredElement.getSource().minSize);
15852
15855
  if (hoveredElement.getWidth() >= 2 * minSize) {
15853
15856
  var cuttingPixel;
@@ -15880,7 +15883,7 @@ module.exports = function (Utils, SourceGroup, Konva) {
15880
15883
  this._stage.off('mouseleave', this._onMouseLeaveInCutMode);
15881
15884
  this._stage.off('click', this._onMouseClickInCutMode);
15882
15885
  this._cutGroup.visible(false);
15883
- if (hoveredElement && hoveredElement instanceof SourceGroup) {
15886
+ if (hoveredElement && hoveredElement instanceof SourceGroup && hoveredElement.isCuttable()) {
15884
15887
  hoveredElement.toggleDragging(hoveredElement.getSource().draggable);
15885
15888
  hoveredElement.toggleResizing(hoveredElement.getSource().resizable);
15886
15889
  }
@@ -15907,7 +15910,7 @@ module.exports = function (Utils, SourceGroup, Konva) {
15907
15910
  this._updateCuttingLine(mousePosition);
15908
15911
  }
15909
15912
  }
15910
- if (hoveredElement && hoveredElement instanceof SourceGroup) {
15913
+ if (hoveredElement && hoveredElement instanceof SourceGroup && hoveredElement.isCuttable()) {
15911
15914
  hoveredElement.toggleDragging(false);
15912
15915
  hoveredElement.toggleResizing(false);
15913
15916
  }
@@ -17607,7 +17610,6 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Konva) {
17607
17610
  this._width = newWidth;
17608
17611
  this._rightHandle.x(newWidth - HANDLE_WIDTH);
17609
17612
  this.updatePreviews();
17610
- this._title.width(newWidth - 10);
17611
17613
  }
17612
17614
  };
17613
17615
  SourceGroup.prototype.setWrapping = function (wrap) {
@@ -17857,19 +17859,29 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Konva) {
17857
17859
  }
17858
17860
  };
17859
17861
  SourceGroup.prototype._createTitle = function () {
17862
+ var self = this;
17863
+ var defaultWidth;
17860
17864
  var title = new Konva.Text({
17861
17865
  x: 5,
17862
17866
  y: 5,
17863
- width: this._width - 10,
17864
17867
  text: Utils.removeLineBreaks(this._source.title),
17865
17868
  textAlign: 'left',
17866
17869
  verticalAlign: 'middle',
17867
- fontSize: 14,
17868
- fontFamily: 'Open Sans',
17870
+ fontSize: this._source.textFontSize,
17871
+ fontFamily: this._source.textFont,
17869
17872
  fill: this._source.textColor,
17870
17873
  wrap: 'none',
17871
17874
  ellipsis: true,
17872
- listening: false
17875
+ listening: false,
17876
+ sceneFunc: function (context, shape) {
17877
+ defaultWidth = defaultWidth ? defaultWidth : shape.width();
17878
+ shape.width(Math.min(self._width - 10, defaultWidth));
17879
+ if (self._source.textBackgroundColor) {
17880
+ context.fillStyle = self._source.textBackgroundColor;
17881
+ context.fillRect(-5, -5, shape.width() + 10, shape.height() ? shape.height() + 10 : 0);
17882
+ }
17883
+ shape._sceneFunc(context);
17884
+ }
17873
17885
  });
17874
17886
  return title;
17875
17887
  };
@@ -18220,6 +18232,12 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Konva) {
18220
18232
  SourceGroup.prototype.isDragged = function () {
18221
18233
  return this._dragged;
18222
18234
  };
18235
+ SourceGroup.prototype.isCuttable = function () {
18236
+ return this._source.cuttable;
18237
+ };
18238
+ SourceGroup.prototype.isDeletable = function () {
18239
+ return this._source.deletable;
18240
+ };
18223
18241
  SourceGroup.prototype.destroy = function () {
18224
18242
  this._group.destroy();
18225
18243
  };
@@ -18308,11 +18326,20 @@ module.exports = function (Utils) {
18308
18326
  } else if (!Utils.isValidColor(options.selectedColor)) {
18309
18327
  throw new TypeError('peaks.sources.' + context + ': selectedColor should be a valid CSS color');
18310
18328
  }
18329
+ if (Utils.isNullOrUndefined(options.textFont)) {
18330
+ options.textFont = 'Arial';
18331
+ }
18332
+ if (Utils.isNullOrUndefined(options.textFontSize)) {
18333
+ options.textFontSize = 12;
18334
+ }
18311
18335
  if (Utils.isNullOrUndefined(options.textColor)) {
18312
18336
  options.textColor = '#000000';
18313
18337
  } else if (!Utils.isValidColor(options.textColor)) {
18314
18338
  throw new TypeError('peaks.sources.' + context + ': textColor should be a valid CSS color');
18315
18339
  }
18340
+ if (!Utils.isNullOrUndefined(options.textBackgroundColor) && !Utils.isValidColor(options.textBackgroundColor)) {
18341
+ throw new TypeError('peaks.sources.' + context + ': textBackgroundColor should be a valid CSS color');
18342
+ }
18316
18343
  if (Utils.isNullOrUndefined(options.textPosition)) {
18317
18344
  options.textPosition = 'bottom';
18318
18345
  } else if (!Utils.isString(options.textPosition)) {
@@ -18339,6 +18366,16 @@ module.exports = function (Utils) {
18339
18366
  } else if (!Utils.isBoolean(options.resizable)) {
18340
18367
  throw new TypeError('peaks.sources.' + context + ': resizable must be a boolean');
18341
18368
  }
18369
+ if (Utils.isNullOrUndefined(options.cuttable)) {
18370
+ options.cuttable = true;
18371
+ } else if (!Utils.isBoolean(options.cuttable)) {
18372
+ throw new TypeError('peaks.sources.' + context + ': cuttable must be a boolean');
18373
+ }
18374
+ if (Utils.isNullOrUndefined(options.deletable)) {
18375
+ options.deletable = true;
18376
+ } else if (!Utils.isBoolean(options.deletable)) {
18377
+ throw new TypeError('peaks.sources.' + context + ': deletable must be a boolean');
18378
+ }
18342
18379
  if (Utils.isNullOrUndefined(options.wrapping)) {
18343
18380
  options.wrapping = 'both';
18344
18381
  } else if (!Utils.isString(options.wrapping)) {
@@ -18370,7 +18407,7 @@ module.exports = function (Utils) {
18370
18407
  options.wrapped = false;
18371
18408
  }
18372
18409
  }
18373
- function Source(peaks, id, originId, elementId, title, url, previewUrl, binaryUrl, kind, subkind, duration, startTime, endTime, mediaStartTime, mediaEndTime, color, backgroundColor, borderColor, selectedColor, textColor, textPosition, borderWidth, borderRadius, wrapped, position, draggable, resizable, wrapping, previewHeight, binaryHeight) {
18410
+ function Source(peaks, id, originId, elementId, title, url, previewUrl, binaryUrl, kind, subkind, duration, startTime, endTime, mediaStartTime, mediaEndTime, color, backgroundColor, borderColor, selectedColor, textFont, textFontSize, textColor, textBackgroundColor, textPosition, borderWidth, borderRadius, wrapped, position, draggable, resizable, cuttable, deletable, wrapping, previewHeight, binaryHeight) {
18374
18411
  var opts = {
18375
18412
  title: title,
18376
18413
  url: url,
@@ -18387,7 +18424,10 @@ module.exports = function (Utils) {
18387
18424
  backgroundColor: backgroundColor,
18388
18425
  borderColor: borderColor,
18389
18426
  selectedColor: selectedColor,
18427
+ textFont: textFont,
18428
+ textFontSize: textFontSize,
18390
18429
  textColor: textColor,
18430
+ textBackgroundColor: textBackgroundColor,
18391
18431
  textPosition: textPosition,
18392
18432
  borderWidth: borderWidth,
18393
18433
  borderRadius: borderRadius,
@@ -18395,6 +18435,8 @@ module.exports = function (Utils) {
18395
18435
  position: position,
18396
18436
  draggable: draggable,
18397
18437
  resizable: resizable,
18438
+ cuttable: cuttable,
18439
+ deletable: deletable,
18398
18440
  wrapping: wrapping,
18399
18441
  previewHeight: previewHeight,
18400
18442
  binaryHeight: binaryHeight
@@ -18419,7 +18461,10 @@ module.exports = function (Utils) {
18419
18461
  this._backgroundColor = opts.backgroundColor;
18420
18462
  this._borderColor = opts.borderColor;
18421
18463
  this._selectedColor = opts.selectedColor || Utils.shadeColor(opts.backgroundColor, 30);
18464
+ this._textFont = opts.textFont;
18465
+ this._textFontSize = opts.textFontSize;
18422
18466
  this._textColor = opts.textColor;
18467
+ this._textBackgroundColor = opts.textBackgroundColor;
18423
18468
  this._textPosition = opts.textPosition;
18424
18469
  this._borderWidth = opts.borderWidth;
18425
18470
  this._borderRadius = opts.borderRadius;
@@ -18427,6 +18472,8 @@ module.exports = function (Utils) {
18427
18472
  this._position = opts.position;
18428
18473
  this._draggable = opts.draggable;
18429
18474
  this._resizable = opts.resizable;
18475
+ this._cuttable = opts.cuttable;
18476
+ this._deletable = opts.deletable;
18430
18477
  this._wrapping = opts.wrapping;
18431
18478
  this._previewHeight = opts.previewHeight;
18432
18479
  this._binaryHeight = opts.binaryHeight;
@@ -18568,6 +18615,24 @@ module.exports = function (Utils) {
18568
18615
  this._selectedColor = selectedColor;
18569
18616
  }
18570
18617
  },
18618
+ textFont: {
18619
+ enumerable: true,
18620
+ get: function () {
18621
+ return this._textFont;
18622
+ },
18623
+ set: function (textFont) {
18624
+ this._textFont = textFont;
18625
+ }
18626
+ },
18627
+ textFontSize: {
18628
+ enumerable: true,
18629
+ get: function () {
18630
+ return this._textFontSize;
18631
+ },
18632
+ set: function (textFontSize) {
18633
+ this._textFontSize = textFontSize;
18634
+ }
18635
+ },
18571
18636
  textColor: {
18572
18637
  enumerable: true,
18573
18638
  get: function () {
@@ -18577,6 +18642,15 @@ module.exports = function (Utils) {
18577
18642
  this._textColor = textColor;
18578
18643
  }
18579
18644
  },
18645
+ textBackgroundColor: {
18646
+ enumerable: true,
18647
+ get: function () {
18648
+ return this._textBackgroundColor;
18649
+ },
18650
+ set: function (textBackgroundColor) {
18651
+ this._textBackgroundColor = textBackgroundColor;
18652
+ }
18653
+ },
18580
18654
  textPosition: {
18581
18655
  enumerable: true,
18582
18656
  get: function () {
@@ -18640,6 +18714,18 @@ module.exports = function (Utils) {
18640
18714
  return this._resizable;
18641
18715
  }
18642
18716
  },
18717
+ cuttable: {
18718
+ enumerable: true,
18719
+ get: function () {
18720
+ return this._cuttable;
18721
+ }
18722
+ },
18723
+ deletable: {
18724
+ enumerable: true,
18725
+ get: function () {
18726
+ return this._deletable;
18727
+ }
18728
+ },
18643
18729
  wrapping: {
18644
18730
  enumerable: true,
18645
18731
  get: function () {
@@ -18775,7 +18861,10 @@ module.exports = function (Utils) {
18775
18861
  backgroundColor: this.backgroundColor,
18776
18862
  borderColor: this.borderColor,
18777
18863
  selectedColor: this.selectedColor,
18864
+ textFont: this.textFont,
18865
+ textFontSize: this.textFontSize,
18778
18866
  textColor: this.textColor,
18867
+ textBackgroundColor: this.textBackgroundColor,
18779
18868
  textPosition: this.textPosition,
18780
18869
  borderWidth: this.borderWidth,
18781
18870
  borderRadius: this.borderRadius,
@@ -18783,6 +18872,8 @@ module.exports = function (Utils) {
18783
18872
  position: this.position,
18784
18873
  draggable: this.draggable,
18785
18874
  resizable: this.resizable,
18875
+ cuttable: this.cuttable,
18876
+ deletable: this.deletable,
18786
18877
  wrapping: this.wrapping,
18787
18878
  previewHeight: this.previewHeight,
18788
18879
  binaryHeight: this.binaryHeight
@@ -18804,7 +18895,10 @@ module.exports = function (Utils) {
18804
18895
  this._backgroundColor = opts.backgroundColor;
18805
18896
  this._borderColor = opts.borderColor;
18806
18897
  this._selectedColor = opts.selectedColor || Utils.shadeColor(opts.backgroundColor, 30);
18898
+ this._textFont = opts.textFont;
18899
+ this._textFontSize = opts.textFontSize;
18807
18900
  this._textColor = opts.textColor;
18901
+ this._textBackgroundColor = opts.textBackgroundColor;
18808
18902
  this._textPosition = opts.textPosition;
18809
18903
  this._borderWidth = opts.borderWidth;
18810
18904
  this._borderRadius = opts.borderRadius;
@@ -18812,6 +18906,8 @@ module.exports = function (Utils) {
18812
18906
  this._position = opts.position;
18813
18907
  this._draggable = opts.draggable;
18814
18908
  this._resizable = opts.resizable;
18909
+ this._cuttable = opts.cuttable;
18910
+ this._deletable = opts.deletable;
18815
18911
  this._wrapping = opts.wrapping;
18816
18912
  this._previewHeight = opts.previewHeight;
18817
18913
  this._binaryHeight = opts.binaryHeight;
@@ -19324,8 +19420,9 @@ module.exports = function (Utils, Konva) {
19324
19420
  break;
19325
19421
  }
19326
19422
  var label = Utils.formatTime(secs, false);
19327
- var labelHeight = context.measureText(label).actualBoundingBoxAscent - context.measureText(label).actualBoundingBoxDescent;
19328
- var labelWidth = context.measureText(label).width;
19423
+ var measures = context.measureText(label);
19424
+ var labelHeight = measures.actualBoundingBoxAscent - measures.actualBoundingBoxDescent;
19425
+ var labelWidth = measures.width;
19329
19426
  var labelX = x + LEFT_PADDING;
19330
19427
  var labelY = labelHeight;
19331
19428
  if (!this._labelIsMasked(labelX + view.getFrameOffset(), labelX + view.getFrameOffset() + labelWidth)) {
@@ -19543,7 +19640,10 @@ module.exports = function (Source, Utils) {
19543
19640
  backgroundColor: sourceToCut.backgroundColor,
19544
19641
  borderColor: sourceToCut.borderColor,
19545
19642
  selectedColor: sourceToCut.selectedColor,
19643
+ textFont: sourceToCut.textFont,
19644
+ textFontSize: sourceToCut.textFontSize,
19546
19645
  textColor: sourceToCut.textColor,
19646
+ textBackgroundColor: sourceToCut.textBackgroundColor,
19547
19647
  textPosition: sourceToCut.textPosition,
19548
19648
  borderWidth: sourceToCut.borderWidth,
19549
19649
  borderRadius: sourceToCut.borderRadius,
@@ -19551,6 +19651,8 @@ module.exports = function (Source, Utils) {
19551
19651
  position: sourceToCut.position,
19552
19652
  draggable: sourceToCut.draggable,
19553
19653
  resizable: sourceToCut.resizable,
19654
+ cuttable: sourceToCut.cuttable,
19655
+ deletable: sourceToCut.deletable,
19554
19656
  wrapping: sourceToCut.wrapping,
19555
19657
  previewHeight: sourceToCut.previewHeight,
19556
19658
  binaryHeight: sourceToCut.binaryHeight
@@ -19568,7 +19670,7 @@ module.exports = function (Source, Utils) {
19568
19670
  if (!Utils.isObject(options)) {
19569
19671
  throw new TypeError('peaks.sources.add(): expected a Source object parameter');
19570
19672
  }
19571
- var source = new Source(this._peaks, options.id || this._getNextSourceId(), options.originId, options.elementId, options.title, options.url, options.previewUrl, options.binaryUrl, options.kind, options.subkind, options.duration, options.startTime, options.endTime, options.mediaStartTime, options.mediaEndTime, options.color, options.backgroundColor, options.borderColor, options.selectedColor, options.textColor, options.textPosition, options.borderWidth, options.borderRadius, options.wrapped, options.position, options.draggable, options.resizable, options.wrapping, options.previewHeight, options.binaryHeight);
19673
+ var source = new Source(this._peaks, options.id || this._getNextSourceId(), options.originId, options.elementId, options.title, options.url, options.previewUrl, options.binaryUrl, options.kind, options.subkind, options.duration, options.startTime, options.endTime, options.mediaStartTime, options.mediaEndTime, options.color, options.backgroundColor, options.borderColor, options.selectedColor, options.textFont, options.textFontSize, options.textColor, options.textBackgroundColor, options.textPosition, options.borderWidth, options.borderRadius, options.wrapped, options.position, options.draggable, options.resizable, options.cuttable, options.deletable, options.wrapping, options.previewHeight, options.binaryHeight);
19572
19674
  return source;
19573
19675
  };
19574
19676
  TimelineSources.prototype.getSources = function () {
@@ -140,7 +140,7 @@ define([
140
140
  var textNode = new Konva.Text({
141
141
  text: text,
142
142
  fontSize: this._sizes.font,
143
- fontFamily: 'Arial',
143
+ fontFamily: this._peaks.options.lineIndicatorFont,
144
144
  fill: this._peaks.options.lineIndicatorTextColor,
145
145
  align: 'center',
146
146
  width: this._width
package/src/main.js CHANGED
@@ -305,6 +305,11 @@ define([
305
305
  */
306
306
  lineIndicatorNoVisibilityIconSize: 24,
307
307
 
308
+ /**
309
+ * Font of the line indicators' text
310
+ */
311
+ lineIndicatorFont: 'Arial',
312
+
308
313
  /**
309
314
  * Font size of the line indicators' text, in pixels
310
315
  */
package/src/mode-layer.js CHANGED
@@ -164,7 +164,9 @@ define([
164
164
  this.deselectElement(true);
165
165
 
166
166
  if (selectedElement instanceof SourceGroup) {
167
- this._peaks.destroySource(selectedElement.getSource().id);
167
+ if (selectedElement.isDeletable()) {
168
+ this._peaks.destroySource(selectedElement.getSource().id);
169
+ }
168
170
  }
169
171
  else {
170
172
  if (selectedElement.getSegment().allowDeletion) {
@@ -183,7 +185,7 @@ define([
183
185
  ModeLayer.prototype._updateCursorTime = function(mousePosition) {
184
186
  var hoveredElement = this._view.getHoveredElement();
185
187
 
186
- if (hoveredElement && hoveredElement instanceof SourceGroup) {
188
+ if (hoveredElement && hoveredElement instanceof SourceGroup && hoveredElement.isCuttable()) {
187
189
  this._timeLabel.text(
188
190
  Utils.formatTime(
189
191
  this._view.pixelsToTime(mousePosition.x + this._view.getFrameOffset()),
@@ -213,7 +215,7 @@ define([
213
215
  ModeLayer.prototype._updateCuttingLine = function(mousePosition) {
214
216
  var hoveredElement = this._view.getHoveredElement();
215
217
 
216
- if (hoveredElement && hoveredElement instanceof SourceGroup) {
218
+ if (hoveredElement && hoveredElement instanceof SourceGroup && hoveredElement.isCuttable()) {
217
219
  var minSize = this._view.timeToPixels(hoveredElement.getSource().minSize);
218
220
 
219
221
  if (hoveredElement.getWidth() >= 2 * minSize) {
@@ -279,7 +281,7 @@ define([
279
281
 
280
282
  var hoveredElement = this._view.getHoveredElement();
281
283
 
282
- if (hoveredElement && hoveredElement instanceof SourceGroup) {
284
+ if (hoveredElement && hoveredElement instanceof SourceGroup && hoveredElement.isCuttable()) {
283
285
  var minSize = this._view.timeToPixels(hoveredElement.getSource().minSize);
284
286
 
285
287
  if (hoveredElement.getWidth() >= 2 * minSize) {
@@ -333,7 +335,9 @@ define([
333
335
  this._stage.off('click', this._onMouseClickInCutMode);
334
336
  this._cutGroup.visible(false);
335
337
 
336
- if (hoveredElement && hoveredElement instanceof SourceGroup) {
338
+ if (hoveredElement
339
+ && hoveredElement instanceof SourceGroup
340
+ && hoveredElement.isCuttable()) {
337
341
  hoveredElement.toggleDragging(hoveredElement.getSource().draggable);
338
342
  hoveredElement.toggleResizing(hoveredElement.getSource().resizable);
339
343
  }
@@ -370,7 +374,9 @@ define([
370
374
  }
371
375
  }
372
376
 
373
- if (hoveredElement && hoveredElement instanceof SourceGroup) {
377
+ if (hoveredElement
378
+ && hoveredElement instanceof SourceGroup
379
+ && hoveredElement.isCuttable()) {
374
380
  hoveredElement.toggleDragging(false);
375
381
  hoveredElement.toggleResizing(false);
376
382
  }
@@ -204,9 +204,6 @@ define([
204
204
 
205
205
  // update unwrap
206
206
  this.updatePreviews();
207
-
208
- // update wrap
209
- this._title.width(newWidth - 10);
210
207
  }
211
208
  };
212
209
 
@@ -526,19 +523,30 @@ define([
526
523
  };
527
524
 
528
525
  SourceGroup.prototype._createTitle = function() {
526
+ var self = this;
527
+ var defaultWidth;
528
+
529
529
  var title = new Konva.Text({
530
530
  x: 5,
531
531
  y: 5,
532
- width: this._width - 10,
533
532
  text: Utils.removeLineBreaks(this._source.title),
534
533
  textAlign: 'left',
535
534
  verticalAlign: 'middle',
536
- fontSize: 14,
537
- fontFamily: 'Open Sans',
535
+ fontSize: this._source.textFontSize,
536
+ fontFamily: this._source.textFont,
538
537
  fill: this._source.textColor,
539
538
  wrap: 'none',
540
539
  ellipsis: true,
541
- listening: false
540
+ listening: false,
541
+ sceneFunc: function(context, shape) {
542
+ defaultWidth = defaultWidth ? defaultWidth : shape.width();
543
+ shape.width(Math.min(self._width - 10, defaultWidth));
544
+ if (self._source.textBackgroundColor) {
545
+ context.fillStyle = self._source.textBackgroundColor;
546
+ context.fillRect(-5, -5, shape.width() + 10, shape.height() ? shape.height() + 10 : 0);
547
+ }
548
+ shape._sceneFunc(context);
549
+ }
542
550
  });
543
551
 
544
552
  return title;
@@ -1003,6 +1011,14 @@ define([
1003
1011
  return this._dragged;
1004
1012
  };
1005
1013
 
1014
+ SourceGroup.prototype.isCuttable = function() {
1015
+ return this._source.cuttable;
1016
+ };
1017
+
1018
+ SourceGroup.prototype.isDeletable = function() {
1019
+ return this._source.deletable;
1020
+ };
1021
+
1006
1022
  SourceGroup.prototype.destroy = function() {
1007
1023
  this._group.destroy();
1008
1024
  };
package/src/source.js CHANGED
@@ -127,6 +127,14 @@ define([
127
127
  );
128
128
  }
129
129
 
130
+ if (Utils.isNullOrUndefined(options.textFont)) {
131
+ options.textFont = 'Arial';
132
+ }
133
+
134
+ if (Utils.isNullOrUndefined(options.textFontSize)) {
135
+ options.textFontSize = 12;
136
+ }
137
+
130
138
  if (Utils.isNullOrUndefined(options.textColor)) {
131
139
  options.textColor = '#000000';
132
140
  }
@@ -134,6 +142,13 @@ define([
134
142
  throw new TypeError('peaks.sources.' + context + ': textColor should be a valid CSS color');
135
143
  }
136
144
 
145
+ if (!Utils.isNullOrUndefined(options.textBackgroundColor)
146
+ && !Utils.isValidColor(options.textBackgroundColor)) {
147
+ throw new TypeError(
148
+ 'peaks.sources.' + context + ': textBackgroundColor should be a valid CSS color'
149
+ );
150
+ }
151
+
137
152
  if (Utils.isNullOrUndefined(options.textPosition)) {
138
153
  options.textPosition = 'bottom';
139
154
  }
@@ -170,6 +185,20 @@ define([
170
185
  throw new TypeError('peaks.sources.' + context + ': resizable must be a boolean');
171
186
  }
172
187
 
188
+ if (Utils.isNullOrUndefined(options.cuttable)) {
189
+ options.cuttable = true;
190
+ }
191
+ else if (!Utils.isBoolean(options.cuttable)) {
192
+ throw new TypeError('peaks.sources.' + context + ': cuttable must be a boolean');
193
+ }
194
+
195
+ if (Utils.isNullOrUndefined(options.deletable)) {
196
+ options.deletable = true;
197
+ }
198
+ else if (!Utils.isBoolean(options.deletable)) {
199
+ throw new TypeError('peaks.sources.' + context + ': deletable must be a boolean');
200
+ }
201
+
173
202
  if (Utils.isNullOrUndefined(options.wrapping)) {
174
203
  options.wrapping = 'both';
175
204
  }
@@ -234,8 +263,9 @@ define([
234
263
 
235
264
  function Source(peaks, id, originId, elementId, title, url, previewUrl, binaryUrl, kind,
236
265
  subkind, duration, startTime, endTime, mediaStartTime, mediaEndTime, color, backgroundColor,
237
- borderColor, selectedColor, textColor, textPosition, borderWidth, borderRadius, wrapped,
238
- position, draggable, resizable, wrapping, previewHeight, binaryHeight) {
266
+ borderColor, selectedColor, textFont, textFontSize, textColor, textBackgroundColor,
267
+ textPosition, borderWidth, borderRadius, wrapped, position, draggable, resizable, cuttable,
268
+ deletable, wrapping, previewHeight, binaryHeight) {
239
269
  var opts = {
240
270
  title: title,
241
271
  url: url,
@@ -252,7 +282,10 @@ define([
252
282
  backgroundColor: backgroundColor,
253
283
  borderColor: borderColor,
254
284
  selectedColor: selectedColor,
285
+ textFont: textFont,
286
+ textFontSize: textFontSize,
255
287
  textColor: textColor,
288
+ textBackgroundColor: textBackgroundColor,
256
289
  textPosition: textPosition,
257
290
  borderWidth: borderWidth,
258
291
  borderRadius: borderRadius,
@@ -260,6 +293,8 @@ define([
260
293
  position: position,
261
294
  draggable: draggable,
262
295
  resizable: resizable,
296
+ cuttable: cuttable,
297
+ deletable: deletable,
263
298
  wrapping: wrapping,
264
299
  previewHeight: previewHeight,
265
300
  binaryHeight: binaryHeight
@@ -286,7 +321,10 @@ define([
286
321
  this._backgroundColor = opts.backgroundColor;
287
322
  this._borderColor = opts.borderColor;
288
323
  this._selectedColor = opts.selectedColor || Utils.shadeColor(opts.backgroundColor, 30);
324
+ this._textFont = opts.textFont;
325
+ this._textFontSize = opts.textFontSize;
289
326
  this._textColor = opts.textColor;
327
+ this._textBackgroundColor = opts.textBackgroundColor;
290
328
  this._textPosition = opts.textPosition;
291
329
  this._borderWidth = opts.borderWidth;
292
330
  this._borderRadius = opts.borderRadius;
@@ -294,6 +332,8 @@ define([
294
332
  this._position = opts.position;
295
333
  this._draggable = opts.draggable;
296
334
  this._resizable = opts.resizable;
335
+ this._cuttable = opts.cuttable;
336
+ this._deletable = opts.deletable;
297
337
  this._wrapping = opts.wrapping;
298
338
  this._previewHeight = opts.previewHeight;
299
339
  this._binaryHeight = opts.binaryHeight;
@@ -445,6 +485,26 @@ define([
445
485
  this._selectedColor = selectedColor;
446
486
  }
447
487
  },
488
+ textFont: {
489
+ enumerable: true,
490
+ get: function() {
491
+ return this._textFont;
492
+ },
493
+
494
+ set: function(textFont) {
495
+ this._textFont = textFont;
496
+ }
497
+ },
498
+ textFontSize: {
499
+ enumerable: true,
500
+ get: function() {
501
+ return this._textFontSize;
502
+ },
503
+
504
+ set: function(textFontSize) {
505
+ this._textFontSize = textFontSize;
506
+ }
507
+ },
448
508
  textColor: {
449
509
  enumerable: true,
450
510
  get: function() {
@@ -455,6 +515,16 @@ define([
455
515
  this._textColor = textColor;
456
516
  }
457
517
  },
518
+ textBackgroundColor: {
519
+ enumerable: true,
520
+ get: function() {
521
+ return this._textBackgroundColor;
522
+ },
523
+
524
+ set: function(textBackgroundColor) {
525
+ this._textBackgroundColor = textBackgroundColor;
526
+ }
527
+ },
458
528
  textPosition: {
459
529
  enumerable: true,
460
530
  get: function() {
@@ -523,6 +593,18 @@ define([
523
593
  return this._resizable;
524
594
  }
525
595
  },
596
+ cuttable: {
597
+ enumerable: true,
598
+ get: function() {
599
+ return this._cuttable;
600
+ }
601
+ },
602
+ deletable: {
603
+ enumerable: true,
604
+ get: function() {
605
+ return this._deletable;
606
+ }
607
+ },
526
608
  wrapping: {
527
609
  enumerable: true,
528
610
  get: function() {
@@ -693,7 +775,10 @@ define([
693
775
  backgroundColor: this.backgroundColor,
694
776
  borderColor: this.borderColor,
695
777
  selectedColor: this.selectedColor,
778
+ textFont: this.textFont,
779
+ textFontSize: this.textFontSize,
696
780
  textColor: this.textColor,
781
+ textBackgroundColor: this.textBackgroundColor,
697
782
  textPosition: this.textPosition,
698
783
  borderWidth: this.borderWidth,
699
784
  borderRadius: this.borderRadius,
@@ -701,6 +786,8 @@ define([
701
786
  position: this.position,
702
787
  draggable: this.draggable,
703
788
  resizable: this.resizable,
789
+ cuttable: this.cuttable,
790
+ deletable: this.deletable,
704
791
  wrapping: this.wrapping,
705
792
  previewHeight: this.previewHeight,
706
793
  binaryHeight: this.binaryHeight
@@ -725,7 +812,10 @@ define([
725
812
  this._backgroundColor = opts.backgroundColor;
726
813
  this._borderColor = opts.borderColor;
727
814
  this._selectedColor = opts.selectedColor || Utils.shadeColor(opts.backgroundColor, 30);
815
+ this._textFont = opts.textFont;
816
+ this._textFontSize = opts.textFontSize;
728
817
  this._textColor = opts.textColor;
818
+ this._textBackgroundColor = opts.textBackgroundColor;
729
819
  this._textPosition = opts.textPosition;
730
820
  this._borderWidth = opts.borderWidth;
731
821
  this._borderRadius = opts.borderRadius;
@@ -733,6 +823,8 @@ define([
733
823
  this._position = opts.position;
734
824
  this._draggable = opts.draggable;
735
825
  this._resizable = opts.resizable;
826
+ this._cuttable = opts.cuttable;
827
+ this._deletable = opts.deletable;
736
828
  this._wrapping = opts.wrapping;
737
829
  this._previewHeight = opts.previewHeight;
738
830
  this._binaryHeight = opts.binaryHeight;
@@ -213,9 +213,10 @@ define([
213
213
  }
214
214
 
215
215
  var label = Utils.formatTime(secs, false);
216
- var labelHeight = context.measureText(label).actualBoundingBoxAscent
217
- - context.measureText(label).actualBoundingBoxDescent;
218
- var labelWidth = context.measureText(label).width;
216
+ var measures = context.measureText(label);
217
+ var labelHeight = measures.actualBoundingBoxAscent
218
+ - measures.actualBoundingBoxDescent;
219
+ var labelWidth = measures.width;
219
220
  var labelX = x + LEFT_PADDING;
220
221
  var labelY = labelHeight;
221
222
 
@@ -81,7 +81,10 @@ define([
81
81
  backgroundColor: sourceToCut.backgroundColor,
82
82
  borderColor: sourceToCut.borderColor,
83
83
  selectedColor: sourceToCut.selectedColor,
84
+ textFont: sourceToCut.textFont,
85
+ textFontSize: sourceToCut.textFontSize,
84
86
  textColor: sourceToCut.textColor,
87
+ textBackgroundColor: sourceToCut.textBackgroundColor,
85
88
  textPosition: sourceToCut.textPosition,
86
89
  borderWidth: sourceToCut.borderWidth,
87
90
  borderRadius: sourceToCut.borderRadius,
@@ -89,6 +92,8 @@ define([
89
92
  position: sourceToCut.position,
90
93
  draggable: sourceToCut.draggable,
91
94
  resizable: sourceToCut.resizable,
95
+ cuttable: sourceToCut.cuttable,
96
+ deletable: sourceToCut.deletable,
92
97
  wrapping: sourceToCut.wrapping,
93
98
  previewHeight: sourceToCut.previewHeight,
94
99
  binaryHeight: sourceToCut.binaryHeight
@@ -157,7 +162,10 @@ define([
157
162
  options.backgroundColor,
158
163
  options.borderColor,
159
164
  options.selectedColor,
165
+ options.textFont,
166
+ options.textFontSize,
160
167
  options.textColor,
168
+ options.textBackgroundColor,
161
169
  options.textPosition,
162
170
  options.borderWidth,
163
171
  options.borderRadius,
@@ -165,6 +173,8 @@ define([
165
173
  options.position,
166
174
  options.draggable,
167
175
  options.resizable,
176
+ options.cuttable,
177
+ options.deletable,
168
178
  options.wrapping,
169
179
  options.previewHeight,
170
180
  options.binaryHeight