wavesurfer.js 6.5.0 → 7.0.0-alpha.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/.eslintrc.json +24 -0
- package/.prettierrc +8 -0
- package/README.md +26 -117
- package/dist/base-plugin.d.ts +10 -0
- package/dist/base-plugin.js +13 -0
- package/dist/decoder.d.ts +10 -0
- package/dist/decoder.js +43 -0
- package/dist/event-emitter.d.ts +11 -0
- package/dist/event-emitter.js +21 -0
- package/dist/fetcher.d.ts +4 -0
- package/dist/fetcher.js +17 -0
- package/dist/index.d.ts +92 -0
- package/dist/index.js +166 -0
- package/dist/player-webaudio.d.ts +8 -0
- package/dist/player-webaudio.js +31 -0
- package/dist/player.d.ts +16 -0
- package/dist/player.js +40 -0
- package/dist/plugins/regions.d.ts +48 -0
- package/dist/plugins/regions.js +183 -0
- package/dist/renderer.d.ts +34 -0
- package/dist/renderer.js +193 -0
- package/dist/timer.d.ts +10 -0
- package/dist/timer.js +17 -0
- package/examples/audio.ogg +0 -0
- package/examples/bars.js +19 -0
- package/examples/basic.js +8 -0
- package/examples/gradient.js +28 -0
- package/examples/regions.js +63 -0
- package/examples/video.js +19 -0
- package/examples/webaudio.js +14 -0
- package/package.json +19 -99
- package/src/base-plugin.ts +20 -0
- package/src/decoder.ts +41 -0
- package/src/event-emitter.ts +35 -0
- package/src/fetcher.ts +7 -0
- package/src/index.ts +252 -0
- package/src/player-webaudio.ts +34 -0
- package/src/player.ts +50 -0
- package/src/plugins/regions.ts +240 -0
- package/src/renderer.ts +250 -0
- package/src/timer.ts +27 -0
- package/tsconfig.json +105 -0
- package/tutorial/index.html +47 -0
- package/tutorial/src/editor.js +70 -0
- package/tutorial/src/init.js +66 -0
- package/tutorial/src/url.js +25 -0
- package/tutorial/style.css +211 -0
- package/yarn-error.log +1049 -0
- package/LICENSE +0 -29
- package/dist/plugin/wavesurfer.cursor.js +0 -418
- package/dist/plugin/wavesurfer.cursor.js.map +0 -1
- package/dist/plugin/wavesurfer.cursor.min.js +0 -7
- package/dist/plugin/wavesurfer.cursor.min.js.map +0 -1
- package/dist/plugin/wavesurfer.elan.js +0 -381
- package/dist/plugin/wavesurfer.elan.js.map +0 -1
- package/dist/plugin/wavesurfer.elan.min.js +0 -7
- package/dist/plugin/wavesurfer.elan.min.js.map +0 -1
- package/dist/plugin/wavesurfer.markers.js +0 -520
- package/dist/plugin/wavesurfer.markers.js.map +0 -1
- package/dist/plugin/wavesurfer.markers.min.js +0 -7
- package/dist/plugin/wavesurfer.markers.min.js.map +0 -1
- package/dist/plugin/wavesurfer.mediasession.js +0 -181
- package/dist/plugin/wavesurfer.mediasession.js.map +0 -1
- package/dist/plugin/wavesurfer.mediasession.min.js +0 -7
- package/dist/plugin/wavesurfer.mediasession.min.js.map +0 -1
- package/dist/plugin/wavesurfer.microphone.js +0 -466
- package/dist/plugin/wavesurfer.microphone.js.map +0 -1
- package/dist/plugin/wavesurfer.microphone.min.js +0 -7
- package/dist/plugin/wavesurfer.microphone.min.js.map +0 -1
- package/dist/plugin/wavesurfer.minimap.js +0 -440
- package/dist/plugin/wavesurfer.minimap.js.map +0 -1
- package/dist/plugin/wavesurfer.minimap.min.js +0 -7
- package/dist/plugin/wavesurfer.minimap.min.js.map +0 -1
- package/dist/plugin/wavesurfer.playhead.js +0 -300
- package/dist/plugin/wavesurfer.playhead.js.map +0 -1
- package/dist/plugin/wavesurfer.playhead.min.js +0 -7
- package/dist/plugin/wavesurfer.playhead.min.js.map +0 -1
- package/dist/plugin/wavesurfer.regions.js +0 -1342
- package/dist/plugin/wavesurfer.regions.js.map +0 -1
- package/dist/plugin/wavesurfer.regions.min.js +0 -7
- package/dist/plugin/wavesurfer.regions.min.js.map +0 -1
- package/dist/plugin/wavesurfer.spectrogram.js +0 -736
- package/dist/plugin/wavesurfer.spectrogram.js.map +0 -1
- package/dist/plugin/wavesurfer.spectrogram.min.js +0 -7
- package/dist/plugin/wavesurfer.spectrogram.min.js.map +0 -1
- package/dist/plugin/wavesurfer.timeline.js +0 -649
- package/dist/plugin/wavesurfer.timeline.js.map +0 -1
- package/dist/plugin/wavesurfer.timeline.min.js +0 -7
- package/dist/plugin/wavesurfer.timeline.min.js.map +0 -1
- package/dist/wavesurfer-html-init.js +0 -381
- package/dist/wavesurfer-html-init.js.map +0 -1
- package/dist/wavesurfer-html-init.min.js +0 -7
- package/dist/wavesurfer-html-init.min.js.map +0 -1
- package/dist/wavesurfer.js +0 -6145
- package/dist/wavesurfer.js.map +0 -1
- package/dist/wavesurfer.min.js +0 -7
- package/dist/wavesurfer.min.js.map +0 -1
- package/src/drawer.canvasentry.js +0 -427
- package/src/drawer.js +0 -413
- package/src/drawer.multicanvas.js +0 -617
- package/src/html-init.js +0 -241
- package/src/mediaelement-webaudio.js +0 -77
- package/src/mediaelement.js +0 -443
- package/src/peakcache.js +0 -127
- package/src/plugin/cursor/index.js +0 -350
- package/src/plugin/elan/index.js +0 -307
- package/src/plugin/markers/index.js +0 -436
- package/src/plugin/mediasession/index.js +0 -94
- package/src/plugin/microphone/index.js +0 -415
- package/src/plugin/minimap/index.js +0 -403
- package/src/plugin/playhead/index.js +0 -226
- package/src/plugin/regions/index.js +0 -478
- package/src/plugin/regions/region.js +0 -883
- package/src/plugin/spectrogram/fft.js +0 -222
- package/src/plugin/spectrogram/index.js +0 -522
- package/src/plugin/timeline/index.js +0 -600
- package/src/util/absMax.js +0 -16
- package/src/util/clamp.js +0 -11
- package/src/util/fetch.js +0 -222
- package/src/util/frame.js +0 -13
- package/src/util/get-id.js +0 -22
- package/src/util/index.js +0 -14
- package/src/util/max.js +0 -16
- package/src/util/min.js +0 -16
- package/src/util/observer.js +0 -144
- package/src/util/orientation.js +0 -98
- package/src/util/prevent-click.js +0 -19
- package/src/util/request-animation-frame.js +0 -15
- package/src/util/silence-mode.js +0 -42
- package/src/util/style.js +0 -16
- package/src/wavesurfer.js +0 -1797
- package/src/webaudio.js +0 -779
|
@@ -1,649 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* wavesurfer.js timeline plugin 6.5.0 (2023-03-11)
|
|
3
|
-
* https://wavesurfer-js.org
|
|
4
|
-
* @license BSD-3-Clause
|
|
5
|
-
*/
|
|
6
|
-
(function webpackUniversalModuleDefinition(root, factory) {
|
|
7
|
-
if(typeof exports === 'object' && typeof module === 'object')
|
|
8
|
-
module.exports = factory();
|
|
9
|
-
else if(typeof define === 'function' && define.amd)
|
|
10
|
-
define("WaveSurfer", [], factory);
|
|
11
|
-
else if(typeof exports === 'object')
|
|
12
|
-
exports["WaveSurfer"] = factory();
|
|
13
|
-
else
|
|
14
|
-
root["WaveSurfer"] = root["WaveSurfer"] || {}, root["WaveSurfer"]["timeline"] = factory();
|
|
15
|
-
})(self, () => {
|
|
16
|
-
return /******/ (() => { // webpackBootstrap
|
|
17
|
-
/******/ "use strict";
|
|
18
|
-
/******/ var __webpack_modules__ = ({
|
|
19
|
-
|
|
20
|
-
/***/ "./src/plugin/timeline/index.js":
|
|
21
|
-
/*!**************************************!*\
|
|
22
|
-
!*** ./src/plugin/timeline/index.js ***!
|
|
23
|
-
\**************************************/
|
|
24
|
-
/***/ ((module, exports) => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
Object.defineProperty(exports, "__esModule", ({
|
|
29
|
-
value: true
|
|
30
|
-
}));
|
|
31
|
-
exports["default"] = void 0;
|
|
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
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
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); } }
|
|
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; }
|
|
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); }
|
|
39
|
-
/**
|
|
40
|
-
* @typedef {Object} TimelinePluginParams
|
|
41
|
-
* @desc Extends the `WavesurferParams` wavesurfer was initialised with
|
|
42
|
-
* @property {!string|HTMLElement} container CSS selector or HTML element where
|
|
43
|
-
* the timeline should be drawn. This is the only required parameter.
|
|
44
|
-
* @property {number} notchPercentHeight=90 Height of notches in percent
|
|
45
|
-
* @property {string} unlabeledNotchColor='#c0c0c0' The colour of the notches
|
|
46
|
-
* that do not have labels
|
|
47
|
-
* @property {string} primaryColor='#000' The colour of the main notches
|
|
48
|
-
* @property {string} secondaryColor='#c0c0c0' The colour of the secondary
|
|
49
|
-
* notches
|
|
50
|
-
* @property {string} primaryFontColor='#000' The colour of the labels next to
|
|
51
|
-
* the main notches
|
|
52
|
-
* @property {string} secondaryFontColor='#000' The colour of the labels next to
|
|
53
|
-
* the secondary notches
|
|
54
|
-
* @property {number} labelPadding=5 The padding between the label and the notch
|
|
55
|
-
* @property {?number} zoomDebounce A debounce timeout to increase rendering
|
|
56
|
-
* performance for large files
|
|
57
|
-
* @property {string} fontFamily='Arial'
|
|
58
|
-
* @property {number} fontSize=10 Font size of labels in pixels
|
|
59
|
-
* @property {?number} duration Length of the track in seconds. Overrides
|
|
60
|
-
* getDuration() for setting length of timeline
|
|
61
|
-
* @property {function} formatTimeCallback (sec, pxPerSec) -> label
|
|
62
|
-
* @property {function} timeInterval (pxPerSec) -> seconds between notches
|
|
63
|
-
* @property {function} primaryLabelInterval (pxPerSec) -> cadence between
|
|
64
|
-
* labels in primary color
|
|
65
|
-
* @property {function} secondaryLabelInterval (pxPerSec) -> cadence between
|
|
66
|
-
* labels in secondary color
|
|
67
|
-
* @property {?number} offset Offset for the timeline start in seconds. May also be
|
|
68
|
-
* negative.
|
|
69
|
-
* @property {?boolean} deferInit Set to true to manually call
|
|
70
|
-
* `initPlugin('timeline')`
|
|
71
|
-
*/
|
|
72
|
-
/**
|
|
73
|
-
* Adds a timeline to the waveform.
|
|
74
|
-
*
|
|
75
|
-
* @implements {PluginClass}
|
|
76
|
-
* @extends {Observer}
|
|
77
|
-
* @example
|
|
78
|
-
* // es6
|
|
79
|
-
* import TimelinePlugin from 'wavesurfer.timeline.js';
|
|
80
|
-
*
|
|
81
|
-
* // commonjs
|
|
82
|
-
* var TimelinePlugin = require('wavesurfer.timeline.js');
|
|
83
|
-
*
|
|
84
|
-
* // if you are using <script> tags
|
|
85
|
-
* var TimelinePlugin = window.WaveSurfer.timeline;
|
|
86
|
-
*
|
|
87
|
-
* // ... initialising wavesurfer with the plugin
|
|
88
|
-
* var wavesurfer = WaveSurfer.create({
|
|
89
|
-
* // wavesurfer options ...
|
|
90
|
-
* plugins: [
|
|
91
|
-
* TimelinePlugin.create({
|
|
92
|
-
* // plugin options ...
|
|
93
|
-
* })
|
|
94
|
-
* ]
|
|
95
|
-
* });
|
|
96
|
-
*/
|
|
97
|
-
var TimelinePlugin = /*#__PURE__*/function () {
|
|
98
|
-
/**
|
|
99
|
-
* Creates an instance of TimelinePlugin.
|
|
100
|
-
*
|
|
101
|
-
* You probably want to use TimelinePlugin.create()
|
|
102
|
-
*
|
|
103
|
-
* @param {TimelinePluginParams} params Plugin parameters
|
|
104
|
-
* @param {object} ws Wavesurfer instance
|
|
105
|
-
*/
|
|
106
|
-
function TimelinePlugin(params, _ws) {
|
|
107
|
-
var _this = this;
|
|
108
|
-
_classCallCheck(this, TimelinePlugin);
|
|
109
|
-
// event handlers
|
|
110
|
-
_defineProperty(this, "_onScroll", function () {
|
|
111
|
-
if (_this.wrapper && _this.drawer.wrapper) {
|
|
112
|
-
_this.wrapper.scrollLeft = _this.drawer.wrapper.scrollLeft;
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
/**
|
|
116
|
-
* @returns {void}
|
|
117
|
-
*/
|
|
118
|
-
_defineProperty(this, "_onRedraw", function () {
|
|
119
|
-
return _this.render();
|
|
120
|
-
});
|
|
121
|
-
_defineProperty(this, "_onReady", function () {
|
|
122
|
-
var ws = _this.wavesurfer;
|
|
123
|
-
_this.drawer = ws.drawer;
|
|
124
|
-
_this.pixelRatio = ws.drawer.params.pixelRatio;
|
|
125
|
-
_this.maxCanvasWidth = ws.drawer.maxCanvasWidth || ws.drawer.width;
|
|
126
|
-
_this.maxCanvasElementWidth = ws.drawer.maxCanvasElementWidth || Math.round(_this.maxCanvasWidth / _this.pixelRatio);
|
|
127
|
-
|
|
128
|
-
// add listeners
|
|
129
|
-
ws.drawer.wrapper.addEventListener('scroll', _this._onScroll);
|
|
130
|
-
ws.on('redraw', _this._onRedraw);
|
|
131
|
-
ws.on('zoom', _this._onZoom);
|
|
132
|
-
_this.render();
|
|
133
|
-
});
|
|
134
|
-
/**
|
|
135
|
-
* @param {object} e Click event
|
|
136
|
-
*/
|
|
137
|
-
_defineProperty(this, "_onWrapperClick", function (e) {
|
|
138
|
-
e.preventDefault();
|
|
139
|
-
var relX = 'offsetX' in e ? e.offsetX : e.layerX;
|
|
140
|
-
_this.fireEvent('click', relX / _this.wrapper.scrollWidth || 0);
|
|
141
|
-
});
|
|
142
|
-
this.container = 'string' == typeof params.container ? document.querySelector(params.container) : params.container;
|
|
143
|
-
if (!this.container) {
|
|
144
|
-
throw new Error('No container for wavesurfer timeline');
|
|
145
|
-
}
|
|
146
|
-
this.wavesurfer = _ws;
|
|
147
|
-
this.util = _ws.util;
|
|
148
|
-
this.params = Object.assign({}, {
|
|
149
|
-
height: 20,
|
|
150
|
-
notchPercentHeight: 90,
|
|
151
|
-
labelPadding: 5,
|
|
152
|
-
unlabeledNotchColor: '#c0c0c0',
|
|
153
|
-
primaryColor: '#000',
|
|
154
|
-
secondaryColor: '#c0c0c0',
|
|
155
|
-
primaryFontColor: '#000',
|
|
156
|
-
secondaryFontColor: '#000',
|
|
157
|
-
fontFamily: 'Arial',
|
|
158
|
-
fontSize: 10,
|
|
159
|
-
duration: null,
|
|
160
|
-
zoomDebounce: false,
|
|
161
|
-
formatTimeCallback: this.defaultFormatTimeCallback,
|
|
162
|
-
timeInterval: this.defaultTimeInterval,
|
|
163
|
-
primaryLabelInterval: this.defaultPrimaryLabelInterval,
|
|
164
|
-
secondaryLabelInterval: this.defaultSecondaryLabelInterval,
|
|
165
|
-
offset: 0
|
|
166
|
-
}, params);
|
|
167
|
-
this.canvases = [];
|
|
168
|
-
this.wrapper = null;
|
|
169
|
-
this.drawer = null;
|
|
170
|
-
this.pixelRatio = null;
|
|
171
|
-
this.maxCanvasWidth = null;
|
|
172
|
-
this.maxCanvasElementWidth = null;
|
|
173
|
-
/**
|
|
174
|
-
* This event handler has to be in the constructor function because it
|
|
175
|
-
* relies on the debounce function which is only available after
|
|
176
|
-
* instantiation
|
|
177
|
-
*
|
|
178
|
-
* Use a debounced function if `params.zoomDebounce` is defined
|
|
179
|
-
*
|
|
180
|
-
* @returns {void}
|
|
181
|
-
*/
|
|
182
|
-
this._onZoom = this.params.zoomDebounce ? this.wavesurfer.util.debounce(function () {
|
|
183
|
-
return _this.render();
|
|
184
|
-
}, this.params.zoomDebounce) : function () {
|
|
185
|
-
return _this.render();
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* Initialisation function used by the plugin API
|
|
191
|
-
*/
|
|
192
|
-
_createClass(TimelinePlugin, [{
|
|
193
|
-
key: "init",
|
|
194
|
-
value: function init() {
|
|
195
|
-
// Check if ws is ready
|
|
196
|
-
if (this.wavesurfer.isReady) {
|
|
197
|
-
this._onReady();
|
|
198
|
-
} else {
|
|
199
|
-
this.wavesurfer.once('ready', this._onReady);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* Destroy function used by the plugin API
|
|
205
|
-
*/
|
|
206
|
-
}, {
|
|
207
|
-
key: "destroy",
|
|
208
|
-
value: function destroy() {
|
|
209
|
-
this.unAll();
|
|
210
|
-
this.wavesurfer.un('redraw', this._onRedraw);
|
|
211
|
-
this.wavesurfer.un('zoom', this._onZoom);
|
|
212
|
-
this.wavesurfer.un('ready', this._onReady);
|
|
213
|
-
this.wavesurfer.drawer.wrapper.removeEventListener('scroll', this._onScroll);
|
|
214
|
-
if (this.wrapper && this.wrapper.parentNode) {
|
|
215
|
-
this.wrapper.removeEventListener('click', this._onWrapperClick);
|
|
216
|
-
this.wrapper.parentNode.removeChild(this.wrapper);
|
|
217
|
-
this.wrapper = null;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* Create a timeline element to wrap the canvases drawn by this plugin
|
|
223
|
-
*
|
|
224
|
-
*/
|
|
225
|
-
}, {
|
|
226
|
-
key: "createWrapper",
|
|
227
|
-
value: function createWrapper() {
|
|
228
|
-
var wsParams = this.wavesurfer.params;
|
|
229
|
-
this.container.innerHTML = '';
|
|
230
|
-
this.wrapper = this.container.appendChild(document.createElement('timeline'));
|
|
231
|
-
this.util.style(this.wrapper, {
|
|
232
|
-
display: 'block',
|
|
233
|
-
position: 'relative',
|
|
234
|
-
userSelect: 'none',
|
|
235
|
-
webkitUserSelect: 'none',
|
|
236
|
-
height: "".concat(this.params.height, "px")
|
|
237
|
-
});
|
|
238
|
-
if (wsParams.fillParent || wsParams.scrollParent) {
|
|
239
|
-
this.util.style(this.wrapper, {
|
|
240
|
-
width: '100%',
|
|
241
|
-
overflowX: 'hidden',
|
|
242
|
-
overflowY: 'hidden'
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
this.wrapper.addEventListener('click', this._onWrapperClick);
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
/**
|
|
249
|
-
* Render the timeline (also updates the already rendered timeline)
|
|
250
|
-
*
|
|
251
|
-
*/
|
|
252
|
-
}, {
|
|
253
|
-
key: "render",
|
|
254
|
-
value: function render() {
|
|
255
|
-
if (!this.wrapper) {
|
|
256
|
-
this.createWrapper();
|
|
257
|
-
}
|
|
258
|
-
this.updateCanvases();
|
|
259
|
-
this.updateCanvasesPositioning();
|
|
260
|
-
this.renderCanvases();
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
/**
|
|
264
|
-
* Add new timeline canvas
|
|
265
|
-
*
|
|
266
|
-
*/
|
|
267
|
-
}, {
|
|
268
|
-
key: "addCanvas",
|
|
269
|
-
value: function addCanvas() {
|
|
270
|
-
var canvas = this.wrapper.appendChild(document.createElement('canvas'));
|
|
271
|
-
this.canvases.push(canvas);
|
|
272
|
-
this.util.style(canvas, {
|
|
273
|
-
position: 'absolute',
|
|
274
|
-
zIndex: 4
|
|
275
|
-
});
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
/**
|
|
279
|
-
* Remove timeline canvas
|
|
280
|
-
*
|
|
281
|
-
*/
|
|
282
|
-
}, {
|
|
283
|
-
key: "removeCanvas",
|
|
284
|
-
value: function removeCanvas() {
|
|
285
|
-
var canvas = this.canvases.pop();
|
|
286
|
-
canvas.parentElement.removeChild(canvas);
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
/**
|
|
290
|
-
* Make sure the correct of timeline canvas elements exist and are cached in
|
|
291
|
-
* this.canvases
|
|
292
|
-
*
|
|
293
|
-
*/
|
|
294
|
-
}, {
|
|
295
|
-
key: "updateCanvases",
|
|
296
|
-
value: function updateCanvases() {
|
|
297
|
-
var totalWidth = Math.round(this.drawer.wrapper.scrollWidth);
|
|
298
|
-
var requiredCanvases = Math.ceil(totalWidth / this.maxCanvasElementWidth);
|
|
299
|
-
while (this.canvases.length < requiredCanvases) {
|
|
300
|
-
this.addCanvas();
|
|
301
|
-
}
|
|
302
|
-
while (this.canvases.length > requiredCanvases) {
|
|
303
|
-
this.removeCanvas();
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
/**
|
|
308
|
-
* Update the dimensions and positioning style for all the timeline canvases
|
|
309
|
-
*
|
|
310
|
-
*/
|
|
311
|
-
}, {
|
|
312
|
-
key: "updateCanvasesPositioning",
|
|
313
|
-
value: function updateCanvasesPositioning() {
|
|
314
|
-
var _this2 = this;
|
|
315
|
-
// cache length for performance
|
|
316
|
-
var canvasesLength = this.canvases.length;
|
|
317
|
-
this.canvases.forEach(function (canvas, i) {
|
|
318
|
-
// canvas width is the max element width, or if it is the last the
|
|
319
|
-
// required width
|
|
320
|
-
var canvasWidth = i === canvasesLength - 1 ? _this2.drawer.wrapper.scrollWidth - _this2.maxCanvasElementWidth * (canvasesLength - 1) : _this2.maxCanvasElementWidth;
|
|
321
|
-
// set dimensions and style
|
|
322
|
-
canvas.width = canvasWidth * _this2.pixelRatio;
|
|
323
|
-
// on certain pixel ratios the canvas appears cut off at the bottom,
|
|
324
|
-
// therefore leave 1px extra
|
|
325
|
-
canvas.height = (_this2.params.height + 1) * _this2.pixelRatio;
|
|
326
|
-
_this2.util.style(canvas, {
|
|
327
|
-
width: "".concat(canvasWidth, "px"),
|
|
328
|
-
height: "".concat(_this2.params.height, "px"),
|
|
329
|
-
left: "".concat(i * _this2.maxCanvasElementWidth, "px")
|
|
330
|
-
});
|
|
331
|
-
});
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
/**
|
|
335
|
-
* Render the timeline labels and notches
|
|
336
|
-
*
|
|
337
|
-
*/
|
|
338
|
-
}, {
|
|
339
|
-
key: "renderCanvases",
|
|
340
|
-
value: function renderCanvases() {
|
|
341
|
-
var _this3 = this;
|
|
342
|
-
var duration = this.params.duration || this.wavesurfer.backend.getDuration();
|
|
343
|
-
if (duration <= 0) {
|
|
344
|
-
return;
|
|
345
|
-
}
|
|
346
|
-
var wsParams = this.wavesurfer.params;
|
|
347
|
-
var fontSize = this.params.fontSize * wsParams.pixelRatio;
|
|
348
|
-
var totalSeconds = parseInt(duration, 10) + 1;
|
|
349
|
-
var width = wsParams.fillParent && !wsParams.scrollParent ? this.drawer.getWidth() : this.drawer.wrapper.scrollWidth * wsParams.pixelRatio;
|
|
350
|
-
var height1 = this.params.height * this.pixelRatio;
|
|
351
|
-
var height2 = this.params.height * (this.params.notchPercentHeight / 100) * this.pixelRatio;
|
|
352
|
-
var pixelsPerSecond = width / duration;
|
|
353
|
-
var formatTime = this.params.formatTimeCallback;
|
|
354
|
-
// if parameter is function, call the function with
|
|
355
|
-
// pixelsPerSecond, otherwise simply take the value as-is
|
|
356
|
-
var intervalFnOrVal = function intervalFnOrVal(option) {
|
|
357
|
-
return typeof option === 'function' ? option(pixelsPerSecond) : option;
|
|
358
|
-
};
|
|
359
|
-
var timeInterval = intervalFnOrVal(this.params.timeInterval);
|
|
360
|
-
var primaryLabelInterval = intervalFnOrVal(this.params.primaryLabelInterval);
|
|
361
|
-
var secondaryLabelInterval = intervalFnOrVal(this.params.secondaryLabelInterval);
|
|
362
|
-
var curPixel = pixelsPerSecond * this.params.offset;
|
|
363
|
-
var curSeconds = 0;
|
|
364
|
-
var i;
|
|
365
|
-
// build an array of position data with index, second and pixel data,
|
|
366
|
-
// this is then used multiple times below
|
|
367
|
-
var positioning = [];
|
|
368
|
-
|
|
369
|
-
// render until end in case we have a negative offset
|
|
370
|
-
var renderSeconds = this.params.offset < 0 ? totalSeconds - this.params.offset : totalSeconds;
|
|
371
|
-
for (i = 0; i < renderSeconds / timeInterval; i++) {
|
|
372
|
-
positioning.push([i, curSeconds, curPixel]);
|
|
373
|
-
curSeconds += timeInterval;
|
|
374
|
-
curPixel += pixelsPerSecond * timeInterval;
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
// iterate over each position
|
|
378
|
-
var renderPositions = function renderPositions(cb) {
|
|
379
|
-
positioning.forEach(function (pos) {
|
|
380
|
-
cb(pos[0], pos[1], pos[2]);
|
|
381
|
-
});
|
|
382
|
-
};
|
|
383
|
-
|
|
384
|
-
// render primary labels
|
|
385
|
-
this.setFillStyles(this.params.primaryColor);
|
|
386
|
-
this.setFonts("".concat(fontSize, "px ").concat(this.params.fontFamily));
|
|
387
|
-
this.setFillStyles(this.params.primaryFontColor);
|
|
388
|
-
renderPositions(function (i, curSeconds, curPixel) {
|
|
389
|
-
if (i % primaryLabelInterval === 0) {
|
|
390
|
-
_this3.fillRect(curPixel, 0, 1, height1);
|
|
391
|
-
_this3.fillText(formatTime(curSeconds, pixelsPerSecond), curPixel + _this3.params.labelPadding * _this3.pixelRatio, height1);
|
|
392
|
-
}
|
|
393
|
-
});
|
|
394
|
-
|
|
395
|
-
// render secondary labels
|
|
396
|
-
this.setFillStyles(this.params.secondaryColor);
|
|
397
|
-
this.setFonts("".concat(fontSize, "px ").concat(this.params.fontFamily));
|
|
398
|
-
this.setFillStyles(this.params.secondaryFontColor);
|
|
399
|
-
renderPositions(function (i, curSeconds, curPixel) {
|
|
400
|
-
if (i % secondaryLabelInterval === 0) {
|
|
401
|
-
_this3.fillRect(curPixel, 0, 1, height1);
|
|
402
|
-
_this3.fillText(formatTime(curSeconds, pixelsPerSecond), curPixel + _this3.params.labelPadding * _this3.pixelRatio, height1);
|
|
403
|
-
}
|
|
404
|
-
});
|
|
405
|
-
|
|
406
|
-
// render the actual notches (when no labels are used)
|
|
407
|
-
this.setFillStyles(this.params.unlabeledNotchColor);
|
|
408
|
-
renderPositions(function (i, curSeconds, curPixel) {
|
|
409
|
-
if (i % secondaryLabelInterval !== 0 && i % primaryLabelInterval !== 0) {
|
|
410
|
-
_this3.fillRect(curPixel, 0, 1, height2);
|
|
411
|
-
}
|
|
412
|
-
});
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
/**
|
|
416
|
-
* Set the canvas fill style
|
|
417
|
-
*
|
|
418
|
-
* @param {DOMString|CanvasGradient|CanvasPattern} fillStyle Fill style to
|
|
419
|
-
* use
|
|
420
|
-
*/
|
|
421
|
-
}, {
|
|
422
|
-
key: "setFillStyles",
|
|
423
|
-
value: function setFillStyles(fillStyle) {
|
|
424
|
-
this.canvases.forEach(function (canvas) {
|
|
425
|
-
var context = canvas.getContext('2d');
|
|
426
|
-
if (context) {
|
|
427
|
-
context.fillStyle = fillStyle;
|
|
428
|
-
}
|
|
429
|
-
});
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
/**
|
|
433
|
-
* Set the canvas font
|
|
434
|
-
*
|
|
435
|
-
* @param {DOMString} font Font to use
|
|
436
|
-
*/
|
|
437
|
-
}, {
|
|
438
|
-
key: "setFonts",
|
|
439
|
-
value: function setFonts(font) {
|
|
440
|
-
this.canvases.forEach(function (canvas) {
|
|
441
|
-
var context = canvas.getContext('2d');
|
|
442
|
-
if (context) {
|
|
443
|
-
context.font = font;
|
|
444
|
-
}
|
|
445
|
-
});
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
/**
|
|
449
|
-
* Draw a rectangle on the canvases
|
|
450
|
-
*
|
|
451
|
-
* (it figures out the offset for each canvas)
|
|
452
|
-
*
|
|
453
|
-
* @param {number} x X-position
|
|
454
|
-
* @param {number} y Y-position
|
|
455
|
-
* @param {number} width Width
|
|
456
|
-
* @param {number} height Height
|
|
457
|
-
*/
|
|
458
|
-
}, {
|
|
459
|
-
key: "fillRect",
|
|
460
|
-
value: function fillRect(x, y, width, height) {
|
|
461
|
-
var _this4 = this;
|
|
462
|
-
this.canvases.forEach(function (canvas, i) {
|
|
463
|
-
var leftOffset = i * _this4.maxCanvasWidth;
|
|
464
|
-
var intersection = {
|
|
465
|
-
x1: Math.max(x, i * _this4.maxCanvasWidth),
|
|
466
|
-
y1: y,
|
|
467
|
-
x2: Math.min(x + width, i * _this4.maxCanvasWidth + canvas.width),
|
|
468
|
-
y2: y + height
|
|
469
|
-
};
|
|
470
|
-
if (intersection.x1 < intersection.x2) {
|
|
471
|
-
var context = canvas.getContext('2d');
|
|
472
|
-
if (context) {
|
|
473
|
-
context.fillRect(intersection.x1 - leftOffset, intersection.y1, intersection.x2 - intersection.x1, intersection.y2 - intersection.y1);
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
});
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
/**
|
|
480
|
-
* Fill a given text on the canvases
|
|
481
|
-
*
|
|
482
|
-
* @param {string} text Text to render
|
|
483
|
-
* @param {number} x X-position
|
|
484
|
-
* @param {number} y Y-position
|
|
485
|
-
*/
|
|
486
|
-
}, {
|
|
487
|
-
key: "fillText",
|
|
488
|
-
value: function fillText(text, x, y) {
|
|
489
|
-
var textWidth;
|
|
490
|
-
var xOffset = 0;
|
|
491
|
-
this.canvases.forEach(function (canvas) {
|
|
492
|
-
var context = canvas.getContext('2d');
|
|
493
|
-
if (context) {
|
|
494
|
-
var canvasWidth = context.canvas.width;
|
|
495
|
-
if (xOffset > x + textWidth) {
|
|
496
|
-
return;
|
|
497
|
-
}
|
|
498
|
-
if (xOffset + canvasWidth > x && context) {
|
|
499
|
-
textWidth = context.measureText(text).width;
|
|
500
|
-
context.fillText(text, x - xOffset, y);
|
|
501
|
-
}
|
|
502
|
-
xOffset += canvasWidth;
|
|
503
|
-
}
|
|
504
|
-
});
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
/**
|
|
508
|
-
* Turn the time into a suitable label for the time.
|
|
509
|
-
*
|
|
510
|
-
* @param {number} seconds Seconds to format
|
|
511
|
-
* @param {number} pxPerSec Pixels per second
|
|
512
|
-
* @returns {number} Time
|
|
513
|
-
*/
|
|
514
|
-
}, {
|
|
515
|
-
key: "defaultFormatTimeCallback",
|
|
516
|
-
value: function defaultFormatTimeCallback(seconds, pxPerSec) {
|
|
517
|
-
if (seconds / 60 > 1) {
|
|
518
|
-
// calculate minutes and seconds from seconds count
|
|
519
|
-
var minutes = parseInt(seconds / 60, 10);
|
|
520
|
-
seconds = parseInt(seconds % 60, 10);
|
|
521
|
-
// fill up seconds with zeroes
|
|
522
|
-
seconds = seconds < 10 ? '0' + seconds : seconds;
|
|
523
|
-
return "".concat(minutes, ":").concat(seconds);
|
|
524
|
-
}
|
|
525
|
-
return Math.round(seconds * 1000) / 1000;
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
/**
|
|
529
|
-
* Return how many seconds should be between each notch
|
|
530
|
-
*
|
|
531
|
-
* @param {number} pxPerSec Pixels per second
|
|
532
|
-
* @returns {number} Time
|
|
533
|
-
*/
|
|
534
|
-
}, {
|
|
535
|
-
key: "defaultTimeInterval",
|
|
536
|
-
value: function defaultTimeInterval(pxPerSec) {
|
|
537
|
-
if (pxPerSec >= 25) {
|
|
538
|
-
return 1;
|
|
539
|
-
} else if (pxPerSec * 5 >= 25) {
|
|
540
|
-
return 5;
|
|
541
|
-
} else if (pxPerSec * 15 >= 25) {
|
|
542
|
-
return 15;
|
|
543
|
-
}
|
|
544
|
-
return Math.ceil(0.5 / pxPerSec) * 60;
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
/**
|
|
548
|
-
* Return the cadence of notches that get labels in the primary color.
|
|
549
|
-
*
|
|
550
|
-
* @param {number} pxPerSec Pixels per second
|
|
551
|
-
* @returns {number} Cadence
|
|
552
|
-
*/
|
|
553
|
-
}, {
|
|
554
|
-
key: "defaultPrimaryLabelInterval",
|
|
555
|
-
value: function defaultPrimaryLabelInterval(pxPerSec) {
|
|
556
|
-
if (pxPerSec >= 25) {
|
|
557
|
-
return 10;
|
|
558
|
-
} else if (pxPerSec * 5 >= 25) {
|
|
559
|
-
return 6;
|
|
560
|
-
} else if (pxPerSec * 15 >= 25) {
|
|
561
|
-
return 4;
|
|
562
|
-
}
|
|
563
|
-
return 4;
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
/**
|
|
567
|
-
* Return the cadence of notches that get labels in the secondary color.
|
|
568
|
-
*
|
|
569
|
-
* @param {number} pxPerSec Pixels per second
|
|
570
|
-
* @returns {number} Cadence
|
|
571
|
-
*/
|
|
572
|
-
}, {
|
|
573
|
-
key: "defaultSecondaryLabelInterval",
|
|
574
|
-
value: function defaultSecondaryLabelInterval(pxPerSec) {
|
|
575
|
-
if (pxPerSec >= 25) {
|
|
576
|
-
return 5;
|
|
577
|
-
} else if (pxPerSec * 5 >= 25) {
|
|
578
|
-
return 2;
|
|
579
|
-
} else if (pxPerSec * 15 >= 25) {
|
|
580
|
-
return 2;
|
|
581
|
-
}
|
|
582
|
-
return 2;
|
|
583
|
-
}
|
|
584
|
-
}], [{
|
|
585
|
-
key: "create",
|
|
586
|
-
value:
|
|
587
|
-
/**
|
|
588
|
-
* Timeline plugin definition factory
|
|
589
|
-
*
|
|
590
|
-
* This function must be used to create a plugin definition which can be
|
|
591
|
-
* used by wavesurfer to correctly instantiate the plugin.
|
|
592
|
-
*
|
|
593
|
-
* @param {TimelinePluginParams} params parameters use to initialise the plugin
|
|
594
|
-
* @return {PluginDefinition} an object representing the plugin
|
|
595
|
-
*/
|
|
596
|
-
function create(params) {
|
|
597
|
-
return {
|
|
598
|
-
name: 'timeline',
|
|
599
|
-
deferInit: params && params.deferInit ? params.deferInit : false,
|
|
600
|
-
params: params,
|
|
601
|
-
instance: TimelinePlugin
|
|
602
|
-
};
|
|
603
|
-
}
|
|
604
|
-
}]);
|
|
605
|
-
return TimelinePlugin;
|
|
606
|
-
}();
|
|
607
|
-
exports["default"] = TimelinePlugin;
|
|
608
|
-
module.exports = exports.default;
|
|
609
|
-
|
|
610
|
-
/***/ })
|
|
611
|
-
|
|
612
|
-
/******/ });
|
|
613
|
-
/************************************************************************/
|
|
614
|
-
/******/ // The module cache
|
|
615
|
-
/******/ var __webpack_module_cache__ = {};
|
|
616
|
-
/******/
|
|
617
|
-
/******/ // The require function
|
|
618
|
-
/******/ function __webpack_require__(moduleId) {
|
|
619
|
-
/******/ // Check if module is in cache
|
|
620
|
-
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
|
621
|
-
/******/ if (cachedModule !== undefined) {
|
|
622
|
-
/******/ return cachedModule.exports;
|
|
623
|
-
/******/ }
|
|
624
|
-
/******/ // Create a new module (and put it into the cache)
|
|
625
|
-
/******/ var module = __webpack_module_cache__[moduleId] = {
|
|
626
|
-
/******/ // no module.id needed
|
|
627
|
-
/******/ // no module.loaded needed
|
|
628
|
-
/******/ exports: {}
|
|
629
|
-
/******/ };
|
|
630
|
-
/******/
|
|
631
|
-
/******/ // Execute the module function
|
|
632
|
-
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
633
|
-
/******/
|
|
634
|
-
/******/ // Return the exports of the module
|
|
635
|
-
/******/ return module.exports;
|
|
636
|
-
/******/ }
|
|
637
|
-
/******/
|
|
638
|
-
/************************************************************************/
|
|
639
|
-
/******/
|
|
640
|
-
/******/ // startup
|
|
641
|
-
/******/ // Load entry module and return exports
|
|
642
|
-
/******/ // This entry module is referenced by other modules so it can't be inlined
|
|
643
|
-
/******/ var __webpack_exports__ = __webpack_require__("./src/plugin/timeline/index.js");
|
|
644
|
-
/******/
|
|
645
|
-
/******/ return __webpack_exports__;
|
|
646
|
-
/******/ })()
|
|
647
|
-
;
|
|
648
|
-
});
|
|
649
|
-
//# sourceMappingURL=wavesurfer.timeline.js.map
|