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