wavesurfer.js 6.2.0 → 6.4.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/LICENSE +1 -1
- package/README.md +1 -10
- package/dist/plugin/wavesurfer.cursor.js +29 -49
- package/dist/plugin/wavesurfer.cursor.js.map +1 -1
- package/dist/plugin/wavesurfer.cursor.min.js +2 -2
- package/dist/plugin/wavesurfer.cursor.min.js.map +1 -1
- package/dist/plugin/wavesurfer.elan.js +19 -49
- package/dist/plugin/wavesurfer.elan.js.map +1 -1
- package/dist/plugin/wavesurfer.elan.min.js +1 -1
- package/dist/plugin/wavesurfer.elan.min.js.map +1 -1
- package/dist/plugin/wavesurfer.markers.js +87 -67
- package/dist/plugin/wavesurfer.markers.js.map +1 -1
- package/dist/plugin/wavesurfer.markers.min.js +2 -2
- package/dist/plugin/wavesurfer.markers.min.js.map +1 -1
- package/dist/plugin/wavesurfer.mediasession.js +5 -15
- package/dist/plugin/wavesurfer.mediasession.js.map +1 -1
- package/dist/plugin/wavesurfer.mediasession.min.js +1 -1
- package/dist/plugin/wavesurfer.mediasession.min.js.map +1 -1
- package/dist/plugin/wavesurfer.microphone.js +44 -62
- package/dist/plugin/wavesurfer.microphone.js.map +1 -1
- package/dist/plugin/wavesurfer.microphone.min.js +1 -1
- package/dist/plugin/wavesurfer.microphone.min.js.map +1 -1
- package/dist/plugin/wavesurfer.minimap.js +16 -68
- package/dist/plugin/wavesurfer.minimap.js.map +1 -1
- package/dist/plugin/wavesurfer.minimap.min.js +1 -1
- package/dist/plugin/wavesurfer.minimap.min.js.map +1 -1
- package/dist/plugin/wavesurfer.playhead.js +2 -29
- package/dist/plugin/wavesurfer.playhead.js.map +1 -1
- package/dist/plugin/wavesurfer.playhead.min.js +1 -1
- package/dist/plugin/wavesurfer.playhead.min.js.map +1 -1
- package/dist/plugin/wavesurfer.regions.js +99 -253
- package/dist/plugin/wavesurfer.regions.js.map +1 -1
- package/dist/plugin/wavesurfer.regions.min.js +2 -2
- package/dist/plugin/wavesurfer.regions.min.js.map +1 -1
- package/dist/plugin/wavesurfer.spectrogram.js +52 -147
- package/dist/plugin/wavesurfer.spectrogram.js.map +1 -1
- package/dist/plugin/wavesurfer.spectrogram.min.js +2 -2
- package/dist/plugin/wavesurfer.spectrogram.min.js.map +1 -1
- package/dist/plugin/wavesurfer.timeline.js +42 -85
- package/dist/plugin/wavesurfer.timeline.js.map +1 -1
- package/dist/plugin/wavesurfer.timeline.min.js +1 -1
- package/dist/plugin/wavesurfer.timeline.min.js.map +1 -1
- package/dist/wavesurfer-html-init.js +31 -53
- package/dist/wavesurfer-html-init.js.map +1 -1
- package/dist/wavesurfer-html-init.min.js +1 -1
- package/dist/wavesurfer-html-init.min.js.map +1 -1
- package/dist/wavesurfer.js +448 -1008
- package/dist/wavesurfer.js.map +1 -1
- package/dist/wavesurfer.min.js +2 -2
- package/dist/wavesurfer.min.js.map +1 -1
- package/package.json +18 -19
- package/src/drawer.multicanvas.js +4 -4
- package/src/plugin/cursor/index.js +15 -3
- package/src/plugin/markers/index.js +70 -5
- package/src/plugin/regions/index.js +1 -1
- package/src/plugin/spectrogram/index.js +1 -1
- package/src/wavesurfer.js +12 -9
- package/CHANGES.md +0 -474
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* wavesurfer.js regions plugin 6.
|
|
2
|
+
* wavesurfer.js regions plugin 6.4.0 (2022-11-05)
|
|
3
3
|
* https://wavesurfer-js.org
|
|
4
4
|
* @license BSD-3-Clause
|
|
5
5
|
*/
|
|
@@ -29,21 +29,13 @@ Object.defineProperty(exports, "__esModule", ({
|
|
|
29
29
|
value: true
|
|
30
30
|
}));
|
|
31
31
|
exports["default"] = void 0;
|
|
32
|
-
|
|
33
32
|
var _region = __webpack_require__(/*! ./region.js */ "./src/plugin/regions/region.js");
|
|
34
|
-
|
|
35
33
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
36
|
-
|
|
37
34
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
38
|
-
|
|
39
35
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
40
|
-
|
|
41
36
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
42
|
-
|
|
43
37
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
44
|
-
|
|
45
38
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
46
|
-
|
|
47
39
|
/**
|
|
48
40
|
* Regions are visual overlays on waveform that can be used to play and loop
|
|
49
41
|
* portions of audio. Regions can be dragged and resized.
|
|
@@ -77,9 +69,7 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
|
|
|
77
69
|
var RegionsPlugin = /*#__PURE__*/function () {
|
|
78
70
|
function RegionsPlugin(params, ws) {
|
|
79
71
|
var _this = this;
|
|
80
|
-
|
|
81
72
|
_classCallCheck(this, RegionsPlugin);
|
|
82
|
-
|
|
83
73
|
this.params = params;
|
|
84
74
|
this.wavesurfer = ws;
|
|
85
75
|
this.util = _objectSpread(_objectSpread({}, ws.util), {}, {
|
|
@@ -88,53 +78,48 @@ var RegionsPlugin = /*#__PURE__*/function () {
|
|
|
88
78
|
}
|
|
89
79
|
});
|
|
90
80
|
this.maxRegions = params.maxRegions;
|
|
91
|
-
this.regionsMinLength = params.regionsMinLength || null;
|
|
81
|
+
this.regionsMinLength = params.regionsMinLength || null;
|
|
92
82
|
|
|
83
|
+
// turn the plugin instance into an observer
|
|
93
84
|
var observerPrototypeKeys = Object.getOwnPropertyNames(this.util.Observer.prototype);
|
|
94
85
|
observerPrototypeKeys.forEach(function (key) {
|
|
95
86
|
_region.Region.prototype[key] = _this.util.Observer.prototype[key];
|
|
96
87
|
});
|
|
97
|
-
this.wavesurfer.Region = _region.Region;
|
|
98
|
-
// within 5% (based on its initial size) of its edge
|
|
88
|
+
this.wavesurfer.Region = _region.Region;
|
|
99
89
|
|
|
90
|
+
// By default, scroll the container if the user drags a region
|
|
91
|
+
// within 5% (based on its initial size) of its edge
|
|
100
92
|
var scrollWidthProportion = 0.05;
|
|
101
|
-
|
|
102
93
|
this._onBackendCreated = function () {
|
|
103
94
|
_this.wrapper = _this.wavesurfer.drawer.wrapper;
|
|
104
95
|
_this.orientation = _this.wavesurfer.drawer.orientation;
|
|
105
96
|
_this.defaultEdgeScrollWidth = _this.wrapper.clientWidth * scrollWidthProportion;
|
|
106
|
-
|
|
107
97
|
if (_this.params.regions) {
|
|
108
98
|
_this.params.regions.forEach(function (region) {
|
|
109
99
|
_this.add(region);
|
|
110
100
|
});
|
|
111
101
|
}
|
|
112
|
-
};
|
|
113
|
-
|
|
102
|
+
};
|
|
114
103
|
|
|
104
|
+
// Id-based hash of regions
|
|
115
105
|
this.list = {};
|
|
116
|
-
|
|
117
106
|
this._onReady = function () {
|
|
118
107
|
_this.wrapper = _this.wavesurfer.drawer.wrapper;
|
|
119
108
|
_this.vertical = _this.wavesurfer.drawer.params.vertical;
|
|
120
|
-
|
|
121
109
|
if (_this.params.dragSelection) {
|
|
122
110
|
_this.enableDragSelection(_this.params);
|
|
123
111
|
}
|
|
124
|
-
|
|
125
112
|
Object.keys(_this.list).forEach(function (id) {
|
|
126
113
|
_this.list[id].updateRender();
|
|
127
114
|
});
|
|
128
115
|
};
|
|
129
116
|
}
|
|
130
|
-
|
|
131
117
|
_createClass(RegionsPlugin, [{
|
|
132
118
|
key: "init",
|
|
133
119
|
value: function init() {
|
|
134
120
|
// Check if ws is ready
|
|
135
121
|
if (this.wavesurfer.isReady) {
|
|
136
122
|
this._onBackendCreated();
|
|
137
|
-
|
|
138
123
|
this._onReady();
|
|
139
124
|
} else {
|
|
140
125
|
this.wavesurfer.once('ready', this._onReady);
|
|
@@ -145,58 +130,55 @@ var RegionsPlugin = /*#__PURE__*/function () {
|
|
|
145
130
|
key: "destroy",
|
|
146
131
|
value: function destroy() {
|
|
147
132
|
this.wavesurfer.un('ready', this._onReady);
|
|
148
|
-
this.wavesurfer.un('backend-created', this._onBackendCreated);
|
|
133
|
+
this.wavesurfer.un('backend-created', this._onBackendCreated);
|
|
134
|
+
// Disabling `region-removed' because destroying the plugin calls
|
|
149
135
|
// the Region.remove() method that is also used to remove regions based
|
|
150
136
|
// on user input. This can cause confusion since teardown is not a
|
|
151
137
|
// user event, but would emit `region-removed` as if it was.
|
|
152
|
-
|
|
153
138
|
this.wavesurfer.setDisabledEventEmissions(['region-removed']);
|
|
154
139
|
this.disableDragSelection();
|
|
155
140
|
this.clear();
|
|
156
141
|
}
|
|
142
|
+
|
|
157
143
|
/**
|
|
158
144
|
* check to see if adding a new region would exceed maxRegions
|
|
159
145
|
* @return {boolean} whether we should proceed and create a region
|
|
160
146
|
* @private
|
|
161
147
|
*/
|
|
162
|
-
|
|
163
148
|
}, {
|
|
164
149
|
key: "wouldExceedMaxRegions",
|
|
165
150
|
value: function wouldExceedMaxRegions() {
|
|
166
151
|
return this.maxRegions && Object.keys(this.list).length >= this.maxRegions;
|
|
167
152
|
}
|
|
153
|
+
|
|
168
154
|
/**
|
|
169
155
|
* Add a region
|
|
170
156
|
*
|
|
171
157
|
* @param {object} params Region parameters
|
|
172
158
|
* @return {Region} The created region
|
|
173
159
|
*/
|
|
174
|
-
|
|
175
160
|
}, {
|
|
176
161
|
key: "add",
|
|
177
162
|
value: function add(params) {
|
|
178
163
|
var _this2 = this;
|
|
179
|
-
|
|
180
164
|
if (this.wouldExceedMaxRegions()) {
|
|
181
165
|
return null;
|
|
182
166
|
}
|
|
183
|
-
|
|
184
167
|
params = _objectSpread({
|
|
185
168
|
edgeScrollWidth: this.params.edgeScrollWidth || this.defaultEdgeScrollWidth
|
|
186
|
-
}, params);
|
|
169
|
+
}, params);
|
|
187
170
|
|
|
171
|
+
// Take formatTimeCallback from plugin params if not already set
|
|
188
172
|
if (!params.formatTimeCallback && this.params.formatTimeCallback) {
|
|
189
173
|
params = _objectSpread(_objectSpread({}, params), {}, {
|
|
190
174
|
formatTimeCallback: this.params.formatTimeCallback
|
|
191
175
|
});
|
|
192
176
|
}
|
|
193
|
-
|
|
194
177
|
if (!params.minLength && this.regionsMinLength) {
|
|
195
178
|
params = _objectSpread(_objectSpread({}, params), {}, {
|
|
196
179
|
minLength: this.regionsMinLength
|
|
197
180
|
});
|
|
198
181
|
}
|
|
199
|
-
|
|
200
182
|
var region = new this.wavesurfer.Region(params, this.util, this.wavesurfer);
|
|
201
183
|
this.list[region.id] = region;
|
|
202
184
|
region.on('remove', function () {
|
|
@@ -204,15 +186,14 @@ var RegionsPlugin = /*#__PURE__*/function () {
|
|
|
204
186
|
});
|
|
205
187
|
return region;
|
|
206
188
|
}
|
|
189
|
+
|
|
207
190
|
/**
|
|
208
191
|
* Remove all regions
|
|
209
192
|
*/
|
|
210
|
-
|
|
211
193
|
}, {
|
|
212
194
|
key: "clear",
|
|
213
195
|
value: function clear() {
|
|
214
196
|
var _this3 = this;
|
|
215
|
-
|
|
216
197
|
Object.keys(this.list).forEach(function (id) {
|
|
217
198
|
_this3.list[id].remove();
|
|
218
199
|
});
|
|
@@ -221,7 +202,6 @@ var RegionsPlugin = /*#__PURE__*/function () {
|
|
|
221
202
|
key: "enableDragSelection",
|
|
222
203
|
value: function enableDragSelection(params) {
|
|
223
204
|
var _this4 = this;
|
|
224
|
-
|
|
225
205
|
this.disableDragSelection();
|
|
226
206
|
var slop = params.slop || 2;
|
|
227
207
|
var container = this.wavesurfer.drawer.container;
|
|
@@ -236,89 +216,80 @@ var RegionsPlugin = /*#__PURE__*/function () {
|
|
|
236
216
|
var touchId;
|
|
237
217
|
var pxMove = 0;
|
|
238
218
|
var scrollDirection;
|
|
239
|
-
var wrapperRect;
|
|
219
|
+
var wrapperRect;
|
|
240
220
|
|
|
221
|
+
// Scroll when the user is dragging within the threshold
|
|
241
222
|
var edgeScroll = function edgeScroll(e) {
|
|
242
223
|
if (!region || !scrollDirection) {
|
|
243
224
|
return;
|
|
244
|
-
}
|
|
245
|
-
|
|
225
|
+
}
|
|
246
226
|
|
|
227
|
+
// Update scroll position
|
|
247
228
|
var scrollLeft = _this4.wrapper.scrollLeft + scrollSpeed * scrollDirection;
|
|
248
|
-
_this4.wrapper.scrollLeft = scrollLeft = Math.min(maxScroll, Math.max(0, scrollLeft));
|
|
229
|
+
_this4.wrapper.scrollLeft = scrollLeft = Math.min(maxScroll, Math.max(0, scrollLeft));
|
|
249
230
|
|
|
231
|
+
// Update range
|
|
250
232
|
var end = _this4.wavesurfer.drawer.handleEvent(e);
|
|
251
|
-
|
|
252
233
|
region.update({
|
|
253
234
|
start: Math.min(end * duration, start * duration),
|
|
254
235
|
end: Math.max(end * duration, start * duration)
|
|
255
|
-
});
|
|
236
|
+
});
|
|
256
237
|
|
|
238
|
+
// Check that there is more to scroll and repeat
|
|
257
239
|
if (scrollLeft < maxScroll && scrollLeft > 0) {
|
|
258
240
|
window.requestAnimationFrame(function () {
|
|
259
241
|
edgeScroll(e);
|
|
260
242
|
});
|
|
261
243
|
}
|
|
262
244
|
};
|
|
263
|
-
|
|
264
245
|
var eventDown = function eventDown(e) {
|
|
265
246
|
if (e.touches && e.touches.length > 1) {
|
|
266
247
|
return;
|
|
267
248
|
}
|
|
268
|
-
|
|
269
249
|
duration = _this4.wavesurfer.getDuration();
|
|
270
|
-
touchId = e.targetTouches ? e.targetTouches[0].identifier : null;
|
|
250
|
+
touchId = e.targetTouches ? e.targetTouches[0].identifier : null;
|
|
271
251
|
|
|
252
|
+
// Store for scroll calculations
|
|
272
253
|
maxScroll = _this4.wrapper.scrollWidth - _this4.wrapper.clientWidth;
|
|
273
|
-
wrapperRect = _this4.util.withOrientation(_this4.wrapper.getBoundingClientRect(), _this4.vertical);
|
|
254
|
+
wrapperRect = _this4.util.withOrientation(_this4.wrapper.getBoundingClientRect(), _this4.vertical);
|
|
274
255
|
|
|
275
|
-
|
|
256
|
+
// set the region channel index based on the clicked area
|
|
257
|
+
if (_this4.wavesurfer.params.splitChannels && _this4.wavesurfer.params.splitChannelsOptions.splitDragSelection) {
|
|
276
258
|
var y = (e.touches ? e.touches[0].clientY : e.clientY) - wrapperRect.top;
|
|
277
259
|
var channelCount = _this4.wavesurfer.backend.buffer != null ? _this4.wavesurfer.backend.buffer.numberOfChannels : 1;
|
|
278
260
|
var channelHeight = _this4.wrapper.clientHeight / channelCount;
|
|
279
261
|
var channelIdx = Math.floor(y / channelHeight);
|
|
280
262
|
params.channelIdx = channelIdx;
|
|
281
263
|
var channelColors = _this4.wavesurfer.params.splitChannelsOptions.channelColors[channelIdx];
|
|
282
|
-
|
|
283
264
|
if (channelColors && channelColors.dragColor) {
|
|
284
265
|
params.color = channelColors.dragColor;
|
|
285
266
|
}
|
|
286
267
|
}
|
|
287
|
-
|
|
288
268
|
drag = true;
|
|
289
269
|
start = _this4.wavesurfer.drawer.handleEvent(e, true);
|
|
290
270
|
region = null;
|
|
291
271
|
scrollDirection = null;
|
|
292
272
|
};
|
|
293
|
-
|
|
294
273
|
this.wrapper.addEventListener('mousedown', eventDown);
|
|
295
274
|
this.wrapper.addEventListener('touchstart', eventDown);
|
|
296
275
|
this.on('disable-drag-selection', function () {
|
|
297
276
|
_this4.wrapper.removeEventListener('touchstart', eventDown);
|
|
298
|
-
|
|
299
277
|
_this4.wrapper.removeEventListener('mousedown', eventDown);
|
|
300
278
|
});
|
|
301
|
-
|
|
302
279
|
var eventUp = function eventUp(e) {
|
|
303
280
|
if (e.touches && e.touches.length > 1) {
|
|
304
281
|
return;
|
|
305
282
|
}
|
|
306
|
-
|
|
307
283
|
drag = false;
|
|
308
284
|
pxMove = 0;
|
|
309
285
|
scrollDirection = null;
|
|
310
|
-
|
|
311
286
|
if (region) {
|
|
312
287
|
_this4.util.preventClick();
|
|
313
|
-
|
|
314
288
|
region.fireEvent('update-end', e);
|
|
315
|
-
|
|
316
289
|
_this4.wavesurfer.fireEvent('region-update-end', region, e);
|
|
317
290
|
}
|
|
318
|
-
|
|
319
291
|
region = null;
|
|
320
292
|
};
|
|
321
|
-
|
|
322
293
|
this.wrapper.addEventListener('mouseleave', eventUp);
|
|
323
294
|
this.wrapper.addEventListener('mouseup', eventUp);
|
|
324
295
|
this.wrapper.addEventListener('touchend', eventUp);
|
|
@@ -327,58 +298,44 @@ var RegionsPlugin = /*#__PURE__*/function () {
|
|
|
327
298
|
this.on('disable-drag-selection', function () {
|
|
328
299
|
document.body.removeEventListener('mouseup', eventUp);
|
|
329
300
|
document.body.removeEventListener('touchend', eventUp);
|
|
330
|
-
|
|
331
301
|
_this4.wrapper.removeEventListener('touchend', eventUp);
|
|
332
|
-
|
|
333
302
|
_this4.wrapper.removeEventListener('mouseup', eventUp);
|
|
334
|
-
|
|
335
303
|
_this4.wrapper.removeEventListener('mouseleave', eventUp);
|
|
336
304
|
});
|
|
337
|
-
|
|
338
305
|
var eventMove = function eventMove(event) {
|
|
339
306
|
if (!drag) {
|
|
340
307
|
return;
|
|
341
308
|
}
|
|
342
|
-
|
|
343
309
|
if (++pxMove <= slop) {
|
|
344
310
|
return;
|
|
345
311
|
}
|
|
346
|
-
|
|
347
312
|
if (event.touches && event.touches.length > 1) {
|
|
348
313
|
return;
|
|
349
314
|
}
|
|
350
|
-
|
|
351
315
|
if (event.targetTouches && event.targetTouches[0].identifier != touchId) {
|
|
352
316
|
return;
|
|
353
|
-
}
|
|
354
|
-
|
|
317
|
+
}
|
|
355
318
|
|
|
319
|
+
// auto-create a region during mouse drag, unless region-count would exceed "maxRegions"
|
|
356
320
|
if (!region) {
|
|
357
321
|
region = _this4.add(params || {});
|
|
358
|
-
|
|
359
322
|
if (!region) {
|
|
360
323
|
return;
|
|
361
324
|
}
|
|
362
325
|
}
|
|
363
|
-
|
|
364
326
|
var end = _this4.wavesurfer.drawer.handleEvent(event);
|
|
365
|
-
|
|
366
327
|
var startUpdate = _this4.wavesurfer.regions.util.getRegionSnapToGridValue(start * duration);
|
|
367
|
-
|
|
368
328
|
var endUpdate = _this4.wavesurfer.regions.util.getRegionSnapToGridValue(end * duration);
|
|
369
|
-
|
|
370
329
|
region.update({
|
|
371
330
|
start: Math.min(endUpdate, startUpdate),
|
|
372
331
|
end: Math.max(endUpdate, startUpdate)
|
|
373
332
|
});
|
|
333
|
+
var orientedEvent = _this4.util.withOrientation(event, _this4.vertical);
|
|
374
334
|
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
335
|
+
// If scrolling is enabled
|
|
378
336
|
if (scroll && container.clientWidth < _this4.wrapper.scrollWidth) {
|
|
379
337
|
// Check threshold based on mouse
|
|
380
338
|
var x = orientedEvent.clientX - wrapperRect.left;
|
|
381
|
-
|
|
382
339
|
if (x <= scrollThreshold) {
|
|
383
340
|
scrollDirection = -1;
|
|
384
341
|
} else if (x >= wrapperRect.right - scrollThreshold) {
|
|
@@ -386,16 +343,13 @@ var RegionsPlugin = /*#__PURE__*/function () {
|
|
|
386
343
|
} else {
|
|
387
344
|
scrollDirection = null;
|
|
388
345
|
}
|
|
389
|
-
|
|
390
346
|
scrollDirection && edgeScroll(event);
|
|
391
347
|
}
|
|
392
348
|
};
|
|
393
|
-
|
|
394
349
|
this.wrapper.addEventListener('mousemove', eventMove);
|
|
395
350
|
this.wrapper.addEventListener('touchmove', eventMove);
|
|
396
351
|
this.on('disable-drag-selection', function () {
|
|
397
352
|
_this4.wrapper.removeEventListener('touchmove', eventMove);
|
|
398
|
-
|
|
399
353
|
_this4.wrapper.removeEventListener('mousemove', eventMove);
|
|
400
354
|
});
|
|
401
355
|
this.wavesurfer.on('region-created', function (region) {
|
|
@@ -409,6 +363,7 @@ var RegionsPlugin = /*#__PURE__*/function () {
|
|
|
409
363
|
value: function disableDragSelection() {
|
|
410
364
|
this.fireEvent('disable-drag-selection');
|
|
411
365
|
}
|
|
366
|
+
|
|
412
367
|
/**
|
|
413
368
|
* Get current region
|
|
414
369
|
*
|
|
@@ -417,17 +372,14 @@ var RegionsPlugin = /*#__PURE__*/function () {
|
|
|
417
372
|
*
|
|
418
373
|
* @returns {Region} The current region
|
|
419
374
|
*/
|
|
420
|
-
|
|
421
375
|
}, {
|
|
422
376
|
key: "getCurrentRegion",
|
|
423
377
|
value: function getCurrentRegion() {
|
|
424
378
|
var _this5 = this;
|
|
425
|
-
|
|
426
379
|
var time = this.wavesurfer.getCurrentTime();
|
|
427
380
|
var min = null;
|
|
428
381
|
Object.keys(this.list).forEach(function (id) {
|
|
429
382
|
var cur = _this5.list[id];
|
|
430
|
-
|
|
431
383
|
if (cur.start <= time && cur.end >= time) {
|
|
432
384
|
if (!min || cur.end - cur.start < min.end - min.start) {
|
|
433
385
|
min = cur;
|
|
@@ -436,6 +388,7 @@ var RegionsPlugin = /*#__PURE__*/function () {
|
|
|
436
388
|
});
|
|
437
389
|
return min;
|
|
438
390
|
}
|
|
391
|
+
|
|
439
392
|
/**
|
|
440
393
|
* Match the value to the grid, if required
|
|
441
394
|
*
|
|
@@ -447,7 +400,6 @@ var RegionsPlugin = /*#__PURE__*/function () {
|
|
|
447
400
|
* @param {Object} params the regions plugin params
|
|
448
401
|
* @returns {number} value
|
|
449
402
|
*/
|
|
450
|
-
|
|
451
403
|
}, {
|
|
452
404
|
key: "getRegionSnapToGridValue",
|
|
453
405
|
value: function getRegionSnapToGridValue(value, params) {
|
|
@@ -455,9 +407,9 @@ var RegionsPlugin = /*#__PURE__*/function () {
|
|
|
455
407
|
// the regions should snap to a grid
|
|
456
408
|
var offset = params.snapToGridOffset || 0;
|
|
457
409
|
return Math.round((value - offset) / params.snapToGridInterval) * params.snapToGridInterval + offset;
|
|
458
|
-
}
|
|
459
|
-
|
|
410
|
+
}
|
|
460
411
|
|
|
412
|
+
// no snap-to-grid
|
|
461
413
|
return value;
|
|
462
414
|
}
|
|
463
415
|
}], [{
|
|
@@ -482,7 +434,6 @@ var RegionsPlugin = /*#__PURE__*/function () {
|
|
|
482
434
|
if (!this.initialisedPluginList.regions) {
|
|
483
435
|
this.initPlugin('regions');
|
|
484
436
|
}
|
|
485
|
-
|
|
486
437
|
return this.regions.add(options);
|
|
487
438
|
},
|
|
488
439
|
clearRegions: function clearRegions() {
|
|
@@ -492,7 +443,6 @@ var RegionsPlugin = /*#__PURE__*/function () {
|
|
|
492
443
|
if (!this.initialisedPluginList.regions) {
|
|
493
444
|
this.initPlugin('regions');
|
|
494
445
|
}
|
|
495
|
-
|
|
496
446
|
this.regions.enableDragSelection(options);
|
|
497
447
|
},
|
|
498
448
|
disableDragSelection: function disableDragSelection() {
|
|
@@ -503,10 +453,8 @@ var RegionsPlugin = /*#__PURE__*/function () {
|
|
|
503
453
|
};
|
|
504
454
|
}
|
|
505
455
|
}]);
|
|
506
|
-
|
|
507
456
|
return RegionsPlugin;
|
|
508
457
|
}();
|
|
509
|
-
|
|
510
458
|
exports["default"] = RegionsPlugin;
|
|
511
459
|
module.exports = exports.default;
|
|
512
460
|
|
|
@@ -524,13 +472,9 @@ Object.defineProperty(exports, "__esModule", ({
|
|
|
524
472
|
value: true
|
|
525
473
|
}));
|
|
526
474
|
exports.Region = void 0;
|
|
527
|
-
|
|
528
475
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
529
|
-
|
|
530
476
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
531
|
-
|
|
532
477
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
533
|
-
|
|
534
478
|
/**
|
|
535
479
|
* @since 4.0.0
|
|
536
480
|
*
|
|
@@ -544,10 +488,8 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
|
|
|
544
488
|
var Region = /*#__PURE__*/function () {
|
|
545
489
|
function Region(params, regionsUtils, ws) {
|
|
546
490
|
var _params$showTooltip,
|
|
547
|
-
|
|
548
|
-
|
|
491
|
+
_this = this;
|
|
549
492
|
_classCallCheck(this, Region);
|
|
550
|
-
|
|
551
493
|
this.wavesurfer = ws;
|
|
552
494
|
this.wrapper = ws.drawer.wrapper;
|
|
553
495
|
this.util = ws.util;
|
|
@@ -556,17 +498,18 @@ var Region = /*#__PURE__*/function () {
|
|
|
556
498
|
this.vertical = ws.drawer.params.vertical;
|
|
557
499
|
this.id = params.id == null ? ws.util.getId() : params.id;
|
|
558
500
|
this.start = Number(params.start) || 0;
|
|
559
|
-
this.end = params.end == null ?
|
|
501
|
+
this.end = params.end == null ?
|
|
502
|
+
// small marker-like region
|
|
560
503
|
this.start + 4 / this.wrapper.scrollWidth * this.wavesurfer.getDuration() : Number(params.end);
|
|
561
504
|
this.resize = params.resize === undefined ? true : Boolean(params.resize);
|
|
562
|
-
this.drag = params.drag === undefined ? true : Boolean(params.drag);
|
|
563
|
-
|
|
505
|
+
this.drag = params.drag === undefined ? true : Boolean(params.drag);
|
|
506
|
+
// reflect resize and drag state of region for region-updated listener
|
|
564
507
|
this.isResizing = false;
|
|
565
508
|
this.isDragging = false;
|
|
566
509
|
this.loop = Boolean(params.loop);
|
|
567
|
-
this.color = params.color || 'rgba(0, 0, 0, 0.1)';
|
|
510
|
+
this.color = params.color || 'rgba(0, 0, 0, 0.1)';
|
|
511
|
+
// The left and right handleStyle properties can be set to 'none' for
|
|
568
512
|
// no styling or can be assigned an object containing CSS properties.
|
|
569
|
-
|
|
570
513
|
this.handleStyle = params.handleStyle || {
|
|
571
514
|
left: {},
|
|
572
515
|
right: {}
|
|
@@ -576,34 +519,30 @@ var Region = /*#__PURE__*/function () {
|
|
|
576
519
|
this.data = params.data || {};
|
|
577
520
|
this.attributes = params.attributes || {};
|
|
578
521
|
this.showTooltip = (_params$showTooltip = params.showTooltip) !== null && _params$showTooltip !== void 0 ? _params$showTooltip : true;
|
|
579
|
-
this.maxLength = params.maxLength;
|
|
580
|
-
|
|
522
|
+
this.maxLength = params.maxLength;
|
|
523
|
+
// It assumes the minLength parameter value, or the regionsMinLength parameter value, if the first one not provided
|
|
581
524
|
this.minLength = params.minLength;
|
|
582
|
-
|
|
583
525
|
this._onRedraw = function () {
|
|
584
526
|
return _this.updateRender();
|
|
585
527
|
};
|
|
586
|
-
|
|
587
528
|
this.scroll = params.scroll !== false && ws.params.scrollParent;
|
|
588
529
|
this.scrollSpeed = params.scrollSpeed || 1;
|
|
589
|
-
this.scrollThreshold = params.scrollThreshold || 10;
|
|
590
|
-
|
|
591
|
-
this.preventContextMenu = params.preventContextMenu === undefined ? false : Boolean(params.preventContextMenu);
|
|
530
|
+
this.scrollThreshold = params.scrollThreshold || 10;
|
|
531
|
+
// Determines whether the context menu is prevented from being opened.
|
|
532
|
+
this.preventContextMenu = params.preventContextMenu === undefined ? false : Boolean(params.preventContextMenu);
|
|
592
533
|
|
|
534
|
+
// select channel ID to set region
|
|
593
535
|
var channelIdx = params.channelIdx == null ? -1 : parseInt(params.channelIdx);
|
|
594
536
|
this.channelIdx = channelIdx;
|
|
595
537
|
this.regionHeight = '100%';
|
|
596
538
|
this.marginTop = '0px';
|
|
597
|
-
|
|
598
539
|
if (channelIdx !== -1) {
|
|
599
540
|
var channelCount = this.wavesurfer.backend.buffer != null ? this.wavesurfer.backend.buffer.numberOfChannels : -1;
|
|
600
|
-
|
|
601
541
|
if (channelCount >= 0 && channelIdx < channelCount) {
|
|
602
542
|
this.regionHeight = Math.floor(1 / channelCount * 100) + '%';
|
|
603
543
|
this.marginTop = this.wavesurfer.getHeight() * channelIdx + 'px';
|
|
604
544
|
}
|
|
605
545
|
}
|
|
606
|
-
|
|
607
546
|
this.formatTimeCallback = params.formatTimeCallback;
|
|
608
547
|
this.edgeScrollWidth = params.edgeScrollWidth;
|
|
609
548
|
this.bindInOut();
|
|
@@ -612,63 +551,51 @@ var Region = /*#__PURE__*/function () {
|
|
|
612
551
|
this.wavesurfer.on('redraw', this._onRedraw);
|
|
613
552
|
this.wavesurfer.fireEvent('region-created', this);
|
|
614
553
|
}
|
|
615
|
-
/* Update region params. */
|
|
616
|
-
|
|
617
554
|
|
|
555
|
+
/* Update region params. */
|
|
618
556
|
_createClass(Region, [{
|
|
619
557
|
key: "update",
|
|
620
558
|
value: function update(params, eventParams) {
|
|
621
559
|
if (params.start != null) {
|
|
622
560
|
this.start = Number(params.start);
|
|
623
561
|
}
|
|
624
|
-
|
|
625
562
|
if (params.end != null) {
|
|
626
563
|
this.end = Number(params.end);
|
|
627
564
|
}
|
|
628
|
-
|
|
629
565
|
if (params.loop != null) {
|
|
630
566
|
this.loop = Boolean(params.loop);
|
|
631
567
|
}
|
|
632
|
-
|
|
633
568
|
if (params.color != null) {
|
|
634
569
|
this.color = params.color;
|
|
635
570
|
}
|
|
636
|
-
|
|
637
571
|
if (params.handleStyle != null) {
|
|
638
572
|
this.handleStyle = params.handleStyle;
|
|
639
573
|
}
|
|
640
|
-
|
|
641
574
|
if (params.data != null) {
|
|
642
575
|
this.data = params.data;
|
|
643
576
|
}
|
|
644
|
-
|
|
645
577
|
if (params.resize != null) {
|
|
646
578
|
this.resize = Boolean(params.resize);
|
|
647
579
|
this.updateHandlesResize(this.resize);
|
|
648
580
|
}
|
|
649
|
-
|
|
650
581
|
if (params.drag != null) {
|
|
651
582
|
this.drag = Boolean(params.drag);
|
|
652
583
|
}
|
|
653
|
-
|
|
654
584
|
if (params.maxLength != null) {
|
|
655
585
|
this.maxLength = Number(params.maxLength);
|
|
656
586
|
}
|
|
657
|
-
|
|
658
587
|
if (params.minLength != null) {
|
|
659
588
|
this.minLength = Number(params.minLength);
|
|
660
589
|
}
|
|
661
|
-
|
|
662
590
|
if (params.attributes != null) {
|
|
663
591
|
this.attributes = params.attributes;
|
|
664
592
|
}
|
|
665
|
-
|
|
666
593
|
this.updateRender();
|
|
667
594
|
this.fireEvent('update');
|
|
668
595
|
this.wavesurfer.fireEvent('region-updated', this, eventParams);
|
|
669
596
|
}
|
|
670
|
-
/* Remove a single region. */
|
|
671
597
|
|
|
598
|
+
/* Remove a single region. */
|
|
672
599
|
}, {
|
|
673
600
|
key: "remove",
|
|
674
601
|
value: function remove() {
|
|
@@ -681,11 +608,11 @@ var Region = /*#__PURE__*/function () {
|
|
|
681
608
|
this.wavesurfer.fireEvent('region-removed', this);
|
|
682
609
|
}
|
|
683
610
|
}
|
|
611
|
+
|
|
684
612
|
/**
|
|
685
613
|
* Play the audio region.
|
|
686
614
|
* @param {number} start Optional offset to start playing at
|
|
687
615
|
*/
|
|
688
|
-
|
|
689
616
|
}, {
|
|
690
617
|
key: "play",
|
|
691
618
|
value: function play(start) {
|
|
@@ -694,59 +621,56 @@ var Region = /*#__PURE__*/function () {
|
|
|
694
621
|
this.fireEvent('play');
|
|
695
622
|
this.wavesurfer.fireEvent('region-play', this);
|
|
696
623
|
}
|
|
624
|
+
|
|
697
625
|
/**
|
|
698
626
|
* Play the audio region in a loop.
|
|
699
627
|
* @param {number} start Optional offset to start playing at
|
|
700
628
|
* */
|
|
701
|
-
|
|
702
629
|
}, {
|
|
703
630
|
key: "playLoop",
|
|
704
631
|
value: function playLoop(start) {
|
|
705
632
|
this.loop = true;
|
|
706
633
|
this.play(start);
|
|
707
634
|
}
|
|
635
|
+
|
|
708
636
|
/**
|
|
709
637
|
* Set looping on/off.
|
|
710
638
|
* @param {boolean} loop True if should play in loop
|
|
711
639
|
*/
|
|
712
|
-
|
|
713
640
|
}, {
|
|
714
641
|
key: "setLoop",
|
|
715
642
|
value: function setLoop(loop) {
|
|
716
643
|
this.loop = loop;
|
|
717
644
|
}
|
|
718
|
-
/* Render a region as a DOM element. */
|
|
719
645
|
|
|
646
|
+
/* Render a region as a DOM element. */
|
|
720
647
|
}, {
|
|
721
648
|
key: "render",
|
|
722
649
|
value: function render() {
|
|
723
650
|
this.element = this.util.withOrientation(this.wrapper.appendChild(document.createElement('region')), this.vertical);
|
|
724
651
|
this.element.className = 'wavesurfer-region';
|
|
725
|
-
|
|
726
652
|
if (this.showTooltip) {
|
|
727
653
|
this.element.title = this.formatTime(this.start, this.end);
|
|
728
654
|
}
|
|
729
|
-
|
|
730
655
|
this.element.setAttribute('data-id', this.id);
|
|
731
|
-
|
|
732
656
|
for (var attrname in this.attributes) {
|
|
733
657
|
this.element.setAttribute('data-region-' + attrname, this.attributes[attrname]);
|
|
734
658
|
}
|
|
735
|
-
|
|
736
659
|
this.style(this.element, {
|
|
737
660
|
position: 'absolute',
|
|
738
661
|
zIndex: 3,
|
|
739
662
|
height: this.regionHeight,
|
|
740
663
|
top: this.marginTop
|
|
741
664
|
});
|
|
742
|
-
/* Resize handles */
|
|
743
665
|
|
|
666
|
+
/* Resize handles */
|
|
744
667
|
if (this.resize) {
|
|
745
668
|
this.handleLeftEl = this.util.withOrientation(this.element.appendChild(document.createElement('handle')), this.vertical);
|
|
746
669
|
this.handleRightEl = this.util.withOrientation(this.element.appendChild(document.createElement('handle')), this.vertical);
|
|
747
670
|
this.handleLeftEl.className = 'wavesurfer-handle wavesurfer-handle-start';
|
|
748
|
-
this.handleRightEl.className = 'wavesurfer-handle wavesurfer-handle-end';
|
|
671
|
+
this.handleRightEl.className = 'wavesurfer-handle wavesurfer-handle-end';
|
|
749
672
|
|
|
673
|
+
// Default CSS properties for both handles.
|
|
750
674
|
var css = {
|
|
751
675
|
cursor: this.vertical ? 'row-resize' : 'col-resize',
|
|
752
676
|
position: 'absolute',
|
|
@@ -754,24 +678,22 @@ var Region = /*#__PURE__*/function () {
|
|
|
754
678
|
width: '2px',
|
|
755
679
|
height: '100%',
|
|
756
680
|
backgroundColor: 'rgba(0, 0, 0, 1)'
|
|
757
|
-
};
|
|
681
|
+
};
|
|
758
682
|
|
|
683
|
+
// Merge CSS properties per handle.
|
|
759
684
|
var handleLeftCss = this.handleStyle.left !== 'none' ? Object.assign({
|
|
760
685
|
left: '0px'
|
|
761
686
|
}, css, this.handleStyle.left) : null;
|
|
762
687
|
var handleRightCss = this.handleStyle.right !== 'none' ? Object.assign({
|
|
763
688
|
right: '0px'
|
|
764
689
|
}, css, this.handleStyle.right) : null;
|
|
765
|
-
|
|
766
690
|
if (handleLeftCss) {
|
|
767
691
|
this.style(this.handleLeftEl, handleLeftCss);
|
|
768
692
|
}
|
|
769
|
-
|
|
770
693
|
if (handleRightCss) {
|
|
771
694
|
this.style(this.handleRightEl, handleRightCss);
|
|
772
695
|
}
|
|
773
696
|
}
|
|
774
|
-
|
|
775
697
|
this.updateRender();
|
|
776
698
|
this.bindEvents();
|
|
777
699
|
}
|
|
@@ -781,9 +703,9 @@ var Region = /*#__PURE__*/function () {
|
|
|
781
703
|
if (this.formatTimeCallback) {
|
|
782
704
|
return this.formatTimeCallback(start, end);
|
|
783
705
|
}
|
|
784
|
-
|
|
785
706
|
return (start == end ? [start] : [start, end]).map(function (time) {
|
|
786
|
-
return [Math.floor(time % 3600 / 60),
|
|
707
|
+
return [Math.floor(time % 3600 / 60),
|
|
708
|
+
// minutes
|
|
787
709
|
('00' + Math.floor(time % 60)).slice(-2) // seconds
|
|
788
710
|
].join(':');
|
|
789
711
|
}).join('-');
|
|
@@ -793,8 +715,8 @@ var Region = /*#__PURE__*/function () {
|
|
|
793
715
|
value: function getWidth() {
|
|
794
716
|
return this.wavesurfer.drawer.width / this.wavesurfer.params.pixelRatio;
|
|
795
717
|
}
|
|
796
|
-
/* Update element's position, width, color. */
|
|
797
718
|
|
|
719
|
+
/* Update element's position, width, color. */
|
|
798
720
|
}, {
|
|
799
721
|
key: "updateRender",
|
|
800
722
|
value: function updateRender() {
|
|
@@ -803,25 +725,20 @@ var Region = /*#__PURE__*/function () {
|
|
|
803
725
|
var width = this.getWidth();
|
|
804
726
|
var startLimited = this.start;
|
|
805
727
|
var endLimited = this.end;
|
|
806
|
-
|
|
807
728
|
if (startLimited < 0) {
|
|
808
729
|
startLimited = 0;
|
|
809
730
|
endLimited = endLimited - startLimited;
|
|
810
731
|
}
|
|
811
|
-
|
|
812
732
|
if (endLimited > dur) {
|
|
813
733
|
endLimited = dur;
|
|
814
734
|
startLimited = dur - (endLimited - startLimited);
|
|
815
735
|
}
|
|
816
|
-
|
|
817
736
|
if (this.minLength != null) {
|
|
818
737
|
endLimited = Math.max(startLimited + this.minLength, endLimited);
|
|
819
738
|
}
|
|
820
|
-
|
|
821
739
|
if (this.maxLength != null) {
|
|
822
740
|
endLimited = Math.min(startLimited + this.maxLength, endLimited);
|
|
823
741
|
}
|
|
824
|
-
|
|
825
742
|
if (this.element != null) {
|
|
826
743
|
// Calculate the left and width values of the region such that
|
|
827
744
|
// no gaps appear between regions.
|
|
@@ -833,110 +750,89 @@ var Region = /*#__PURE__*/function () {
|
|
|
833
750
|
backgroundColor: this.color,
|
|
834
751
|
cursor: this.drag ? 'move' : 'default'
|
|
835
752
|
});
|
|
836
|
-
|
|
837
753
|
for (var attrname in this.attributes) {
|
|
838
754
|
this.element.setAttribute('data-region-' + attrname, this.attributes[attrname]);
|
|
839
755
|
}
|
|
840
|
-
|
|
841
756
|
if (this.showTooltip) {
|
|
842
757
|
this.element.title = this.formatTime(this.start, this.end);
|
|
843
758
|
}
|
|
844
759
|
}
|
|
845
760
|
}
|
|
846
|
-
/* Bind audio events. */
|
|
847
761
|
|
|
762
|
+
/* Bind audio events. */
|
|
848
763
|
}, {
|
|
849
764
|
key: "bindInOut",
|
|
850
765
|
value: function bindInOut() {
|
|
851
766
|
var _this2 = this;
|
|
852
|
-
|
|
853
767
|
this.firedIn = false;
|
|
854
768
|
this.firedOut = false;
|
|
855
|
-
|
|
856
769
|
var onProcess = function onProcess(time) {
|
|
857
770
|
var start = Math.round(_this2.start * 10) / 10;
|
|
858
771
|
var end = Math.round(_this2.end * 10) / 10;
|
|
859
772
|
time = Math.round(time * 10) / 10;
|
|
860
|
-
|
|
861
773
|
if (!_this2.firedOut && _this2.firedIn && (start > time || end <= time)) {
|
|
862
774
|
_this2.firedOut = true;
|
|
863
775
|
_this2.firedIn = false;
|
|
864
|
-
|
|
865
776
|
_this2.fireEvent('out');
|
|
866
|
-
|
|
867
777
|
_this2.wavesurfer.fireEvent('region-out', _this2);
|
|
868
778
|
}
|
|
869
|
-
|
|
870
779
|
if (!_this2.firedIn && start <= time && end > time) {
|
|
871
780
|
_this2.firedIn = true;
|
|
872
781
|
_this2.firedOut = false;
|
|
873
|
-
|
|
874
782
|
_this2.fireEvent('in');
|
|
875
|
-
|
|
876
783
|
_this2.wavesurfer.fireEvent('region-in', _this2);
|
|
877
784
|
}
|
|
878
785
|
};
|
|
879
|
-
|
|
880
786
|
this.wavesurfer.backend.on('audioprocess', onProcess);
|
|
881
787
|
this.on('remove', function () {
|
|
882
788
|
_this2.wavesurfer.backend.un('audioprocess', onProcess);
|
|
883
789
|
});
|
|
884
|
-
/* Loop playback. */
|
|
885
790
|
|
|
791
|
+
/* Loop playback. */
|
|
886
792
|
this.on('out', function () {
|
|
887
793
|
if (_this2.loop) {
|
|
888
794
|
var realTime = _this2.wavesurfer.getCurrentTime();
|
|
889
|
-
|
|
890
795
|
if (realTime >= _this2.start && realTime <= _this2.end) {
|
|
891
796
|
_this2.wavesurfer.play(_this2.start);
|
|
892
797
|
}
|
|
893
798
|
}
|
|
894
799
|
});
|
|
895
800
|
}
|
|
896
|
-
/* Bind DOM events. */
|
|
897
801
|
|
|
802
|
+
/* Bind DOM events. */
|
|
898
803
|
}, {
|
|
899
804
|
key: "bindEvents",
|
|
900
805
|
value: function bindEvents() {
|
|
901
806
|
var _this3 = this;
|
|
902
|
-
|
|
903
807
|
var preventContextMenu = this.preventContextMenu;
|
|
904
808
|
this.element.addEventListener('mouseenter', function (e) {
|
|
905
809
|
_this3.fireEvent('mouseenter', e);
|
|
906
|
-
|
|
907
810
|
_this3.wavesurfer.fireEvent('region-mouseenter', _this3, e);
|
|
908
811
|
});
|
|
909
812
|
this.element.addEventListener('mouseleave', function (e) {
|
|
910
813
|
_this3.fireEvent('mouseleave', e);
|
|
911
|
-
|
|
912
814
|
_this3.wavesurfer.fireEvent('region-mouseleave', _this3, e);
|
|
913
815
|
});
|
|
914
816
|
this.element.addEventListener('click', function (e) {
|
|
915
817
|
e.preventDefault();
|
|
916
|
-
|
|
917
818
|
_this3.fireEvent('click', e);
|
|
918
|
-
|
|
919
819
|
_this3.wavesurfer.fireEvent('region-click', _this3, e);
|
|
920
820
|
});
|
|
921
821
|
this.element.addEventListener('dblclick', function (e) {
|
|
922
822
|
e.stopPropagation();
|
|
923
823
|
e.preventDefault();
|
|
924
|
-
|
|
925
824
|
_this3.fireEvent('dblclick', e);
|
|
926
|
-
|
|
927
825
|
_this3.wavesurfer.fireEvent('region-dblclick', _this3, e);
|
|
928
826
|
});
|
|
929
827
|
this.element.addEventListener('contextmenu', function (e) {
|
|
930
828
|
if (preventContextMenu) {
|
|
931
829
|
e.preventDefault();
|
|
932
830
|
}
|
|
933
|
-
|
|
934
831
|
_this3.fireEvent('contextmenu', e);
|
|
935
|
-
|
|
936
832
|
_this3.wavesurfer.fireEvent('region-contextmenu', _this3, e);
|
|
937
833
|
});
|
|
938
|
-
/* Drag or resize on mousemove. */
|
|
939
834
|
|
|
835
|
+
/* Drag or resize on mousemove. */
|
|
940
836
|
if (this.drag || this.resize) {
|
|
941
837
|
this.bindDragEvents();
|
|
942
838
|
}
|
|
@@ -945,7 +841,6 @@ var Region = /*#__PURE__*/function () {
|
|
|
945
841
|
key: "bindDragEvents",
|
|
946
842
|
value: function bindDragEvents() {
|
|
947
843
|
var _this4 = this;
|
|
948
|
-
|
|
949
844
|
var container = this.wavesurfer.drawer.container;
|
|
950
845
|
var scrollSpeed = this.scrollSpeed;
|
|
951
846
|
var scrollThreshold = this.scrollThreshold;
|
|
@@ -958,24 +853,22 @@ var Region = /*#__PURE__*/function () {
|
|
|
958
853
|
var scrollDirection;
|
|
959
854
|
var wrapperRect;
|
|
960
855
|
var regionLeftHalfTime;
|
|
961
|
-
var regionRightHalfTime;
|
|
856
|
+
var regionRightHalfTime;
|
|
962
857
|
|
|
858
|
+
// Scroll when the user is dragging within the threshold
|
|
963
859
|
var edgeScroll = function edgeScroll(event) {
|
|
964
860
|
var orientedEvent = _this4.util.withOrientation(event, _this4.vertical);
|
|
965
|
-
|
|
966
861
|
var duration = _this4.wavesurfer.getDuration();
|
|
967
|
-
|
|
968
862
|
if (!scrollDirection || !drag && !resize) {
|
|
969
863
|
return;
|
|
970
864
|
}
|
|
971
|
-
|
|
972
865
|
var x = orientedEvent.clientX;
|
|
973
866
|
var distanceBetweenCursorAndWrapperEdge = 0;
|
|
974
867
|
var regionHalfTimeWidth = 0;
|
|
975
|
-
var adjustment = 0;
|
|
868
|
+
var adjustment = 0;
|
|
976
869
|
|
|
870
|
+
// Get the currently selected time according to the mouse position
|
|
977
871
|
var time = _this4.regionsUtil.getRegionSnapToGridValue(_this4.wavesurfer.drawer.handleEvent(event) * duration);
|
|
978
|
-
|
|
979
872
|
if (drag) {
|
|
980
873
|
// Considering the point of contact with the region while edgescrolling
|
|
981
874
|
if (scrollDirection === -1) {
|
|
@@ -988,17 +881,14 @@ var Region = /*#__PURE__*/function () {
|
|
|
988
881
|
} else {
|
|
989
882
|
// Considering minLength while edgescroll
|
|
990
883
|
var minLength = _this4.minLength;
|
|
991
|
-
|
|
992
884
|
if (!minLength) {
|
|
993
885
|
minLength = 0;
|
|
994
886
|
}
|
|
995
|
-
|
|
996
887
|
if (resize === 'start') {
|
|
997
888
|
if (time > _this4.end - minLength) {
|
|
998
889
|
time = _this4.end - minLength;
|
|
999
890
|
adjustment = scrollSpeed * scrollDirection;
|
|
1000
891
|
}
|
|
1001
|
-
|
|
1002
892
|
if (time < 0) {
|
|
1003
893
|
time = 0;
|
|
1004
894
|
}
|
|
@@ -1007,21 +897,18 @@ var Region = /*#__PURE__*/function () {
|
|
|
1007
897
|
time = _this4.start + minLength;
|
|
1008
898
|
adjustment = scrollSpeed * scrollDirection;
|
|
1009
899
|
}
|
|
1010
|
-
|
|
1011
900
|
if (time > duration) {
|
|
1012
901
|
time = duration;
|
|
1013
902
|
}
|
|
1014
903
|
}
|
|
1015
|
-
}
|
|
1016
|
-
|
|
904
|
+
}
|
|
1017
905
|
|
|
906
|
+
// Don't edgescroll if region has reached min or max limit
|
|
1018
907
|
var wrapperScrollLeft = _this4.wrapper.scrollLeft;
|
|
1019
|
-
|
|
1020
908
|
if (scrollDirection === -1) {
|
|
1021
909
|
if (Math.round(wrapperScrollLeft) === 0) {
|
|
1022
910
|
return;
|
|
1023
911
|
}
|
|
1024
|
-
|
|
1025
912
|
if (Math.round(wrapperScrollLeft - regionHalfTimeWidth + distanceBetweenCursorAndWrapperEdge) <= 0) {
|
|
1026
913
|
return;
|
|
1027
914
|
}
|
|
@@ -1029,15 +916,13 @@ var Region = /*#__PURE__*/function () {
|
|
|
1029
916
|
if (Math.round(wrapperScrollLeft) === maxScroll) {
|
|
1030
917
|
return;
|
|
1031
918
|
}
|
|
1032
|
-
|
|
1033
919
|
if (Math.round(wrapperScrollLeft + regionHalfTimeWidth - distanceBetweenCursorAndWrapperEdge) >= maxScroll) {
|
|
1034
920
|
return;
|
|
1035
921
|
}
|
|
1036
|
-
}
|
|
1037
|
-
|
|
922
|
+
}
|
|
1038
923
|
|
|
924
|
+
// Update scroll position
|
|
1039
925
|
var scrollLeft = wrapperScrollLeft - adjustment + scrollSpeed * scrollDirection;
|
|
1040
|
-
|
|
1041
926
|
if (scrollDirection === -1) {
|
|
1042
927
|
var calculatedLeft = Math.max(0 + regionHalfTimeWidth - distanceBetweenCursorAndWrapperEdge, scrollLeft);
|
|
1043
928
|
_this4.wrapper.scrollLeft = scrollLeft = calculatedLeft;
|
|
@@ -1045,42 +930,42 @@ var Region = /*#__PURE__*/function () {
|
|
|
1045
930
|
var calculatedRight = Math.min(maxScroll - regionHalfTimeWidth + distanceBetweenCursorAndWrapperEdge, scrollLeft);
|
|
1046
931
|
_this4.wrapper.scrollLeft = scrollLeft = calculatedRight;
|
|
1047
932
|
}
|
|
1048
|
-
|
|
1049
933
|
var delta = time - startTime;
|
|
1050
|
-
startTime = time;
|
|
934
|
+
startTime = time;
|
|
1051
935
|
|
|
1052
|
-
|
|
936
|
+
// Continue dragging or resizing
|
|
937
|
+
drag ? _this4.onDrag(delta) : _this4.onResize(delta, resize);
|
|
1053
938
|
|
|
939
|
+
// Repeat
|
|
1054
940
|
window.requestAnimationFrame(function () {
|
|
1055
941
|
edgeScroll(event);
|
|
1056
942
|
});
|
|
1057
943
|
};
|
|
1058
|
-
|
|
1059
944
|
var onDown = function onDown(event) {
|
|
1060
945
|
var duration = _this4.wavesurfer.getDuration();
|
|
1061
|
-
|
|
1062
946
|
if (event.touches && event.touches.length > 1) {
|
|
1063
947
|
return;
|
|
1064
948
|
}
|
|
949
|
+
touchId = event.targetTouches ? event.targetTouches[0].identifier : null;
|
|
1065
950
|
|
|
1066
|
-
|
|
951
|
+
// stop the event propagation, if this region is resizable or draggable
|
|
1067
952
|
// and the event is therefore handled here.
|
|
1068
|
-
|
|
1069
953
|
if (_this4.drag || _this4.resize) {
|
|
1070
954
|
event.stopPropagation();
|
|
1071
|
-
}
|
|
1072
|
-
|
|
955
|
+
}
|
|
1073
956
|
|
|
1074
|
-
|
|
957
|
+
// Store the selected startTime we begun dragging or resizing
|
|
958
|
+
startTime = _this4.regionsUtil.getRegionSnapToGridValue(_this4.wavesurfer.drawer.handleEvent(event, true) * duration);
|
|
1075
959
|
|
|
960
|
+
// Store the selected point of contact when we begin dragging
|
|
1076
961
|
regionLeftHalfTime = startTime - _this4.start;
|
|
1077
|
-
regionRightHalfTime = _this4.end - startTime;
|
|
962
|
+
regionRightHalfTime = _this4.end - startTime;
|
|
1078
963
|
|
|
964
|
+
// Store for scroll calculations
|
|
1079
965
|
maxScroll = _this4.wrapper.scrollWidth - _this4.wrapper.clientWidth;
|
|
1080
966
|
wrapperRect = _this4.util.withOrientation(_this4.wrapper.getBoundingClientRect(), _this4.vertical);
|
|
1081
967
|
_this4.isResizing = false;
|
|
1082
968
|
_this4.isDragging = false;
|
|
1083
|
-
|
|
1084
969
|
if (event.target.tagName.toLowerCase() === 'handle') {
|
|
1085
970
|
_this4.isResizing = true;
|
|
1086
971
|
resize = event.target.classList.contains('wavesurfer-handle-start') ? 'start' : 'end';
|
|
@@ -1090,12 +975,10 @@ var Region = /*#__PURE__*/function () {
|
|
|
1090
975
|
resize = false;
|
|
1091
976
|
}
|
|
1092
977
|
};
|
|
1093
|
-
|
|
1094
978
|
var onUp = function onUp(event) {
|
|
1095
979
|
if (event.touches && event.touches.length > 1) {
|
|
1096
980
|
return;
|
|
1097
981
|
}
|
|
1098
|
-
|
|
1099
982
|
if (drag || resize) {
|
|
1100
983
|
_this4.isDragging = false;
|
|
1101
984
|
_this4.isResizing = false;
|
|
@@ -1103,66 +986,48 @@ var Region = /*#__PURE__*/function () {
|
|
|
1103
986
|
scrollDirection = null;
|
|
1104
987
|
resize = false;
|
|
1105
988
|
}
|
|
1106
|
-
|
|
1107
989
|
if (updated) {
|
|
1108
990
|
updated = false;
|
|
1109
|
-
|
|
1110
991
|
_this4.util.preventClick();
|
|
1111
|
-
|
|
1112
992
|
_this4.fireEvent('update-end', event);
|
|
1113
|
-
|
|
1114
993
|
_this4.wavesurfer.fireEvent('region-update-end', _this4, event);
|
|
1115
994
|
}
|
|
1116
995
|
};
|
|
1117
|
-
|
|
1118
996
|
var onMove = function onMove(event) {
|
|
1119
997
|
var duration = _this4.wavesurfer.getDuration();
|
|
1120
|
-
|
|
1121
998
|
var orientedEvent = _this4.util.withOrientation(event, _this4.vertical);
|
|
1122
|
-
|
|
1123
999
|
if (event.touches && event.touches.length > 1) {
|
|
1124
1000
|
return;
|
|
1125
1001
|
}
|
|
1126
|
-
|
|
1127
1002
|
if (event.targetTouches && event.targetTouches[0].identifier != touchId) {
|
|
1128
1003
|
return;
|
|
1129
1004
|
}
|
|
1130
|
-
|
|
1131
1005
|
if (!drag && !resize) {
|
|
1132
1006
|
return;
|
|
1133
1007
|
}
|
|
1134
|
-
|
|
1135
1008
|
var oldTime = startTime;
|
|
1136
|
-
|
|
1137
1009
|
var time = _this4.regionsUtil.getRegionSnapToGridValue(_this4.wavesurfer.drawer.handleEvent(event) * duration);
|
|
1138
|
-
|
|
1139
1010
|
if (drag) {
|
|
1140
1011
|
// To maintain relative cursor start point while dragging
|
|
1141
1012
|
var maxEnd = _this4.wavesurfer.getDuration();
|
|
1142
|
-
|
|
1143
1013
|
if (time > maxEnd - regionRightHalfTime) {
|
|
1144
1014
|
time = maxEnd - regionRightHalfTime;
|
|
1145
1015
|
}
|
|
1146
|
-
|
|
1147
1016
|
if (time - regionLeftHalfTime < 0) {
|
|
1148
1017
|
time = regionLeftHalfTime;
|
|
1149
1018
|
}
|
|
1150
1019
|
}
|
|
1151
|
-
|
|
1152
1020
|
if (resize) {
|
|
1153
1021
|
// To maintain relative cursor start point while resizing
|
|
1154
1022
|
// we have to handle for minLength
|
|
1155
1023
|
var minLength = _this4.minLength;
|
|
1156
|
-
|
|
1157
1024
|
if (!minLength) {
|
|
1158
1025
|
minLength = 0;
|
|
1159
1026
|
}
|
|
1160
|
-
|
|
1161
1027
|
if (resize === 'start') {
|
|
1162
1028
|
if (time > _this4.end - minLength) {
|
|
1163
1029
|
time = _this4.end - minLength;
|
|
1164
1030
|
}
|
|
1165
|
-
|
|
1166
1031
|
if (time < 0) {
|
|
1167
1032
|
time = 0;
|
|
1168
1033
|
}
|
|
@@ -1170,33 +1035,30 @@ var Region = /*#__PURE__*/function () {
|
|
|
1170
1035
|
if (time < _this4.start + minLength) {
|
|
1171
1036
|
time = _this4.start + minLength;
|
|
1172
1037
|
}
|
|
1173
|
-
|
|
1174
1038
|
if (time > duration) {
|
|
1175
1039
|
time = duration;
|
|
1176
1040
|
}
|
|
1177
1041
|
}
|
|
1178
1042
|
}
|
|
1179
|
-
|
|
1180
1043
|
var delta = time - startTime;
|
|
1181
|
-
startTime = time;
|
|
1044
|
+
startTime = time;
|
|
1182
1045
|
|
|
1046
|
+
// Drag
|
|
1183
1047
|
if (_this4.drag && drag) {
|
|
1184
1048
|
updated = updated || !!delta;
|
|
1185
|
-
|
|
1186
1049
|
_this4.onDrag(delta);
|
|
1187
|
-
}
|
|
1188
|
-
|
|
1050
|
+
}
|
|
1189
1051
|
|
|
1052
|
+
// Resize
|
|
1190
1053
|
if (_this4.resize && resize) {
|
|
1191
1054
|
updated = updated || !!delta;
|
|
1192
|
-
|
|
1193
1055
|
_this4.onResize(delta, resize);
|
|
1194
1056
|
}
|
|
1195
|
-
|
|
1196
1057
|
if (_this4.scroll && container.clientWidth < _this4.wrapper.scrollWidth) {
|
|
1197
1058
|
// Triggering edgescroll from within edgeScrollWidth
|
|
1198
|
-
var x = orientedEvent.clientX;
|
|
1059
|
+
var x = orientedEvent.clientX;
|
|
1199
1060
|
|
|
1061
|
+
// Check direction
|
|
1200
1062
|
if (x < wrapperRect.left + _this4.edgeScrollWidth) {
|
|
1201
1063
|
scrollDirection = -1;
|
|
1202
1064
|
} else if (x > wrapperRect.right - _this4.edgeScrollWidth) {
|
|
@@ -1204,13 +1066,11 @@ var Region = /*#__PURE__*/function () {
|
|
|
1204
1066
|
} else {
|
|
1205
1067
|
scrollDirection = null;
|
|
1206
1068
|
}
|
|
1207
|
-
|
|
1208
1069
|
if (scrollDirection) {
|
|
1209
1070
|
edgeScroll(event);
|
|
1210
1071
|
}
|
|
1211
1072
|
}
|
|
1212
1073
|
};
|
|
1213
|
-
|
|
1214
1074
|
this.element.addEventListener('mousedown', onDown);
|
|
1215
1075
|
this.element.addEventListener('touchstart', onDown);
|
|
1216
1076
|
document.body.addEventListener('mousemove', onMove);
|
|
@@ -1234,15 +1094,12 @@ var Region = /*#__PURE__*/function () {
|
|
|
1234
1094
|
key: "onDrag",
|
|
1235
1095
|
value: function onDrag(delta) {
|
|
1236
1096
|
var maxEnd = this.wavesurfer.getDuration();
|
|
1237
|
-
|
|
1238
1097
|
if (this.end + delta > maxEnd) {
|
|
1239
1098
|
delta = maxEnd - this.end;
|
|
1240
1099
|
}
|
|
1241
|
-
|
|
1242
1100
|
if (this.start + delta < 0) {
|
|
1243
1101
|
delta = this.start * -1;
|
|
1244
1102
|
}
|
|
1245
|
-
|
|
1246
1103
|
var eventParams = {
|
|
1247
1104
|
direction: this._getDragDirection(delta),
|
|
1248
1105
|
action: 'drag'
|
|
@@ -1252,6 +1109,7 @@ var Region = /*#__PURE__*/function () {
|
|
|
1252
1109
|
end: this.end + delta
|
|
1253
1110
|
}, eventParams);
|
|
1254
1111
|
}
|
|
1112
|
+
|
|
1255
1113
|
/**
|
|
1256
1114
|
* Returns the direction of dragging region based on delta
|
|
1257
1115
|
* Negative delta means region is moving to the left
|
|
@@ -1260,20 +1118,18 @@ var Region = /*#__PURE__*/function () {
|
|
|
1260
1118
|
* @param {number} delta Drag offset
|
|
1261
1119
|
* @returns {string|null} Direction 'left', 'right' or null
|
|
1262
1120
|
*/
|
|
1263
|
-
|
|
1264
1121
|
}, {
|
|
1265
1122
|
key: "_getDragDirection",
|
|
1266
1123
|
value: function _getDragDirection(delta) {
|
|
1267
1124
|
if (delta < 0) {
|
|
1268
1125
|
return 'left';
|
|
1269
1126
|
}
|
|
1270
|
-
|
|
1271
1127
|
if (delta > 0) {
|
|
1272
1128
|
return 'right';
|
|
1273
1129
|
}
|
|
1274
|
-
|
|
1275
1130
|
return null;
|
|
1276
1131
|
}
|
|
1132
|
+
|
|
1277
1133
|
/**
|
|
1278
1134
|
* @example
|
|
1279
1135
|
* onResize(-5, 'start') // Moves the start point 5 seconds back
|
|
@@ -1282,7 +1138,6 @@ var Region = /*#__PURE__*/function () {
|
|
|
1282
1138
|
* @param {number} delta How much to add or subtract, given in seconds
|
|
1283
1139
|
* @param {string} direction 'start 'or 'end'
|
|
1284
1140
|
*/
|
|
1285
|
-
|
|
1286
1141
|
}, {
|
|
1287
1142
|
key: "onResize",
|
|
1288
1143
|
value: function onResize(delta, direction) {
|
|
@@ -1291,22 +1146,19 @@ var Region = /*#__PURE__*/function () {
|
|
|
1291
1146
|
action: 'resize',
|
|
1292
1147
|
direction: direction === 'start' ? 'left' : 'right'
|
|
1293
1148
|
};
|
|
1294
|
-
|
|
1295
1149
|
if (direction === 'start') {
|
|
1296
1150
|
// Check if changing the start by the given delta would result in the region being smaller than minLength
|
|
1297
1151
|
if (delta > 0 && this.end - (this.start + delta) < this.minLength) {
|
|
1298
1152
|
delta = this.end - this.minLength - this.start;
|
|
1299
|
-
}
|
|
1300
|
-
|
|
1153
|
+
}
|
|
1301
1154
|
|
|
1155
|
+
// Check if changing the start by the given delta would result in the region being larger than maxLength
|
|
1302
1156
|
if (delta < 0 && this.end - (this.start + delta) > this.maxLength) {
|
|
1303
1157
|
delta = this.end - this.start - this.maxLength;
|
|
1304
1158
|
}
|
|
1305
|
-
|
|
1306
1159
|
if (delta < 0 && this.start + delta < 0) {
|
|
1307
1160
|
delta = this.start * -1;
|
|
1308
1161
|
}
|
|
1309
|
-
|
|
1310
1162
|
this.update({
|
|
1311
1163
|
start: Math.min(this.start + delta, this.end),
|
|
1312
1164
|
end: Math.max(this.start + delta, this.end)
|
|
@@ -1315,17 +1167,15 @@ var Region = /*#__PURE__*/function () {
|
|
|
1315
1167
|
// Check if changing the end by the given delta would result in the region being smaller than minLength
|
|
1316
1168
|
if (delta < 0 && this.end + delta - this.start < this.minLength) {
|
|
1317
1169
|
delta = this.start + this.minLength - this.end;
|
|
1318
|
-
}
|
|
1319
|
-
|
|
1170
|
+
}
|
|
1320
1171
|
|
|
1172
|
+
// Check if changing the end by the given delta would result in the region being larger than maxLength
|
|
1321
1173
|
if (delta > 0 && this.end + delta - this.start > this.maxLength) {
|
|
1322
1174
|
delta = this.maxLength - (this.end - this.start);
|
|
1323
1175
|
}
|
|
1324
|
-
|
|
1325
1176
|
if (delta > 0 && this.end + delta > duration) {
|
|
1326
1177
|
delta = duration - this.end;
|
|
1327
1178
|
}
|
|
1328
|
-
|
|
1329
1179
|
this.update({
|
|
1330
1180
|
start: Math.min(this.end + delta, this.start),
|
|
1331
1181
|
end: Math.max(this.end + delta, this.start)
|
|
@@ -1336,13 +1186,11 @@ var Region = /*#__PURE__*/function () {
|
|
|
1336
1186
|
key: "updateHandlesResize",
|
|
1337
1187
|
value: function updateHandlesResize(resize) {
|
|
1338
1188
|
var cursorStyle;
|
|
1339
|
-
|
|
1340
1189
|
if (resize) {
|
|
1341
1190
|
cursorStyle = this.vertical ? 'row-resize' : 'col-resize';
|
|
1342
1191
|
} else {
|
|
1343
1192
|
cursorStyle = 'auto';
|
|
1344
1193
|
}
|
|
1345
|
-
|
|
1346
1194
|
this.handleLeftEl && this.style(this.handleLeftEl, {
|
|
1347
1195
|
cursor: cursorStyle
|
|
1348
1196
|
});
|
|
@@ -1351,10 +1199,8 @@ var Region = /*#__PURE__*/function () {
|
|
|
1351
1199
|
});
|
|
1352
1200
|
}
|
|
1353
1201
|
}]);
|
|
1354
|
-
|
|
1355
1202
|
return Region;
|
|
1356
1203
|
}();
|
|
1357
|
-
|
|
1358
1204
|
exports.Region = Region;
|
|
1359
1205
|
|
|
1360
1206
|
/***/ })
|