wavesurfer.js 4.6.0 → 5.2.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.
Files changed (66) hide show
  1. package/CHANGES.md +41 -0
  2. package/README.md +6 -3
  3. package/dist/plugin/wavesurfer.cursor.js +9 -5
  4. package/dist/plugin/wavesurfer.cursor.js.map +1 -1
  5. package/dist/plugin/wavesurfer.cursor.min.js +2 -2
  6. package/dist/plugin/wavesurfer.cursor.min.js.map +1 -1
  7. package/dist/plugin/wavesurfer.elan.js +5 -4
  8. package/dist/plugin/wavesurfer.elan.js.map +1 -1
  9. package/dist/plugin/wavesurfer.elan.min.js +2 -2
  10. package/dist/plugin/wavesurfer.elan.min.js.map +1 -1
  11. package/dist/plugin/wavesurfer.markers.js +31 -12
  12. package/dist/plugin/wavesurfer.markers.js.map +1 -1
  13. package/dist/plugin/wavesurfer.markers.min.js +2 -2
  14. package/dist/plugin/wavesurfer.markers.min.js.map +1 -1
  15. package/dist/plugin/wavesurfer.mediasession.js +5 -4
  16. package/dist/plugin/wavesurfer.mediasession.js.map +1 -1
  17. package/dist/plugin/wavesurfer.mediasession.min.js +2 -2
  18. package/dist/plugin/wavesurfer.mediasession.min.js.map +1 -1
  19. package/dist/plugin/wavesurfer.microphone.js +5 -4
  20. package/dist/plugin/wavesurfer.microphone.js.map +1 -1
  21. package/dist/plugin/wavesurfer.microphone.min.js +2 -2
  22. package/dist/plugin/wavesurfer.microphone.min.js.map +1 -1
  23. package/dist/plugin/wavesurfer.minimap.js +5 -4
  24. package/dist/plugin/wavesurfer.minimap.js.map +1 -1
  25. package/dist/plugin/wavesurfer.minimap.min.js +2 -2
  26. package/dist/plugin/wavesurfer.minimap.min.js.map +1 -1
  27. package/dist/plugin/wavesurfer.playhead.js +324 -0
  28. package/dist/plugin/wavesurfer.playhead.js.map +1 -0
  29. package/dist/plugin/wavesurfer.playhead.min.js +7 -0
  30. package/dist/plugin/wavesurfer.playhead.min.js.map +1 -0
  31. package/dist/plugin/wavesurfer.regions.js +141 -86
  32. package/dist/plugin/wavesurfer.regions.js.map +1 -1
  33. package/dist/plugin/wavesurfer.regions.min.js +2 -2
  34. package/dist/plugin/wavesurfer.regions.min.js.map +1 -1
  35. package/dist/plugin/wavesurfer.spectrogram.js +70 -63
  36. package/dist/plugin/wavesurfer.spectrogram.js.map +1 -1
  37. package/dist/plugin/wavesurfer.spectrogram.min.js +2 -2
  38. package/dist/plugin/wavesurfer.spectrogram.min.js.map +1 -1
  39. package/dist/plugin/wavesurfer.timeline.js +32 -16
  40. package/dist/plugin/wavesurfer.timeline.js.map +1 -1
  41. package/dist/plugin/wavesurfer.timeline.min.js +2 -2
  42. package/dist/plugin/wavesurfer.timeline.min.js.map +1 -1
  43. package/dist/wavesurfer-html-init.js +5 -4
  44. package/dist/wavesurfer-html-init.js.map +1 -1
  45. package/dist/wavesurfer-html-init.min.js +2 -2
  46. package/dist/wavesurfer-html-init.min.js.map +1 -1
  47. package/dist/wavesurfer.js +326 -60
  48. package/dist/wavesurfer.js.map +1 -1
  49. package/dist/wavesurfer.min.js +2 -2
  50. package/dist/wavesurfer.min.js.map +1 -1
  51. package/package.json +19 -16
  52. package/src/drawer.canvasentry.js +16 -0
  53. package/src/drawer.js +30 -21
  54. package/src/drawer.multicanvas.js +63 -39
  55. package/src/plugin/cursor/index.js +3 -1
  56. package/src/plugin/markers/index.js +22 -8
  57. package/src/plugin/playhead/index.js +226 -0
  58. package/src/plugin/regions/index.js +28 -11
  59. package/src/plugin/regions/region.js +116 -75
  60. package/src/plugin/spectrogram/index.js +65 -61
  61. package/src/plugin/timeline/index.js +30 -19
  62. package/src/util/index.js +2 -0
  63. package/src/util/orientation.js +98 -0
  64. package/src/util/silence-mode.js +35 -0
  65. package/src/wavesurfer.js +41 -22
  66. package/src/webaudio.js +11 -2
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * wavesurfer.js regions plugin 4.6.0 (2021-03-05)
2
+ * wavesurfer.js regions plugin 5.2.0 (2021-08-16)
3
3
  * https://wavesurfer-js.org
4
4
  * @license BSD-3-Clause
5
5
  */
@@ -12,7 +12,7 @@
12
12
  exports["WaveSurfer"] = factory();
13
13
  else
14
14
  root["WaveSurfer"] = root["WaveSurfer"] || {}, root["WaveSurfer"]["regions"] = factory();
15
- })(this, function() {
15
+ })(self, function() {
16
16
  return /******/ (() => { // webpackBootstrap
17
17
  /******/ "use strict";
18
18
  /******/ var __webpack_modules__ = ({
@@ -32,7 +32,7 @@ exports.default = void 0;
32
32
 
33
33
  var _region = __webpack_require__(/*! ./region.js */ "./src/plugin/regions/region.js");
34
34
 
35
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
35
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
36
36
 
37
37
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
38
38
 
@@ -94,14 +94,18 @@ var RegionsPlugin = /*#__PURE__*/function () {
94
94
  observerPrototypeKeys.forEach(function (key) {
95
95
  _region.Region.prototype[key] = _this.util.Observer.prototype[key];
96
96
  });
97
- this.wavesurfer.Region = _region.Region;
97
+ this.wavesurfer.Region = _region.Region; // By default, scroll the container if the user drags a region
98
+ // within 5% of its edge
99
+
100
+ var scrollWidthProportion = 0.05;
98
101
 
99
102
  this._onBackendCreated = function () {
100
103
  _this.wrapper = _this.wavesurfer.drawer.wrapper;
104
+ _this.orientation = _this.wavesurfer.drawer.orientation;
101
105
 
102
106
  if (_this.params.regions) {
103
107
  _this.params.regions.forEach(function (region) {
104
- region.edgeScrollWidth = _this.params.edgeScrollWidth || _this.wrapper.clientWidth * 0.05;
108
+ region.edgeScrollWidth = _this.params.edgeScrollWidth || _this.wrapper.clientWidth * scrollWidthProportion;
105
109
 
106
110
  _this.add(region);
107
111
  });
@@ -113,6 +117,7 @@ var RegionsPlugin = /*#__PURE__*/function () {
113
117
 
114
118
  this._onReady = function () {
115
119
  _this.wrapper = _this.wavesurfer.drawer.wrapper;
120
+ _this.vertical = _this.wavesurfer.drawer.params.vertical;
116
121
 
117
122
  if (_this.params.dragSelection) {
118
123
  _this.enableDragSelection(_this.params);
@@ -168,7 +173,9 @@ var RegionsPlugin = /*#__PURE__*/function () {
168
173
  value: function add(params) {
169
174
  var _this2 = this;
170
175
 
171
- if (this.wouldExceedMaxRegions()) return null;
176
+ if (this.wouldExceedMaxRegions()) {
177
+ return null;
178
+ }
172
179
 
173
180
  if (!params.minLength && this.regionsMinLength) {
174
181
  params = _objectSpread(_objectSpread({}, params), {}, {
@@ -249,7 +256,7 @@ var RegionsPlugin = /*#__PURE__*/function () {
249
256
  touchId = e.targetTouches ? e.targetTouches[0].identifier : null; // Store for scroll calculations
250
257
 
251
258
  maxScroll = _this4.wrapper.scrollWidth - _this4.wrapper.clientWidth;
252
- wrapperRect = _this4.wrapper.getBoundingClientRect();
259
+ wrapperRect = _this4.util.withOrientation(_this4.wrapper.getBoundingClientRect(), _this4.vertical);
253
260
  drag = true;
254
261
  start = _this4.wavesurfer.drawer.handleEvent(e, true);
255
262
  region = null;
@@ -300,7 +307,7 @@ var RegionsPlugin = /*#__PURE__*/function () {
300
307
  _this4.wrapper.removeEventListener('mouseleave', eventUp);
301
308
  });
302
309
 
303
- var eventMove = function eventMove(e) {
310
+ var eventMove = function eventMove(event) {
304
311
  if (!drag) {
305
312
  return;
306
313
  }
@@ -309,21 +316,24 @@ var RegionsPlugin = /*#__PURE__*/function () {
309
316
  return;
310
317
  }
311
318
 
312
- if (e.touches && e.touches.length > 1) {
319
+ if (event.touches && event.touches.length > 1) {
313
320
  return;
314
321
  }
315
322
 
316
- if (e.targetTouches && e.targetTouches[0].identifier != touchId) {
323
+ if (event.targetTouches && event.targetTouches[0].identifier != touchId) {
317
324
  return;
318
325
  } // auto-create a region during mouse drag, unless region-count would exceed "maxRegions"
319
326
 
320
327
 
321
328
  if (!region) {
322
329
  region = _this4.add(params || {});
323
- if (!region) return;
330
+
331
+ if (!region) {
332
+ return;
333
+ }
324
334
  }
325
335
 
326
- var end = _this4.wavesurfer.drawer.handleEvent(e);
336
+ var end = _this4.wavesurfer.drawer.handleEvent(event);
327
337
 
328
338
  var startUpdate = _this4.wavesurfer.regions.util.getRegionSnapToGridValue(start * duration);
329
339
 
@@ -332,11 +342,14 @@ var RegionsPlugin = /*#__PURE__*/function () {
332
342
  region.update({
333
343
  start: Math.min(endUpdate, startUpdate),
334
344
  end: Math.max(endUpdate, startUpdate)
335
- }); // If scrolling is enabled
345
+ });
346
+
347
+ var orientedEvent = _this4.util.withOrientation(event, _this4.vertical); // If scrolling is enabled
348
+
336
349
 
337
350
  if (scroll && container.clientWidth < _this4.wrapper.scrollWidth) {
338
351
  // Check threshold based on mouse
339
- var x = e.clientX - wrapperRect.left;
352
+ var x = orientedEvent.clientX - wrapperRect.left;
340
353
 
341
354
  if (x <= scrollThreshold) {
342
355
  scrollDirection = -1;
@@ -346,7 +359,7 @@ var RegionsPlugin = /*#__PURE__*/function () {
346
359
  scrollDirection = null;
347
360
  }
348
361
 
349
- scrollDirection && edgeScroll(e);
362
+ scrollDirection && edgeScroll(event);
350
363
  }
351
364
  };
352
365
 
@@ -502,7 +515,8 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
502
515
  */
503
516
  var Region = /*#__PURE__*/function () {
504
517
  function Region(params, regionsUtils, ws) {
505
- var _this = this;
518
+ var _params$showTooltip,
519
+ _this = this;
506
520
 
507
521
  _classCallCheck(this, Region);
508
522
 
@@ -511,6 +525,7 @@ var Region = /*#__PURE__*/function () {
511
525
  this.util = ws.util;
512
526
  this.style = this.util.style;
513
527
  this.regionsUtil = regionsUtils;
528
+ this.vertical = ws.drawer.params.vertical;
514
529
  this.id = params.id == null ? ws.util.getId() : params.id;
515
530
  this.start = Number(params.start) || 0;
516
531
  this.end = params.end == null ? // small marker-like region
@@ -532,6 +547,7 @@ var Region = /*#__PURE__*/function () {
532
547
  this.handleRightEl = null;
533
548
  this.data = params.data || {};
534
549
  this.attributes = params.attributes || {};
550
+ this.showTooltip = (_params$showTooltip = params.showTooltip) !== null && _params$showTooltip !== void 0 ? _params$showTooltip : true;
535
551
  this.maxLength = params.maxLength; // It assumes the minLength parameter value, or the regionsMinLength parameter value, if the first one not provided
536
552
 
537
553
  this.minLength = params.minLength;
@@ -572,7 +588,7 @@ var Region = /*#__PURE__*/function () {
572
588
 
573
589
  _createClass(Region, [{
574
590
  key: "update",
575
- value: function update(params) {
591
+ value: function update(params, eventParams) {
576
592
  if (params.start != null) {
577
593
  this.start = Number(params.start);
578
594
  }
@@ -620,7 +636,7 @@ var Region = /*#__PURE__*/function () {
620
636
 
621
637
  this.updateRender();
622
638
  this.fireEvent('update');
623
- this.wavesurfer.fireEvent('region-updated', this);
639
+ this.wavesurfer.fireEvent('region-updated', this, eventParams);
624
640
  }
625
641
  /* Remove a single region. */
626
642
 
@@ -628,7 +644,7 @@ var Region = /*#__PURE__*/function () {
628
644
  key: "remove",
629
645
  value: function remove() {
630
646
  if (this.element) {
631
- this.wrapper.removeChild(this.element);
647
+ this.wrapper.removeChild(this.element.domElement);
632
648
  this.element = null;
633
649
  this.fireEvent('remove');
634
650
  this.wavesurfer.un('zoom', this._onRedraw);
@@ -675,16 +691,20 @@ var Region = /*#__PURE__*/function () {
675
691
  }, {
676
692
  key: "render",
677
693
  value: function render() {
678
- var regionEl = document.createElement('region');
679
- regionEl.className = 'wavesurfer-region';
680
- regionEl.title = this.formatTime(this.start, this.end);
681
- regionEl.setAttribute('data-id', this.id);
694
+ this.element = this.util.withOrientation(this.wrapper.appendChild(document.createElement('region')), this.vertical);
695
+ this.element.className = 'wavesurfer-region';
696
+
697
+ if (this.showTooltip) {
698
+ this.element.title = this.formatTime(this.start, this.end);
699
+ }
700
+
701
+ this.element.setAttribute('data-id', this.id);
682
702
 
683
703
  for (var attrname in this.attributes) {
684
- regionEl.setAttribute('data-region-' + attrname, this.attributes[attrname]);
704
+ this.element.setAttribute('data-region-' + attrname, this.attributes[attrname]);
685
705
  }
686
706
 
687
- this.style(regionEl, {
707
+ this.style(this.element, {
688
708
  position: 'absolute',
689
709
  zIndex: 2,
690
710
  height: this.regionHeight,
@@ -693,13 +713,13 @@ var Region = /*#__PURE__*/function () {
693
713
  /* Resize handles */
694
714
 
695
715
  if (this.resize) {
696
- this.handleLeftEl = regionEl.appendChild(document.createElement('handle'));
697
- this.handleRightEl = regionEl.appendChild(document.createElement('handle'));
716
+ this.handleLeftEl = this.util.withOrientation(this.element.appendChild(document.createElement('handle')), this.vertical);
717
+ this.handleRightEl = this.util.withOrientation(this.element.appendChild(document.createElement('handle')), this.vertical);
698
718
  this.handleLeftEl.className = 'wavesurfer-handle wavesurfer-handle-start';
699
719
  this.handleRightEl.className = 'wavesurfer-handle wavesurfer-handle-end'; // Default CSS properties for both handles.
700
720
 
701
721
  var css = {
702
- cursor: 'col-resize',
722
+ cursor: this.vertical ? 'row-resize' : 'col-resize',
703
723
  position: 'absolute',
704
724
  top: '0px',
705
725
  width: '2px',
@@ -723,9 +743,8 @@ var Region = /*#__PURE__*/function () {
723
743
  }
724
744
  }
725
745
 
726
- this.element = this.wrapper.appendChild(regionEl);
727
746
  this.updateRender();
728
- this.bindEvents(regionEl);
747
+ this.bindEvents();
729
748
  }
730
749
  }, {
731
750
  key: "formatTime",
@@ -790,7 +809,9 @@ var Region = /*#__PURE__*/function () {
790
809
  this.element.setAttribute('data-region-' + attrname, this.attributes[attrname]);
791
810
  }
792
811
 
793
- this.element.title = this.formatTime(this.start, this.end);
812
+ if (this.showTooltip) {
813
+ this.element.title = this.formatTime(this.start, this.end);
814
+ }
794
815
  }
795
816
  }
796
817
  /* Bind audio events. */
@@ -910,19 +931,21 @@ var Region = /*#__PURE__*/function () {
910
931
  var regionLeftHalfTime;
911
932
  var regionRightHalfTime; // Scroll when the user is dragging within the threshold
912
933
 
913
- var edgeScroll = function edgeScroll(e) {
934
+ var edgeScroll = function edgeScroll(event) {
935
+ var orientedEvent = _this4.util.withOrientation(event, _this4.vertical);
936
+
914
937
  var duration = _this4.wavesurfer.getDuration();
915
938
 
916
939
  if (!scrollDirection || !drag && !resize) {
917
940
  return;
918
941
  }
919
942
 
920
- var x = e.clientX;
943
+ var x = orientedEvent.clientX;
921
944
  var distanceBetweenCursorAndWrapperEdge = 0;
922
945
  var regionHalfTimeWidth = 0;
923
946
  var adjustment = 0; // Get the currently selected time according to the mouse position
924
947
 
925
- var time = _this4.regionsUtil.getRegionSnapToGridValue(_this4.wavesurfer.drawer.handleEvent(e) * duration);
948
+ var time = _this4.regionsUtil.getRegionSnapToGridValue(_this4.wavesurfer.drawer.handleEvent(event) * duration);
926
949
 
927
950
  if (drag) {
928
951
  // Considering the point of contact with the region while edgescrolling
@@ -963,26 +986,28 @@ var Region = /*#__PURE__*/function () {
963
986
  } // Don't edgescroll if region has reached min or max limit
964
987
 
965
988
 
989
+ var wrapperScrollLeft = _this4.wrapper.scrollLeft;
990
+
966
991
  if (scrollDirection === -1) {
967
- if (Math.round(_this4.wrapper.scrollLeft) === 0) {
992
+ if (Math.round(wrapperScrollLeft) === 0) {
968
993
  return;
969
994
  }
970
995
 
971
- if (Math.round(_this4.wrapper.scrollLeft - regionHalfTimeWidth + distanceBetweenCursorAndWrapperEdge) <= 0) {
996
+ if (Math.round(wrapperScrollLeft - regionHalfTimeWidth + distanceBetweenCursorAndWrapperEdge) <= 0) {
972
997
  return;
973
998
  }
974
999
  } else {
975
- if (Math.round(_this4.wrapper.scrollLeft) === maxScroll) {
1000
+ if (Math.round(wrapperScrollLeft) === maxScroll) {
976
1001
  return;
977
1002
  }
978
1003
 
979
- if (Math.round(_this4.wrapper.scrollLeft + regionHalfTimeWidth - distanceBetweenCursorAndWrapperEdge) >= maxScroll) {
1004
+ if (Math.round(wrapperScrollLeft + regionHalfTimeWidth - distanceBetweenCursorAndWrapperEdge) >= maxScroll) {
980
1005
  return;
981
1006
  }
982
1007
  } // Update scroll position
983
1008
 
984
1009
 
985
- var scrollLeft = _this4.wrapper.scrollLeft - adjustment + scrollSpeed * scrollDirection;
1010
+ var scrollLeft = wrapperScrollLeft - adjustment + scrollSpeed * scrollDirection;
986
1011
 
987
1012
  if (scrollDirection === -1) {
988
1013
  var calculatedLeft = Math.max(0 + regionHalfTimeWidth - distanceBetweenCursorAndWrapperEdge, scrollLeft);
@@ -998,38 +1023,38 @@ var Region = /*#__PURE__*/function () {
998
1023
  drag ? _this4.onDrag(delta) : _this4.onResize(delta, resize); // Repeat
999
1024
 
1000
1025
  window.requestAnimationFrame(function () {
1001
- edgeScroll(e);
1026
+ edgeScroll(event);
1002
1027
  });
1003
1028
  };
1004
1029
 
1005
- var onDown = function onDown(e) {
1030
+ var onDown = function onDown(event) {
1006
1031
  var duration = _this4.wavesurfer.getDuration();
1007
1032
 
1008
- if (e.touches && e.touches.length > 1) {
1033
+ if (event.touches && event.touches.length > 1) {
1009
1034
  return;
1010
1035
  }
1011
1036
 
1012
- touchId = e.targetTouches ? e.targetTouches[0].identifier : null; // stop the event propagation, if this region is resizable or draggable
1037
+ touchId = event.targetTouches ? event.targetTouches[0].identifier : null; // stop the event propagation, if this region is resizable or draggable
1013
1038
  // and the event is therefore handled here.
1014
1039
 
1015
1040
  if (_this4.drag || _this4.resize) {
1016
- e.stopPropagation();
1041
+ event.stopPropagation();
1017
1042
  } // Store the selected startTime we begun dragging or resizing
1018
1043
 
1019
1044
 
1020
- startTime = _this4.regionsUtil.getRegionSnapToGridValue(_this4.wavesurfer.drawer.handleEvent(e, true) * duration); // Store the selected point of contact when we begin dragging
1045
+ startTime = _this4.regionsUtil.getRegionSnapToGridValue(_this4.wavesurfer.drawer.handleEvent(event, true) * duration); // Store the selected point of contact when we begin dragging
1021
1046
 
1022
1047
  regionLeftHalfTime = startTime - _this4.start;
1023
1048
  regionRightHalfTime = _this4.end - startTime; // Store for scroll calculations
1024
1049
 
1025
1050
  maxScroll = _this4.wrapper.scrollWidth - _this4.wrapper.clientWidth;
1026
- wrapperRect = _this4.wrapper.getBoundingClientRect();
1051
+ wrapperRect = _this4.util.withOrientation(_this4.wrapper.getBoundingClientRect(), _this4.vertical);
1027
1052
  _this4.isResizing = false;
1028
1053
  _this4.isDragging = false;
1029
1054
 
1030
- if (e.target.tagName.toLowerCase() === 'handle') {
1055
+ if (event.target.tagName.toLowerCase() === 'handle') {
1031
1056
  _this4.isResizing = true;
1032
- resize = e.target.classList.contains('wavesurfer-handle-start') ? 'start' : 'end';
1057
+ resize = event.target.classList.contains('wavesurfer-handle-start') ? 'start' : 'end';
1033
1058
  } else {
1034
1059
  _this4.isDragging = true;
1035
1060
  drag = true;
@@ -1037,8 +1062,8 @@ var Region = /*#__PURE__*/function () {
1037
1062
  }
1038
1063
  };
1039
1064
 
1040
- var onUp = function onUp(e) {
1041
- if (e.touches && e.touches.length > 1) {
1065
+ var onUp = function onUp(event) {
1066
+ if (event.touches && event.touches.length > 1) {
1042
1067
  return;
1043
1068
  }
1044
1069
 
@@ -1055,20 +1080,22 @@ var Region = /*#__PURE__*/function () {
1055
1080
 
1056
1081
  _this4.util.preventClick();
1057
1082
 
1058
- _this4.fireEvent('update-end', e);
1083
+ _this4.fireEvent('update-end', event);
1059
1084
 
1060
- _this4.wavesurfer.fireEvent('region-update-end', _this4, e);
1085
+ _this4.wavesurfer.fireEvent('region-update-end', _this4, event);
1061
1086
  }
1062
1087
  };
1063
1088
 
1064
- var onMove = function onMove(e) {
1089
+ var onMove = function onMove(event) {
1065
1090
  var duration = _this4.wavesurfer.getDuration();
1066
1091
 
1067
- if (e.touches && e.touches.length > 1) {
1092
+ var orientedEvent = _this4.util.withOrientation(event, _this4.vertical);
1093
+
1094
+ if (event.touches && event.touches.length > 1) {
1068
1095
  return;
1069
1096
  }
1070
1097
 
1071
- if (e.targetTouches && e.targetTouches[0].identifier != touchId) {
1098
+ if (event.targetTouches && event.targetTouches[0].identifier != touchId) {
1072
1099
  return;
1073
1100
  }
1074
1101
 
@@ -1078,7 +1105,7 @@ var Region = /*#__PURE__*/function () {
1078
1105
 
1079
1106
  var oldTime = startTime;
1080
1107
 
1081
- var time = _this4.regionsUtil.getRegionSnapToGridValue(_this4.wavesurfer.drawer.handleEvent(e) * duration);
1108
+ var time = _this4.regionsUtil.getRegionSnapToGridValue(_this4.wavesurfer.drawer.handleEvent(event) * duration);
1082
1109
 
1083
1110
  if (drag) {
1084
1111
  // To maintain relative cursor start point while dragging
@@ -1139,30 +1166,18 @@ var Region = /*#__PURE__*/function () {
1139
1166
 
1140
1167
  if (_this4.scroll && container.clientWidth < _this4.wrapper.scrollWidth) {
1141
1168
  // Triggering edgescroll from within edgeScrollWidth
1142
- if (drag) {
1143
- var x = e.clientX; // Check direction
1144
-
1145
- if (x < wrapperRect.left + _this4.edgeScrollWidth) {
1146
- scrollDirection = -1;
1147
- } else if (x > wrapperRect.right - _this4.edgeScrollWidth) {
1148
- scrollDirection = 1;
1149
- } else {
1150
- scrollDirection = null;
1151
- }
1169
+ var x = orientedEvent.clientX; // Check direction
1170
+
1171
+ if (x < wrapperRect.left + _this4.edgeScrollWidth) {
1172
+ scrollDirection = -1;
1173
+ } else if (x > wrapperRect.right - _this4.edgeScrollWidth) {
1174
+ scrollDirection = 1;
1152
1175
  } else {
1153
- var _x = e.clientX; // Check direction
1154
-
1155
- if (_x < wrapperRect.left + _this4.edgeScrollWidth) {
1156
- scrollDirection = -1;
1157
- } else if (_x > wrapperRect.right - _this4.edgeScrollWidth) {
1158
- scrollDirection = 1;
1159
- } else {
1160
- scrollDirection = null;
1161
- }
1176
+ scrollDirection = null;
1162
1177
  }
1163
1178
 
1164
1179
  if (scrollDirection) {
1165
- edgeScroll(e);
1180
+ edgeScroll(event);
1166
1181
  }
1167
1182
  }
1168
1183
  };
@@ -1170,17 +1185,19 @@ var Region = /*#__PURE__*/function () {
1170
1185
  this.element.addEventListener('mousedown', onDown);
1171
1186
  this.element.addEventListener('touchstart', onDown);
1172
1187
  document.body.addEventListener('mousemove', onMove);
1173
- document.body.addEventListener('touchmove', onMove);
1174
- document.body.addEventListener('mouseup', onUp);
1188
+ document.body.addEventListener('touchmove', onMove, {
1189
+ passive: false
1190
+ });
1191
+ document.addEventListener('mouseup', onUp);
1175
1192
  document.body.addEventListener('touchend', onUp);
1176
1193
  this.on('remove', function () {
1177
- document.body.removeEventListener('mouseup', onUp);
1194
+ document.removeEventListener('mouseup', onUp);
1178
1195
  document.body.removeEventListener('touchend', onUp);
1179
1196
  document.body.removeEventListener('mousemove', onMove);
1180
1197
  document.body.removeEventListener('touchmove', onMove);
1181
1198
  });
1182
1199
  this.wavesurfer.on('destroy', function () {
1183
- document.body.removeEventListener('mouseup', onUp);
1200
+ document.removeEventListener('mouseup', onUp);
1184
1201
  document.body.removeEventListener('touchend', onUp);
1185
1202
  });
1186
1203
  }
@@ -1197,10 +1214,36 @@ var Region = /*#__PURE__*/function () {
1197
1214
  delta = this.start * -1;
1198
1215
  }
1199
1216
 
1217
+ var eventParams = {
1218
+ direction: this._getDragDirection(delta),
1219
+ action: 'drag'
1220
+ };
1200
1221
  this.update({
1201
1222
  start: this.start + delta,
1202
1223
  end: this.end + delta
1203
- });
1224
+ }, eventParams);
1225
+ }
1226
+ /**
1227
+ * Returns the direction of dragging region based on delta
1228
+ * Negative delta means region is moving to the left
1229
+ * Positive - to the right
1230
+ * For zero delta the direction is not defined
1231
+ * @param {number} delta Drag offset
1232
+ * @returns {string|null} Direction 'left', 'right' or null
1233
+ */
1234
+
1235
+ }, {
1236
+ key: "_getDragDirection",
1237
+ value: function _getDragDirection(delta) {
1238
+ if (delta < 0) {
1239
+ return 'left';
1240
+ }
1241
+
1242
+ if (delta > 0) {
1243
+ return 'right';
1244
+ }
1245
+
1246
+ return null;
1204
1247
  }
1205
1248
  /**
1206
1249
  * @example
@@ -1215,6 +1258,10 @@ var Region = /*#__PURE__*/function () {
1215
1258
  key: "onResize",
1216
1259
  value: function onResize(delta, direction) {
1217
1260
  var duration = this.wavesurfer.getDuration();
1261
+ var eventParams = {
1262
+ action: 'resize',
1263
+ direction: direction === 'start' ? 'right' : 'left'
1264
+ };
1218
1265
 
1219
1266
  if (direction === 'start') {
1220
1267
  // Check if changing the start by the given delta would result in the region being smaller than minLength
@@ -1230,7 +1277,7 @@ var Region = /*#__PURE__*/function () {
1230
1277
  this.update({
1231
1278
  start: Math.min(this.start + delta, this.end),
1232
1279
  end: Math.max(this.start + delta, this.end)
1233
- });
1280
+ }, eventParams);
1234
1281
  } else {
1235
1282
  // Check if changing the end by the given delta would result in the region being smaller than minLength
1236
1283
  // Ignore cases where we are making the region wider rather than shrinking it
@@ -1245,13 +1292,20 @@ var Region = /*#__PURE__*/function () {
1245
1292
  this.update({
1246
1293
  start: Math.min(this.end + delta, this.start),
1247
1294
  end: Math.max(this.end + delta, this.start)
1248
- });
1295
+ }, eventParams);
1249
1296
  }
1250
1297
  }
1251
1298
  }, {
1252
1299
  key: "updateHandlesResize",
1253
1300
  value: function updateHandlesResize(resize) {
1254
- var cursorStyle = resize ? 'col-resize' : 'auto';
1301
+ var cursorStyle;
1302
+
1303
+ if (resize) {
1304
+ cursorStyle = this.vertical ? 'row-resize' : 'col-resize';
1305
+ } else {
1306
+ cursorStyle = 'auto';
1307
+ }
1308
+
1255
1309
  this.handleLeftEl && this.style(this.handleLeftEl, {
1256
1310
  cursor: cursorStyle
1257
1311
  });
@@ -1276,8 +1330,9 @@ exports.Region = Region;
1276
1330
  /******/ // The require function
1277
1331
  /******/ function __webpack_require__(moduleId) {
1278
1332
  /******/ // Check if module is in cache
1279
- /******/ if(__webpack_module_cache__[moduleId]) {
1280
- /******/ return __webpack_module_cache__[moduleId].exports;
1333
+ /******/ var cachedModule = __webpack_module_cache__[moduleId];
1334
+ /******/ if (cachedModule !== undefined) {
1335
+ /******/ return cachedModule.exports;
1281
1336
  /******/ }
1282
1337
  /******/ // Create a new module (and put it into the cache)
1283
1338
  /******/ var module = __webpack_module_cache__[moduleId] = {