wavesurfer.js 6.2.0 → 6.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +1 -10
- package/dist/plugin/wavesurfer.cursor.js +29 -49
- package/dist/plugin/wavesurfer.cursor.js.map +1 -1
- package/dist/plugin/wavesurfer.cursor.min.js +2 -2
- package/dist/plugin/wavesurfer.cursor.min.js.map +1 -1
- package/dist/plugin/wavesurfer.elan.js +19 -49
- package/dist/plugin/wavesurfer.elan.js.map +1 -1
- package/dist/plugin/wavesurfer.elan.min.js +1 -1
- package/dist/plugin/wavesurfer.elan.min.js.map +1 -1
- package/dist/plugin/wavesurfer.markers.js +87 -67
- package/dist/plugin/wavesurfer.markers.js.map +1 -1
- package/dist/plugin/wavesurfer.markers.min.js +2 -2
- package/dist/plugin/wavesurfer.markers.min.js.map +1 -1
- package/dist/plugin/wavesurfer.mediasession.js +5 -15
- package/dist/plugin/wavesurfer.mediasession.js.map +1 -1
- package/dist/plugin/wavesurfer.mediasession.min.js +1 -1
- package/dist/plugin/wavesurfer.mediasession.min.js.map +1 -1
- package/dist/plugin/wavesurfer.microphone.js +44 -62
- package/dist/plugin/wavesurfer.microphone.js.map +1 -1
- package/dist/plugin/wavesurfer.microphone.min.js +1 -1
- package/dist/plugin/wavesurfer.microphone.min.js.map +1 -1
- package/dist/plugin/wavesurfer.minimap.js +16 -68
- package/dist/plugin/wavesurfer.minimap.js.map +1 -1
- package/dist/plugin/wavesurfer.minimap.min.js +1 -1
- package/dist/plugin/wavesurfer.minimap.min.js.map +1 -1
- package/dist/plugin/wavesurfer.playhead.js +2 -29
- package/dist/plugin/wavesurfer.playhead.js.map +1 -1
- package/dist/plugin/wavesurfer.playhead.min.js +1 -1
- package/dist/plugin/wavesurfer.playhead.min.js.map +1 -1
- package/dist/plugin/wavesurfer.regions.js +99 -253
- package/dist/plugin/wavesurfer.regions.js.map +1 -1
- package/dist/plugin/wavesurfer.regions.min.js +2 -2
- package/dist/plugin/wavesurfer.regions.min.js.map +1 -1
- package/dist/plugin/wavesurfer.spectrogram.js +52 -147
- package/dist/plugin/wavesurfer.spectrogram.js.map +1 -1
- package/dist/plugin/wavesurfer.spectrogram.min.js +2 -2
- package/dist/plugin/wavesurfer.spectrogram.min.js.map +1 -1
- package/dist/plugin/wavesurfer.timeline.js +42 -85
- package/dist/plugin/wavesurfer.timeline.js.map +1 -1
- package/dist/plugin/wavesurfer.timeline.min.js +1 -1
- package/dist/plugin/wavesurfer.timeline.min.js.map +1 -1
- package/dist/wavesurfer-html-init.js +31 -53
- package/dist/wavesurfer-html-init.js.map +1 -1
- package/dist/wavesurfer-html-init.min.js +1 -1
- package/dist/wavesurfer-html-init.min.js.map +1 -1
- package/dist/wavesurfer.js +448 -1008
- package/dist/wavesurfer.js.map +1 -1
- package/dist/wavesurfer.min.js +2 -2
- package/dist/wavesurfer.min.js.map +1 -1
- package/package.json +18 -19
- package/src/drawer.multicanvas.js +4 -4
- package/src/plugin/cursor/index.js +15 -3
- package/src/plugin/markers/index.js +70 -5
- package/src/plugin/regions/index.js +1 -1
- package/src/plugin/spectrogram/index.js +1 -1
- package/src/wavesurfer.js +12 -9
- package/CHANGES.md +0 -474
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* wavesurfer.js timeline plugin 6.
|
|
2
|
+
* wavesurfer.js timeline plugin 6.4.0 (2022-11-05)
|
|
3
3
|
* https://wavesurfer-js.org
|
|
4
4
|
* @license BSD-3-Clause
|
|
5
5
|
*/
|
|
@@ -29,15 +29,10 @@ Object.defineProperty(exports, "__esModule", ({
|
|
|
29
29
|
value: true
|
|
30
30
|
}));
|
|
31
31
|
exports["default"] = void 0;
|
|
32
|
-
|
|
33
32
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
34
|
-
|
|
35
33
|
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
|
-
|
|
37
34
|
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
35
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
40
|
-
|
|
41
36
|
/**
|
|
42
37
|
* @typedef {Object} TimelinePluginParams
|
|
43
38
|
* @desc Extends the `WavesurferParams` wavesurfer was initialised with
|
|
@@ -71,7 +66,6 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
71
66
|
* @property {?boolean} deferInit Set to true to manually call
|
|
72
67
|
* `initPlugin('timeline')`
|
|
73
68
|
*/
|
|
74
|
-
|
|
75
69
|
/**
|
|
76
70
|
* Adds a timeline to the waveform.
|
|
77
71
|
*
|
|
@@ -108,46 +102,37 @@ var TimelinePlugin = /*#__PURE__*/function () {
|
|
|
108
102
|
*/
|
|
109
103
|
function TimelinePlugin(params, _ws) {
|
|
110
104
|
var _this = this;
|
|
111
|
-
|
|
112
105
|
_classCallCheck(this, TimelinePlugin);
|
|
113
|
-
|
|
114
106
|
_defineProperty(this, "_onScroll", function () {
|
|
115
107
|
if (_this.wrapper && _this.drawer.wrapper) {
|
|
116
108
|
_this.wrapper.scrollLeft = _this.drawer.wrapper.scrollLeft;
|
|
117
109
|
}
|
|
118
110
|
});
|
|
119
|
-
|
|
120
111
|
_defineProperty(this, "_onRedraw", function () {
|
|
121
112
|
return _this.render();
|
|
122
113
|
});
|
|
123
|
-
|
|
124
114
|
_defineProperty(this, "_onReady", function () {
|
|
125
115
|
var ws = _this.wavesurfer;
|
|
126
116
|
_this.drawer = ws.drawer;
|
|
127
117
|
_this.pixelRatio = ws.drawer.params.pixelRatio;
|
|
128
118
|
_this.maxCanvasWidth = ws.drawer.maxCanvasWidth || ws.drawer.width;
|
|
129
|
-
_this.maxCanvasElementWidth = ws.drawer.maxCanvasElementWidth || Math.round(_this.maxCanvasWidth / _this.pixelRatio);
|
|
119
|
+
_this.maxCanvasElementWidth = ws.drawer.maxCanvasElementWidth || Math.round(_this.maxCanvasWidth / _this.pixelRatio);
|
|
130
120
|
|
|
121
|
+
// add listeners
|
|
131
122
|
ws.drawer.wrapper.addEventListener('scroll', _this._onScroll);
|
|
132
123
|
ws.on('redraw', _this._onRedraw);
|
|
133
124
|
ws.on('zoom', _this._onZoom);
|
|
134
|
-
|
|
135
125
|
_this.render();
|
|
136
126
|
});
|
|
137
|
-
|
|
138
127
|
_defineProperty(this, "_onWrapperClick", function (e) {
|
|
139
128
|
e.preventDefault();
|
|
140
129
|
var relX = 'offsetX' in e ? e.offsetX : e.layerX;
|
|
141
|
-
|
|
142
130
|
_this.fireEvent('click', relX / _this.wrapper.scrollWidth || 0);
|
|
143
131
|
});
|
|
144
|
-
|
|
145
132
|
this.container = 'string' == typeof params.container ? document.querySelector(params.container) : params.container;
|
|
146
|
-
|
|
147
133
|
if (!this.container) {
|
|
148
134
|
throw new Error('No container for wavesurfer timeline');
|
|
149
135
|
}
|
|
150
|
-
|
|
151
136
|
this.wavesurfer = _ws;
|
|
152
137
|
this.util = _ws.util;
|
|
153
138
|
this.params = Object.assign({}, {
|
|
@@ -184,18 +169,16 @@ var TimelinePlugin = /*#__PURE__*/function () {
|
|
|
184
169
|
*
|
|
185
170
|
* @returns {void}
|
|
186
171
|
*/
|
|
187
|
-
|
|
188
172
|
this._onZoom = this.params.zoomDebounce ? this.wavesurfer.util.debounce(function () {
|
|
189
173
|
return _this.render();
|
|
190
174
|
}, this.params.zoomDebounce) : function () {
|
|
191
175
|
return _this.render();
|
|
192
176
|
};
|
|
193
177
|
}
|
|
178
|
+
|
|
194
179
|
/**
|
|
195
180
|
* Initialisation function used by the plugin API
|
|
196
181
|
*/
|
|
197
|
-
|
|
198
|
-
|
|
199
182
|
_createClass(TimelinePlugin, [{
|
|
200
183
|
key: "init",
|
|
201
184
|
value: function init() {
|
|
@@ -206,10 +189,10 @@ var TimelinePlugin = /*#__PURE__*/function () {
|
|
|
206
189
|
this.wavesurfer.once('ready', this._onReady);
|
|
207
190
|
}
|
|
208
191
|
}
|
|
192
|
+
|
|
209
193
|
/**
|
|
210
194
|
* Destroy function used by the plugin API
|
|
211
195
|
*/
|
|
212
|
-
|
|
213
196
|
}, {
|
|
214
197
|
key: "destroy",
|
|
215
198
|
value: function destroy() {
|
|
@@ -218,18 +201,17 @@ var TimelinePlugin = /*#__PURE__*/function () {
|
|
|
218
201
|
this.wavesurfer.un('zoom', this._onZoom);
|
|
219
202
|
this.wavesurfer.un('ready', this._onReady);
|
|
220
203
|
this.wavesurfer.drawer.wrapper.removeEventListener('scroll', this._onScroll);
|
|
221
|
-
|
|
222
204
|
if (this.wrapper && this.wrapper.parentNode) {
|
|
223
205
|
this.wrapper.removeEventListener('click', this._onWrapperClick);
|
|
224
206
|
this.wrapper.parentNode.removeChild(this.wrapper);
|
|
225
207
|
this.wrapper = null;
|
|
226
208
|
}
|
|
227
209
|
}
|
|
210
|
+
|
|
228
211
|
/**
|
|
229
212
|
* Create a timeline element to wrap the canvases drawn by this plugin
|
|
230
213
|
*
|
|
231
214
|
*/
|
|
232
|
-
|
|
233
215
|
}, {
|
|
234
216
|
key: "createWrapper",
|
|
235
217
|
value: function createWrapper() {
|
|
@@ -243,7 +225,6 @@ var TimelinePlugin = /*#__PURE__*/function () {
|
|
|
243
225
|
webkitUserSelect: 'none',
|
|
244
226
|
height: "".concat(this.params.height, "px")
|
|
245
227
|
});
|
|
246
|
-
|
|
247
228
|
if (wsParams.fillParent || wsParams.scrollParent) {
|
|
248
229
|
this.util.style(this.wrapper, {
|
|
249
230
|
width: '100%',
|
|
@@ -251,30 +232,28 @@ var TimelinePlugin = /*#__PURE__*/function () {
|
|
|
251
232
|
overflowY: 'hidden'
|
|
252
233
|
});
|
|
253
234
|
}
|
|
254
|
-
|
|
255
235
|
this.wrapper.addEventListener('click', this._onWrapperClick);
|
|
256
236
|
}
|
|
237
|
+
|
|
257
238
|
/**
|
|
258
239
|
* Render the timeline (also updates the already rendered timeline)
|
|
259
240
|
*
|
|
260
241
|
*/
|
|
261
|
-
|
|
262
242
|
}, {
|
|
263
243
|
key: "render",
|
|
264
244
|
value: function render() {
|
|
265
245
|
if (!this.wrapper) {
|
|
266
246
|
this.createWrapper();
|
|
267
247
|
}
|
|
268
|
-
|
|
269
248
|
this.updateCanvases();
|
|
270
249
|
this.updateCanvasesPositioning();
|
|
271
250
|
this.renderCanvases();
|
|
272
251
|
}
|
|
252
|
+
|
|
273
253
|
/**
|
|
274
254
|
* Add new timeline canvas
|
|
275
255
|
*
|
|
276
256
|
*/
|
|
277
|
-
|
|
278
257
|
}, {
|
|
279
258
|
key: "addCanvas",
|
|
280
259
|
value: function addCanvas() {
|
|
@@ -285,59 +264,55 @@ var TimelinePlugin = /*#__PURE__*/function () {
|
|
|
285
264
|
zIndex: 4
|
|
286
265
|
});
|
|
287
266
|
}
|
|
267
|
+
|
|
288
268
|
/**
|
|
289
269
|
* Remove timeline canvas
|
|
290
270
|
*
|
|
291
271
|
*/
|
|
292
|
-
|
|
293
272
|
}, {
|
|
294
273
|
key: "removeCanvas",
|
|
295
274
|
value: function removeCanvas() {
|
|
296
275
|
var canvas = this.canvases.pop();
|
|
297
276
|
canvas.parentElement.removeChild(canvas);
|
|
298
277
|
}
|
|
278
|
+
|
|
299
279
|
/**
|
|
300
280
|
* Make sure the correct of timeline canvas elements exist and are cached in
|
|
301
281
|
* this.canvases
|
|
302
282
|
*
|
|
303
283
|
*/
|
|
304
|
-
|
|
305
284
|
}, {
|
|
306
285
|
key: "updateCanvases",
|
|
307
286
|
value: function updateCanvases() {
|
|
308
287
|
var totalWidth = Math.round(this.drawer.wrapper.scrollWidth);
|
|
309
288
|
var requiredCanvases = Math.ceil(totalWidth / this.maxCanvasElementWidth);
|
|
310
|
-
|
|
311
289
|
while (this.canvases.length < requiredCanvases) {
|
|
312
290
|
this.addCanvas();
|
|
313
291
|
}
|
|
314
|
-
|
|
315
292
|
while (this.canvases.length > requiredCanvases) {
|
|
316
293
|
this.removeCanvas();
|
|
317
294
|
}
|
|
318
295
|
}
|
|
296
|
+
|
|
319
297
|
/**
|
|
320
298
|
* Update the dimensions and positioning style for all the timeline canvases
|
|
321
299
|
*
|
|
322
300
|
*/
|
|
323
|
-
|
|
324
301
|
}, {
|
|
325
302
|
key: "updateCanvasesPositioning",
|
|
326
303
|
value: function updateCanvasesPositioning() {
|
|
327
304
|
var _this2 = this;
|
|
328
|
-
|
|
329
305
|
// cache length for performance
|
|
330
306
|
var canvasesLength = this.canvases.length;
|
|
331
307
|
this.canvases.forEach(function (canvas, i) {
|
|
332
308
|
// canvas width is the max element width, or if it is the last the
|
|
333
309
|
// required width
|
|
334
|
-
var canvasWidth = i === canvasesLength - 1 ? _this2.drawer.wrapper.scrollWidth - _this2.maxCanvasElementWidth * (canvasesLength - 1) : _this2.maxCanvasElementWidth;
|
|
335
|
-
|
|
336
|
-
canvas.width = canvasWidth * _this2.pixelRatio;
|
|
310
|
+
var canvasWidth = i === canvasesLength - 1 ? _this2.drawer.wrapper.scrollWidth - _this2.maxCanvasElementWidth * (canvasesLength - 1) : _this2.maxCanvasElementWidth;
|
|
311
|
+
// set dimensions and style
|
|
312
|
+
canvas.width = canvasWidth * _this2.pixelRatio;
|
|
313
|
+
// on certain pixel ratios the canvas appears cut off at the bottom,
|
|
337
314
|
// therefore leave 1px extra
|
|
338
|
-
|
|
339
315
|
canvas.height = (_this2.params.height + 1) * _this2.pixelRatio;
|
|
340
|
-
|
|
341
316
|
_this2.util.style(canvas, {
|
|
342
317
|
width: "".concat(canvasWidth, "px"),
|
|
343
318
|
height: "".concat(_this2.params.height, "px"),
|
|
@@ -345,22 +320,19 @@ var TimelinePlugin = /*#__PURE__*/function () {
|
|
|
345
320
|
});
|
|
346
321
|
});
|
|
347
322
|
}
|
|
323
|
+
|
|
348
324
|
/**
|
|
349
325
|
* Render the timeline labels and notches
|
|
350
326
|
*
|
|
351
327
|
*/
|
|
352
|
-
|
|
353
328
|
}, {
|
|
354
329
|
key: "renderCanvases",
|
|
355
330
|
value: function renderCanvases() {
|
|
356
331
|
var _this3 = this;
|
|
357
|
-
|
|
358
332
|
var duration = this.params.duration || this.wavesurfer.backend.getDuration();
|
|
359
|
-
|
|
360
333
|
if (duration <= 0) {
|
|
361
334
|
return;
|
|
362
335
|
}
|
|
363
|
-
|
|
364
336
|
var wsParams = this.wavesurfer.params;
|
|
365
337
|
var fontSize = this.params.fontSize * wsParams.pixelRatio;
|
|
366
338
|
var totalSeconds = parseInt(duration, 10) + 1;
|
|
@@ -368,61 +340,60 @@ var TimelinePlugin = /*#__PURE__*/function () {
|
|
|
368
340
|
var height1 = this.params.height * this.pixelRatio;
|
|
369
341
|
var height2 = this.params.height * (this.params.notchPercentHeight / 100) * this.pixelRatio;
|
|
370
342
|
var pixelsPerSecond = width / duration;
|
|
371
|
-
var formatTime = this.params.formatTimeCallback;
|
|
343
|
+
var formatTime = this.params.formatTimeCallback;
|
|
344
|
+
// if parameter is function, call the function with
|
|
372
345
|
// pixelsPerSecond, otherwise simply take the value as-is
|
|
373
|
-
|
|
374
346
|
var intervalFnOrVal = function intervalFnOrVal(option) {
|
|
375
347
|
return typeof option === 'function' ? option(pixelsPerSecond) : option;
|
|
376
348
|
};
|
|
377
|
-
|
|
378
349
|
var timeInterval = intervalFnOrVal(this.params.timeInterval);
|
|
379
350
|
var primaryLabelInterval = intervalFnOrVal(this.params.primaryLabelInterval);
|
|
380
351
|
var secondaryLabelInterval = intervalFnOrVal(this.params.secondaryLabelInterval);
|
|
381
352
|
var curPixel = pixelsPerSecond * this.params.offset;
|
|
382
353
|
var curSeconds = 0;
|
|
383
|
-
var i;
|
|
354
|
+
var i;
|
|
355
|
+
// build an array of position data with index, second and pixel data,
|
|
384
356
|
// this is then used multiple times below
|
|
357
|
+
var positioning = [];
|
|
385
358
|
|
|
386
|
-
|
|
387
|
-
|
|
359
|
+
// render until end in case we have a negative offset
|
|
388
360
|
var renderSeconds = this.params.offset < 0 ? totalSeconds - this.params.offset : totalSeconds;
|
|
389
|
-
|
|
390
361
|
for (i = 0; i < renderSeconds / timeInterval; i++) {
|
|
391
362
|
positioning.push([i, curSeconds, curPixel]);
|
|
392
363
|
curSeconds += timeInterval;
|
|
393
364
|
curPixel += pixelsPerSecond * timeInterval;
|
|
394
|
-
}
|
|
395
|
-
|
|
365
|
+
}
|
|
396
366
|
|
|
367
|
+
// iterate over each position
|
|
397
368
|
var renderPositions = function renderPositions(cb) {
|
|
398
369
|
positioning.forEach(function (pos) {
|
|
399
370
|
cb(pos[0], pos[1], pos[2]);
|
|
400
371
|
});
|
|
401
|
-
};
|
|
402
|
-
|
|
372
|
+
};
|
|
403
373
|
|
|
374
|
+
// render primary labels
|
|
404
375
|
this.setFillStyles(this.params.primaryColor);
|
|
405
376
|
this.setFonts("".concat(fontSize, "px ").concat(this.params.fontFamily));
|
|
406
377
|
this.setFillStyles(this.params.primaryFontColor);
|
|
407
378
|
renderPositions(function (i, curSeconds, curPixel) {
|
|
408
379
|
if (i % primaryLabelInterval === 0) {
|
|
409
380
|
_this3.fillRect(curPixel, 0, 1, height1);
|
|
410
|
-
|
|
411
381
|
_this3.fillText(formatTime(curSeconds, pixelsPerSecond), curPixel + _this3.params.labelPadding * _this3.pixelRatio, height1);
|
|
412
382
|
}
|
|
413
|
-
});
|
|
383
|
+
});
|
|
414
384
|
|
|
385
|
+
// render secondary labels
|
|
415
386
|
this.setFillStyles(this.params.secondaryColor);
|
|
416
387
|
this.setFonts("".concat(fontSize, "px ").concat(this.params.fontFamily));
|
|
417
388
|
this.setFillStyles(this.params.secondaryFontColor);
|
|
418
389
|
renderPositions(function (i, curSeconds, curPixel) {
|
|
419
390
|
if (i % secondaryLabelInterval === 0) {
|
|
420
391
|
_this3.fillRect(curPixel, 0, 1, height1);
|
|
421
|
-
|
|
422
392
|
_this3.fillText(formatTime(curSeconds, pixelsPerSecond), curPixel + _this3.params.labelPadding * _this3.pixelRatio, height1);
|
|
423
393
|
}
|
|
424
|
-
});
|
|
394
|
+
});
|
|
425
395
|
|
|
396
|
+
// render the actual notches (when no labels are used)
|
|
426
397
|
this.setFillStyles(this.params.unlabeledNotchColor);
|
|
427
398
|
renderPositions(function (i, curSeconds, curPixel) {
|
|
428
399
|
if (i % secondaryLabelInterval !== 0 && i % primaryLabelInterval !== 0) {
|
|
@@ -430,41 +401,40 @@ var TimelinePlugin = /*#__PURE__*/function () {
|
|
|
430
401
|
}
|
|
431
402
|
});
|
|
432
403
|
}
|
|
404
|
+
|
|
433
405
|
/**
|
|
434
406
|
* Set the canvas fill style
|
|
435
407
|
*
|
|
436
408
|
* @param {DOMString|CanvasGradient|CanvasPattern} fillStyle Fill style to
|
|
437
409
|
* use
|
|
438
410
|
*/
|
|
439
|
-
|
|
440
411
|
}, {
|
|
441
412
|
key: "setFillStyles",
|
|
442
413
|
value: function setFillStyles(fillStyle) {
|
|
443
414
|
this.canvases.forEach(function (canvas) {
|
|
444
415
|
var context = canvas.getContext('2d');
|
|
445
|
-
|
|
446
416
|
if (context) {
|
|
447
417
|
context.fillStyle = fillStyle;
|
|
448
418
|
}
|
|
449
419
|
});
|
|
450
420
|
}
|
|
421
|
+
|
|
451
422
|
/**
|
|
452
423
|
* Set the canvas font
|
|
453
424
|
*
|
|
454
425
|
* @param {DOMString} font Font to use
|
|
455
426
|
*/
|
|
456
|
-
|
|
457
427
|
}, {
|
|
458
428
|
key: "setFonts",
|
|
459
429
|
value: function setFonts(font) {
|
|
460
430
|
this.canvases.forEach(function (canvas) {
|
|
461
431
|
var context = canvas.getContext('2d');
|
|
462
|
-
|
|
463
432
|
if (context) {
|
|
464
433
|
context.font = font;
|
|
465
434
|
}
|
|
466
435
|
});
|
|
467
436
|
}
|
|
437
|
+
|
|
468
438
|
/**
|
|
469
439
|
* Draw a rectangle on the canvases
|
|
470
440
|
*
|
|
@@ -475,12 +445,10 @@ var TimelinePlugin = /*#__PURE__*/function () {
|
|
|
475
445
|
* @param {number} width Width
|
|
476
446
|
* @param {number} height Height
|
|
477
447
|
*/
|
|
478
|
-
|
|
479
448
|
}, {
|
|
480
449
|
key: "fillRect",
|
|
481
450
|
value: function fillRect(x, y, width, height) {
|
|
482
451
|
var _this4 = this;
|
|
483
|
-
|
|
484
452
|
this.canvases.forEach(function (canvas, i) {
|
|
485
453
|
var leftOffset = i * _this4.maxCanvasWidth;
|
|
486
454
|
var intersection = {
|
|
@@ -489,16 +457,15 @@ var TimelinePlugin = /*#__PURE__*/function () {
|
|
|
489
457
|
x2: Math.min(x + width, i * _this4.maxCanvasWidth + canvas.width),
|
|
490
458
|
y2: y + height
|
|
491
459
|
};
|
|
492
|
-
|
|
493
460
|
if (intersection.x1 < intersection.x2) {
|
|
494
461
|
var context = canvas.getContext('2d');
|
|
495
|
-
|
|
496
462
|
if (context) {
|
|
497
463
|
context.fillRect(intersection.x1 - leftOffset, intersection.y1, intersection.x2 - intersection.x1, intersection.y2 - intersection.y1);
|
|
498
464
|
}
|
|
499
465
|
}
|
|
500
466
|
});
|
|
501
467
|
}
|
|
468
|
+
|
|
502
469
|
/**
|
|
503
470
|
* Fill a given text on the canvases
|
|
504
471
|
*
|
|
@@ -506,7 +473,6 @@ var TimelinePlugin = /*#__PURE__*/function () {
|
|
|
506
473
|
* @param {number} x X-position
|
|
507
474
|
* @param {number} y Y-position
|
|
508
475
|
*/
|
|
509
|
-
|
|
510
476
|
}, {
|
|
511
477
|
key: "fillText",
|
|
512
478
|
value: function fillText(text, x, y) {
|
|
@@ -514,23 +480,20 @@ var TimelinePlugin = /*#__PURE__*/function () {
|
|
|
514
480
|
var xOffset = 0;
|
|
515
481
|
this.canvases.forEach(function (canvas) {
|
|
516
482
|
var context = canvas.getContext('2d');
|
|
517
|
-
|
|
518
483
|
if (context) {
|
|
519
484
|
var canvasWidth = context.canvas.width;
|
|
520
|
-
|
|
521
485
|
if (xOffset > x + textWidth) {
|
|
522
486
|
return;
|
|
523
487
|
}
|
|
524
|
-
|
|
525
488
|
if (xOffset + canvasWidth > x && context) {
|
|
526
489
|
textWidth = context.measureText(text).width;
|
|
527
490
|
context.fillText(text, x - xOffset, y);
|
|
528
491
|
}
|
|
529
|
-
|
|
530
492
|
xOffset += canvasWidth;
|
|
531
493
|
}
|
|
532
494
|
});
|
|
533
495
|
}
|
|
496
|
+
|
|
534
497
|
/**
|
|
535
498
|
* Turn the time into a suitable label for the time.
|
|
536
499
|
*
|
|
@@ -538,28 +501,26 @@ var TimelinePlugin = /*#__PURE__*/function () {
|
|
|
538
501
|
* @param {number} pxPerSec Pixels per second
|
|
539
502
|
* @returns {number} Time
|
|
540
503
|
*/
|
|
541
|
-
|
|
542
504
|
}, {
|
|
543
505
|
key: "defaultFormatTimeCallback",
|
|
544
506
|
value: function defaultFormatTimeCallback(seconds, pxPerSec) {
|
|
545
507
|
if (seconds / 60 > 1) {
|
|
546
508
|
// calculate minutes and seconds from seconds count
|
|
547
509
|
var minutes = parseInt(seconds / 60, 10);
|
|
548
|
-
seconds = parseInt(seconds % 60, 10);
|
|
549
|
-
|
|
510
|
+
seconds = parseInt(seconds % 60, 10);
|
|
511
|
+
// fill up seconds with zeroes
|
|
550
512
|
seconds = seconds < 10 ? '0' + seconds : seconds;
|
|
551
513
|
return "".concat(minutes, ":").concat(seconds);
|
|
552
514
|
}
|
|
553
|
-
|
|
554
515
|
return Math.round(seconds * 1000) / 1000;
|
|
555
516
|
}
|
|
517
|
+
|
|
556
518
|
/**
|
|
557
519
|
* Return how many seconds should be between each notch
|
|
558
520
|
*
|
|
559
521
|
* @param {number} pxPerSec Pixels per second
|
|
560
522
|
* @returns {number} Time
|
|
561
523
|
*/
|
|
562
|
-
|
|
563
524
|
}, {
|
|
564
525
|
key: "defaultTimeInterval",
|
|
565
526
|
value: function defaultTimeInterval(pxPerSec) {
|
|
@@ -570,16 +531,15 @@ var TimelinePlugin = /*#__PURE__*/function () {
|
|
|
570
531
|
} else if (pxPerSec * 15 >= 25) {
|
|
571
532
|
return 15;
|
|
572
533
|
}
|
|
573
|
-
|
|
574
534
|
return Math.ceil(0.5 / pxPerSec) * 60;
|
|
575
535
|
}
|
|
536
|
+
|
|
576
537
|
/**
|
|
577
538
|
* Return the cadence of notches that get labels in the primary color.
|
|
578
539
|
*
|
|
579
540
|
* @param {number} pxPerSec Pixels per second
|
|
580
541
|
* @returns {number} Cadence
|
|
581
542
|
*/
|
|
582
|
-
|
|
583
543
|
}, {
|
|
584
544
|
key: "defaultPrimaryLabelInterval",
|
|
585
545
|
value: function defaultPrimaryLabelInterval(pxPerSec) {
|
|
@@ -590,16 +550,15 @@ var TimelinePlugin = /*#__PURE__*/function () {
|
|
|
590
550
|
} else if (pxPerSec * 15 >= 25) {
|
|
591
551
|
return 4;
|
|
592
552
|
}
|
|
593
|
-
|
|
594
553
|
return 4;
|
|
595
554
|
}
|
|
555
|
+
|
|
596
556
|
/**
|
|
597
557
|
* Return the cadence of notches that get labels in the secondary color.
|
|
598
558
|
*
|
|
599
559
|
* @param {number} pxPerSec Pixels per second
|
|
600
560
|
* @returns {number} Cadence
|
|
601
561
|
*/
|
|
602
|
-
|
|
603
562
|
}, {
|
|
604
563
|
key: "defaultSecondaryLabelInterval",
|
|
605
564
|
value: function defaultSecondaryLabelInterval(pxPerSec) {
|
|
@@ -610,7 +569,6 @@ var TimelinePlugin = /*#__PURE__*/function () {
|
|
|
610
569
|
} else if (pxPerSec * 15 >= 25) {
|
|
611
570
|
return 2;
|
|
612
571
|
}
|
|
613
|
-
|
|
614
572
|
return 2;
|
|
615
573
|
}
|
|
616
574
|
}], [{
|
|
@@ -632,13 +590,12 @@ var TimelinePlugin = /*#__PURE__*/function () {
|
|
|
632
590
|
params: params,
|
|
633
591
|
instance: TimelinePlugin
|
|
634
592
|
};
|
|
635
|
-
}
|
|
593
|
+
}
|
|
636
594
|
|
|
595
|
+
// event handlers
|
|
637
596
|
}]);
|
|
638
|
-
|
|
639
597
|
return TimelinePlugin;
|
|
640
598
|
}();
|
|
641
|
-
|
|
642
599
|
exports["default"] = TimelinePlugin;
|
|
643
600
|
module.exports = exports.default;
|
|
644
601
|
|