@checksub_team/peaks_timeline 1.6.6 → 1.8.0
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 +42 -20
- package/src/main.js +12 -0
- package/src/mode-layer.js +44 -18
- package/src/timeline-zoomview.js +1 -1
package/package.json
CHANGED
package/peaks.js
CHANGED
|
@@ -15631,6 +15631,12 @@ module.exports = function (Colors, EventEmitter, TimelineSegments, TimelineSourc
|
|
|
15631
15631
|
this.options.lineHeight = newLineHeight;
|
|
15632
15632
|
this.emit('options.set.line_height', oldHeight);
|
|
15633
15633
|
};
|
|
15634
|
+
Peaks.prototype.zoomIn = function () {
|
|
15635
|
+
this.view.setZoom(this.view.getTimeToPixelsScale() + Math.floor(this.view.getTimeToPixelsScale() / 10) + 1);
|
|
15636
|
+
};
|
|
15637
|
+
Peaks.prototype.zoomOut = function () {
|
|
15638
|
+
this.view.setZoom(this.view.getTimeToPixelsScale() - Math.floor(this.view.getTimeToPixelsScale() / 10) + 1);
|
|
15639
|
+
};
|
|
15634
15640
|
Peaks.prototype.destroy = function () {
|
|
15635
15641
|
this._removeWindowResizeHandler();
|
|
15636
15642
|
if (this.keyboardHandler) {
|
|
@@ -15685,9 +15691,10 @@ module.exports = function (Utils, SourceGroup, Konva) {
|
|
|
15685
15691
|
'use strict';
|
|
15686
15692
|
var TIME_X_OFFSET = 20;
|
|
15687
15693
|
var TIME_Y_OFFSET = 10;
|
|
15688
|
-
function ModeLayer(peaks, view, stage, initialMode) {
|
|
15694
|
+
function ModeLayer(peaks, view, playheadLayer, stage, initialMode) {
|
|
15689
15695
|
this._peaks = peaks;
|
|
15690
15696
|
this._view = view;
|
|
15697
|
+
this._playheadLayer = playheadLayer;
|
|
15691
15698
|
this._stage = stage;
|
|
15692
15699
|
this._layer = new Konva.Layer({ listening: this._mode !== 'default' });
|
|
15693
15700
|
this._prepareDefaultMode();
|
|
@@ -15805,37 +15812,37 @@ module.exports = function (Utils, SourceGroup, Konva) {
|
|
|
15805
15812
|
this._cutGroup.visible(true);
|
|
15806
15813
|
this._layer.draw();
|
|
15807
15814
|
};
|
|
15808
|
-
ModeLayer.prototype._updateCursorTime = function (
|
|
15815
|
+
ModeLayer.prototype._updateCursorTime = function (position) {
|
|
15809
15816
|
var hoveredElement = this._view.getHoveredElement();
|
|
15810
15817
|
if (hoveredElement && hoveredElement instanceof SourceGroup && hoveredElement.isCuttable()) {
|
|
15811
|
-
this._timeLabel.text(Utils.formatTime(this._view.pixelsToTime(
|
|
15818
|
+
this._timeLabel.text(Utils.formatTime(this._view.pixelsToTime(position.x + this._view.getFrameOffset()), false));
|
|
15812
15819
|
this._timeBackground.width(this._timeLabel.width() + 8);
|
|
15813
|
-
this._cursorTime.x(
|
|
15814
|
-
if (
|
|
15815
|
-
this._cursorTime.y(
|
|
15820
|
+
this._cursorTime.x(position.x + TIME_X_OFFSET);
|
|
15821
|
+
if (position.y > this._view.getHeight() - this._timeBackground.height() - TIME_Y_OFFSET) {
|
|
15822
|
+
this._cursorTime.y(position.y - TIME_Y_OFFSET);
|
|
15816
15823
|
} else {
|
|
15817
|
-
this._cursorTime.y(
|
|
15824
|
+
this._cursorTime.y(position.y + TIME_Y_OFFSET);
|
|
15818
15825
|
}
|
|
15819
15826
|
this._cursorTime.visible(true);
|
|
15820
15827
|
} else {
|
|
15821
15828
|
this._cursorTime.visible(false);
|
|
15822
15829
|
}
|
|
15823
15830
|
};
|
|
15824
|
-
ModeLayer.prototype._updateCuttingLine = function (
|
|
15831
|
+
ModeLayer.prototype._updateCuttingLine = function (position) {
|
|
15825
15832
|
var hoveredElement = this._view.getHoveredElement();
|
|
15826
15833
|
if (hoveredElement && hoveredElement instanceof SourceGroup && hoveredElement.isCuttable()) {
|
|
15827
15834
|
var minSize = this._view.timeToPixels(hoveredElement.getSource().minSize);
|
|
15828
15835
|
if (hoveredElement.getWidth() >= 2 * minSize) {
|
|
15829
15836
|
var height = hoveredElement.getCurrentHeight();
|
|
15830
15837
|
var y = hoveredElement.getY();
|
|
15831
|
-
if (
|
|
15838
|
+
if (position.x < hoveredElement.x() + minSize) {
|
|
15832
15839
|
this._cuttingLine.points([
|
|
15833
15840
|
hoveredElement.x() + minSize,
|
|
15834
15841
|
y,
|
|
15835
15842
|
hoveredElement.x() + minSize,
|
|
15836
15843
|
y + height
|
|
15837
15844
|
]);
|
|
15838
|
-
} else if (
|
|
15845
|
+
} else if (position.x > hoveredElement.x() + hoveredElement.getWidth() - minSize) {
|
|
15839
15846
|
this._cuttingLine.points([
|
|
15840
15847
|
hoveredElement.x() + hoveredElement.getWidth() - minSize,
|
|
15841
15848
|
y,
|
|
@@ -15844,9 +15851,9 @@ module.exports = function (Utils, SourceGroup, Konva) {
|
|
|
15844
15851
|
]);
|
|
15845
15852
|
} else {
|
|
15846
15853
|
this._cuttingLine.points([
|
|
15847
|
-
|
|
15854
|
+
position.x,
|
|
15848
15855
|
y,
|
|
15849
|
-
|
|
15856
|
+
position.x,
|
|
15850
15857
|
y + height
|
|
15851
15858
|
]);
|
|
15852
15859
|
}
|
|
@@ -15864,8 +15871,17 @@ module.exports = function (Utils, SourceGroup, Konva) {
|
|
|
15864
15871
|
ModeLayer.prototype._onMouseMoveInCutMode = function () {
|
|
15865
15872
|
var mousePosition = this._stage.getPointerPosition();
|
|
15866
15873
|
mousePosition.x = this._view.timeToPixels(this._view.pixelsToTime(mousePosition.x));
|
|
15867
|
-
|
|
15868
|
-
this.
|
|
15874
|
+
var cuttingPosition = mousePosition;
|
|
15875
|
+
var hoveredElement = this._view.getHoveredElement();
|
|
15876
|
+
if (hoveredElement && hoveredElement instanceof SourceGroup && hoveredElement.isCuttable()) {
|
|
15877
|
+
var playheadPositionX = this._view.timeToPixels(this._playheadLayer._time);
|
|
15878
|
+
var playheadIsOnHoveredElement = playheadPositionX >= hoveredElement.x() && playheadPositionX <= hoveredElement.x() + hoveredElement.getWidth();
|
|
15879
|
+
if (Math.abs(mousePosition.x - playheadPositionX) < 10 && playheadIsOnHoveredElement) {
|
|
15880
|
+
cuttingPosition.x = playheadPositionX;
|
|
15881
|
+
}
|
|
15882
|
+
}
|
|
15883
|
+
this._updateCursorTime(cuttingPosition);
|
|
15884
|
+
this._updateCuttingLine(cuttingPosition);
|
|
15869
15885
|
this._layer.draw();
|
|
15870
15886
|
};
|
|
15871
15887
|
ModeLayer.prototype._onMouseLeaveInCutMode = function () {
|
|
@@ -15877,22 +15893,28 @@ module.exports = function (Utils, SourceGroup, Konva) {
|
|
|
15877
15893
|
mousePosition.x = this._view.timeToPixels(this._view.pixelsToTime(mousePosition.x));
|
|
15878
15894
|
var hoveredElement = this._view.getHoveredElement();
|
|
15879
15895
|
if (hoveredElement && hoveredElement instanceof SourceGroup && hoveredElement.isCuttable()) {
|
|
15896
|
+
var cuttingPosition = mousePosition;
|
|
15897
|
+
var playheadPositionX = this._view.timeToPixels(this._playheadLayer._time);
|
|
15898
|
+
var playheadIsOnHoveredElement = playheadPositionX >= hoveredElement.x() && playheadPositionX <= hoveredElement.x() + hoveredElement.getWidth();
|
|
15899
|
+
if (Math.abs(mousePosition.x - playheadPositionX) < 10 && playheadIsOnHoveredElement) {
|
|
15900
|
+
cuttingPosition.x = playheadPositionX;
|
|
15901
|
+
}
|
|
15880
15902
|
var minSize = this._view.timeToPixels(hoveredElement.getSource().minSize);
|
|
15881
15903
|
if (hoveredElement.getWidth() >= 2 * minSize) {
|
|
15882
15904
|
var cuttingPixel;
|
|
15883
|
-
if (
|
|
15905
|
+
if (cuttingPosition.x < hoveredElement.x() + minSize) {
|
|
15884
15906
|
cuttingPixel = hoveredElement.x() + minSize;
|
|
15885
|
-
} else if (
|
|
15907
|
+
} else if (cuttingPosition.x > hoveredElement.x() + hoveredElement.getWidth() - minSize) {
|
|
15886
15908
|
cuttingPixel = hoveredElement.x() + hoveredElement.getWidth() - minSize;
|
|
15887
15909
|
} else {
|
|
15888
|
-
cuttingPixel =
|
|
15910
|
+
cuttingPixel = cuttingPosition.x;
|
|
15889
15911
|
}
|
|
15890
15912
|
cuttingPixel -= hoveredElement.x();
|
|
15891
15913
|
this._cuttingLine.visible(false);
|
|
15892
15914
|
this._peaks.emit('source.cut', hoveredElement.getSource(), this._view.pixelsToTime(cuttingPixel));
|
|
15893
15915
|
this._view.setHoveredElement(null);
|
|
15894
|
-
this._updateCursorTime(
|
|
15895
|
-
this._updateCuttingLine(
|
|
15916
|
+
this._updateCursorTime(cuttingPosition);
|
|
15917
|
+
this._updateCuttingLine(cuttingPosition);
|
|
15896
15918
|
this._layer.draw();
|
|
15897
15919
|
}
|
|
15898
15920
|
}
|
|
@@ -19911,7 +19933,7 @@ module.exports = function (MouseDragHandler, PlayheadLayer, SourcesLayer, ModeLa
|
|
|
19911
19933
|
var time = self._peaks.player.getCurrentTime();
|
|
19912
19934
|
self._syncPlayhead(time);
|
|
19913
19935
|
self._hoveredElement = null;
|
|
19914
|
-
self._modeLayer = new ModeLayer(peaks, self, self._stage, 'default');
|
|
19936
|
+
self._modeLayer = new ModeLayer(peaks, self, self._playheadLayer, self._stage, 'default');
|
|
19915
19937
|
self._modeLayer.addToStage(self._stage);
|
|
19916
19938
|
self._mouseDragHandler = new MouseDragHandler(self._stage, {
|
|
19917
19939
|
onMouseDown: function (mousePosX, mousePosY) {
|
package/src/main.js
CHANGED
|
@@ -745,6 +745,18 @@ define([
|
|
|
745
745
|
this.emit('options.set.line_height', oldHeight);
|
|
746
746
|
};
|
|
747
747
|
|
|
748
|
+
Peaks.prototype.zoomIn = function() {
|
|
749
|
+
this.view.setZoom(
|
|
750
|
+
this.view.getTimeToPixelsScale() + Math.floor(this.view.getTimeToPixelsScale() / 10) + 1
|
|
751
|
+
);
|
|
752
|
+
};
|
|
753
|
+
|
|
754
|
+
Peaks.prototype.zoomOut = function() {
|
|
755
|
+
this.view.setZoom(
|
|
756
|
+
this.view.getTimeToPixelsScale() - Math.floor(this.view.getTimeToPixelsScale() / 10) + 1
|
|
757
|
+
);
|
|
758
|
+
};
|
|
759
|
+
|
|
748
760
|
/**
|
|
749
761
|
* Cleans up a Peaks instance after use.
|
|
750
762
|
*/
|
package/src/mode-layer.js
CHANGED
|
@@ -27,9 +27,10 @@ define([
|
|
|
27
27
|
* @param {String} initialMode
|
|
28
28
|
*/
|
|
29
29
|
|
|
30
|
-
function ModeLayer(peaks, view, stage, initialMode) {
|
|
30
|
+
function ModeLayer(peaks, view, playheadLayer, stage, initialMode) {
|
|
31
31
|
this._peaks = peaks;
|
|
32
32
|
this._view = view;
|
|
33
|
+
this._playheadLayer = playheadLayer;
|
|
33
34
|
this._stage = stage;
|
|
34
35
|
|
|
35
36
|
this._layer = new Konva.Layer({
|
|
@@ -182,27 +183,27 @@ define([
|
|
|
182
183
|
this._layer.draw();
|
|
183
184
|
};
|
|
184
185
|
|
|
185
|
-
ModeLayer.prototype._updateCursorTime = function(
|
|
186
|
+
ModeLayer.prototype._updateCursorTime = function(position) {
|
|
186
187
|
var hoveredElement = this._view.getHoveredElement();
|
|
187
188
|
|
|
188
189
|
if (hoveredElement && hoveredElement instanceof SourceGroup && hoveredElement.isCuttable()) {
|
|
189
190
|
this._timeLabel.text(
|
|
190
191
|
Utils.formatTime(
|
|
191
|
-
this._view.pixelsToTime(
|
|
192
|
+
this._view.pixelsToTime(position.x + this._view.getFrameOffset()),
|
|
192
193
|
false
|
|
193
194
|
)
|
|
194
195
|
);
|
|
195
196
|
|
|
196
197
|
this._timeBackground.width(this._timeLabel.width() + 8);
|
|
197
198
|
|
|
198
|
-
this._cursorTime.x(
|
|
199
|
+
this._cursorTime.x(position.x + TIME_X_OFFSET);
|
|
199
200
|
|
|
200
|
-
if (
|
|
201
|
+
if (position.y > this._view.getHeight()
|
|
201
202
|
- this._timeBackground.height() - TIME_Y_OFFSET) {
|
|
202
|
-
this._cursorTime.y(
|
|
203
|
+
this._cursorTime.y(position.y - TIME_Y_OFFSET);
|
|
203
204
|
}
|
|
204
205
|
else {
|
|
205
|
-
this._cursorTime.y(
|
|
206
|
+
this._cursorTime.y(position.y + TIME_Y_OFFSET);
|
|
206
207
|
}
|
|
207
208
|
|
|
208
209
|
this._cursorTime.visible(true);
|
|
@@ -212,7 +213,7 @@ define([
|
|
|
212
213
|
}
|
|
213
214
|
};
|
|
214
215
|
|
|
215
|
-
ModeLayer.prototype._updateCuttingLine = function(
|
|
216
|
+
ModeLayer.prototype._updateCuttingLine = function(position) {
|
|
216
217
|
var hoveredElement = this._view.getHoveredElement();
|
|
217
218
|
|
|
218
219
|
if (hoveredElement && hoveredElement instanceof SourceGroup && hoveredElement.isCuttable()) {
|
|
@@ -222,7 +223,7 @@ define([
|
|
|
222
223
|
var height = hoveredElement.getCurrentHeight();
|
|
223
224
|
var y = hoveredElement.getY();
|
|
224
225
|
|
|
225
|
-
if (
|
|
226
|
+
if (position.x < hoveredElement.x() + minSize) {
|
|
226
227
|
this._cuttingLine.points([
|
|
227
228
|
hoveredElement.x() + minSize,
|
|
228
229
|
y,
|
|
@@ -230,7 +231,7 @@ define([
|
|
|
230
231
|
y + height
|
|
231
232
|
]);
|
|
232
233
|
}
|
|
233
|
-
else if (
|
|
234
|
+
else if (position.x
|
|
234
235
|
> hoveredElement.x() + hoveredElement.getWidth() - minSize) {
|
|
235
236
|
this._cuttingLine.points([
|
|
236
237
|
hoveredElement.x() + hoveredElement.getWidth() - minSize,
|
|
@@ -240,7 +241,7 @@ define([
|
|
|
240
241
|
]);
|
|
241
242
|
}
|
|
242
243
|
else {
|
|
243
|
-
this._cuttingLine.points([
|
|
244
|
+
this._cuttingLine.points([position.x, y, position.x, y + height]);
|
|
244
245
|
}
|
|
245
246
|
this._cuttingLine.visible(true);
|
|
246
247
|
}
|
|
@@ -262,8 +263,22 @@ define([
|
|
|
262
263
|
|
|
263
264
|
mousePosition.x = this._view.timeToPixels(this._view.pixelsToTime(mousePosition.x));
|
|
264
265
|
|
|
265
|
-
|
|
266
|
-
this.
|
|
266
|
+
var cuttingPosition = mousePosition;
|
|
267
|
+
var hoveredElement = this._view.getHoveredElement();
|
|
268
|
+
|
|
269
|
+
if (hoveredElement && hoveredElement instanceof SourceGroup && hoveredElement.isCuttable()) {
|
|
270
|
+
var playheadPositionX = this._view.timeToPixels(this._playheadLayer._time);
|
|
271
|
+
var playheadIsOnHoveredElement =
|
|
272
|
+
playheadPositionX >= hoveredElement.x() &&
|
|
273
|
+
playheadPositionX <= (hoveredElement.x() + hoveredElement.getWidth());
|
|
274
|
+
|
|
275
|
+
if (Math.abs(mousePosition.x - playheadPositionX) < 10 && playheadIsOnHoveredElement) {
|
|
276
|
+
cuttingPosition.x = playheadPositionX;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
this._updateCursorTime(cuttingPosition);
|
|
281
|
+
this._updateCuttingLine(cuttingPosition);
|
|
267
282
|
|
|
268
283
|
this._layer.draw();
|
|
269
284
|
};
|
|
@@ -282,21 +297,32 @@ define([
|
|
|
282
297
|
var hoveredElement = this._view.getHoveredElement();
|
|
283
298
|
|
|
284
299
|
if (hoveredElement && hoveredElement instanceof SourceGroup && hoveredElement.isCuttable()) {
|
|
300
|
+
var cuttingPosition = mousePosition;
|
|
301
|
+
var playheadPositionX = this._view.timeToPixels(this._playheadLayer._time);
|
|
302
|
+
|
|
303
|
+
var playheadIsOnHoveredElement =
|
|
304
|
+
playheadPositionX >= hoveredElement.x() &&
|
|
305
|
+
playheadPositionX <= (hoveredElement.x() + hoveredElement.getWidth());
|
|
306
|
+
|
|
307
|
+
if (Math.abs(mousePosition.x - playheadPositionX) < 10 && playheadIsOnHoveredElement) {
|
|
308
|
+
cuttingPosition.x = playheadPositionX;
|
|
309
|
+
}
|
|
310
|
+
|
|
285
311
|
var minSize = this._view.timeToPixels(hoveredElement.getSource().minSize);
|
|
286
312
|
|
|
287
313
|
if (hoveredElement.getWidth() >= 2 * minSize) {
|
|
288
314
|
var cuttingPixel;
|
|
289
315
|
|
|
290
|
-
if (
|
|
316
|
+
if (cuttingPosition.x < hoveredElement.x() + minSize) {
|
|
291
317
|
cuttingPixel = hoveredElement.x() + minSize;
|
|
292
318
|
}
|
|
293
|
-
else if (
|
|
319
|
+
else if (cuttingPosition.x
|
|
294
320
|
> hoveredElement.x() + hoveredElement.getWidth() - minSize) {
|
|
295
321
|
cuttingPixel = hoveredElement.x()
|
|
296
322
|
+ hoveredElement.getWidth() - minSize;
|
|
297
323
|
}
|
|
298
324
|
else {
|
|
299
|
-
cuttingPixel =
|
|
325
|
+
cuttingPixel = cuttingPosition.x;
|
|
300
326
|
}
|
|
301
327
|
|
|
302
328
|
// Relative cuttingPixel
|
|
@@ -312,8 +338,8 @@ define([
|
|
|
312
338
|
|
|
313
339
|
this._view.setHoveredElement(null);
|
|
314
340
|
|
|
315
|
-
this._updateCursorTime(
|
|
316
|
-
this._updateCuttingLine(
|
|
341
|
+
this._updateCursorTime(cuttingPosition);
|
|
342
|
+
this._updateCuttingLine(cuttingPosition);
|
|
317
343
|
|
|
318
344
|
this._layer.draw();
|
|
319
345
|
}
|
package/src/timeline-zoomview.js
CHANGED
|
@@ -146,7 +146,7 @@ define([
|
|
|
146
146
|
|
|
147
147
|
self._hoveredElement = null;
|
|
148
148
|
|
|
149
|
-
self._modeLayer = new ModeLayer(peaks, self, self._stage, 'default');
|
|
149
|
+
self._modeLayer = new ModeLayer(peaks, self, self._playheadLayer, self._stage, 'default');
|
|
150
150
|
self._modeLayer.addToStage(self._stage);
|
|
151
151
|
|
|
152
152
|
self._mouseDragHandler = new MouseDragHandler(self._stage, {
|