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
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,33 +1,45 @@
|
|
|
1
1
|
# [wavesurfer.js](https://wavesurfer-js.org)
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/wavesurfer.js)
|
|
4
|
-
 [ [](https://gitter.im/wavesurfer-js/wavesurfer.js?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
|
5
|
+
[](https://www.gitpoap.io/gh/wavesurfer-js/wavesurfer.js)
|
|
5
6
|
|
|
6
7
|
Interactive navigable audio visualization using Web Audio and Canvas.
|
|
7
8
|
|
|
8
|
-
[](https://wavesurfer-js.org)
|
|
9
10
|
|
|
10
11
|
See a [tutorial](https://wavesurfer-js.org/docs) and [examples](https://wavesurfer-js.org/examples) on [wavesurfer-js.org](https://wavesurfer-js.org).
|
|
11
12
|
|
|
12
|
-
##
|
|
13
|
-
wavesurfer.js
|
|
13
|
+
## Questions
|
|
14
|
+
Have a question about integrating wavesurfer.js on your website? Feel free to ask in our forum: https://github.com/wavesurfer-js/wavesurfer.js/discussions/categories/q-a
|
|
14
15
|
|
|
15
|
-
|
|
16
|
+
## Quick start
|
|
17
|
+
Install the package:
|
|
16
18
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
```
|
|
20
|
+
npm install wavesurfer.js --save
|
|
21
|
+
|
|
22
|
+
# or
|
|
23
|
+
|
|
24
|
+
yarn add wavesurfer.js
|
|
25
|
+
```
|
|
20
26
|
|
|
21
|
-
|
|
22
|
-
|
|
27
|
+
And import it like so:
|
|
28
|
+
```
|
|
29
|
+
import WaveSurfer from 'wavesurfer.js'
|
|
30
|
+
```
|
|
23
31
|
|
|
24
|
-
|
|
32
|
+
If you're not using a package manager, simply insert the script from a CDN:
|
|
33
|
+
```
|
|
34
|
+
<script src="https://unpkg.com/wavesurfer.js"></script>
|
|
35
|
+
```
|
|
25
36
|
|
|
26
|
-
|
|
37
|
+
Create a container in your HTML:
|
|
27
38
|
```html
|
|
28
39
|
<div id="waveform"></div>
|
|
29
40
|
```
|
|
30
|
-
|
|
41
|
+
|
|
42
|
+
Create an instance of wavesufer.js, passing the container selector and a few [options](https://wavesurfer-js.org/docs/options.html):
|
|
31
43
|
|
|
32
44
|
```javascript
|
|
33
45
|
var wavesurfer = WaveSurfer.create({
|
|
@@ -55,43 +67,20 @@ wavesurfer.load('example/media/demo.wav');
|
|
|
55
67
|
|
|
56
68
|
See the documentation on all available [methods](https://wavesurfer-js.org/docs/methods.html), [options](https://wavesurfer-js.org/docs/options.html) and [events](https://wavesurfer-js.org/docs/events.html) on the [homepage](https://wavesurfer-js.org/docs/).
|
|
57
69
|
|
|
58
|
-
##
|
|
59
|
-
|
|
60
|
-
See the [upgrade](https://github.com/katspaugh/wavesurfer.js/blob/master/UPGRADE.md) document if you're upgrading from a previous version of wavesurfer.js.
|
|
61
|
-
|
|
62
|
-
## Using with a module bundler
|
|
70
|
+
## Projects using wavesurfer.js
|
|
63
71
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
npm install wavesurfer.js --save
|
|
67
|
-
# or
|
|
68
|
-
yarn add wavesurfer.js
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
Use it with a module system like this:
|
|
72
|
-
```javascript
|
|
73
|
-
// import
|
|
74
|
-
import WaveSurfer from 'wavesurfer.js';
|
|
75
|
-
|
|
76
|
-
// commonjs/requirejs
|
|
77
|
-
var WaveSurfer = require('wavesurfer.js');
|
|
78
|
-
|
|
79
|
-
// amd
|
|
80
|
-
define(['WaveSurfer'], function(WaveSurfer) {
|
|
81
|
-
// ... code
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
```
|
|
72
|
+
For the list of projects using wavesurfer.js, check out
|
|
73
|
+
[the projects page](https://wavesurfer-js.org/projects/).
|
|
85
74
|
|
|
86
|
-
##
|
|
75
|
+
## Contributing
|
|
87
76
|
|
|
88
|
-
|
|
89
|
-
|
|
77
|
+
Have an idea and want to contribute to wavesurfer.js?
|
|
78
|
+
Please first start a discussion in the [Ideas section of our forum](https://github.com/wavesurfer-js/wavesurfer.js/discussions/categories/ideas) to coordinate with the maintainers.
|
|
90
79
|
|
|
91
|
-
|
|
80
|
+
### Development
|
|
92
81
|
|
|
93
|
-
[](https://github.com/wavesurfer-js/wavesurfer.js/actions?workflow=wavesurfer.js)
|
|
83
|
+
[](https://coveralls.io/github/wavesurfer-js/wavesurfer.js)
|
|
95
84
|

|
|
96
85
|
|
|
97
86
|
Install development dependencies:
|
|
@@ -133,7 +122,7 @@ npm run doc
|
|
|
133
122
|
If you want to use [the VS Code - Debugger for Chrome](https://github.com/Microsoft/vscode-chrome-debug), there is already a [launch.json](.vscode/launch.json) with a properly configured ``sourceMapPathOverrides`` for you.
|
|
134
123
|
|
|
135
124
|
## Editing documentation
|
|
136
|
-
The homepage and documentation files are maintained in the [`gh-pages` branch](https://github.com/
|
|
125
|
+
The homepage and documentation files are maintained in the [`gh-pages` branch](https://github.com/wavesurfer-js/wavesurfer.js/tree/gh-pages). Contributions to the documentation are especially welcome.
|
|
137
126
|
|
|
138
127
|
## Updating the NPM package
|
|
139
128
|
When preparing a new release, update the version in the `package.json` and have it merged to master. The new version of the package will be published to NPM automatically via GitHub Actions.
|
|
@@ -142,7 +131,7 @@ When preparing a new release, update the version in the `package.json` and have
|
|
|
142
131
|
|
|
143
132
|
The main maintainer: <img src="https://avatars.githubusercontent.com/u/305679" width="16" height="16" /> [Thijs Triemstra](https://github.com/thijstriemstra)
|
|
144
133
|
|
|
145
|
-
Many thanks to [all the awesome contributors](https://github.com/
|
|
134
|
+
Many thanks to [all the awesome contributors](https://github.com/wavesurfer-js/wavesurfer.js/contributors)!
|
|
146
135
|
|
|
147
136
|
## License
|
|
148
137
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* wavesurfer.js cursor plugin 6.
|
|
2
|
+
* wavesurfer.js cursor plugin 6.5.0 (2023-03-11)
|
|
3
3
|
* https://wavesurfer-js.org
|
|
4
4
|
* @license BSD-3-Clause
|
|
5
5
|
*/
|
|
@@ -29,15 +29,13 @@ Object.defineProperty(exports, "__esModule", ({
|
|
|
29
29
|
value: true
|
|
30
30
|
}));
|
|
31
31
|
exports["default"] = void 0;
|
|
32
|
-
|
|
32
|
+
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); }
|
|
33
33
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
34
|
-
|
|
35
|
-
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); } }
|
|
36
|
-
|
|
34
|
+
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); } }
|
|
37
35
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
38
|
-
|
|
39
|
-
function
|
|
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; }
|
|
37
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
38
|
+
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); }
|
|
41
39
|
/**
|
|
42
40
|
* @typedef {Object} CursorPluginParams
|
|
43
41
|
* @property {?boolean} deferInit Set to true to stop auto init in `addPlugin()`
|
|
@@ -57,8 +55,8 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
57
55
|
* the cursor follow the x and the y-position of the mouse. Use `false` to make the
|
|
58
56
|
* it only follow the x-position of the mouse.
|
|
59
57
|
* @property {function} formatTimeCallback Formats the timestamp on the cursor.
|
|
58
|
+
* @property {boolean} isDestroyCalled true if called destroy before the ready event fired
|
|
60
59
|
*/
|
|
61
|
-
|
|
62
60
|
/**
|
|
63
61
|
* Displays a thin line at the position of the cursor on the waveform.
|
|
64
62
|
*
|
|
@@ -94,9 +92,10 @@ var CursorPlugin = /*#__PURE__*/function () {
|
|
|
94
92
|
*/
|
|
95
93
|
function CursorPlugin(params, ws) {
|
|
96
94
|
var _this = this;
|
|
97
|
-
|
|
98
95
|
_classCallCheck(this, CursorPlugin);
|
|
99
|
-
|
|
96
|
+
/**
|
|
97
|
+
* @type {CursorPluginParams}
|
|
98
|
+
*/
|
|
100
99
|
_defineProperty(this, "defaultParams", {
|
|
101
100
|
hideOnBlur: true,
|
|
102
101
|
width: '1px',
|
|
@@ -110,33 +109,34 @@ var CursorPlugin = /*#__PURE__*/function () {
|
|
|
110
109
|
followCursorY: false,
|
|
111
110
|
formatTimeCallback: null
|
|
112
111
|
});
|
|
113
|
-
|
|
112
|
+
/**
|
|
113
|
+
* @param {object} e Mouse move event
|
|
114
|
+
*/
|
|
114
115
|
_defineProperty(this, "_onMousemove", function (e) {
|
|
115
116
|
var event = _this.util.withOrientation(e, _this.wavesurfer.params.vertical);
|
|
116
|
-
|
|
117
117
|
var bbox = _this.wrapper.getBoundingClientRect();
|
|
118
|
-
|
|
119
118
|
var y = 0;
|
|
120
119
|
var x = _this.wrapper.scrollLeft + event.clientX - bbox.left;
|
|
121
120
|
var displayTimeWidth = _this.displayTime ? _this.displayTime.getBoundingClientRect().width : 0;
|
|
122
121
|
var flip = bbox.right < event.clientX + displayTimeWidth;
|
|
123
|
-
|
|
124
122
|
if (_this.params.showTime && _this.params.followCursorY) {
|
|
125
123
|
// follow y-position of the mouse
|
|
126
124
|
y = event.clientY - (bbox.top + bbox.height / 2);
|
|
127
125
|
}
|
|
128
|
-
|
|
129
126
|
_this.updateCursorPosition(x, y, flip);
|
|
130
127
|
});
|
|
131
|
-
|
|
128
|
+
/**
|
|
129
|
+
* @returns {void}
|
|
130
|
+
*/
|
|
132
131
|
_defineProperty(this, "_onMouseenter", function () {
|
|
133
132
|
return _this.showCursor();
|
|
134
133
|
});
|
|
135
|
-
|
|
134
|
+
/**
|
|
135
|
+
* @returns {void}
|
|
136
|
+
*/
|
|
136
137
|
_defineProperty(this, "_onMouseleave", function () {
|
|
137
138
|
return _this.hideCursor();
|
|
138
139
|
});
|
|
139
|
-
|
|
140
140
|
this.wavesurfer = ws;
|
|
141
141
|
this.style = ws.util.style;
|
|
142
142
|
this.util = ws.util;
|
|
@@ -145,28 +145,32 @@ var CursorPlugin = /*#__PURE__*/function () {
|
|
|
145
145
|
*
|
|
146
146
|
* @type {?HTMLElement}
|
|
147
147
|
*/
|
|
148
|
-
|
|
149
148
|
this.cursor = null;
|
|
150
149
|
/**
|
|
151
150
|
* displays the time next to the cursor
|
|
152
151
|
*
|
|
153
152
|
* @type {?HTMLElement}
|
|
154
153
|
*/
|
|
155
|
-
|
|
156
154
|
this.showTime = null;
|
|
157
155
|
/**
|
|
158
156
|
* The html container that will display the time
|
|
159
157
|
*
|
|
160
158
|
* @type {?HTMLElement}
|
|
161
159
|
*/
|
|
162
|
-
|
|
163
160
|
this.displayTime = null;
|
|
161
|
+
/**
|
|
162
|
+
* true when `destroy` was called before `ready` event
|
|
163
|
+
* @type {boolean}
|
|
164
|
+
*/
|
|
165
|
+
this.isDestroyCalled = false;
|
|
164
166
|
this.params = Object.assign({}, this.defaultParams, params);
|
|
165
167
|
}
|
|
166
|
-
|
|
167
168
|
_createClass(CursorPlugin, [{
|
|
168
169
|
key: "_onReady",
|
|
169
170
|
value: function _onReady() {
|
|
171
|
+
if (this.isDestroyCalled) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
170
174
|
this.wrapper = this.wavesurfer.drawer.wrapper;
|
|
171
175
|
this.cursor = this.util.withOrientation(this.wrapper.appendChild(document.createElement('cursor')), this.wavesurfer.params.vertical);
|
|
172
176
|
this.style(this.cursor, Object.assign({
|
|
@@ -183,7 +187,6 @@ var CursorPlugin = /*#__PURE__*/function () {
|
|
|
183
187
|
opacity: this.params.opacity,
|
|
184
188
|
pointerEvents: 'none'
|
|
185
189
|
}, this.params.customStyle));
|
|
186
|
-
|
|
187
190
|
if (this.params.showTime) {
|
|
188
191
|
this.showTime = this.util.withOrientation(this.wrapper.appendChild(document.createElement('showTitle')), this.wavesurfer.params.vertical);
|
|
189
192
|
this.style(this.showTime, Object.assign({
|
|
@@ -204,14 +207,12 @@ var CursorPlugin = /*#__PURE__*/function () {
|
|
|
204
207
|
pointerEvents: 'none',
|
|
205
208
|
margin: 'auto',
|
|
206
209
|
visibility: 'hidden' // initial value will be hidden just for measuring purpose
|
|
210
|
+
}, this.params.customShowTimeStyle));
|
|
207
211
|
|
|
208
|
-
|
|
209
|
-
|
|
212
|
+
// initial value to measure display width
|
|
210
213
|
this.displayTime.innerHTML = this.formatTime(0);
|
|
211
214
|
}
|
|
212
|
-
|
|
213
215
|
this.wrapper.addEventListener('mousemove', this._onMousemove);
|
|
214
|
-
|
|
215
216
|
if (this.params.hideOnBlur) {
|
|
216
217
|
// ensure elements are hidden initially
|
|
217
218
|
this.hideCursor();
|
|
@@ -219,15 +220,14 @@ var CursorPlugin = /*#__PURE__*/function () {
|
|
|
219
220
|
this.wrapper.addEventListener('mouseleave', this._onMouseleave);
|
|
220
221
|
}
|
|
221
222
|
}
|
|
223
|
+
|
|
222
224
|
/**
|
|
223
225
|
* Initialise the plugin (used by the Plugin API)
|
|
224
226
|
*/
|
|
225
|
-
|
|
226
227
|
}, {
|
|
227
228
|
key: "init",
|
|
228
229
|
value: function init() {
|
|
229
230
|
var _this2 = this;
|
|
230
|
-
|
|
231
231
|
if (this.wavesurfer.isReady) {
|
|
232
232
|
this._onReady();
|
|
233
233
|
} else {
|
|
@@ -236,25 +236,28 @@ var CursorPlugin = /*#__PURE__*/function () {
|
|
|
236
236
|
});
|
|
237
237
|
}
|
|
238
238
|
}
|
|
239
|
+
|
|
239
240
|
/**
|
|
240
241
|
* Destroy the plugin (used by the Plugin API)
|
|
241
242
|
*/
|
|
242
|
-
|
|
243
243
|
}, {
|
|
244
244
|
key: "destroy",
|
|
245
245
|
value: function destroy() {
|
|
246
|
+
if (!this.cursorTime || !this.showTime) {
|
|
247
|
+
this.isDestroyCalled = true;
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
246
250
|
if (this.params.showTime) {
|
|
247
|
-
this.showTime.remove();
|
|
251
|
+
this.showTime && this.showTime.remove();
|
|
248
252
|
}
|
|
249
|
-
|
|
250
|
-
this.cursor.remove();
|
|
253
|
+
this.cursor && this.cursor.remove();
|
|
251
254
|
this.wrapper.removeEventListener('mousemove', this._onMousemove);
|
|
252
|
-
|
|
253
255
|
if (this.params.hideOnBlur) {
|
|
254
256
|
this.wrapper.removeEventListener('mouseenter', this._onMouseenter);
|
|
255
257
|
this.wrapper.removeEventListener('mouseleave', this._onMouseleave);
|
|
256
258
|
}
|
|
257
259
|
}
|
|
260
|
+
|
|
258
261
|
/**
|
|
259
262
|
* Update the cursor position
|
|
260
263
|
*
|
|
@@ -262,7 +265,6 @@ var CursorPlugin = /*#__PURE__*/function () {
|
|
|
262
265
|
* @param {number} ypos The y offset of the cursor in pixels
|
|
263
266
|
* @param {boolean} flip Flag to flip duration text from right to left
|
|
264
267
|
*/
|
|
265
|
-
|
|
266
268
|
}, {
|
|
267
269
|
key: "updateCursorPosition",
|
|
268
270
|
value: function updateCursorPosition(xpos, ypos) {
|
|
@@ -270,7 +272,6 @@ var CursorPlugin = /*#__PURE__*/function () {
|
|
|
270
272
|
this.style(this.cursor, {
|
|
271
273
|
left: "".concat(xpos, "px")
|
|
272
274
|
});
|
|
273
|
-
|
|
274
275
|
if (this.params.showTime) {
|
|
275
276
|
var duration = this.wavesurfer.getDuration();
|
|
276
277
|
var elementWidth = this.wavesurfer.drawer.width / this.wavesurfer.params.pixelRatio;
|
|
@@ -278,12 +279,10 @@ var CursorPlugin = /*#__PURE__*/function () {
|
|
|
278
279
|
var scrollTime = duration / this.wavesurfer.drawer.width * scrollWidth;
|
|
279
280
|
var timeValue = Math.max(0, (xpos - this.wrapper.scrollLeft) / elementWidth * duration) + scrollTime;
|
|
280
281
|
var formatValue = this.formatTime(timeValue);
|
|
281
|
-
|
|
282
282
|
if (flip) {
|
|
283
283
|
var textOffset = this.displayTime.getBoundingClientRect().width;
|
|
284
284
|
xpos -= textOffset;
|
|
285
285
|
}
|
|
286
|
-
|
|
287
286
|
this.style(this.showTime, {
|
|
288
287
|
left: "".concat(xpos, "px"),
|
|
289
288
|
top: "".concat(ypos, "px")
|
|
@@ -294,59 +293,57 @@ var CursorPlugin = /*#__PURE__*/function () {
|
|
|
294
293
|
this.displayTime.innerHTML = "".concat(formatValue);
|
|
295
294
|
}
|
|
296
295
|
}
|
|
296
|
+
|
|
297
297
|
/**
|
|
298
298
|
* Show the cursor
|
|
299
299
|
*/
|
|
300
|
-
|
|
301
300
|
}, {
|
|
302
301
|
key: "showCursor",
|
|
303
302
|
value: function showCursor() {
|
|
304
303
|
this.style(this.cursor, {
|
|
305
304
|
display: 'flex'
|
|
306
305
|
});
|
|
307
|
-
|
|
308
306
|
if (this.params.showTime) {
|
|
309
307
|
this.style(this.showTime, {
|
|
310
308
|
display: 'flex'
|
|
311
309
|
});
|
|
312
310
|
}
|
|
313
311
|
}
|
|
312
|
+
|
|
314
313
|
/**
|
|
315
314
|
* Hide the cursor
|
|
316
315
|
*/
|
|
317
|
-
|
|
318
316
|
}, {
|
|
319
317
|
key: "hideCursor",
|
|
320
318
|
value: function hideCursor() {
|
|
321
319
|
this.style(this.cursor, {
|
|
322
320
|
display: 'none'
|
|
323
321
|
});
|
|
324
|
-
|
|
325
322
|
if (this.params.showTime) {
|
|
326
323
|
this.style(this.showTime, {
|
|
327
324
|
display: 'none'
|
|
328
325
|
});
|
|
329
326
|
}
|
|
330
327
|
}
|
|
328
|
+
|
|
331
329
|
/**
|
|
332
330
|
* Format the timestamp for `cursorTime`.
|
|
333
331
|
*
|
|
334
332
|
* @param {number} cursorTime Time in seconds
|
|
335
333
|
* @returns {string} Formatted timestamp
|
|
336
334
|
*/
|
|
337
|
-
|
|
338
335
|
}, {
|
|
339
336
|
key: "formatTime",
|
|
340
337
|
value: function formatTime(cursorTime) {
|
|
341
338
|
cursorTime = isNaN(cursorTime) ? 0 : cursorTime;
|
|
342
|
-
|
|
343
339
|
if (this.params.formatTimeCallback) {
|
|
344
340
|
return this.params.formatTimeCallback(cursorTime);
|
|
345
341
|
}
|
|
346
|
-
|
|
347
342
|
return [cursorTime].map(function (time) {
|
|
348
|
-
return [Math.floor(time % 3600 / 60),
|
|
349
|
-
|
|
343
|
+
return [Math.floor(time % 3600 / 60),
|
|
344
|
+
// minutes
|
|
345
|
+
('00' + Math.floor(time % 60)).slice(-2),
|
|
346
|
+
// seconds
|
|
350
347
|
('000' + Math.floor(time % 1 * 1000)).slice(-3) // milliseconds
|
|
351
348
|
].join(':');
|
|
352
349
|
});
|
|
@@ -373,15 +370,9 @@ var CursorPlugin = /*#__PURE__*/function () {
|
|
|
373
370
|
instance: CursorPlugin
|
|
374
371
|
};
|
|
375
372
|
}
|
|
376
|
-
/**
|
|
377
|
-
* @type {CursorPluginParams}
|
|
378
|
-
*/
|
|
379
|
-
|
|
380
373
|
}]);
|
|
381
|
-
|
|
382
374
|
return CursorPlugin;
|
|
383
375
|
}();
|
|
384
|
-
|
|
385
376
|
exports["default"] = CursorPlugin;
|
|
386
377
|
module.exports = exports.default;
|
|
387
378
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wavesurfer.cursor.js","mappings":";;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,+CAA+C;AAC/C,CAAC;AACD;;;;;;;;;;;;;;;;;;;;;;;;;ACVA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAC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;AACA;AACA;AACA;AACA;AACA;IACI,gBAAcrF,MAAd,EAAsB;MAClB,OAAO;QACHsF,IAAI,EAAE,QADH;QAEHC,SAAS,EAAEvF,MAAM,IAAIA,MAAM,CAACuF,SAAjB,GAA6BvF,MAAM,CAACuF,SAApC,GAAgD,KAFxD;QAGHvF,MAAM,EAAEA,MAHL;QAIHwF,WAAW,EAAE,EAJV;QAKHC,QAAQ,EAAE1F;MALP,CAAP;IAOH;IAED;AACJ;AACA;;;;;;;;;;;;;;UCrEA;UACA;;UAEA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;;UAEA;UACA;;UAEA;UACA;UACA;;;;UEtBA;UACA;UACA;UACA","sources":["webpack://WaveSurfer/webpack/universalModuleDefinition","webpack://WaveSurfer/./src/plugin/cursor/index.js","webpack://WaveSurfer/webpack/bootstrap","webpack://WaveSurfer/webpack/before-startup","webpack://WaveSurfer/webpack/startup","webpack://WaveSurfer/webpack/after-startup"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine(\"WaveSurfer\", [], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"WaveSurfer\"] = factory();\n\telse\n\t\troot[\"WaveSurfer\"] = root[\"WaveSurfer\"] || {}, root[\"WaveSurfer\"][\"cursor\"] = factory();\n})(self, () => {\nreturn ","/**\n * @typedef {Object} CursorPluginParams\n * @property {?boolean} deferInit Set to true to stop auto init in `addPlugin()`\n * @property {boolean} hideOnBlur=true Hide the cursor when the mouse leaves the\n * waveform\n * @property {string} width='1px' The width of the cursor\n * @property {string} color='black' The color of the cursor\n * @property {number|string} opacity='0.25' The opacity of the cursor\n * @property {string} style='solid' The border style of the cursor\n * @property {number} zIndex=3 The z-index of the cursor element\n * @property {object} customStyle An object with custom styles which are applied\n * to the cursor element\n * @property {boolean} showTime=false Show the time on the cursor.\n * @property {object} customShowTimeStyle An object with custom styles which are\n * applied to the cursor time element.\n * @property {boolean} followCursorY=false Use `true` to make the time on\n * the cursor follow the x and the y-position of the mouse. Use `false` to make the\n * it only follow the x-position of the mouse.\n * @property {function} formatTimeCallback Formats the timestamp on the cursor.\n */\n\n/**\n * Displays a thin line at the position of the cursor on the waveform.\n *\n * @implements {PluginClass}\n * @extends {Observer}\n * @example\n * // es6\n * import CursorPlugin from 'wavesurfer.cursor.js';\n *\n * // commonjs\n * var CursorPlugin = require('wavesurfer.cursor.js');\n *\n * // if you are using <script> tags\n * var CursorPlugin = window.WaveSurfer.cursor;\n *\n * // ... initialising wavesurfer with the plugin\n * var wavesurfer = WaveSurfer.create({\n * // wavesurfer options ...\n * plugins: [\n * CursorPlugin.create({\n * // plugin options ...\n * })\n * ]\n * });\n */\nexport default class CursorPlugin {\n /**\n * Cursor plugin definition factory\n *\n * This function must be used to create a plugin definition which can be\n * used by wavesurfer to correctly instantiate the plugin.\n *\n * @param {CursorPluginParams} params parameters use to initialise the\n * plugin\n * @return {PluginDefinition} an object representing the plugin\n */\n static create(params) {\n return {\n name: 'cursor',\n deferInit: params && params.deferInit ? params.deferInit : false,\n params: params,\n staticProps: {},\n instance: CursorPlugin\n };\n }\n\n /**\n * @type {CursorPluginParams}\n */\n defaultParams = {\n hideOnBlur: true,\n width: '1px',\n color: 'black',\n opacity: '0.25',\n style: 'solid',\n zIndex: 4,\n customStyle: {},\n customShowTimeStyle: {},\n showTime: false,\n followCursorY: false,\n formatTimeCallback: null\n };\n\n /**\n * @param {object} e Mouse move event\n */\n _onMousemove = e => {\n const event = this.util.withOrientation(e, this.wavesurfer.params.vertical);\n const bbox = this.wrapper.getBoundingClientRect();\n let y = 0;\n let x = this.wrapper.scrollLeft + event.clientX - bbox.left;\n const displayTimeWidth = this.displayTime ? this.displayTime.getBoundingClientRect().width : 0;\n let flip = bbox.right < event.clientX + displayTimeWidth;\n\n if (this.params.showTime && this.params.followCursorY) {\n // follow y-position of the mouse\n y = event.clientY - (bbox.top + bbox.height / 2);\n }\n\n this.updateCursorPosition(x, y, flip);\n };\n\n /**\n * @returns {void}\n */\n _onMouseenter = () => this.showCursor();\n\n /**\n * @returns {void}\n */\n _onMouseleave = () => this.hideCursor();\n\n /**\n * Construct the plugin class. You probably want to use `CursorPlugin.create`\n * instead.\n *\n * @param {CursorPluginParams} params Plugin parameters\n * @param {object} ws Wavesurfer instance\n */\n constructor(params, ws) {\n this.wavesurfer = ws;\n this.style = ws.util.style;\n this.util = ws.util;\n /**\n * The cursor HTML element\n *\n * @type {?HTMLElement}\n */\n this.cursor = null;\n /**\n * displays the time next to the cursor\n *\n * @type {?HTMLElement}\n */\n this.showTime = null;\n /**\n * The html container that will display the time\n *\n * @type {?HTMLElement}\n */\n this.displayTime = null;\n\n this.params = Object.assign({}, this.defaultParams, params);\n }\n\n _onReady() {\n this.wrapper = this.wavesurfer.drawer.wrapper;\n this.cursor = this.util.withOrientation(this.wrapper.appendChild(\n document.createElement('cursor'),\n ), this.wavesurfer.params.vertical);\n\n this.style(this.cursor,\n Object.assign(\n {\n position: 'absolute',\n zIndex: this.params.zIndex,\n left: 0,\n top: 0,\n bottom: 0,\n width: '0',\n display: 'flex',\n borderRightStyle: this.params.style,\n borderRightWidth: this.params.width,\n borderRightColor: this.params.color,\n opacity: this.params.opacity,\n pointerEvents: 'none'\n },\n this.params.customStyle\n )\n );\n\n if (this.params.showTime) {\n this.showTime = this.util.withOrientation(this.wrapper.appendChild(\n document.createElement('showTitle')\n ), this.wavesurfer.params.vertical);\n this.style(\n this.showTime,\n Object.assign(\n {\n position: 'absolute',\n zIndex: this.params.zIndex,\n left: 0,\n top: 0,\n bottom: 0,\n width: 'auto',\n display: 'flex',\n opacity: this.params.opacity,\n pointerEvents: 'none',\n height: '100%'\n },\n this.params.customStyle\n )\n );\n\n this.displayTime = this.util.withOrientation(this.showTime.appendChild(\n document.createElement('div'),\n ), this.wavesurfer.params.vertical);\n\n this.style(this.displayTime,\n Object.assign(\n {\n display: 'inline',\n pointerEvents: 'none',\n margin: 'auto',\n visibility: 'hidden' // initial value will be hidden just for measuring purpose\n },\n this.params.customShowTimeStyle\n )\n );\n\n // initial value to measure display width\n this.displayTime.innerHTML = this.formatTime(0);\n }\n\n this.wrapper.addEventListener('mousemove', this._onMousemove);\n if (this.params.hideOnBlur) {\n // ensure elements are hidden initially\n this.hideCursor();\n this.wrapper.addEventListener('mouseenter', this._onMouseenter);\n this.wrapper.addEventListener('mouseleave', this._onMouseleave);\n }\n }\n\n /**\n * Initialise the plugin (used by the Plugin API)\n */\n init() {\n if (this.wavesurfer.isReady) {\n this._onReady();\n } else {\n this.wavesurfer.once('ready', () => this._onReady());\n }\n }\n\n /**\n * Destroy the plugin (used by the Plugin API)\n */\n destroy() {\n if (this.params.showTime) {\n this.showTime.remove();\n }\n this.cursor.remove();\n this.wrapper.removeEventListener('mousemove', this._onMousemove);\n if (this.params.hideOnBlur) {\n this.wrapper.removeEventListener('mouseenter', this._onMouseenter);\n this.wrapper.removeEventListener('mouseleave', this._onMouseleave);\n }\n }\n\n /**\n * Update the cursor position\n *\n * @param {number} xpos The x offset of the cursor in pixels\n * @param {number} ypos The y offset of the cursor in pixels\n * @param {boolean} flip Flag to flip duration text from right to left\n */\n updateCursorPosition(xpos, ypos, flip = false) {\n this.style(this.cursor, {\n left: `${xpos}px`\n });\n if (this.params.showTime) {\n const duration = this.wavesurfer.getDuration();\n const elementWidth =\n this.wavesurfer.drawer.width /\n this.wavesurfer.params.pixelRatio;\n const scrollWidth = this.wavesurfer.drawer.getScrollX();\n\n const scrollTime =\n (duration / this.wavesurfer.drawer.width) * scrollWidth;\n\n const timeValue =\n Math.max(0, ((xpos - this.wrapper.scrollLeft) / elementWidth) * duration) + scrollTime;\n const formatValue = this.formatTime(timeValue);\n if (flip) {\n const textOffset = this.displayTime.getBoundingClientRect().width;\n xpos -= textOffset;\n }\n this.style(this.showTime, {\n left: `${xpos}px`,\n top: `${ypos}px`\n });\n this.style(this.displayTime, {\n visibility: 'visible'\n });\n this.displayTime.innerHTML = `${formatValue}`;\n }\n }\n\n /**\n * Show the cursor\n */\n showCursor() {\n this.style(this.cursor, {\n display: 'flex'\n });\n if (this.params.showTime) {\n this.style(this.showTime, {\n display: 'flex'\n });\n }\n }\n\n /**\n * Hide the cursor\n */\n hideCursor() {\n this.style(this.cursor, {\n display: 'none'\n });\n if (this.params.showTime) {\n this.style(this.showTime, {\n display: 'none'\n });\n }\n }\n\n /**\n * Format the timestamp for `cursorTime`.\n *\n * @param {number} cursorTime Time in seconds\n * @returns {string} Formatted timestamp\n */\n formatTime(cursorTime) {\n cursorTime = isNaN(cursorTime) ? 0 : cursorTime;\n\n if (this.params.formatTimeCallback) {\n return this.params.formatTimeCallback(cursorTime);\n }\n return [cursorTime].map(time =>\n [\n Math.floor((time % 3600) / 60), // minutes\n ('00' + Math.floor(time % 60)).slice(-2), // seconds\n ('000' + Math.floor((time % 1) * 1000)).slice(-3) // milliseconds\n ].join(':')\n );\n }\n}\n","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","","// startup\n// Load entry module and return exports\n// This entry module is referenced by other modules so it can't be inlined\nvar __webpack_exports__ = __webpack_require__(\"./src/plugin/cursor/index.js\");\n",""],"names":["CursorPlugin","params","ws","hideOnBlur","width","color","opacity","style","zIndex","customStyle","customShowTimeStyle","showTime","followCursorY","formatTimeCallback","e","event","util","withOrientation","wavesurfer","vertical","bbox","wrapper","getBoundingClientRect","y","x","scrollLeft","clientX","left","displayTimeWidth","displayTime","flip","right","clientY","top","height","updateCursorPosition","showCursor","hideCursor","cursor","Object","assign","defaultParams","drawer","appendChild","document","createElement","position","bottom","display","borderRightStyle","borderRightWidth","borderRightColor","pointerEvents","margin","visibility","innerHTML","formatTime","addEventListener","_onMousemove","_onMouseenter","_onMouseleave","isReady","_onReady","once","remove","removeEventListener","xpos","ypos","duration","getDuration","elementWidth","pixelRatio","scrollWidth","getScrollX","scrollTime","timeValue","Math","max","formatValue","textOffset","cursorTime","isNaN","map","time","floor","slice","join","name","deferInit","staticProps","instance"],"sourceRoot":""}
|
|
1
|
+
{"version":3,"file":"wavesurfer.cursor.js","mappings":";;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,+CAA+C;AAC/C,CAAC;AACD;;;;;;;;;;;;;;;;;;;;;;;ACVA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAxBA,IAyBqBA,YAAY;EAmE7B;AACJ;AACA;AACA;AACA;AACA;AACA;EACI,SAAAA,aAAYC,MAAM,EAAEC,EAAE,EAAE;IAAA,IAAAC,KAAA;IAAAC,eAAA,OAAAJ,YAAA;IArDxB;AACJ;AACA;IAFIK,eAAA,wBAGgB;MACZC,UAAU,EAAE,IAAI;MAChBC,KAAK,EAAE,KAAK;MACZC,KAAK,EAAE,OAAO;MACdC,OAAO,EAAE,MAAM;MACfC,KAAK,EAAE,OAAO;MACdC,MAAM,EAAE,CAAC;MACTC,WAAW,EAAE,CAAC,CAAC;MACfC,mBAAmB,EAAE,CAAC,CAAC;MACvBC,QAAQ,EAAE,KAAK;MACfC,aAAa,EAAE,KAAK;MACpBC,kBAAkB,EAAE;IACx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;UACA;UACA;UACA;UACA;;UAEA;UACA;;UAEA;UACA;UACA;;;;UEtBA;UACA;UACA;UACA","sources":["webpack://WaveSurfer/webpack/universalModuleDefinition","webpack://WaveSurfer/./src/plugin/cursor/index.js","webpack://WaveSurfer/webpack/bootstrap","webpack://WaveSurfer/webpack/before-startup","webpack://WaveSurfer/webpack/startup","webpack://WaveSurfer/webpack/after-startup"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine(\"WaveSurfer\", [], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"WaveSurfer\"] = factory();\n\telse\n\t\troot[\"WaveSurfer\"] = root[\"WaveSurfer\"] || {}, root[\"WaveSurfer\"][\"cursor\"] = factory();\n})(self, () => {\nreturn ","/**\n * @typedef {Object} CursorPluginParams\n * @property {?boolean} deferInit Set to true to stop auto init in `addPlugin()`\n * @property {boolean} hideOnBlur=true Hide the cursor when the mouse leaves the\n * waveform\n * @property {string} width='1px' The width of the cursor\n * @property {string} color='black' The color of the cursor\n * @property {number|string} opacity='0.25' The opacity of the cursor\n * @property {string} style='solid' The border style of the cursor\n * @property {number} zIndex=3 The z-index of the cursor element\n * @property {object} customStyle An object with custom styles which are applied\n * to the cursor element\n * @property {boolean} showTime=false Show the time on the cursor.\n * @property {object} customShowTimeStyle An object with custom styles which are\n * applied to the cursor time element.\n * @property {boolean} followCursorY=false Use `true` to make the time on\n * the cursor follow the x and the y-position of the mouse. Use `false` to make the\n * it only follow the x-position of the mouse.\n * @property {function} formatTimeCallback Formats the timestamp on the cursor.\n * @property {boolean} isDestroyCalled true if called destroy before the ready event fired\n */\n\n/**\n * Displays a thin line at the position of the cursor on the waveform.\n *\n * @implements {PluginClass}\n * @extends {Observer}\n * @example\n * // es6\n * import CursorPlugin from 'wavesurfer.cursor.js';\n *\n * // commonjs\n * var CursorPlugin = require('wavesurfer.cursor.js');\n *\n * // if you are using <script> tags\n * var CursorPlugin = window.WaveSurfer.cursor;\n *\n * // ... initialising wavesurfer with the plugin\n * var wavesurfer = WaveSurfer.create({\n * // wavesurfer options ...\n * plugins: [\n * CursorPlugin.create({\n * // plugin options ...\n * })\n * ]\n * });\n */\nexport default class CursorPlugin {\n /**\n * Cursor plugin definition factory\n *\n * This function must be used to create a plugin definition which can be\n * used by wavesurfer to correctly instantiate the plugin.\n *\n * @param {CursorPluginParams} params parameters use to initialise the\n * plugin\n * @return {PluginDefinition} an object representing the plugin\n */\n static create(params) {\n return {\n name: 'cursor',\n deferInit: params && params.deferInit ? params.deferInit : false,\n params: params,\n staticProps: {},\n instance: CursorPlugin\n };\n }\n\n /**\n * @type {CursorPluginParams}\n */\n defaultParams = {\n hideOnBlur: true,\n width: '1px',\n color: 'black',\n opacity: '0.25',\n style: 'solid',\n zIndex: 4,\n customStyle: {},\n customShowTimeStyle: {},\n showTime: false,\n followCursorY: false,\n formatTimeCallback: null\n };\n\n /**\n * @param {object} e Mouse move event\n */\n _onMousemove = e => {\n const event = this.util.withOrientation(e, this.wavesurfer.params.vertical);\n const bbox = this.wrapper.getBoundingClientRect();\n let y = 0;\n let x = this.wrapper.scrollLeft + event.clientX - bbox.left;\n const displayTimeWidth = this.displayTime ? this.displayTime.getBoundingClientRect().width : 0;\n let flip = bbox.right < event.clientX + displayTimeWidth;\n\n if (this.params.showTime && this.params.followCursorY) {\n // follow y-position of the mouse\n y = event.clientY - (bbox.top + bbox.height / 2);\n }\n\n this.updateCursorPosition(x, y, flip);\n };\n\n /**\n * @returns {void}\n */\n _onMouseenter = () => this.showCursor();\n\n /**\n * @returns {void}\n */\n _onMouseleave = () => this.hideCursor();\n\n /**\n * Construct the plugin class. You probably want to use `CursorPlugin.create`\n * instead.\n *\n * @param {CursorPluginParams} params Plugin parameters\n * @param {object} ws Wavesurfer instance\n */\n constructor(params, ws) {\n this.wavesurfer = ws;\n this.style = ws.util.style;\n this.util = ws.util;\n /**\n * The cursor HTML element\n *\n * @type {?HTMLElement}\n */\n this.cursor = null;\n /**\n * displays the time next to the cursor\n *\n * @type {?HTMLElement}\n */\n this.showTime = null;\n /**\n * The html container that will display the time\n *\n * @type {?HTMLElement}\n */\n this.displayTime = null;\n /**\n * true when `destroy` was called before `ready` event\n * @type {boolean}\n */\n this.isDestroyCalled = false;\n\n this.params = Object.assign({}, this.defaultParams, params);\n }\n\n _onReady() {\n if (this.isDestroyCalled) {\n return;\n }\n this.wrapper = this.wavesurfer.drawer.wrapper;\n this.cursor = this.util.withOrientation(this.wrapper.appendChild(\n document.createElement('cursor'),\n ), this.wavesurfer.params.vertical);\n\n this.style(this.cursor,\n Object.assign(\n {\n position: 'absolute',\n zIndex: this.params.zIndex,\n left: 0,\n top: 0,\n bottom: 0,\n width: '0',\n display: 'flex',\n borderRightStyle: this.params.style,\n borderRightWidth: this.params.width,\n borderRightColor: this.params.color,\n opacity: this.params.opacity,\n pointerEvents: 'none'\n },\n this.params.customStyle\n )\n );\n\n if (this.params.showTime) {\n this.showTime = this.util.withOrientation(this.wrapper.appendChild(\n document.createElement('showTitle')\n ), this.wavesurfer.params.vertical);\n this.style(\n this.showTime,\n Object.assign(\n {\n position: 'absolute',\n zIndex: this.params.zIndex,\n left: 0,\n top: 0,\n bottom: 0,\n width: 'auto',\n display: 'flex',\n opacity: this.params.opacity,\n pointerEvents: 'none',\n height: '100%'\n },\n this.params.customStyle\n )\n );\n\n this.displayTime = this.util.withOrientation(this.showTime.appendChild(\n document.createElement('div'),\n ), this.wavesurfer.params.vertical);\n\n this.style(this.displayTime,\n Object.assign(\n {\n display: 'inline',\n pointerEvents: 'none',\n margin: 'auto',\n visibility: 'hidden' // initial value will be hidden just for measuring purpose\n },\n this.params.customShowTimeStyle\n )\n );\n\n // initial value to measure display width\n this.displayTime.innerHTML = this.formatTime(0);\n }\n\n this.wrapper.addEventListener('mousemove', this._onMousemove);\n if (this.params.hideOnBlur) {\n // ensure elements are hidden initially\n this.hideCursor();\n this.wrapper.addEventListener('mouseenter', this._onMouseenter);\n this.wrapper.addEventListener('mouseleave', this._onMouseleave);\n }\n }\n\n /**\n * Initialise the plugin (used by the Plugin API)\n */\n init() {\n if (this.wavesurfer.isReady) {\n this._onReady();\n } else {\n this.wavesurfer.once('ready', () => this._onReady());\n }\n }\n\n /**\n * Destroy the plugin (used by the Plugin API)\n */\n destroy() {\n if (!this.cursorTime || !this.showTime){\n this.isDestroyCalled = true;\n return;\n }\n if (this.params.showTime) {\n this.showTime && this.showTime.remove();\n }\n this.cursor && this.cursor.remove();\n this.wrapper.removeEventListener('mousemove', this._onMousemove);\n if (this.params.hideOnBlur) {\n this.wrapper.removeEventListener('mouseenter', this._onMouseenter);\n this.wrapper.removeEventListener('mouseleave', this._onMouseleave);\n }\n }\n\n /**\n * Update the cursor position\n *\n * @param {number} xpos The x offset of the cursor in pixels\n * @param {number} ypos The y offset of the cursor in pixels\n * @param {boolean} flip Flag to flip duration text from right to left\n */\n updateCursorPosition(xpos, ypos, flip = false) {\n this.style(this.cursor, {\n left: `${xpos}px`\n });\n if (this.params.showTime) {\n const duration = this.wavesurfer.getDuration();\n const elementWidth =\n this.wavesurfer.drawer.width /\n this.wavesurfer.params.pixelRatio;\n const scrollWidth = this.wavesurfer.drawer.getScrollX();\n\n const scrollTime =\n (duration / this.wavesurfer.drawer.width) * scrollWidth;\n\n const timeValue =\n Math.max(0, ((xpos - this.wrapper.scrollLeft) / elementWidth) * duration) + scrollTime;\n const formatValue = this.formatTime(timeValue);\n if (flip) {\n const textOffset = this.displayTime.getBoundingClientRect().width;\n xpos -= textOffset;\n }\n this.style(this.showTime, {\n left: `${xpos}px`,\n top: `${ypos}px`\n });\n this.style(this.displayTime, {\n visibility: 'visible'\n });\n this.displayTime.innerHTML = `${formatValue}`;\n }\n }\n\n /**\n * Show the cursor\n */\n showCursor() {\n this.style(this.cursor, {\n display: 'flex'\n });\n if (this.params.showTime) {\n this.style(this.showTime, {\n display: 'flex'\n });\n }\n }\n\n /**\n * Hide the cursor\n */\n hideCursor() {\n this.style(this.cursor, {\n display: 'none'\n });\n if (this.params.showTime) {\n this.style(this.showTime, {\n display: 'none'\n });\n }\n }\n\n /**\n * Format the timestamp for `cursorTime`.\n *\n * @param {number} cursorTime Time in seconds\n * @returns {string} Formatted timestamp\n */\n formatTime(cursorTime) {\n cursorTime = isNaN(cursorTime) ? 0 : cursorTime;\n if (this.params.formatTimeCallback) {\n return this.params.formatTimeCallback(cursorTime);\n }\n return [cursorTime].map(time =>\n [\n Math.floor((time % 3600) / 60), // minutes\n ('00' + Math.floor(time % 60)).slice(-2), // seconds\n ('000' + Math.floor((time % 1) * 1000)).slice(-3) // milliseconds\n ].join(':')\n );\n }\n}\n","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","","// startup\n// Load entry module and return exports\n// This entry module is referenced by other modules so it can't be inlined\nvar __webpack_exports__ = __webpack_require__(\"./src/plugin/cursor/index.js\");\n",""],"names":["CursorPlugin","params","ws","_this","_classCallCheck","_defineProperty","hideOnBlur","width","color","opacity","style","zIndex","customStyle","customShowTimeStyle","showTime","followCursorY","formatTimeCallback","e","event","util","withOrientation","wavesurfer","vertical","bbox","wrapper","getBoundingClientRect","y","x","scrollLeft","clientX","left","displayTimeWidth","displayTime","flip","right","clientY","top","height","updateCursorPosition","showCursor","hideCursor","cursor","isDestroyCalled","Object","assign","defaultParams","_createClass","key","value","_onReady","drawer","appendChild","document","createElement","position","bottom","display","borderRightStyle","borderRightWidth","borderRightColor","pointerEvents","margin","visibility","innerHTML","formatTime","addEventListener","_onMousemove","_onMouseenter","_onMouseleave","init","_this2","isReady","once","destroy","cursorTime","remove","removeEventListener","xpos","ypos","arguments","length","undefined","concat","duration","getDuration","elementWidth","pixelRatio","scrollWidth","getScrollX","scrollTime","timeValue","Math","max","formatValue","textOffset","isNaN","map","time","floor","slice","join","create","name","deferInit","staticProps","instance","exports","default","module"],"sourceRoot":""}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* wavesurfer.js cursor plugin 6.
|
|
2
|
+
* wavesurfer.js cursor plugin 6.5.0 (2023-03-11)
|
|
3
3
|
* https://wavesurfer-js.org
|
|
4
4
|
* @license BSD-3-Clause
|
|
5
5
|
*/
|
|
6
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("WaveSurfer",[],t):"object"==typeof exports?exports.WaveSurfer=t():(e.WaveSurfer=e.WaveSurfer||{},e.WaveSurfer.cursor=t())}(self,(()=>(()=>{"use strict";var e={178:(e,t)=>{function i(e,t){for(var i=0;i<t.length;i++){var
|
|
6
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("WaveSurfer",[],t):"object"==typeof exports?exports.WaveSurfer=t():(e.WaveSurfer=e.WaveSurfer||{},e.WaveSurfer.cursor=t())}(self,(()=>(()=>{"use strict";var e={178:(e,t)=>{function i(e){return i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},i(e)}function r(e,t){for(var i=0;i<t.length;i++){var r=t[i];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,o(r.key),r)}}function s(e,t,i){return(t=o(t))in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}function o(e){var t=function(e,t){if("object"!==i(e)||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var s=r.call(e,t||"default");if("object"!==i(s))return s;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"===i(t)?t:String(t)}Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var a=function(){function e(t,i){var r=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),s(this,"defaultParams",{hideOnBlur:!0,width:"1px",color:"black",opacity:"0.25",style:"solid",zIndex:4,customStyle:{},customShowTimeStyle:{},showTime:!1,followCursorY:!1,formatTimeCallback:null}),s(this,"_onMousemove",(function(e){var t=r.util.withOrientation(e,r.wavesurfer.params.vertical),i=r.wrapper.getBoundingClientRect(),s=0,o=r.wrapper.scrollLeft+t.clientX-i.left,a=r.displayTime?r.displayTime.getBoundingClientRect().width:0,n=i.right<t.clientX+a;r.params.showTime&&r.params.followCursorY&&(s=t.clientY-(i.top+i.height/2)),r.updateCursorPosition(o,s,n)})),s(this,"_onMouseenter",(function(){return r.showCursor()})),s(this,"_onMouseleave",(function(){return r.hideCursor()})),this.wavesurfer=i,this.style=i.util.style,this.util=i.util,this.cursor=null,this.showTime=null,this.displayTime=null,this.isDestroyCalled=!1,this.params=Object.assign({},this.defaultParams,t)}var t,i,o;return t=e,i=[{key:"_onReady",value:function(){this.isDestroyCalled||(this.wrapper=this.wavesurfer.drawer.wrapper,this.cursor=this.util.withOrientation(this.wrapper.appendChild(document.createElement("cursor")),this.wavesurfer.params.vertical),this.style(this.cursor,Object.assign({position:"absolute",zIndex:this.params.zIndex,left:0,top:0,bottom:0,width:"0",display:"flex",borderRightStyle:this.params.style,borderRightWidth:this.params.width,borderRightColor:this.params.color,opacity:this.params.opacity,pointerEvents:"none"},this.params.customStyle)),this.params.showTime&&(this.showTime=this.util.withOrientation(this.wrapper.appendChild(document.createElement("showTitle")),this.wavesurfer.params.vertical),this.style(this.showTime,Object.assign({position:"absolute",zIndex:this.params.zIndex,left:0,top:0,bottom:0,width:"auto",display:"flex",opacity:this.params.opacity,pointerEvents:"none",height:"100%"},this.params.customStyle)),this.displayTime=this.util.withOrientation(this.showTime.appendChild(document.createElement("div")),this.wavesurfer.params.vertical),this.style(this.displayTime,Object.assign({display:"inline",pointerEvents:"none",margin:"auto",visibility:"hidden"},this.params.customShowTimeStyle)),this.displayTime.innerHTML=this.formatTime(0)),this.wrapper.addEventListener("mousemove",this._onMousemove),this.params.hideOnBlur&&(this.hideCursor(),this.wrapper.addEventListener("mouseenter",this._onMouseenter),this.wrapper.addEventListener("mouseleave",this._onMouseleave)))}},{key:"init",value:function(){var e=this;this.wavesurfer.isReady?this._onReady():this.wavesurfer.once("ready",(function(){return e._onReady()}))}},{key:"destroy",value:function(){this.cursorTime&&this.showTime?(this.params.showTime&&this.showTime&&this.showTime.remove(),this.cursor&&this.cursor.remove(),this.wrapper.removeEventListener("mousemove",this._onMousemove),this.params.hideOnBlur&&(this.wrapper.removeEventListener("mouseenter",this._onMouseenter),this.wrapper.removeEventListener("mouseleave",this._onMouseleave))):this.isDestroyCalled=!0}},{key:"updateCursorPosition",value:function(e,t){var i=arguments.length>2&&void 0!==arguments[2]&&arguments[2];if(this.style(this.cursor,{left:"".concat(e,"px")}),this.params.showTime){var r=this.wavesurfer.getDuration(),s=this.wavesurfer.drawer.width/this.wavesurfer.params.pixelRatio,o=this.wavesurfer.drawer.getScrollX(),a=r/this.wavesurfer.drawer.width*o,n=Math.max(0,(e-this.wrapper.scrollLeft)/s*r)+a,l=this.formatTime(n);i&&(e-=this.displayTime.getBoundingClientRect().width),this.style(this.showTime,{left:"".concat(e,"px"),top:"".concat(t,"px")}),this.style(this.displayTime,{visibility:"visible"}),this.displayTime.innerHTML="".concat(l)}}},{key:"showCursor",value:function(){this.style(this.cursor,{display:"flex"}),this.params.showTime&&this.style(this.showTime,{display:"flex"})}},{key:"hideCursor",value:function(){this.style(this.cursor,{display:"none"}),this.params.showTime&&this.style(this.showTime,{display:"none"})}},{key:"formatTime",value:function(e){return e=isNaN(e)?0:e,this.params.formatTimeCallback?this.params.formatTimeCallback(e):[e].map((function(e){return[Math.floor(e%3600/60),("00"+Math.floor(e%60)).slice(-2),("000"+Math.floor(e%1*1e3)).slice(-3)].join(":")}))}}],o=[{key:"create",value:function(t){return{name:"cursor",deferInit:!(!t||!t.deferInit)&&t.deferInit,params:t,staticProps:{},instance:e}}}],i&&r(t.prototype,i),o&&r(t,o),Object.defineProperty(t,"prototype",{writable:!1}),e}();t.default=a,e.exports=t.default}},t={};var i=function i(r){var s=t[r];if(void 0!==s)return s.exports;var o=t[r]={exports:{}};return e[r](o,o.exports,i),o.exports}(178);return i})()));
|
|
7
7
|
//# sourceMappingURL=wavesurfer.cursor.min.js.map
|