@checksub_team/peaks_timeline 1.14.1 → 1.15.0-alpha.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 +1 -1
- package/peaks.js +136 -5
- package/src/main.js +10 -0
- package/src/source-group.js +150 -3
- package/src/source.js +19 -1
- package/src/timeline-sources.js +2 -0
package/package.json
CHANGED
package/peaks.js
CHANGED
|
@@ -15916,6 +15916,8 @@ module.exports = function (Colors, EventEmitter, TimelineSegments, TimelineSourc
|
|
|
15916
15916
|
sourceTextYOffset: 10,
|
|
15917
15917
|
sourceIndicatorsXOffset: 8,
|
|
15918
15918
|
sourceIndicatorsYOffset: 12,
|
|
15919
|
+
sourceButtonsGap: 2,
|
|
15920
|
+
sourceButtonsPadding: 4,
|
|
15919
15921
|
autoScrollThreshold: 0.05,
|
|
15920
15922
|
enableLineIndicatorContextMenu: true,
|
|
15921
15923
|
minSourceSize: 0.05,
|
|
@@ -18122,6 +18124,7 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Konva) {
|
|
|
18122
18124
|
this._borderWidth = this._source.borderWidth || 0;
|
|
18123
18125
|
this._height = this._unwrappedHeight;
|
|
18124
18126
|
this._currentTimeToPixelsScaleUsed = this._view.getTimeToPixelsScale();
|
|
18127
|
+
this._selected = this._source.selected;
|
|
18125
18128
|
this._previewList = [];
|
|
18126
18129
|
this._markersGroup = this._createMarkers();
|
|
18127
18130
|
this._group = new Konva.Group({
|
|
@@ -18144,6 +18147,9 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Konva) {
|
|
|
18144
18147
|
self.toggleDragging(false);
|
|
18145
18148
|
self.toggleResizing(false);
|
|
18146
18149
|
}
|
|
18150
|
+
if (!self._selected) {
|
|
18151
|
+
self._showButtons();
|
|
18152
|
+
}
|
|
18147
18153
|
});
|
|
18148
18154
|
this._group.on('mouseout', function () {
|
|
18149
18155
|
self._view.setHoveredElement(null);
|
|
@@ -18152,6 +18158,9 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Konva) {
|
|
|
18152
18158
|
self.toggleDragging(true);
|
|
18153
18159
|
self.toggleResizing(true);
|
|
18154
18160
|
}
|
|
18161
|
+
if (!self._selected) {
|
|
18162
|
+
self._hideButtons();
|
|
18163
|
+
}
|
|
18155
18164
|
});
|
|
18156
18165
|
this._group.add(new Konva.Group());
|
|
18157
18166
|
if (this._borderWidth) {
|
|
@@ -18212,6 +18221,7 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Konva) {
|
|
|
18212
18221
|
}
|
|
18213
18222
|
}
|
|
18214
18223
|
this._updateVolumeSlider();
|
|
18224
|
+
this._updateButtons();
|
|
18215
18225
|
this.updatePreviews();
|
|
18216
18226
|
}
|
|
18217
18227
|
};
|
|
@@ -18379,6 +18389,9 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Konva) {
|
|
|
18379
18389
|
if (this._source.volumeRange && this._source.volume !== undefined) {
|
|
18380
18390
|
unwrap.add(this._getVolumeSlider());
|
|
18381
18391
|
}
|
|
18392
|
+
if (this._source.buttons.length > 0) {
|
|
18393
|
+
unwrap.add(this._getButtons());
|
|
18394
|
+
}
|
|
18382
18395
|
unwrap.add(this._createTitle(false));
|
|
18383
18396
|
return unwrap;
|
|
18384
18397
|
};
|
|
@@ -18420,6 +18433,9 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Konva) {
|
|
|
18420
18433
|
if (this._source.volumeRange && this._source.volume !== undefined) {
|
|
18421
18434
|
wrap.add(this._getVolumeSlider());
|
|
18422
18435
|
}
|
|
18436
|
+
if (this._source.buttons.length > 0) {
|
|
18437
|
+
wrap.add(this._getButtons());
|
|
18438
|
+
}
|
|
18423
18439
|
wrap.add(this._createTitle(true));
|
|
18424
18440
|
return wrap;
|
|
18425
18441
|
};
|
|
@@ -18676,13 +18692,16 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Konva) {
|
|
|
18676
18692
|
});
|
|
18677
18693
|
};
|
|
18678
18694
|
SourceGroup.prototype.setSelected = function () {
|
|
18695
|
+
this._selected = this._source.selected;
|
|
18679
18696
|
if (this._border) {
|
|
18680
|
-
if (this.
|
|
18697
|
+
if (this._selected) {
|
|
18681
18698
|
this._border.fill(this._source.selectedColor);
|
|
18682
18699
|
this._borderWidth = this._peaks.options.sourceSelectedBorderWidth;
|
|
18700
|
+
this._showButtons();
|
|
18683
18701
|
} else {
|
|
18684
18702
|
this._border.fill(this._source.borderColor);
|
|
18685
18703
|
this._borderWidth = this._source.borderWidth;
|
|
18704
|
+
this._hideButtons();
|
|
18686
18705
|
}
|
|
18687
18706
|
} else {
|
|
18688
18707
|
if (this._unwrap) {
|
|
@@ -18690,7 +18709,7 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Konva) {
|
|
|
18690
18709
|
return node.getClassName() === 'Shape';
|
|
18691
18710
|
})[0];
|
|
18692
18711
|
if (unwrap_background) {
|
|
18693
|
-
if (this.
|
|
18712
|
+
if (this._selected) {
|
|
18694
18713
|
unwrap_background.stroke(this._source.selectedColor);
|
|
18695
18714
|
unwrap_background.strokeWidth(this._peaks.options.sourceSelectedBorderWidth);
|
|
18696
18715
|
} else {
|
|
@@ -18703,7 +18722,7 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Konva) {
|
|
|
18703
18722
|
return node.getClassName() === 'Shape';
|
|
18704
18723
|
})[0];
|
|
18705
18724
|
if (wrap_background) {
|
|
18706
|
-
if (this.
|
|
18725
|
+
if (this._selected) {
|
|
18707
18726
|
wrap_background.stroke(this._source.selectedColor);
|
|
18708
18727
|
wrap_background.strokeWidth(this._peaks.options.sourceSelectedBorderWidth);
|
|
18709
18728
|
} else {
|
|
@@ -18887,6 +18906,81 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Konva) {
|
|
|
18887
18906
|
}.bind(this));
|
|
18888
18907
|
return markersGroup;
|
|
18889
18908
|
};
|
|
18909
|
+
SourceGroup.prototype._createButtons = function () {
|
|
18910
|
+
var buttonsGroup = new Konva.Group({
|
|
18911
|
+
listening: true,
|
|
18912
|
+
x: this._width,
|
|
18913
|
+
visible: false
|
|
18914
|
+
});
|
|
18915
|
+
var buttonsGroupWidth = 0;
|
|
18916
|
+
var buttonsGap = this._peaks.options.sourceButtonsGap;
|
|
18917
|
+
var self = this;
|
|
18918
|
+
this._source.buttons.forEach(function (button) {
|
|
18919
|
+
const {id, width, height, cornerRadius, color, borderColor, borderWidth, svg, image} = button;
|
|
18920
|
+
if (buttonsGroupWidth > 0) {
|
|
18921
|
+
buttonsGroupWidth += buttonsGap;
|
|
18922
|
+
}
|
|
18923
|
+
var buttonGroup = new Konva.Group({
|
|
18924
|
+
x: buttonsGroupWidth,
|
|
18925
|
+
y: 0,
|
|
18926
|
+
listening: true
|
|
18927
|
+
});
|
|
18928
|
+
var buttonRect = new Konva.Rect({
|
|
18929
|
+
width: width,
|
|
18930
|
+
height: height,
|
|
18931
|
+
fill: color,
|
|
18932
|
+
stroke: borderColor,
|
|
18933
|
+
strokeWidth: borderWidth,
|
|
18934
|
+
cornerRadius: cornerRadius
|
|
18935
|
+
});
|
|
18936
|
+
buttonsGroupWidth += width;
|
|
18937
|
+
buttonGroup.add(buttonRect);
|
|
18938
|
+
if (svg) {
|
|
18939
|
+
var svgIcon = new Konva.Path({
|
|
18940
|
+
x: width / 2,
|
|
18941
|
+
y: height / 2,
|
|
18942
|
+
data: svg.path,
|
|
18943
|
+
fill: svg.color,
|
|
18944
|
+
offsetX: svg.width / 2,
|
|
18945
|
+
offsetY: svg.height / 2,
|
|
18946
|
+
listening: false
|
|
18947
|
+
});
|
|
18948
|
+
buttonGroup.add(svgIcon);
|
|
18949
|
+
} else if (image) {
|
|
18950
|
+
var imageObj = new Image();
|
|
18951
|
+
imageObj.onload = function () {
|
|
18952
|
+
var imageIcon = new Konva.Image({
|
|
18953
|
+
x: width / 2,
|
|
18954
|
+
y: height / 2,
|
|
18955
|
+
image: imageObj,
|
|
18956
|
+
offsetX: image.width / 2,
|
|
18957
|
+
offsetY: image.height / 2,
|
|
18958
|
+
listening: false
|
|
18959
|
+
});
|
|
18960
|
+
buttonGroup.add(imageIcon);
|
|
18961
|
+
buttonGroup.draw();
|
|
18962
|
+
};
|
|
18963
|
+
imageObj.src = image.data;
|
|
18964
|
+
}
|
|
18965
|
+
if (button.hoverColor) {
|
|
18966
|
+
buttonGroup.on('mouseover', function () {
|
|
18967
|
+
buttonRect.fill(button.hoverColor);
|
|
18968
|
+
buttonGroup.draw();
|
|
18969
|
+
});
|
|
18970
|
+
buttonGroup.on('mouseout', function () {
|
|
18971
|
+
buttonRect.fill(button.color);
|
|
18972
|
+
buttonGroup.draw();
|
|
18973
|
+
});
|
|
18974
|
+
}
|
|
18975
|
+
buttonGroup.on('click', function () {
|
|
18976
|
+
self._peaks.emit('source.buttonClicked', self._source, id);
|
|
18977
|
+
});
|
|
18978
|
+
buttonsGroup.add(buttonGroup);
|
|
18979
|
+
});
|
|
18980
|
+
buttonsGroup.offsetX(buttonsGroupWidth + this._borderWidth + this._peaks.options.sourceButtonsPadding);
|
|
18981
|
+
buttonsGroup.offsetY(-this._borderWidth - this._peaks.options.sourceButtonsPadding);
|
|
18982
|
+
return buttonsGroup;
|
|
18983
|
+
};
|
|
18890
18984
|
SourceGroup.prototype._updateMarkers = function () {
|
|
18891
18985
|
const self = this;
|
|
18892
18986
|
if (this._markersGroup) {
|
|
@@ -18902,6 +18996,27 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Konva) {
|
|
|
18902
18996
|
});
|
|
18903
18997
|
}
|
|
18904
18998
|
};
|
|
18999
|
+
SourceGroup.prototype._updateButtons = function () {
|
|
19000
|
+
if (this._buttonsGroup) {
|
|
19001
|
+
this._buttonsGroup.x(this._width);
|
|
19002
|
+
}
|
|
19003
|
+
};
|
|
19004
|
+
SourceGroup.prototype._getButtons = function () {
|
|
19005
|
+
if (!this._buttonsGroup) {
|
|
19006
|
+
this._buttonsGroup = this._createButtons();
|
|
19007
|
+
}
|
|
19008
|
+
return this._buttonsGroup;
|
|
19009
|
+
};
|
|
19010
|
+
SourceGroup.prototype._showButtons = function () {
|
|
19011
|
+
if (this._buttonsGroup) {
|
|
19012
|
+
this._buttonsGroup.visible(true);
|
|
19013
|
+
}
|
|
19014
|
+
};
|
|
19015
|
+
SourceGroup.prototype._hideButtons = function () {
|
|
19016
|
+
if (this._buttonsGroup) {
|
|
19017
|
+
this._buttonsGroup.visible(false);
|
|
19018
|
+
}
|
|
19019
|
+
};
|
|
18905
19020
|
SourceGroup.prototype._getYFromVolume = function (volume) {
|
|
18906
19021
|
return this._borderWidth + (this._height - 2 * this._borderWidth) * (this._source.volumeRange[1] - volume) / (this._source.volumeRange[1] - this._source.volumeRange[0]);
|
|
18907
19022
|
};
|
|
@@ -19220,6 +19335,11 @@ module.exports = function (Utils) {
|
|
|
19220
19335
|
if (Utils.isNullOrUndefined(options.markers)) {
|
|
19221
19336
|
options.markers = [];
|
|
19222
19337
|
}
|
|
19338
|
+
if (Utils.isNullOrUndefined(options.buttons)) {
|
|
19339
|
+
options.buttons = [];
|
|
19340
|
+
} else if (!Array.isArray(options.buttons)) {
|
|
19341
|
+
throw new TypeError('peaks.sources.' + context + ': buttons must be an array');
|
|
19342
|
+
}
|
|
19223
19343
|
if (Utils.isNullOrUndefined(options.markerColor) || !Utils.isValidColor(options.markerColor)) {
|
|
19224
19344
|
options.markerColor = options.color;
|
|
19225
19345
|
}
|
|
@@ -19241,7 +19361,7 @@ module.exports = function (Utils) {
|
|
|
19241
19361
|
}
|
|
19242
19362
|
}
|
|
19243
19363
|
}
|
|
19244
|
-
function Source(peaks, id, originId, elementId, title, titleAlignments, url, previewUrl, binaryUrl, kind, subkind, duration, startTime, endTime, mediaStartTime, mediaEndTime, color, backgroundColor, borderColor, selectedColor, warningColor, warningWidth, volumeSliderColor, volumeSliderWidth, volumeSliderDraggingWidth, textFont, textFontSize, textColor, textBackgroundColor, textPosition, textAutoScroll, borderWidth, borderRadius, wrapped, position, draggable, orderable, resizable, cuttable, deletable, wrapping, previewHeight, binaryHeight, indicators, markers, markerColor, markerWidth, volume, volumeRange) {
|
|
19364
|
+
function Source(peaks, id, originId, elementId, title, titleAlignments, url, previewUrl, binaryUrl, kind, subkind, duration, startTime, endTime, mediaStartTime, mediaEndTime, color, backgroundColor, borderColor, selectedColor, warningColor, warningWidth, volumeSliderColor, volumeSliderWidth, volumeSliderDraggingWidth, textFont, textFontSize, textColor, textBackgroundColor, textPosition, textAutoScroll, borderWidth, borderRadius, wrapped, position, draggable, orderable, resizable, cuttable, deletable, wrapping, previewHeight, binaryHeight, indicators, markers, buttons, markerColor, markerWidth, volume, volumeRange) {
|
|
19245
19365
|
var opts = {
|
|
19246
19366
|
title: title,
|
|
19247
19367
|
titleAlignments: titleAlignments,
|
|
@@ -19284,6 +19404,7 @@ module.exports = function (Utils) {
|
|
|
19284
19404
|
binaryHeight: binaryHeight,
|
|
19285
19405
|
indicators: indicators,
|
|
19286
19406
|
markers: markers,
|
|
19407
|
+
buttons: buttons,
|
|
19287
19408
|
markerColor: markerColor,
|
|
19288
19409
|
markerWidth: markerWidth,
|
|
19289
19410
|
volume: volume,
|
|
@@ -19335,6 +19456,7 @@ module.exports = function (Utils) {
|
|
|
19335
19456
|
this._binaryHeight = opts.binaryHeight;
|
|
19336
19457
|
this._indicators = opts.indicators;
|
|
19337
19458
|
this._markers = opts.markers;
|
|
19459
|
+
this._buttons = opts.buttons;
|
|
19338
19460
|
this._markerColor = opts.markerColor;
|
|
19339
19461
|
this._markerWidth = opts.markerWidth;
|
|
19340
19462
|
this._volume = opts.volume;
|
|
@@ -19685,6 +19807,12 @@ module.exports = function (Utils) {
|
|
|
19685
19807
|
return this._markers;
|
|
19686
19808
|
}
|
|
19687
19809
|
},
|
|
19810
|
+
buttons: {
|
|
19811
|
+
enumerable: true,
|
|
19812
|
+
get: function () {
|
|
19813
|
+
return this._buttons;
|
|
19814
|
+
}
|
|
19815
|
+
},
|
|
19688
19816
|
markerColor: {
|
|
19689
19817
|
enumerable: true,
|
|
19690
19818
|
get: function () {
|
|
@@ -19855,6 +19983,7 @@ module.exports = function (Utils) {
|
|
|
19855
19983
|
binaryHeight: this.binaryHeight,
|
|
19856
19984
|
indicators: this.indicators,
|
|
19857
19985
|
markers: this.markers,
|
|
19986
|
+
buttons: this.buttons,
|
|
19858
19987
|
markerColor: this.markerColor,
|
|
19859
19988
|
markerWidth: this.markerWidth,
|
|
19860
19989
|
volume: this.volume,
|
|
@@ -19903,6 +20032,7 @@ module.exports = function (Utils) {
|
|
|
19903
20032
|
this._binaryHeight = opts.binaryHeight;
|
|
19904
20033
|
this._indicators = opts.indicators;
|
|
19905
20034
|
this._markers = opts.markers;
|
|
20035
|
+
this._buttons = opts.buttons;
|
|
19906
20036
|
this._markerColor = opts.markerColor;
|
|
19907
20037
|
this._markerWidth = opts.markerWidth;
|
|
19908
20038
|
this._volume = opts.volume;
|
|
@@ -20759,6 +20889,7 @@ module.exports = function (Source, Utils) {
|
|
|
20759
20889
|
previewHeight: sourceToCut.previewHeight,
|
|
20760
20890
|
binaryHeight: sourceToCut.binaryHeight,
|
|
20761
20891
|
markers: sourceToCut.markers,
|
|
20892
|
+
buttons: sourceToCut.buttons,
|
|
20762
20893
|
markerColor: sourceToCut.markerColor,
|
|
20763
20894
|
markerWidth: sourceToCut.markerWidth,
|
|
20764
20895
|
volume: sourceToCut.volume,
|
|
@@ -20780,7 +20911,7 @@ module.exports = function (Source, Utils) {
|
|
|
20780
20911
|
if (!Utils.isObject(options)) {
|
|
20781
20912
|
throw new TypeError('peaks.sources.add(): expected a Source object parameter');
|
|
20782
20913
|
}
|
|
20783
|
-
var source = new Source(this._peaks, options.id || this._getNextSourceId(), options.originId, options.elementId, options.title, options.titleAlignments, 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.warningColor, options.warningWidth, options.volumeSliderColor, options.volumeSliderWidth, options.volumeSliderDraggingWidth, options.textFont, options.textFontSize, options.textColor, options.textBackgroundColor, options.textPosition, options.textAutoScroll, options.borderWidth, options.borderRadius, options.wrapped, options.position, options.draggable, options.orderable, options.resizable, options.cuttable, options.deletable, options.wrapping, options.previewHeight, options.binaryHeight, options.indicators, options.markers, options.markerColor, options.markerWidth, options.volume, options.volumeRange);
|
|
20914
|
+
var source = new Source(this._peaks, options.id || this._getNextSourceId(), options.originId, options.elementId, options.title, options.titleAlignments, 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.warningColor, options.warningWidth, options.volumeSliderColor, options.volumeSliderWidth, options.volumeSliderDraggingWidth, options.textFont, options.textFontSize, options.textColor, options.textBackgroundColor, options.textPosition, options.textAutoScroll, options.borderWidth, options.borderRadius, options.wrapped, options.position, options.draggable, options.orderable, options.resizable, options.cuttable, options.deletable, options.wrapping, options.previewHeight, options.binaryHeight, options.indicators, options.markers, options.buttons, options.markerColor, options.markerWidth, options.volume, options.volumeRange);
|
|
20784
20915
|
return source;
|
|
20785
20916
|
};
|
|
20786
20917
|
TimelineSources.prototype.getSources = function () {
|
package/src/main.js
CHANGED
|
@@ -369,6 +369,16 @@ define([
|
|
|
369
369
|
*/
|
|
370
370
|
sourceIndicatorsYOffset: 12,
|
|
371
371
|
|
|
372
|
+
/**
|
|
373
|
+
* Spacing between the source buttons, in pixels
|
|
374
|
+
*/
|
|
375
|
+
sourceButtonsGap: 2,
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* Padding around the source buttons, in pixels
|
|
379
|
+
*/
|
|
380
|
+
sourceButtonsPadding: 4,
|
|
381
|
+
|
|
372
382
|
/**
|
|
373
383
|
* Threshold size on the left and right border of the view,
|
|
374
384
|
* where auto scrolling is activated, between 0 and 1.
|
package/src/source-group.js
CHANGED
|
@@ -53,6 +53,7 @@ define([
|
|
|
53
53
|
this._borderWidth = this._source.borderWidth || 0;
|
|
54
54
|
this._height = this._unwrappedHeight;
|
|
55
55
|
this._currentTimeToPixelsScaleUsed = this._view.getTimeToPixelsScale();
|
|
56
|
+
this._selected = this._source.selected;
|
|
56
57
|
|
|
57
58
|
this._previewList = [];
|
|
58
59
|
|
|
@@ -80,6 +81,9 @@ define([
|
|
|
80
81
|
self.toggleDragging(false);
|
|
81
82
|
self.toggleResizing(false);
|
|
82
83
|
}
|
|
84
|
+
if (!self._selected) {
|
|
85
|
+
self._showButtons();
|
|
86
|
+
}
|
|
83
87
|
});
|
|
84
88
|
this._group.on('mouseout', function() {
|
|
85
89
|
self._view.setHoveredElement(null);
|
|
@@ -88,6 +92,9 @@ define([
|
|
|
88
92
|
self.toggleDragging(true);
|
|
89
93
|
self.toggleResizing(true);
|
|
90
94
|
}
|
|
95
|
+
if (!self._selected) {
|
|
96
|
+
self._hideButtons();
|
|
97
|
+
}
|
|
91
98
|
});
|
|
92
99
|
|
|
93
100
|
this._group.add(new Konva.Group());
|
|
@@ -198,6 +205,7 @@ define([
|
|
|
198
205
|
}
|
|
199
206
|
|
|
200
207
|
this._updateVolumeSlider();
|
|
208
|
+
this._updateButtons();
|
|
201
209
|
|
|
202
210
|
// update unwrap
|
|
203
211
|
this.updatePreviews();
|
|
@@ -428,6 +436,9 @@ define([
|
|
|
428
436
|
if (this._source.volumeRange && this._source.volume !== undefined) {
|
|
429
437
|
unwrap.add(this._getVolumeSlider());
|
|
430
438
|
}
|
|
439
|
+
if (this._source.buttons.length > 0) {
|
|
440
|
+
unwrap.add(this._getButtons());
|
|
441
|
+
}
|
|
431
442
|
unwrap.add(this._createTitle(false));
|
|
432
443
|
|
|
433
444
|
return unwrap;
|
|
@@ -480,6 +491,9 @@ define([
|
|
|
480
491
|
if (this._source.volumeRange && this._source.volume !== undefined) {
|
|
481
492
|
wrap.add(this._getVolumeSlider());
|
|
482
493
|
}
|
|
494
|
+
if (this._source.buttons.length > 0) {
|
|
495
|
+
wrap.add(this._getButtons());
|
|
496
|
+
}
|
|
483
497
|
wrap.add(this._createTitle(true));
|
|
484
498
|
|
|
485
499
|
return wrap;
|
|
@@ -814,14 +828,17 @@ define([
|
|
|
814
828
|
};
|
|
815
829
|
|
|
816
830
|
SourceGroup.prototype.setSelected = function() {
|
|
831
|
+
this._selected = this._source.selected;
|
|
817
832
|
if (this._border) {
|
|
818
|
-
if (this.
|
|
833
|
+
if (this._selected) {
|
|
819
834
|
this._border.fill(this._source.selectedColor);
|
|
820
835
|
this._borderWidth = this._peaks.options.sourceSelectedBorderWidth;
|
|
836
|
+
this._showButtons();
|
|
821
837
|
}
|
|
822
838
|
else {
|
|
823
839
|
this._border.fill(this._source.borderColor);
|
|
824
840
|
this._borderWidth = this._source.borderWidth;
|
|
841
|
+
this._hideButtons();
|
|
825
842
|
}
|
|
826
843
|
}
|
|
827
844
|
else {
|
|
@@ -832,7 +849,7 @@ define([
|
|
|
832
849
|
})[0];
|
|
833
850
|
|
|
834
851
|
if (unwrap_background) {
|
|
835
|
-
if (this.
|
|
852
|
+
if (this._selected) {
|
|
836
853
|
unwrap_background.stroke(this._source.selectedColor);
|
|
837
854
|
unwrap_background.strokeWidth(this._peaks.options.sourceSelectedBorderWidth);
|
|
838
855
|
}
|
|
@@ -849,7 +866,7 @@ define([
|
|
|
849
866
|
})[0];
|
|
850
867
|
|
|
851
868
|
if (wrap_background) {
|
|
852
|
-
if (this.
|
|
869
|
+
if (this._selected) {
|
|
853
870
|
wrap_background.stroke(this._source.selectedColor);
|
|
854
871
|
wrap_background.strokeWidth(this._peaks.options.sourceSelectedBorderWidth);
|
|
855
872
|
}
|
|
@@ -1092,6 +1109,110 @@ define([
|
|
|
1092
1109
|
return markersGroup;
|
|
1093
1110
|
};
|
|
1094
1111
|
|
|
1112
|
+
SourceGroup.prototype._createButtons = function() {
|
|
1113
|
+
var buttonsGroup = new Konva.Group({
|
|
1114
|
+
listening: true,
|
|
1115
|
+
x: this._width,
|
|
1116
|
+
visible: false
|
|
1117
|
+
});
|
|
1118
|
+
var buttonsGroupWidth = 0;
|
|
1119
|
+
var buttonsGap = this._peaks.options.sourceButtonsGap;
|
|
1120
|
+
var self = this;
|
|
1121
|
+
|
|
1122
|
+
this._source.buttons.forEach(function(button) {
|
|
1123
|
+
const {
|
|
1124
|
+
id,
|
|
1125
|
+
width,
|
|
1126
|
+
height,
|
|
1127
|
+
cornerRadius,
|
|
1128
|
+
color,
|
|
1129
|
+
borderColor,
|
|
1130
|
+
borderWidth,
|
|
1131
|
+
svg,
|
|
1132
|
+
image
|
|
1133
|
+
} = button;
|
|
1134
|
+
|
|
1135
|
+
if (buttonsGroupWidth > 0) {
|
|
1136
|
+
buttonsGroupWidth += buttonsGap;
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1139
|
+
var buttonGroup = new Konva.Group({
|
|
1140
|
+
x: buttonsGroupWidth,
|
|
1141
|
+
y: 0,
|
|
1142
|
+
listening: true
|
|
1143
|
+
});
|
|
1144
|
+
|
|
1145
|
+
var buttonRect = new Konva.Rect({
|
|
1146
|
+
width: width,
|
|
1147
|
+
height: height,
|
|
1148
|
+
fill: color,
|
|
1149
|
+
stroke: borderColor,
|
|
1150
|
+
strokeWidth: borderWidth,
|
|
1151
|
+
cornerRadius: cornerRadius
|
|
1152
|
+
});
|
|
1153
|
+
|
|
1154
|
+
buttonsGroupWidth += width;
|
|
1155
|
+
|
|
1156
|
+
buttonGroup.add(buttonRect);
|
|
1157
|
+
|
|
1158
|
+
if (svg) {
|
|
1159
|
+
var svgIcon = new Konva.Path({
|
|
1160
|
+
x: width / 2,
|
|
1161
|
+
y: height / 2,
|
|
1162
|
+
data: svg.path,
|
|
1163
|
+
fill: svg.color,
|
|
1164
|
+
offsetX: svg.width / 2,
|
|
1165
|
+
offsetY: svg.height / 2,
|
|
1166
|
+
listening: false
|
|
1167
|
+
});
|
|
1168
|
+
|
|
1169
|
+
buttonGroup.add(svgIcon);
|
|
1170
|
+
}
|
|
1171
|
+
else if (image) {
|
|
1172
|
+
var imageObj = new Image();
|
|
1173
|
+
|
|
1174
|
+
imageObj.onload = function() {
|
|
1175
|
+
var imageIcon = new Konva.Image({
|
|
1176
|
+
x: width / 2,
|
|
1177
|
+
y: height / 2,
|
|
1178
|
+
image: imageObj,
|
|
1179
|
+
offsetX: image.width / 2,
|
|
1180
|
+
offsetY: image.height / 2,
|
|
1181
|
+
listening: false
|
|
1182
|
+
});
|
|
1183
|
+
|
|
1184
|
+
buttonGroup.add(imageIcon);
|
|
1185
|
+
buttonGroup.draw();
|
|
1186
|
+
};
|
|
1187
|
+
|
|
1188
|
+
imageObj.src = image.data;
|
|
1189
|
+
}
|
|
1190
|
+
|
|
1191
|
+
if (button.hoverColor) {
|
|
1192
|
+
buttonGroup.on('mouseover', function() {
|
|
1193
|
+
buttonRect.fill(button.hoverColor);
|
|
1194
|
+
buttonGroup.draw();
|
|
1195
|
+
});
|
|
1196
|
+
|
|
1197
|
+
buttonGroup.on('mouseout', function() {
|
|
1198
|
+
buttonRect.fill(button.color);
|
|
1199
|
+
buttonGroup.draw();
|
|
1200
|
+
});
|
|
1201
|
+
}
|
|
1202
|
+
|
|
1203
|
+
buttonGroup.on('click', function() {
|
|
1204
|
+
self._peaks.emit('source.buttonClicked', self._source, id);
|
|
1205
|
+
});
|
|
1206
|
+
|
|
1207
|
+
buttonsGroup.add(buttonGroup);
|
|
1208
|
+
});
|
|
1209
|
+
|
|
1210
|
+
buttonsGroup.offsetX(buttonsGroupWidth + this._borderWidth + this._peaks.options.sourceButtonsPadding);
|
|
1211
|
+
buttonsGroup.offsetY(-this._borderWidth - this._peaks.options.sourceButtonsPadding);
|
|
1212
|
+
|
|
1213
|
+
return buttonsGroup;
|
|
1214
|
+
};
|
|
1215
|
+
|
|
1095
1216
|
SourceGroup.prototype._updateMarkers = function() {
|
|
1096
1217
|
const self = this;
|
|
1097
1218
|
|
|
@@ -1105,6 +1226,32 @@ define([
|
|
|
1105
1226
|
}
|
|
1106
1227
|
};
|
|
1107
1228
|
|
|
1229
|
+
SourceGroup.prototype._updateButtons = function() {
|
|
1230
|
+
if (this._buttonsGroup) {
|
|
1231
|
+
this._buttonsGroup.x(this._width);
|
|
1232
|
+
}
|
|
1233
|
+
};
|
|
1234
|
+
|
|
1235
|
+
SourceGroup.prototype._getButtons = function() {
|
|
1236
|
+
if (!this._buttonsGroup) {
|
|
1237
|
+
this._buttonsGroup = this._createButtons();
|
|
1238
|
+
}
|
|
1239
|
+
|
|
1240
|
+
return this._buttonsGroup;
|
|
1241
|
+
};
|
|
1242
|
+
|
|
1243
|
+
SourceGroup.prototype._showButtons = function() {
|
|
1244
|
+
if (this._buttonsGroup) {
|
|
1245
|
+
this._buttonsGroup.visible(true);
|
|
1246
|
+
}
|
|
1247
|
+
};
|
|
1248
|
+
|
|
1249
|
+
SourceGroup.prototype._hideButtons = function() {
|
|
1250
|
+
if (this._buttonsGroup) {
|
|
1251
|
+
this._buttonsGroup.visible(false);
|
|
1252
|
+
}
|
|
1253
|
+
};
|
|
1254
|
+
|
|
1108
1255
|
SourceGroup.prototype._getYFromVolume = function(volume) {
|
|
1109
1256
|
return this._borderWidth + (this._height - 2 * this._borderWidth) * (
|
|
1110
1257
|
this._source.volumeRange[1] - volume
|
package/src/source.js
CHANGED
|
@@ -307,6 +307,13 @@ define([
|
|
|
307
307
|
options.markers = [];
|
|
308
308
|
}
|
|
309
309
|
|
|
310
|
+
if (Utils.isNullOrUndefined(options.buttons)) {
|
|
311
|
+
options.buttons = [];
|
|
312
|
+
}
|
|
313
|
+
else if (!Array.isArray(options.buttons)) {
|
|
314
|
+
throw new TypeError('peaks.sources.' + context + ': buttons must be an array');
|
|
315
|
+
}
|
|
316
|
+
|
|
310
317
|
if (Utils.isNullOrUndefined(options.markerColor)
|
|
311
318
|
|| !Utils.isValidColor(options.markerColor)) {
|
|
312
319
|
options.markerColor = options.color;
|
|
@@ -388,6 +395,7 @@ define([
|
|
|
388
395
|
* @param {Number} binaryHeight Height of the binary data visualization.
|
|
389
396
|
* @param {Array} indicators Array containing indicator data for the source.
|
|
390
397
|
* @param {Array} markers Array containing marker data for the source.
|
|
398
|
+
* @param {Array} buttons Array containing button data for the source.
|
|
391
399
|
* @param {String} markerColor Color of the markers.
|
|
392
400
|
* @param {Number} markerWidth Width of the markers.
|
|
393
401
|
* @param {Number} volume Current volume level of the source.
|
|
@@ -399,7 +407,7 @@ define([
|
|
|
399
407
|
borderColor, selectedColor, warningColor, warningWidth, volumeSliderColor, volumeSliderWidth,
|
|
400
408
|
volumeSliderDraggingWidth, textFont, textFontSize, textColor, textBackgroundColor, textPosition,
|
|
401
409
|
textAutoScroll, borderWidth, borderRadius, wrapped, position, draggable, orderable, resizable,
|
|
402
|
-
cuttable, deletable, wrapping, previewHeight, binaryHeight, indicators, markers, markerColor,
|
|
410
|
+
cuttable, deletable, wrapping, previewHeight, binaryHeight, indicators, markers, buttons, markerColor,
|
|
403
411
|
markerWidth, volume, volumeRange) {
|
|
404
412
|
var opts = {
|
|
405
413
|
title: title,
|
|
@@ -443,6 +451,7 @@ define([
|
|
|
443
451
|
binaryHeight: binaryHeight,
|
|
444
452
|
indicators: indicators,
|
|
445
453
|
markers: markers,
|
|
454
|
+
buttons: buttons,
|
|
446
455
|
markerColor: markerColor,
|
|
447
456
|
markerWidth: markerWidth,
|
|
448
457
|
volume: volume,
|
|
@@ -496,6 +505,7 @@ define([
|
|
|
496
505
|
this._binaryHeight = opts.binaryHeight;
|
|
497
506
|
this._indicators = opts.indicators;
|
|
498
507
|
this._markers = opts.markers;
|
|
508
|
+
this._buttons = opts.buttons;
|
|
499
509
|
this._markerColor = opts.markerColor;
|
|
500
510
|
this._markerWidth = opts.markerWidth;
|
|
501
511
|
this._volume = opts.volume;
|
|
@@ -871,6 +881,12 @@ define([
|
|
|
871
881
|
return this._markers;
|
|
872
882
|
}
|
|
873
883
|
},
|
|
884
|
+
buttons: {
|
|
885
|
+
enumerable: true,
|
|
886
|
+
get: function() {
|
|
887
|
+
return this._buttons;
|
|
888
|
+
}
|
|
889
|
+
},
|
|
874
890
|
markerColor: {
|
|
875
891
|
enumerable: true,
|
|
876
892
|
get: function() {
|
|
@@ -1075,6 +1091,7 @@ define([
|
|
|
1075
1091
|
binaryHeight: this.binaryHeight,
|
|
1076
1092
|
indicators: this.indicators,
|
|
1077
1093
|
markers: this.markers,
|
|
1094
|
+
buttons: this.buttons,
|
|
1078
1095
|
markerColor: this.markerColor,
|
|
1079
1096
|
markerWidth: this.markerWidth,
|
|
1080
1097
|
volume: this.volume,
|
|
@@ -1126,6 +1143,7 @@ define([
|
|
|
1126
1143
|
this._binaryHeight = opts.binaryHeight;
|
|
1127
1144
|
this._indicators = opts.indicators;
|
|
1128
1145
|
this._markers = opts.markers;
|
|
1146
|
+
this._buttons = opts.buttons;
|
|
1129
1147
|
this._markerColor = opts.markerColor;
|
|
1130
1148
|
this._markerWidth = opts.markerWidth;
|
|
1131
1149
|
this._volume = opts.volume;
|
package/src/timeline-sources.js
CHANGED
|
@@ -106,6 +106,7 @@ define([
|
|
|
106
106
|
previewHeight: sourceToCut.previewHeight,
|
|
107
107
|
binaryHeight: sourceToCut.binaryHeight,
|
|
108
108
|
markers: sourceToCut.markers,
|
|
109
|
+
buttons: sourceToCut.buttons,
|
|
109
110
|
markerColor: sourceToCut.markerColor,
|
|
110
111
|
markerWidth: sourceToCut.markerWidth,
|
|
111
112
|
volume: sourceToCut.volume,
|
|
@@ -200,6 +201,7 @@ define([
|
|
|
200
201
|
options.binaryHeight,
|
|
201
202
|
options.indicators,
|
|
202
203
|
options.markers,
|
|
204
|
+
options.buttons,
|
|
203
205
|
options.markerColor,
|
|
204
206
|
options.markerWidth,
|
|
205
207
|
options.volume,
|