@micromag/screen-audio 0.3.150 → 0.3.156
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/assets/css/styles.css +1 -1
- package/es/index.js +107 -124
- package/lib/index.js +104 -122
- package/package.json +11 -11
package/assets/css/styles.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.micromag-screen-audio-container{position:relative;width:100%;height:100%;overflow:hidden}.micromag-screen-audio-disabled.micromag-screen-audio-container{overflow:hidden;pointer-events:none}.micromag-screen-audio-hidden.micromag-screen-audio-container{display:none;visibility:hidden}.micromag-screen-audio-placeholder.micromag-screen-audio-container .micromag-screen-audio-content{position:relative;padding:6px}.micromag-screen-audio-container .micromag-screen-audio-empty{margin:5px auto;border:2px dashed #343434;color:#343434}.micromag-screen-audio-container .micromag-screen-audio-
|
|
1
|
+
.micromag-screen-audio-container{position:relative;width:100%;height:100%;overflow:hidden}.micromag-screen-audio-disabled.micromag-screen-audio-container{overflow:hidden;pointer-events:none}.micromag-screen-audio-hidden.micromag-screen-audio-container{display:none;visibility:hidden}.micromag-screen-audio-placeholder.micromag-screen-audio-container .micromag-screen-audio-content{position:relative;padding:6px}.micromag-screen-audio-container .micromag-screen-audio-empty{margin:5px auto;border:2px dashed #343434;color:#343434}.micromag-screen-audio-container .micromag-screen-audio-audio{position:absolute;bottom:50%;left:0;width:100%;-webkit-transform:translateY(50%);-ms-transform:translateY(50%);transform:translateY(50%)}.micromag-screen-audio-container .micromag-screen-audio-bottom{position:absolute;bottom:0;left:0;width:100%;-webkit-transition:padding .2s ease-out,-webkit-transform .2s ease-out;transition:padding .2s ease-out,-webkit-transform .2s ease-out;-o-transition:transform .2s ease-out,padding .2s ease-out;transition:transform .2s ease-out,padding .2s ease-out;transition:transform .2s ease-out,padding .2s ease-out,-webkit-transform .2s ease-out}.micromag-screen-audio-container .micromag-screen-audio-bottom>*{margin-bottom:10px}.micromag-screen-audio-container .micromag-screen-audio-bottom>:last-child{margin-bottom:0}.micromag-screen-audio-container .micromag-screen-audio-empty{width:100%;height:100px;margin:0 auto}.micromag-screen-audio-container.micromag-screen-audio-isPreview{pointer-events:none}
|
package/es/index.js
CHANGED
|
@@ -4,11 +4,11 @@ import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
|
4
4
|
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
5
5
|
import classNames from 'classnames';
|
|
6
6
|
import PropTypes from 'prop-types';
|
|
7
|
-
import React, { useState,
|
|
7
|
+
import React, { useState, useEffect, useCallback, useMemo } from 'react';
|
|
8
8
|
import { PropTypes as PropTypes$1 } from '@micromag/core';
|
|
9
9
|
import { ScreenElement, Transitions } from '@micromag/core/components';
|
|
10
|
-
import { useScreenSize, useScreenRenderContext,
|
|
11
|
-
import { useTrackScreenMedia
|
|
10
|
+
import { useScreenSize, useScreenRenderContext, useViewerContext, useViewerWebView, usePlaybackContext, usePlaybackMediaRef } from '@micromag/core/contexts';
|
|
11
|
+
import { useTrackScreenMedia } from '@micromag/core/hooks';
|
|
12
12
|
import { isIos } from '@micromag/core/utils';
|
|
13
13
|
import Audio from '@micromag/element-audio';
|
|
14
14
|
import Background from '@micromag/element-background';
|
|
@@ -16,11 +16,10 @@ import CallToAction from '@micromag/element-call-to-action';
|
|
|
16
16
|
import ClosedCaptions from '@micromag/element-closed-captions';
|
|
17
17
|
import Container from '@micromag/element-container';
|
|
18
18
|
import Layout, { Spacer } from '@micromag/element-layout';
|
|
19
|
-
import MediaControls from '@micromag/element-media-controls';
|
|
20
19
|
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
|
|
21
20
|
import { Audio as Audio$1, Container as Container$1 } from '@micromag/transforms/apple-news';
|
|
22
21
|
|
|
23
|
-
var styles = {"container":"micromag-screen-audio-container","disabled":"micromag-screen-audio-disabled","hidden":"micromag-screen-audio-hidden","placeholder":"micromag-screen-audio-placeholder","content":"micromag-screen-audio-content","empty":"micromag-screen-audio-empty","
|
|
22
|
+
var styles = {"container":"micromag-screen-audio-container","disabled":"micromag-screen-audio-disabled","hidden":"micromag-screen-audio-hidden","placeholder":"micromag-screen-audio-placeholder","content":"micromag-screen-audio-content","empty":"micromag-screen-audio-empty","audio":"micromag-screen-audio-audio","bottom":"micromag-screen-audio-bottom","isPreview":"micromag-screen-audio-isPreview"};
|
|
24
23
|
|
|
25
24
|
var propTypes = {
|
|
26
25
|
layout: PropTypes.oneOf(['middle']),
|
|
@@ -31,10 +30,8 @@ var propTypes = {
|
|
|
31
30
|
current: PropTypes.bool,
|
|
32
31
|
active: PropTypes.bool,
|
|
33
32
|
transitions: PropTypes$1.transitions,
|
|
34
|
-
|
|
33
|
+
mediaRef: PropTypes.func,
|
|
35
34
|
showWave: PropTypes.bool,
|
|
36
|
-
enableInteraction: PropTypes.func,
|
|
37
|
-
disableInteraction: PropTypes.func,
|
|
38
35
|
className: PropTypes.string
|
|
39
36
|
};
|
|
40
37
|
var defaultProps = {
|
|
@@ -46,10 +43,8 @@ var defaultProps = {
|
|
|
46
43
|
current: true,
|
|
47
44
|
active: true,
|
|
48
45
|
transitions: null,
|
|
49
|
-
|
|
46
|
+
mediaRef: null,
|
|
50
47
|
showWave: false,
|
|
51
|
-
enableInteraction: null,
|
|
52
|
-
disableInteraction: null,
|
|
53
48
|
className: null
|
|
54
49
|
};
|
|
55
50
|
|
|
@@ -64,17 +59,13 @@ var AudioScreen = function AudioScreen(_ref) {
|
|
|
64
59
|
current = _ref.current,
|
|
65
60
|
active = _ref.active,
|
|
66
61
|
transitions = _ref.transitions,
|
|
67
|
-
|
|
62
|
+
customMediaRef = _ref.mediaRef,
|
|
68
63
|
showWave = _ref.showWave,
|
|
69
|
-
enableInteraction = _ref.enableInteraction,
|
|
70
|
-
disableInteraction = _ref.disableInteraction,
|
|
71
64
|
className = _ref.className;
|
|
72
|
-
var trackScreenMedia = useTrackScreenMedia('audio');
|
|
73
65
|
|
|
74
66
|
var _useScreenSize = useScreenSize(),
|
|
75
67
|
width = _useScreenSize.width,
|
|
76
68
|
height = _useScreenSize.height,
|
|
77
|
-
menuOverScreen = _useScreenSize.menuOverScreen,
|
|
78
69
|
resolution = _useScreenSize.resolution;
|
|
79
70
|
|
|
80
71
|
var _useScreenRenderConte = useScreenRenderContext(),
|
|
@@ -85,10 +76,15 @@ var AudioScreen = function AudioScreen(_ref) {
|
|
|
85
76
|
isStatic = _useScreenRenderConte.isStatic,
|
|
86
77
|
isCapture = _useScreenRenderConte.isCapture;
|
|
87
78
|
|
|
88
|
-
var
|
|
89
|
-
|
|
79
|
+
var _useViewerContext = useViewerContext(),
|
|
80
|
+
viewerTopHeight = _useViewerContext.topHeight,
|
|
81
|
+
viewerBottomHeight = _useViewerContext.bottomHeight,
|
|
82
|
+
viewerBottomSidesWidth = _useViewerContext.bottomSidesWidth;
|
|
83
|
+
|
|
84
|
+
var _useViewerWebView = useViewerWebView(),
|
|
85
|
+
openWebView = _useViewerWebView.open;
|
|
90
86
|
|
|
91
|
-
var
|
|
87
|
+
var trackScreenMedia = useTrackScreenMedia('audio');
|
|
92
88
|
|
|
93
89
|
var _useState = useState(isStatic || isPlaceholder),
|
|
94
90
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -99,50 +95,78 @@ var AudioScreen = function AudioScreen(_ref) {
|
|
|
99
95
|
var mediaShouldLoad = current || active;
|
|
100
96
|
var transitionPlaying = current && ready;
|
|
101
97
|
var transitionDisabled = isStatic || isCapture || isPlaceholder || isPreview || isEdit;
|
|
98
|
+
|
|
99
|
+
var _ref2 = callToAction || {},
|
|
100
|
+
_ref2$active = _ref2.active,
|
|
101
|
+
hasCallToAction = _ref2$active === void 0 ? false : _ref2$active;
|
|
102
|
+
|
|
102
103
|
var hasAudio = audio !== null;
|
|
103
104
|
|
|
104
|
-
var
|
|
105
|
-
|
|
106
|
-
audioMedia =
|
|
107
|
-
|
|
108
|
-
autoPlay =
|
|
109
|
-
|
|
110
|
-
closedCaptions =
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
105
|
+
var _ref3 = audio || {},
|
|
106
|
+
_ref3$media = _ref3.media,
|
|
107
|
+
audioMedia = _ref3$media === void 0 ? null : _ref3$media,
|
|
108
|
+
_ref3$autoPlay = _ref3.autoPlay,
|
|
109
|
+
autoPlay = _ref3$autoPlay === void 0 ? true : _ref3$autoPlay,
|
|
110
|
+
_ref3$closedCaptions = _ref3.closedCaptions,
|
|
111
|
+
closedCaptions = _ref3$closedCaptions === void 0 ? null : _ref3$closedCaptions,
|
|
112
|
+
_ref3$withControls = _ref3.withControls,
|
|
113
|
+
withControls = _ref3$withControls === void 0 ? false : _ref3$withControls,
|
|
114
|
+
_ref3$withSeekBar = _ref3.withSeekBar,
|
|
115
|
+
withSeekBar = _ref3$withSeekBar === void 0 ? false : _ref3$withSeekBar,
|
|
116
|
+
_ref3$color = _ref3.color,
|
|
117
|
+
color = _ref3$color === void 0 ? null : _ref3$color,
|
|
118
|
+
_ref3$progressColor = _ref3.progressColor,
|
|
119
|
+
progressColor = _ref3$progressColor === void 0 ? null : _ref3$progressColor;
|
|
120
|
+
|
|
121
|
+
var _ref4 = audioMedia || {},
|
|
122
|
+
_ref4$url = _ref4.url,
|
|
123
|
+
audioUrl = _ref4$url === void 0 ? null : _ref4$url;
|
|
121
124
|
|
|
122
125
|
var hasAudioUrl = audioUrl !== null;
|
|
123
126
|
var finalAudio = hasAudio ? _objectSpread(_objectSpread({}, audio), {}, {
|
|
124
127
|
autoPlay: !isPreview && !isStatic && !isCapture && autoPlay && current
|
|
125
128
|
}) : null;
|
|
126
129
|
var hasClosedCaptions = closedCaptions !== null;
|
|
127
|
-
var onAudioReady = useCallback(function () {
|
|
128
|
-
setReady(true);
|
|
129
|
-
}, [setReady]);
|
|
130
|
-
var apiRef = useRef();
|
|
131
130
|
|
|
132
|
-
var
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
apiMediaRef = _ref4$mediaRef === void 0 ? null : _ref4$mediaRef;
|
|
131
|
+
var _usePlaybackContext = usePlaybackContext(),
|
|
132
|
+
playing = _usePlaybackContext.playing,
|
|
133
|
+
muted = _usePlaybackContext.muted,
|
|
134
|
+
setControls = _usePlaybackContext.setControls,
|
|
135
|
+
setControlsTheme = _usePlaybackContext.setControlsTheme;
|
|
136
|
+
_usePlaybackContext.setMedia;
|
|
137
|
+
var setPlaying = _usePlaybackContext.setPlaying;
|
|
140
138
|
|
|
139
|
+
var mediaRef = usePlaybackMediaRef(current);
|
|
141
140
|
useEffect(function () {
|
|
142
|
-
if (
|
|
143
|
-
|
|
141
|
+
if (!current) {
|
|
142
|
+
return function () {};
|
|
144
143
|
}
|
|
145
|
-
|
|
144
|
+
|
|
145
|
+
if (withControls || withSeekBar) {
|
|
146
|
+
setControls(true);
|
|
147
|
+
setControlsTheme({
|
|
148
|
+
seekBarOnly: withSeekBar,
|
|
149
|
+
color: color,
|
|
150
|
+
progressColor: progressColor
|
|
151
|
+
});
|
|
152
|
+
} else {
|
|
153
|
+
setControls(false);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return function () {
|
|
157
|
+
if (withControls || withSeekBar) {
|
|
158
|
+
setControls(false);
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
}, [current, withControls, withSeekBar, setControls, color, progressColor]);
|
|
162
|
+
useEffect(function () {
|
|
163
|
+
if (customMediaRef !== null) {
|
|
164
|
+
customMediaRef(mediaRef.current);
|
|
165
|
+
}
|
|
166
|
+
}, [mediaRef.current]);
|
|
167
|
+
var onAudioReady = useCallback(function () {
|
|
168
|
+
setReady(true);
|
|
169
|
+
}, [setReady]);
|
|
146
170
|
|
|
147
171
|
var _useState3 = useState(null),
|
|
148
172
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
@@ -154,82 +178,39 @@ var AudioScreen = function AudioScreen(_ref) {
|
|
|
154
178
|
duration = _useState6[0],
|
|
155
179
|
setDuration = _useState6[1];
|
|
156
180
|
|
|
157
|
-
var _useState7 = useState(false),
|
|
158
|
-
_useState8 = _slicedToArray(_useState7, 2),
|
|
159
|
-
playing = _useState8[0],
|
|
160
|
-
setPlaying = _useState8[1];
|
|
161
|
-
|
|
162
|
-
var _useState9 = useState(false),
|
|
163
|
-
_useState10 = _slicedToArray(_useState9, 2),
|
|
164
|
-
muted = _useState10[0],
|
|
165
|
-
setMuted = _useState10[1];
|
|
166
|
-
|
|
167
181
|
var isIOS = useMemo(function () {
|
|
168
182
|
return isIos();
|
|
169
183
|
}, [isIos]);
|
|
184
|
+
useEffect(function () {
|
|
185
|
+
if (current && autoPlay && !playing) {
|
|
186
|
+
setPlaying(true);
|
|
187
|
+
}
|
|
188
|
+
}, [current, autoPlay]);
|
|
170
189
|
var onTimeUpdate = useCallback(function (time) {
|
|
171
190
|
setCurrentTime(time);
|
|
172
191
|
}, [setDuration, duration]);
|
|
173
192
|
var onProgressStep = useCallback(function (step) {
|
|
174
193
|
trackScreenMedia(audio, "progress_".concat(Math.round(step * 100, 10), "%"));
|
|
175
194
|
}, [trackScreenMedia, audio]);
|
|
176
|
-
var
|
|
195
|
+
var onDurationChange = useCallback(function (dur) {
|
|
177
196
|
setDuration(dur);
|
|
178
197
|
}, [setDuration]);
|
|
179
198
|
var onPlay = useCallback(function (_ref5) {
|
|
180
199
|
var initial = _ref5.initial;
|
|
181
|
-
setPlaying(true);
|
|
182
200
|
trackScreenMedia(audio, initial ? 'play' : 'resume');
|
|
183
201
|
}, [trackScreenMedia, audio]);
|
|
184
202
|
var onPause = useCallback(function (_ref6) {
|
|
185
203
|
var midway = _ref6.midway;
|
|
186
|
-
setPlaying(false);
|
|
187
204
|
trackScreenMedia(audio, midway ? 'pause' : 'ended');
|
|
188
205
|
}, [trackScreenMedia, audio]);
|
|
189
|
-
var
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
}, [seek, play]);
|
|
193
|
-
var onVolumeChanged = useCallback(function (isMuted) {
|
|
194
|
-
setMuted(isMuted);
|
|
195
|
-
trackScreenMedia(audio, isMuted ? 'mute' : 'unmute');
|
|
196
|
-
}, [trackScreenMedia, audio]);
|
|
206
|
+
var onEnded = useCallback(function () {
|
|
207
|
+
setPlaying(false);
|
|
208
|
+
}, [setPlaying]);
|
|
197
209
|
var onSeeked = useCallback(function (time) {
|
|
198
210
|
if (time > 0) {
|
|
199
211
|
trackScreenMedia(audio, 'seek');
|
|
200
212
|
}
|
|
201
213
|
}, [trackScreenMedia, audio]);
|
|
202
|
-
var onToggleMute = useCallback(function () {
|
|
203
|
-
if (muted && !playing) {
|
|
204
|
-
play();
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
toggleMute();
|
|
208
|
-
}, [muted, toggleMute]);
|
|
209
|
-
useEffect(function () {
|
|
210
|
-
if (!current && playing) {
|
|
211
|
-
pause();
|
|
212
|
-
}
|
|
213
|
-
}, [playing, current]);
|
|
214
|
-
var longPressBind = useLongPress({
|
|
215
|
-
onLongPress: togglePlay
|
|
216
|
-
});
|
|
217
|
-
var cta = !isPlaceholder && hasCallToAction ? /*#__PURE__*/React.createElement("div", {
|
|
218
|
-
style: {
|
|
219
|
-
marginTop: -spacing / 2
|
|
220
|
-
},
|
|
221
|
-
key: "call-to-action"
|
|
222
|
-
}, /*#__PURE__*/React.createElement(CallToAction, {
|
|
223
|
-
callToAction: callToAction,
|
|
224
|
-
animationDisabled: isPreview,
|
|
225
|
-
focusable: current && isView,
|
|
226
|
-
screenSize: {
|
|
227
|
-
width: width,
|
|
228
|
-
height: height
|
|
229
|
-
},
|
|
230
|
-
enableInteraction: enableInteraction,
|
|
231
|
-
disableInteraction: disableInteraction
|
|
232
|
-
})) : null;
|
|
233
214
|
var elements = [/*#__PURE__*/React.createElement(Spacer, {
|
|
234
215
|
key: "spacer-top"
|
|
235
216
|
}), /*#__PURE__*/React.createElement(ScreenElement, {
|
|
@@ -249,7 +230,7 @@ var AudioScreen = function AudioScreen(_ref) {
|
|
|
249
230
|
playing: transitionPlaying,
|
|
250
231
|
disabled: transitionDisabled
|
|
251
232
|
}, /*#__PURE__*/React.createElement(Audio, Object.assign({}, finalAudio, {
|
|
252
|
-
|
|
233
|
+
mediaRef: mediaRef,
|
|
253
234
|
waveFake: isIOS || isPreview,
|
|
254
235
|
waveProps: isPreview ? {
|
|
255
236
|
sampleWidth: 10,
|
|
@@ -261,44 +242,46 @@ var AudioScreen = function AudioScreen(_ref) {
|
|
|
261
242
|
backgroundColor: color,
|
|
262
243
|
progressColor: progressColor
|
|
263
244
|
},
|
|
245
|
+
paused: !current || !playing,
|
|
246
|
+
muted: muted,
|
|
264
247
|
className: styles.audio,
|
|
265
248
|
onReady: onAudioReady,
|
|
266
249
|
onPlay: onPlay,
|
|
267
250
|
onPause: onPause,
|
|
268
251
|
onTimeUpdate: onTimeUpdate,
|
|
269
252
|
onProgressStep: onProgressStep,
|
|
270
|
-
|
|
253
|
+
onDurationChange: onDurationChange,
|
|
271
254
|
onSeeked: onSeeked,
|
|
272
|
-
|
|
273
|
-
|
|
255
|
+
onEnded: onEnded,
|
|
256
|
+
withWave: showWave
|
|
274
257
|
})))), /*#__PURE__*/React.createElement(Spacer, {
|
|
275
258
|
key: "spacer-middle"
|
|
276
259
|
}), !isPlaceholder ? /*#__PURE__*/React.createElement("div", {
|
|
277
|
-
key: "
|
|
278
|
-
className: styles.
|
|
260
|
+
key: "bottom",
|
|
261
|
+
className: styles.bottom,
|
|
262
|
+
style: {
|
|
263
|
+
transform: !isPreview ? "translate(0, -".concat(viewerBottomHeight, "px)") : null,
|
|
264
|
+
paddingLeft: Math.max(spacing / 2, viewerBottomSidesWidth),
|
|
265
|
+
paddingRight: Math.max(spacing / 2, viewerBottomSidesWidth),
|
|
266
|
+
paddingBottom: spacing / 2,
|
|
267
|
+
paddingTop: 0
|
|
268
|
+
}
|
|
279
269
|
}, hasClosedCaptions && !isPreview && !isCapture && !isStatic ? /*#__PURE__*/React.createElement(ClosedCaptions, {
|
|
280
270
|
className: styles.closedCaptions,
|
|
281
271
|
media: closedCaptions,
|
|
282
272
|
currentTime: currentTime
|
|
283
|
-
}) : null,
|
|
284
|
-
className: styles.
|
|
285
|
-
|
|
286
|
-
playing: playing,
|
|
287
|
-
muted: muted,
|
|
288
|
-
onTogglePlay: togglePlay,
|
|
289
|
-
onToggleMute: onToggleMute,
|
|
273
|
+
}) : null, hasCallToAction ? /*#__PURE__*/React.createElement(CallToAction, Object.assign({}, callToAction, {
|
|
274
|
+
className: styles.callToAction,
|
|
275
|
+
animationDisabled: isPreview,
|
|
290
276
|
focusable: current && isView,
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
currentTime: currentTime,
|
|
294
|
-
onSeek: onSeek
|
|
295
|
-
}) : null, cta) : null].filter(function (el) {
|
|
277
|
+
openWebView: openWebView
|
|
278
|
+
})) : null) : null].filter(function (el) {
|
|
296
279
|
return el !== null;
|
|
297
280
|
});
|
|
298
|
-
return /*#__PURE__*/React.createElement("div",
|
|
281
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
299
282
|
className: classNames([styles.container, (_ref7 = {}, _defineProperty(_ref7, className, className !== null), _defineProperty(_ref7, styles.placeholder, isPlaceholder), _defineProperty(_ref7, styles.isPreview, isPreview), _ref7)]),
|
|
300
283
|
"data-screen-ready": ready
|
|
301
|
-
},
|
|
284
|
+
}, !isPlaceholder ? /*#__PURE__*/React.createElement(Background, {
|
|
302
285
|
background: background,
|
|
303
286
|
width: width,
|
|
304
287
|
height: height,
|
|
@@ -312,7 +295,7 @@ var AudioScreen = function AudioScreen(_ref) {
|
|
|
312
295
|
fullscreen: true,
|
|
313
296
|
style: !isPlaceholder ? {
|
|
314
297
|
padding: spacing,
|
|
315
|
-
paddingTop: (
|
|
298
|
+
paddingTop: (!isPreview ? viewerTopHeight : 0) + spacing
|
|
316
299
|
} : null
|
|
317
300
|
}, elements)));
|
|
318
301
|
};
|
package/lib/index.js
CHANGED
|
@@ -20,7 +20,6 @@ var CallToAction = require('@micromag/element-call-to-action');
|
|
|
20
20
|
var ClosedCaptions = require('@micromag/element-closed-captions');
|
|
21
21
|
var Container = require('@micromag/element-container');
|
|
22
22
|
var Layout = require('@micromag/element-layout');
|
|
23
|
-
var MediaControls = require('@micromag/element-media-controls');
|
|
24
23
|
var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
|
|
25
24
|
var appleNews = require('@micromag/transforms/apple-news');
|
|
26
25
|
|
|
@@ -38,10 +37,9 @@ var CallToAction__default = /*#__PURE__*/_interopDefaultLegacy(CallToAction);
|
|
|
38
37
|
var ClosedCaptions__default = /*#__PURE__*/_interopDefaultLegacy(ClosedCaptions);
|
|
39
38
|
var Container__default = /*#__PURE__*/_interopDefaultLegacy(Container);
|
|
40
39
|
var Layout__default = /*#__PURE__*/_interopDefaultLegacy(Layout);
|
|
41
|
-
var MediaControls__default = /*#__PURE__*/_interopDefaultLegacy(MediaControls);
|
|
42
40
|
var _toConsumableArray__default = /*#__PURE__*/_interopDefaultLegacy(_toConsumableArray);
|
|
43
41
|
|
|
44
|
-
var styles = {"container":"micromag-screen-audio-container","disabled":"micromag-screen-audio-disabled","hidden":"micromag-screen-audio-hidden","placeholder":"micromag-screen-audio-placeholder","content":"micromag-screen-audio-content","empty":"micromag-screen-audio-empty","
|
|
42
|
+
var styles = {"container":"micromag-screen-audio-container","disabled":"micromag-screen-audio-disabled","hidden":"micromag-screen-audio-hidden","placeholder":"micromag-screen-audio-placeholder","content":"micromag-screen-audio-content","empty":"micromag-screen-audio-empty","audio":"micromag-screen-audio-audio","bottom":"micromag-screen-audio-bottom","isPreview":"micromag-screen-audio-isPreview"};
|
|
45
43
|
|
|
46
44
|
var propTypes = {
|
|
47
45
|
layout: PropTypes__default["default"].oneOf(['middle']),
|
|
@@ -52,10 +50,8 @@ var propTypes = {
|
|
|
52
50
|
current: PropTypes__default["default"].bool,
|
|
53
51
|
active: PropTypes__default["default"].bool,
|
|
54
52
|
transitions: core.PropTypes.transitions,
|
|
55
|
-
|
|
53
|
+
mediaRef: PropTypes__default["default"].func,
|
|
56
54
|
showWave: PropTypes__default["default"].bool,
|
|
57
|
-
enableInteraction: PropTypes__default["default"].func,
|
|
58
|
-
disableInteraction: PropTypes__default["default"].func,
|
|
59
55
|
className: PropTypes__default["default"].string
|
|
60
56
|
};
|
|
61
57
|
var defaultProps = {
|
|
@@ -67,10 +63,8 @@ var defaultProps = {
|
|
|
67
63
|
current: true,
|
|
68
64
|
active: true,
|
|
69
65
|
transitions: null,
|
|
70
|
-
|
|
66
|
+
mediaRef: null,
|
|
71
67
|
showWave: false,
|
|
72
|
-
enableInteraction: null,
|
|
73
|
-
disableInteraction: null,
|
|
74
68
|
className: null
|
|
75
69
|
};
|
|
76
70
|
|
|
@@ -85,17 +79,13 @@ var AudioScreen = function AudioScreen(_ref) {
|
|
|
85
79
|
current = _ref.current,
|
|
86
80
|
active = _ref.active,
|
|
87
81
|
transitions = _ref.transitions,
|
|
88
|
-
|
|
82
|
+
customMediaRef = _ref.mediaRef,
|
|
89
83
|
showWave = _ref.showWave,
|
|
90
|
-
enableInteraction = _ref.enableInteraction,
|
|
91
|
-
disableInteraction = _ref.disableInteraction,
|
|
92
84
|
className = _ref.className;
|
|
93
|
-
var trackScreenMedia = hooks.useTrackScreenMedia('audio');
|
|
94
85
|
|
|
95
86
|
var _useScreenSize = contexts.useScreenSize(),
|
|
96
87
|
width = _useScreenSize.width,
|
|
97
88
|
height = _useScreenSize.height,
|
|
98
|
-
menuOverScreen = _useScreenSize.menuOverScreen,
|
|
99
89
|
resolution = _useScreenSize.resolution;
|
|
100
90
|
|
|
101
91
|
var _useScreenRenderConte = contexts.useScreenRenderContext(),
|
|
@@ -106,10 +96,15 @@ var AudioScreen = function AudioScreen(_ref) {
|
|
|
106
96
|
isStatic = _useScreenRenderConte.isStatic,
|
|
107
97
|
isCapture = _useScreenRenderConte.isCapture;
|
|
108
98
|
|
|
109
|
-
var
|
|
110
|
-
|
|
99
|
+
var _useViewerContext = contexts.useViewerContext(),
|
|
100
|
+
viewerTopHeight = _useViewerContext.topHeight,
|
|
101
|
+
viewerBottomHeight = _useViewerContext.bottomHeight,
|
|
102
|
+
viewerBottomSidesWidth = _useViewerContext.bottomSidesWidth;
|
|
103
|
+
|
|
104
|
+
var _useViewerWebView = contexts.useViewerWebView(),
|
|
105
|
+
openWebView = _useViewerWebView.open;
|
|
111
106
|
|
|
112
|
-
var
|
|
107
|
+
var trackScreenMedia = hooks.useTrackScreenMedia('audio');
|
|
113
108
|
|
|
114
109
|
var _useState = React.useState(isStatic || isPlaceholder),
|
|
115
110
|
_useState2 = _slicedToArray__default["default"](_useState, 2),
|
|
@@ -120,50 +115,78 @@ var AudioScreen = function AudioScreen(_ref) {
|
|
|
120
115
|
var mediaShouldLoad = current || active;
|
|
121
116
|
var transitionPlaying = current && ready;
|
|
122
117
|
var transitionDisabled = isStatic || isCapture || isPlaceholder || isPreview || isEdit;
|
|
118
|
+
|
|
119
|
+
var _ref2 = callToAction || {},
|
|
120
|
+
_ref2$active = _ref2.active,
|
|
121
|
+
hasCallToAction = _ref2$active === void 0 ? false : _ref2$active;
|
|
122
|
+
|
|
123
123
|
var hasAudio = audio !== null;
|
|
124
124
|
|
|
125
|
-
var
|
|
126
|
-
|
|
127
|
-
audioMedia =
|
|
128
|
-
|
|
129
|
-
autoPlay =
|
|
130
|
-
|
|
131
|
-
closedCaptions =
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
125
|
+
var _ref3 = audio || {},
|
|
126
|
+
_ref3$media = _ref3.media,
|
|
127
|
+
audioMedia = _ref3$media === void 0 ? null : _ref3$media,
|
|
128
|
+
_ref3$autoPlay = _ref3.autoPlay,
|
|
129
|
+
autoPlay = _ref3$autoPlay === void 0 ? true : _ref3$autoPlay,
|
|
130
|
+
_ref3$closedCaptions = _ref3.closedCaptions,
|
|
131
|
+
closedCaptions = _ref3$closedCaptions === void 0 ? null : _ref3$closedCaptions,
|
|
132
|
+
_ref3$withControls = _ref3.withControls,
|
|
133
|
+
withControls = _ref3$withControls === void 0 ? false : _ref3$withControls,
|
|
134
|
+
_ref3$withSeekBar = _ref3.withSeekBar,
|
|
135
|
+
withSeekBar = _ref3$withSeekBar === void 0 ? false : _ref3$withSeekBar,
|
|
136
|
+
_ref3$color = _ref3.color,
|
|
137
|
+
color = _ref3$color === void 0 ? null : _ref3$color,
|
|
138
|
+
_ref3$progressColor = _ref3.progressColor,
|
|
139
|
+
progressColor = _ref3$progressColor === void 0 ? null : _ref3$progressColor;
|
|
140
|
+
|
|
141
|
+
var _ref4 = audioMedia || {},
|
|
142
|
+
_ref4$url = _ref4.url,
|
|
143
|
+
audioUrl = _ref4$url === void 0 ? null : _ref4$url;
|
|
142
144
|
|
|
143
145
|
var hasAudioUrl = audioUrl !== null;
|
|
144
146
|
var finalAudio = hasAudio ? _objectSpread__default["default"](_objectSpread__default["default"]({}, audio), {}, {
|
|
145
147
|
autoPlay: !isPreview && !isStatic && !isCapture && autoPlay && current
|
|
146
148
|
}) : null;
|
|
147
149
|
var hasClosedCaptions = closedCaptions !== null;
|
|
148
|
-
var onAudioReady = React.useCallback(function () {
|
|
149
|
-
setReady(true);
|
|
150
|
-
}, [setReady]);
|
|
151
|
-
var apiRef = React.useRef();
|
|
152
150
|
|
|
153
|
-
var
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
apiMediaRef = _ref4$mediaRef === void 0 ? null : _ref4$mediaRef;
|
|
151
|
+
var _usePlaybackContext = contexts.usePlaybackContext(),
|
|
152
|
+
playing = _usePlaybackContext.playing,
|
|
153
|
+
muted = _usePlaybackContext.muted,
|
|
154
|
+
setControls = _usePlaybackContext.setControls,
|
|
155
|
+
setControlsTheme = _usePlaybackContext.setControlsTheme;
|
|
156
|
+
_usePlaybackContext.setMedia;
|
|
157
|
+
var setPlaying = _usePlaybackContext.setPlaying;
|
|
161
158
|
|
|
159
|
+
var mediaRef = contexts.usePlaybackMediaRef(current);
|
|
162
160
|
React.useEffect(function () {
|
|
163
|
-
if (
|
|
164
|
-
|
|
161
|
+
if (!current) {
|
|
162
|
+
return function () {};
|
|
165
163
|
}
|
|
166
|
-
|
|
164
|
+
|
|
165
|
+
if (withControls || withSeekBar) {
|
|
166
|
+
setControls(true);
|
|
167
|
+
setControlsTheme({
|
|
168
|
+
seekBarOnly: withSeekBar,
|
|
169
|
+
color: color,
|
|
170
|
+
progressColor: progressColor
|
|
171
|
+
});
|
|
172
|
+
} else {
|
|
173
|
+
setControls(false);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return function () {
|
|
177
|
+
if (withControls || withSeekBar) {
|
|
178
|
+
setControls(false);
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
}, [current, withControls, withSeekBar, setControls, color, progressColor]);
|
|
182
|
+
React.useEffect(function () {
|
|
183
|
+
if (customMediaRef !== null) {
|
|
184
|
+
customMediaRef(mediaRef.current);
|
|
185
|
+
}
|
|
186
|
+
}, [mediaRef.current]);
|
|
187
|
+
var onAudioReady = React.useCallback(function () {
|
|
188
|
+
setReady(true);
|
|
189
|
+
}, [setReady]);
|
|
167
190
|
|
|
168
191
|
var _useState3 = React.useState(null),
|
|
169
192
|
_useState4 = _slicedToArray__default["default"](_useState3, 2),
|
|
@@ -175,82 +198,39 @@ var AudioScreen = function AudioScreen(_ref) {
|
|
|
175
198
|
duration = _useState6[0],
|
|
176
199
|
setDuration = _useState6[1];
|
|
177
200
|
|
|
178
|
-
var _useState7 = React.useState(false),
|
|
179
|
-
_useState8 = _slicedToArray__default["default"](_useState7, 2),
|
|
180
|
-
playing = _useState8[0],
|
|
181
|
-
setPlaying = _useState8[1];
|
|
182
|
-
|
|
183
|
-
var _useState9 = React.useState(false),
|
|
184
|
-
_useState10 = _slicedToArray__default["default"](_useState9, 2),
|
|
185
|
-
muted = _useState10[0],
|
|
186
|
-
setMuted = _useState10[1];
|
|
187
|
-
|
|
188
201
|
var isIOS = React.useMemo(function () {
|
|
189
202
|
return utils.isIos();
|
|
190
203
|
}, [utils.isIos]);
|
|
204
|
+
React.useEffect(function () {
|
|
205
|
+
if (current && autoPlay && !playing) {
|
|
206
|
+
setPlaying(true);
|
|
207
|
+
}
|
|
208
|
+
}, [current, autoPlay]);
|
|
191
209
|
var onTimeUpdate = React.useCallback(function (time) {
|
|
192
210
|
setCurrentTime(time);
|
|
193
211
|
}, [setDuration, duration]);
|
|
194
212
|
var onProgressStep = React.useCallback(function (step) {
|
|
195
213
|
trackScreenMedia(audio, "progress_".concat(Math.round(step * 100, 10), "%"));
|
|
196
214
|
}, [trackScreenMedia, audio]);
|
|
197
|
-
var
|
|
215
|
+
var onDurationChange = React.useCallback(function (dur) {
|
|
198
216
|
setDuration(dur);
|
|
199
217
|
}, [setDuration]);
|
|
200
218
|
var onPlay = React.useCallback(function (_ref5) {
|
|
201
219
|
var initial = _ref5.initial;
|
|
202
|
-
setPlaying(true);
|
|
203
220
|
trackScreenMedia(audio, initial ? 'play' : 'resume');
|
|
204
221
|
}, [trackScreenMedia, audio]);
|
|
205
222
|
var onPause = React.useCallback(function (_ref6) {
|
|
206
223
|
var midway = _ref6.midway;
|
|
207
|
-
setPlaying(false);
|
|
208
224
|
trackScreenMedia(audio, midway ? 'pause' : 'ended');
|
|
209
225
|
}, [trackScreenMedia, audio]);
|
|
210
|
-
var
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
}, [seek, play]);
|
|
214
|
-
var onVolumeChanged = React.useCallback(function (isMuted) {
|
|
215
|
-
setMuted(isMuted);
|
|
216
|
-
trackScreenMedia(audio, isMuted ? 'mute' : 'unmute');
|
|
217
|
-
}, [trackScreenMedia, audio]);
|
|
226
|
+
var onEnded = React.useCallback(function () {
|
|
227
|
+
setPlaying(false);
|
|
228
|
+
}, [setPlaying]);
|
|
218
229
|
var onSeeked = React.useCallback(function (time) {
|
|
219
230
|
if (time > 0) {
|
|
220
231
|
trackScreenMedia(audio, 'seek');
|
|
221
232
|
}
|
|
222
233
|
}, [trackScreenMedia, audio]);
|
|
223
|
-
var onToggleMute = React.useCallback(function () {
|
|
224
|
-
if (muted && !playing) {
|
|
225
|
-
play();
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
toggleMute();
|
|
229
|
-
}, [muted, toggleMute]);
|
|
230
|
-
React.useEffect(function () {
|
|
231
|
-
if (!current && playing) {
|
|
232
|
-
pause();
|
|
233
|
-
}
|
|
234
|
-
}, [playing, current]);
|
|
235
|
-
var longPressBind = hooks.useLongPress({
|
|
236
|
-
onLongPress: togglePlay
|
|
237
|
-
});
|
|
238
|
-
var cta = !isPlaceholder && hasCallToAction ? /*#__PURE__*/React__default["default"].createElement("div", {
|
|
239
|
-
style: {
|
|
240
|
-
marginTop: -spacing / 2
|
|
241
|
-
},
|
|
242
|
-
key: "call-to-action"
|
|
243
|
-
}, /*#__PURE__*/React__default["default"].createElement(CallToAction__default["default"], {
|
|
244
|
-
callToAction: callToAction,
|
|
245
|
-
animationDisabled: isPreview,
|
|
246
|
-
focusable: current && isView,
|
|
247
|
-
screenSize: {
|
|
248
|
-
width: width,
|
|
249
|
-
height: height
|
|
250
|
-
},
|
|
251
|
-
enableInteraction: enableInteraction,
|
|
252
|
-
disableInteraction: disableInteraction
|
|
253
|
-
})) : null;
|
|
254
234
|
var elements = [/*#__PURE__*/React__default["default"].createElement(Layout.Spacer, {
|
|
255
235
|
key: "spacer-top"
|
|
256
236
|
}), /*#__PURE__*/React__default["default"].createElement(components.ScreenElement, {
|
|
@@ -270,7 +250,7 @@ var AudioScreen = function AudioScreen(_ref) {
|
|
|
270
250
|
playing: transitionPlaying,
|
|
271
251
|
disabled: transitionDisabled
|
|
272
252
|
}, /*#__PURE__*/React__default["default"].createElement(Audio__default["default"], Object.assign({}, finalAudio, {
|
|
273
|
-
|
|
253
|
+
mediaRef: mediaRef,
|
|
274
254
|
waveFake: isIOS || isPreview,
|
|
275
255
|
waveProps: isPreview ? {
|
|
276
256
|
sampleWidth: 10,
|
|
@@ -282,44 +262,46 @@ var AudioScreen = function AudioScreen(_ref) {
|
|
|
282
262
|
backgroundColor: color,
|
|
283
263
|
progressColor: progressColor
|
|
284
264
|
},
|
|
265
|
+
paused: !current || !playing,
|
|
266
|
+
muted: muted,
|
|
285
267
|
className: styles.audio,
|
|
286
268
|
onReady: onAudioReady,
|
|
287
269
|
onPlay: onPlay,
|
|
288
270
|
onPause: onPause,
|
|
289
271
|
onTimeUpdate: onTimeUpdate,
|
|
290
272
|
onProgressStep: onProgressStep,
|
|
291
|
-
|
|
273
|
+
onDurationChange: onDurationChange,
|
|
292
274
|
onSeeked: onSeeked,
|
|
293
|
-
|
|
294
|
-
|
|
275
|
+
onEnded: onEnded,
|
|
276
|
+
withWave: showWave
|
|
295
277
|
})))), /*#__PURE__*/React__default["default"].createElement(Layout.Spacer, {
|
|
296
278
|
key: "spacer-middle"
|
|
297
279
|
}), !isPlaceholder ? /*#__PURE__*/React__default["default"].createElement("div", {
|
|
298
|
-
key: "
|
|
299
|
-
className: styles.
|
|
280
|
+
key: "bottom",
|
|
281
|
+
className: styles.bottom,
|
|
282
|
+
style: {
|
|
283
|
+
transform: !isPreview ? "translate(0, -".concat(viewerBottomHeight, "px)") : null,
|
|
284
|
+
paddingLeft: Math.max(spacing / 2, viewerBottomSidesWidth),
|
|
285
|
+
paddingRight: Math.max(spacing / 2, viewerBottomSidesWidth),
|
|
286
|
+
paddingBottom: spacing / 2,
|
|
287
|
+
paddingTop: 0
|
|
288
|
+
}
|
|
300
289
|
}, hasClosedCaptions && !isPreview && !isCapture && !isStatic ? /*#__PURE__*/React__default["default"].createElement(ClosedCaptions__default["default"], {
|
|
301
290
|
className: styles.closedCaptions,
|
|
302
291
|
media: closedCaptions,
|
|
303
292
|
currentTime: currentTime
|
|
304
|
-
}) : null,
|
|
305
|
-
className: styles.
|
|
306
|
-
|
|
307
|
-
playing: playing,
|
|
308
|
-
muted: muted,
|
|
309
|
-
onTogglePlay: togglePlay,
|
|
310
|
-
onToggleMute: onToggleMute,
|
|
293
|
+
}) : null, hasCallToAction ? /*#__PURE__*/React__default["default"].createElement(CallToAction__default["default"], Object.assign({}, callToAction, {
|
|
294
|
+
className: styles.callToAction,
|
|
295
|
+
animationDisabled: isPreview,
|
|
311
296
|
focusable: current && isView,
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
currentTime: currentTime,
|
|
315
|
-
onSeek: onSeek
|
|
316
|
-
}) : null, cta) : null].filter(function (el) {
|
|
297
|
+
openWebView: openWebView
|
|
298
|
+
})) : null) : null].filter(function (el) {
|
|
317
299
|
return el !== null;
|
|
318
300
|
});
|
|
319
|
-
return /*#__PURE__*/React__default["default"].createElement("div",
|
|
301
|
+
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
320
302
|
className: classNames__default["default"]([styles.container, (_ref7 = {}, _defineProperty__default["default"](_ref7, className, className !== null), _defineProperty__default["default"](_ref7, styles.placeholder, isPlaceholder), _defineProperty__default["default"](_ref7, styles.isPreview, isPreview), _ref7)]),
|
|
321
303
|
"data-screen-ready": ready
|
|
322
|
-
},
|
|
304
|
+
}, !isPlaceholder ? /*#__PURE__*/React__default["default"].createElement(Background__default["default"], {
|
|
323
305
|
background: background,
|
|
324
306
|
width: width,
|
|
325
307
|
height: height,
|
|
@@ -333,7 +315,7 @@ var AudioScreen = function AudioScreen(_ref) {
|
|
|
333
315
|
fullscreen: true,
|
|
334
316
|
style: !isPlaceholder ? {
|
|
335
317
|
padding: spacing,
|
|
336
|
-
paddingTop: (
|
|
318
|
+
paddingTop: (!isPreview ? viewerTopHeight : 0) + spacing
|
|
337
319
|
} : null
|
|
338
320
|
}, elements)));
|
|
339
321
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@micromag/screen-audio",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.156",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"javascript"
|
|
@@ -49,15 +49,15 @@
|
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"@babel/runtime": "^7.13.10",
|
|
52
|
-
"@micromag/core": "^0.3.
|
|
53
|
-
"@micromag/element-audio": "^0.3.
|
|
54
|
-
"@micromag/element-background": "^0.3.
|
|
55
|
-
"@micromag/element-call-to-action": "^0.3.
|
|
56
|
-
"@micromag/element-closed-captions": "^0.3.
|
|
57
|
-
"@micromag/element-container": "^0.3.
|
|
58
|
-
"@micromag/element-layout": "^0.3.
|
|
59
|
-
"@micromag/element-media-controls": "^0.3.
|
|
60
|
-
"@micromag/transforms": "^0.3.
|
|
52
|
+
"@micromag/core": "^0.3.156",
|
|
53
|
+
"@micromag/element-audio": "^0.3.156",
|
|
54
|
+
"@micromag/element-background": "^0.3.156",
|
|
55
|
+
"@micromag/element-call-to-action": "^0.3.156",
|
|
56
|
+
"@micromag/element-closed-captions": "^0.3.156",
|
|
57
|
+
"@micromag/element-container": "^0.3.156",
|
|
58
|
+
"@micromag/element-layout": "^0.3.156",
|
|
59
|
+
"@micromag/element-media-controls": "^0.3.156",
|
|
60
|
+
"@micromag/transforms": "^0.3.156",
|
|
61
61
|
"classnames": "^2.2.6",
|
|
62
62
|
"lodash": "^4.17.21",
|
|
63
63
|
"prop-types": "^15.7.2",
|
|
@@ -67,5 +67,5 @@
|
|
|
67
67
|
"publishConfig": {
|
|
68
68
|
"access": "public"
|
|
69
69
|
},
|
|
70
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "026d0eb445367f824d3d07a04a0fa90cc00d49f2"
|
|
71
71
|
}
|