@micromag/element-audio 0.3.423 → 0.3.430
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/lib/index.js +70 -81
- package/package.json +10 -4
package/lib/index.js
CHANGED
|
@@ -19,27 +19,16 @@ var web = require('@react-spring/web');
|
|
|
19
19
|
require('whatwg-fetch');
|
|
20
20
|
var utils = require('@micromag/core/utils');
|
|
21
21
|
|
|
22
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
23
|
-
|
|
24
|
-
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
|
|
25
|
-
var classNames__default = /*#__PURE__*/_interopDefaultLegacy(classNames);
|
|
26
|
-
var isFunction__default = /*#__PURE__*/_interopDefaultLegacy(isFunction);
|
|
27
|
-
var isNumber__default = /*#__PURE__*/_interopDefaultLegacy(isNumber);
|
|
28
|
-
var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
|
|
29
|
-
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
30
|
-
var _toConsumableArray__default = /*#__PURE__*/_interopDefaultLegacy(_toConsumableArray);
|
|
31
|
-
var _slicedToArray__default = /*#__PURE__*/_interopDefaultLegacy(_slicedToArray);
|
|
32
|
-
|
|
33
22
|
var styles$2 = {"container":"micromag-element-audio-audio-bars-container","seekButton":"micromag-element-audio-audio-bars-seekButton"};
|
|
34
23
|
|
|
35
24
|
var propTypes$2 = {
|
|
36
|
-
progress:
|
|
37
|
-
duration:
|
|
38
|
-
playing:
|
|
39
|
-
seek:
|
|
40
|
-
play:
|
|
25
|
+
progress: PropTypes.number,
|
|
26
|
+
duration: PropTypes.number,
|
|
27
|
+
playing: PropTypes.bool,
|
|
28
|
+
seek: PropTypes.func,
|
|
29
|
+
play: PropTypes.func,
|
|
41
30
|
// onReady: PropTypes.func,
|
|
42
|
-
className:
|
|
31
|
+
className: PropTypes.string
|
|
43
32
|
};
|
|
44
33
|
var defaultProps$2 = {
|
|
45
34
|
progress: 0,
|
|
@@ -68,12 +57,12 @@ function AudioBars(_ref) {
|
|
|
68
57
|
var barSize = barWidth + barGap;
|
|
69
58
|
var current = progress * elWidth;
|
|
70
59
|
var _useState = React.useState(null),
|
|
71
|
-
_useState2 =
|
|
60
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
72
61
|
currentSeek = _useState2[0],
|
|
73
62
|
setCurrentSeek = _useState2[1];
|
|
74
63
|
var items = React.useMemo(function () {
|
|
75
64
|
var count = Math.floor(elWidth / barSize);
|
|
76
|
-
return
|
|
65
|
+
return _toConsumableArray(Array(count).keys()).map(function () {
|
|
77
66
|
return Math.floor(Math.random() * 100);
|
|
78
67
|
});
|
|
79
68
|
}, [elWidth, barSize]);
|
|
@@ -108,7 +97,7 @@ function AudioBars(_ref) {
|
|
|
108
97
|
}, [seekFromX, setCurrentSeek]);
|
|
109
98
|
var bind = react.useGesture({
|
|
110
99
|
onDrag: function onDrag(_ref2) {
|
|
111
|
-
var _ref2$xy =
|
|
100
|
+
var _ref2$xy = _slicedToArray(_ref2.xy, 1),
|
|
112
101
|
x = _ref2$xy[0],
|
|
113
102
|
elapsedTime = _ref2.elapsedTime,
|
|
114
103
|
active = _ref2.active;
|
|
@@ -118,7 +107,7 @@ function AudioBars(_ref) {
|
|
|
118
107
|
seekTemporary(x);
|
|
119
108
|
},
|
|
120
109
|
onDragStart: function onDragStart(_ref3) {
|
|
121
|
-
var _ref3$xy =
|
|
110
|
+
var _ref3$xy = _slicedToArray(_ref3.xy, 1),
|
|
122
111
|
x = _ref3$xy[0],
|
|
123
112
|
elapsedTime = _ref3.elapsedTime,
|
|
124
113
|
active = _ref3.active;
|
|
@@ -128,7 +117,7 @@ function AudioBars(_ref) {
|
|
|
128
117
|
seekTemporary(x);
|
|
129
118
|
},
|
|
130
119
|
onDragEnd: function onDragEnd(_ref4) {
|
|
131
|
-
var _ref4$xy =
|
|
120
|
+
var _ref4$xy = _slicedToArray(_ref4.xy, 1),
|
|
132
121
|
x = _ref4$xy[0];
|
|
133
122
|
seekFromX(x);
|
|
134
123
|
setTimeout(function () {
|
|
@@ -141,10 +130,10 @@ function AudioBars(_ref) {
|
|
|
141
130
|
filterTaps: true
|
|
142
131
|
}
|
|
143
132
|
});
|
|
144
|
-
return /*#__PURE__*/
|
|
145
|
-
className:
|
|
133
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
134
|
+
className: classNames([styles$2.container, _defineProperty({}, className, className !== null)]),
|
|
146
135
|
ref: elRef
|
|
147
|
-
}, /*#__PURE__*/
|
|
136
|
+
}, /*#__PURE__*/React.createElement("svg", {
|
|
148
137
|
version: "1.1",
|
|
149
138
|
xmlns: "http://www.w3.org/2000/svg",
|
|
150
139
|
xmlnsXlink: "http://www.w3.org/1999/xlink",
|
|
@@ -156,7 +145,7 @@ function AudioBars(_ref) {
|
|
|
156
145
|
className: className,
|
|
157
146
|
xmlSpace: "preserve"
|
|
158
147
|
}, items.map(function (size, i) {
|
|
159
|
-
return /*#__PURE__*/
|
|
148
|
+
return /*#__PURE__*/React.createElement("rect", {
|
|
160
149
|
key: "bar-".concat(i + 1),
|
|
161
150
|
width: barWidth,
|
|
162
151
|
height: size,
|
|
@@ -168,7 +157,7 @@ function AudioBars(_ref) {
|
|
|
168
157
|
strokeLinejoin: "round",
|
|
169
158
|
strokeLinecap: "round"
|
|
170
159
|
});
|
|
171
|
-
})), /*#__PURE__*/
|
|
160
|
+
})), /*#__PURE__*/React.createElement("button", Object.assign({}, bind(), {
|
|
172
161
|
onClick: onClick,
|
|
173
162
|
type: "button",
|
|
174
163
|
className: styles$2.seekButton,
|
|
@@ -195,35 +184,35 @@ var styles$1 = {"container":"micromag-element-audio-container","wave":"micromag-
|
|
|
195
184
|
|
|
196
185
|
var propTypes$1 = {
|
|
197
186
|
media: core.PropTypes.audioMedia,
|
|
198
|
-
mediaRef:
|
|
199
|
-
current:
|
|
187
|
+
mediaRef: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({
|
|
188
|
+
current: PropTypes.any
|
|
200
189
|
})]),
|
|
201
|
-
muted:
|
|
202
|
-
autoPlay:
|
|
203
|
-
paused:
|
|
204
|
-
loop:
|
|
205
|
-
preload:
|
|
206
|
-
shouldLoad:
|
|
207
|
-
waveFake:
|
|
190
|
+
muted: PropTypes.bool,
|
|
191
|
+
autoPlay: PropTypes.bool,
|
|
192
|
+
paused: PropTypes.bool,
|
|
193
|
+
loop: PropTypes.bool,
|
|
194
|
+
preload: PropTypes.oneOf(['auto', 'none', 'metadata']),
|
|
195
|
+
shouldLoad: PropTypes.bool,
|
|
196
|
+
waveFake: PropTypes.bool,
|
|
208
197
|
// waveProps: PropTypes.shape({
|
|
209
198
|
// sampleWidth: PropTypes.number,
|
|
210
199
|
// sampleMargin: PropTypes.number,
|
|
211
200
|
// minSampleHeight: PropTypes.number,
|
|
212
201
|
// }),
|
|
213
|
-
withWave:
|
|
214
|
-
autoWaveHeight:
|
|
202
|
+
withWave: PropTypes.bool,
|
|
203
|
+
autoWaveHeight: PropTypes.bool,
|
|
215
204
|
// reduceBufferFactor: PropTypes.number,
|
|
216
|
-
updateInterval:
|
|
217
|
-
className:
|
|
218
|
-
onReady:
|
|
219
|
-
onPlay:
|
|
220
|
-
onPause:
|
|
221
|
-
onEnded:
|
|
222
|
-
onSeeked:
|
|
223
|
-
onTimeUpdate:
|
|
224
|
-
onProgressStep:
|
|
225
|
-
onDurationChange:
|
|
226
|
-
onVolumeChange:
|
|
205
|
+
updateInterval: PropTypes.number,
|
|
206
|
+
className: PropTypes.string,
|
|
207
|
+
onReady: PropTypes.func,
|
|
208
|
+
onPlay: PropTypes.func,
|
|
209
|
+
onPause: PropTypes.func,
|
|
210
|
+
onEnded: PropTypes.func,
|
|
211
|
+
onSeeked: PropTypes.func,
|
|
212
|
+
onTimeUpdate: PropTypes.func,
|
|
213
|
+
onProgressStep: PropTypes.func,
|
|
214
|
+
onDurationChange: PropTypes.func,
|
|
215
|
+
onVolumeChange: PropTypes.func
|
|
227
216
|
};
|
|
228
217
|
var defaultProps$1 = {
|
|
229
218
|
media: null,
|
|
@@ -329,7 +318,7 @@ var Audio = function Audio(_ref) {
|
|
|
329
318
|
if (element === null) {
|
|
330
319
|
return;
|
|
331
320
|
}
|
|
332
|
-
if (
|
|
321
|
+
if (isNumber(newTime)) {
|
|
333
322
|
element.currentTime = newTime;
|
|
334
323
|
}
|
|
335
324
|
}, [_ref4.current]);
|
|
@@ -358,13 +347,13 @@ var Audio = function Audio(_ref) {
|
|
|
358
347
|
onStep: onProgressStep
|
|
359
348
|
});
|
|
360
349
|
var progress = currentTime !== null && duration > 0 ? currentTime / duration : 0;
|
|
361
|
-
return /*#__PURE__*/
|
|
362
|
-
className:
|
|
363
|
-
}, /*#__PURE__*/
|
|
350
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
351
|
+
className: classNames([styles$1.container, _defineProperty({}, className, className !== null)])
|
|
352
|
+
}, /*#__PURE__*/React.createElement("audio", {
|
|
364
353
|
key: url,
|
|
365
354
|
ref: function ref(newRef) {
|
|
366
355
|
_ref4.current = newRef;
|
|
367
|
-
if (mediaRef !== null &&
|
|
356
|
+
if (mediaRef !== null && isFunction(mediaRef)) {
|
|
368
357
|
mediaRef(newRef);
|
|
369
358
|
} else if (mediaRef !== null) {
|
|
370
359
|
mediaRef.current = newRef;
|
|
@@ -382,8 +371,8 @@ var Audio = function Audio(_ref) {
|
|
|
382
371
|
onSeeked: onSeeked,
|
|
383
372
|
onTimeUpdate: onTimeUpdate,
|
|
384
373
|
onVolumeChange: onVolumeChange
|
|
385
|
-
}), withWave ? /*#__PURE__*/
|
|
386
|
-
className:
|
|
374
|
+
}), withWave ? /*#__PURE__*/React.createElement(AudioBars, {
|
|
375
|
+
className: classNames([styles$1.wave, _defineProperty({}, styles$1.withAutoHeight, autoWaveHeight)]),
|
|
387
376
|
progress: progress
|
|
388
377
|
// {...waveProps}
|
|
389
378
|
,
|
|
@@ -395,8 +384,8 @@ var Audio = function Audio(_ref) {
|
|
|
395
384
|
};
|
|
396
385
|
Audio.propTypes = propTypes$1;
|
|
397
386
|
Audio.defaultProps = defaultProps$1;
|
|
398
|
-
var Audio$1 = /*#__PURE__*/
|
|
399
|
-
return /*#__PURE__*/
|
|
387
|
+
var Audio$1 = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
388
|
+
return /*#__PURE__*/React.createElement(Audio, Object.assign({
|
|
400
389
|
mediaRef: ref
|
|
401
390
|
}, props));
|
|
402
391
|
});
|
|
@@ -404,19 +393,19 @@ var Audio$1 = /*#__PURE__*/React__default["default"].forwardRef(function (props,
|
|
|
404
393
|
var styles = {"container":"micromag-element-audio-audio-wave-container","button":"micromag-element-audio-audio-wave-button","canvasBackground":"micromag-element-audio-audio-wave-canvasBackground","canvasProgress":"micromag-element-audio-audio-wave-canvasProgress"};
|
|
405
394
|
|
|
406
395
|
var propTypes = {
|
|
407
|
-
currentTime:
|
|
408
|
-
duration:
|
|
409
|
-
playing:
|
|
410
|
-
sampleWidth:
|
|
411
|
-
sampleMargin:
|
|
412
|
-
minSampleHeight:
|
|
396
|
+
currentTime: PropTypes.number,
|
|
397
|
+
duration: PropTypes.number,
|
|
398
|
+
playing: PropTypes.bool,
|
|
399
|
+
sampleWidth: PropTypes.number,
|
|
400
|
+
sampleMargin: PropTypes.number,
|
|
401
|
+
minSampleHeight: PropTypes.number,
|
|
413
402
|
backgroundColor: core.PropTypes.color,
|
|
414
403
|
progressColor: core.PropTypes.color,
|
|
415
|
-
audioLevels:
|
|
416
|
-
className:
|
|
417
|
-
onSeek:
|
|
418
|
-
onResume:
|
|
419
|
-
onReady:
|
|
404
|
+
audioLevels: PropTypes.arrayOf(PropTypes.number),
|
|
405
|
+
className: PropTypes.string,
|
|
406
|
+
onSeek: PropTypes.func,
|
|
407
|
+
onResume: PropTypes.func,
|
|
408
|
+
onReady: PropTypes.func
|
|
420
409
|
};
|
|
421
410
|
var defaultProps = {
|
|
422
411
|
currentTime: null,
|
|
@@ -474,7 +463,7 @@ function AudioWave(_ref) {
|
|
|
474
463
|
}
|
|
475
464
|
};
|
|
476
465
|
}),
|
|
477
|
-
_useSpring2 =
|
|
466
|
+
_useSpring2 = _slicedToArray(_useSpring, 2),
|
|
478
467
|
springProps = _useSpring2[0],
|
|
479
468
|
setSpringProps = _useSpring2[1];
|
|
480
469
|
React.useEffect(function () {
|
|
@@ -511,16 +500,16 @@ function AudioWave(_ref) {
|
|
|
511
500
|
// get samples
|
|
512
501
|
|
|
513
502
|
var levelsBySamples = audioLevels.length / samplesCount;
|
|
514
|
-
var amplitudes =
|
|
503
|
+
var amplitudes = _toConsumableArray(Array(samplesCount).keys()).reduce(function (newAmplitudes, index) {
|
|
515
504
|
var levelStartIndex = index * levelsBySamples;
|
|
516
505
|
var levelEndIndex = levelStartIndex + levelsBySamples;
|
|
517
506
|
var newValues = [];
|
|
518
507
|
for (var i = Math.floor(levelStartIndex); i < Math.round(levelEndIndex); i += 1) {
|
|
519
508
|
newValues.push(audioLevels[i]);
|
|
520
509
|
}
|
|
521
|
-
return levelsBySamples >= 1 ? [].concat(
|
|
510
|
+
return levelsBySamples >= 1 ? [].concat(_toConsumableArray(newAmplitudes), [newValues.reduce(function (total, value) {
|
|
522
511
|
return total + value;
|
|
523
|
-
}, 0) / newValues.length]) : [].concat(
|
|
512
|
+
}, 0) / newValues.length]) : [].concat(_toConsumableArray(newAmplitudes), newValues);
|
|
524
513
|
}, []);
|
|
525
514
|
|
|
526
515
|
// for (let sampleI = 0; sampleI < samplesCount; sampleI += levelsBySamples) {
|
|
@@ -541,8 +530,8 @@ function AudioWave(_ref) {
|
|
|
541
530
|
// // }
|
|
542
531
|
// // }
|
|
543
532
|
// }
|
|
544
|
-
var minAmplitude = Math.min.apply(Math,
|
|
545
|
-
var maxAmplitude = Math.max.apply(Math,
|
|
533
|
+
var minAmplitude = Math.min.apply(Math, _toConsumableArray(amplitudes));
|
|
534
|
+
var maxAmplitude = Math.max.apply(Math, _toConsumableArray(amplitudes));
|
|
546
535
|
var delta = maxAmplitude - minAmplitude;
|
|
547
536
|
var normalizedAmplitudes = amplitudes.map(function (n) {
|
|
548
537
|
return (n - minAmplitude) / delta;
|
|
@@ -590,7 +579,7 @@ function AudioWave(_ref) {
|
|
|
590
579
|
}, [duration, playing, onSeek, onResume]);
|
|
591
580
|
var bind = react.useGesture({
|
|
592
581
|
onDrag: function onDrag(_ref3) {
|
|
593
|
-
var _ref3$xy =
|
|
582
|
+
var _ref3$xy = _slicedToArray(_ref3.xy, 1),
|
|
594
583
|
x = _ref3$xy[0],
|
|
595
584
|
elapsedTime = _ref3.elapsedTime,
|
|
596
585
|
active = _ref3.active;
|
|
@@ -605,13 +594,13 @@ function AudioWave(_ref) {
|
|
|
605
594
|
filterTaps: true
|
|
606
595
|
}
|
|
607
596
|
});
|
|
608
|
-
return /*#__PURE__*/
|
|
609
|
-
className:
|
|
597
|
+
return /*#__PURE__*/React.createElement("div", Object.assign({
|
|
598
|
+
className: classNames([styles.container, _defineProperty({}, className, className !== null)]),
|
|
610
599
|
ref: elRef
|
|
611
|
-
}, bind()), /*#__PURE__*/
|
|
600
|
+
}, bind()), /*#__PURE__*/React.createElement("canvas", {
|
|
612
601
|
ref: canvasBackgroundRef,
|
|
613
602
|
className: styles.canvasBackground
|
|
614
|
-
}), /*#__PURE__*/
|
|
603
|
+
}), /*#__PURE__*/React.createElement(web.animated.canvas, {
|
|
615
604
|
ref: canvasProgressRef,
|
|
616
605
|
className: styles.canvasProgress,
|
|
617
606
|
style: {
|
|
@@ -625,4 +614,4 @@ AudioWave.propTypes = propTypes;
|
|
|
625
614
|
AudioWave.defaultProps = defaultProps;
|
|
626
615
|
|
|
627
616
|
exports.AudioWave = AudioWave;
|
|
628
|
-
exports
|
|
617
|
+
exports.default = Audio$1;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@micromag/element-audio",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.430",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"keywords": [
|
|
@@ -32,6 +32,12 @@
|
|
|
32
32
|
"license": "ISC",
|
|
33
33
|
"main": "lib/index.js",
|
|
34
34
|
"module": "es/index.js",
|
|
35
|
+
"exports": {
|
|
36
|
+
".": {
|
|
37
|
+
"require": "./lib/index.js",
|
|
38
|
+
"import": "./es/index.js"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
35
41
|
"files": [
|
|
36
42
|
"lib",
|
|
37
43
|
"es",
|
|
@@ -53,8 +59,8 @@
|
|
|
53
59
|
"@fortawesome/fontawesome-svg-core": "^1.2.32",
|
|
54
60
|
"@fortawesome/free-solid-svg-icons": "^5.15.1",
|
|
55
61
|
"@fortawesome/react-fontawesome": "^0.1.13",
|
|
56
|
-
"@micromag/core": "^0.3.
|
|
57
|
-
"@micromag/element-closed-captions": "^0.3.
|
|
62
|
+
"@micromag/core": "^0.3.430",
|
|
63
|
+
"@micromag/element-closed-captions": "^0.3.430",
|
|
58
64
|
"@react-spring/core": "^9.6.1",
|
|
59
65
|
"@react-spring/web": "^9.6.1",
|
|
60
66
|
"@use-gesture/react": "^10.2.4",
|
|
@@ -69,5 +75,5 @@
|
|
|
69
75
|
"access": "public",
|
|
70
76
|
"registry": "https://registry.npmjs.org/"
|
|
71
77
|
},
|
|
72
|
-
"gitHead": "
|
|
78
|
+
"gitHead": "da790d76dba9d8e308d9f9c4e51d93a4a0e012a9"
|
|
73
79
|
}
|