@micromag/element-video 0.3.541 → 0.3.569
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/package.json +5 -6
- package/lib/index.js +0 -337
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@micromag/element-video",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.569",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"keywords": [
|
|
@@ -30,11 +30,10 @@
|
|
|
30
30
|
}
|
|
31
31
|
],
|
|
32
32
|
"license": "ISC",
|
|
33
|
-
"
|
|
33
|
+
"type": "module",
|
|
34
34
|
"module": "es/index.js",
|
|
35
35
|
"exports": {
|
|
36
36
|
".": {
|
|
37
|
-
"require": "./lib/index.js",
|
|
38
37
|
"import": "./es/index.js"
|
|
39
38
|
},
|
|
40
39
|
"./assets/css/styles": "./assets/css/styles.css",
|
|
@@ -60,8 +59,8 @@
|
|
|
60
59
|
},
|
|
61
60
|
"dependencies": {
|
|
62
61
|
"@babel/runtime": "^7.13.10",
|
|
63
|
-
"@micromag/core": "^0.3.
|
|
64
|
-
"@micromag/element-closed-captions": "^0.3.
|
|
62
|
+
"@micromag/core": "^0.3.569",
|
|
63
|
+
"@micromag/element-closed-captions": "^0.3.569",
|
|
65
64
|
"classnames": "^2.2.6",
|
|
66
65
|
"lodash": "^4.17.21",
|
|
67
66
|
"prop-types": "^15.7.2",
|
|
@@ -72,5 +71,5 @@
|
|
|
72
71
|
"access": "public",
|
|
73
72
|
"registry": "https://registry.npmjs.org/"
|
|
74
73
|
},
|
|
75
|
-
"gitHead": "
|
|
74
|
+
"gitHead": "ceb71f23a32ab8df4a1563a1e5cd5598e539de4d"
|
|
76
75
|
}
|
package/lib/index.js
DELETED
|
@@ -1,337 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
4
|
-
var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
|
|
5
|
-
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
|
|
6
|
-
var classNames = require('classnames');
|
|
7
|
-
var isFunction = require('lodash/isFunction');
|
|
8
|
-
var PropTypes = require('prop-types');
|
|
9
|
-
var React = require('react');
|
|
10
|
-
var core = require('@micromag/core');
|
|
11
|
-
var components = require('@micromag/core/components');
|
|
12
|
-
var hooks = require('@micromag/core/hooks');
|
|
13
|
-
var utils = require('@micromag/core/utils');
|
|
14
|
-
|
|
15
|
-
var styles = {"container":"micromag-element-video-container","withSize":"micromag-element-video-withSize","media":"micromag-element-video-media","spinner":"micromag-element-video-spinner"};
|
|
16
|
-
|
|
17
|
-
var propTypes = {
|
|
18
|
-
media: core.PropTypes.videoMedia,
|
|
19
|
-
thumbnail: PropTypes.oneOf([PropTypes.string, core.PropTypes.imageMedia]),
|
|
20
|
-
width: PropTypes.number,
|
|
21
|
-
height: PropTypes.number,
|
|
22
|
-
mediaRef: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({
|
|
23
|
-
current: PropTypes.any
|
|
24
|
-
})]),
|
|
25
|
-
muted: PropTypes.bool,
|
|
26
|
-
autoPlay: PropTypes.bool,
|
|
27
|
-
paused: PropTypes.bool,
|
|
28
|
-
loop: PropTypes.bool,
|
|
29
|
-
playsInline: PropTypes.bool,
|
|
30
|
-
preload: PropTypes.oneOf(['auto', 'metadata', 'none', null]),
|
|
31
|
-
disablePictureInPicture: PropTypes.bool,
|
|
32
|
-
shouldLoad: PropTypes.bool,
|
|
33
|
-
withoutCors: PropTypes.bool,
|
|
34
|
-
className: PropTypes.string,
|
|
35
|
-
innerClassName: PropTypes.string,
|
|
36
|
-
onReady: PropTypes.func,
|
|
37
|
-
onPlay: PropTypes.func,
|
|
38
|
-
onPause: PropTypes.func,
|
|
39
|
-
onEnded: PropTypes.func,
|
|
40
|
-
onSeeked: PropTypes.func,
|
|
41
|
-
onTimeUpdate: PropTypes.func,
|
|
42
|
-
onProgressStep: PropTypes.func,
|
|
43
|
-
onDurationChange: PropTypes.func,
|
|
44
|
-
onVolumeChange: PropTypes.func,
|
|
45
|
-
onSuspend: PropTypes.func,
|
|
46
|
-
onSuspended: PropTypes.func,
|
|
47
|
-
onPlayError: PropTypes.func,
|
|
48
|
-
focusable: PropTypes.bool,
|
|
49
|
-
withPoster: PropTypes.bool,
|
|
50
|
-
withLoading: PropTypes.bool
|
|
51
|
-
};
|
|
52
|
-
var defaultProps = {
|
|
53
|
-
media: null,
|
|
54
|
-
thumbnail: null,
|
|
55
|
-
width: null,
|
|
56
|
-
height: null,
|
|
57
|
-
mediaRef: null,
|
|
58
|
-
muted: false,
|
|
59
|
-
autoPlay: false,
|
|
60
|
-
paused: false,
|
|
61
|
-
loop: false,
|
|
62
|
-
playsInline: true,
|
|
63
|
-
preload: 'auto',
|
|
64
|
-
disablePictureInPicture: true,
|
|
65
|
-
shouldLoad: true,
|
|
66
|
-
withoutCors: false,
|
|
67
|
-
className: null,
|
|
68
|
-
innerClassName: null,
|
|
69
|
-
onReady: null,
|
|
70
|
-
onPlay: null,
|
|
71
|
-
onPause: null,
|
|
72
|
-
onEnded: null,
|
|
73
|
-
onSeeked: null,
|
|
74
|
-
onTimeUpdate: null,
|
|
75
|
-
onProgressStep: null,
|
|
76
|
-
onDurationChange: null,
|
|
77
|
-
onVolumeChange: null,
|
|
78
|
-
onSuspend: null,
|
|
79
|
-
onSuspended: null,
|
|
80
|
-
onPlayError: null,
|
|
81
|
-
focusable: true,
|
|
82
|
-
withPoster: false,
|
|
83
|
-
withLoading: false
|
|
84
|
-
};
|
|
85
|
-
var Video = function Video(_ref) {
|
|
86
|
-
var media = _ref.media,
|
|
87
|
-
thumbnail = _ref.thumbnail,
|
|
88
|
-
width = _ref.width,
|
|
89
|
-
height = _ref.height,
|
|
90
|
-
mediaRef = _ref.mediaRef,
|
|
91
|
-
muted = _ref.muted,
|
|
92
|
-
autoPlay = _ref.autoPlay,
|
|
93
|
-
paused = _ref.paused,
|
|
94
|
-
loop = _ref.loop,
|
|
95
|
-
playsInline = _ref.playsInline,
|
|
96
|
-
preload = _ref.preload,
|
|
97
|
-
shouldLoad = _ref.shouldLoad,
|
|
98
|
-
withoutCors = _ref.withoutCors,
|
|
99
|
-
className = _ref.className,
|
|
100
|
-
innerClassName = _ref.innerClassName,
|
|
101
|
-
onReady = _ref.onReady,
|
|
102
|
-
customOnPlay = _ref.onPlay,
|
|
103
|
-
onPause = _ref.onPause,
|
|
104
|
-
onEnded = _ref.onEnded,
|
|
105
|
-
onSeeked = _ref.onSeeked,
|
|
106
|
-
onTimeUpdate = _ref.onTimeUpdate,
|
|
107
|
-
onProgressStep = _ref.onProgressStep,
|
|
108
|
-
customOnDurationChange = _ref.onDurationChange,
|
|
109
|
-
customOnVolumeChange = _ref.onVolumeChange,
|
|
110
|
-
customOnSuspend = _ref.onSuspend,
|
|
111
|
-
onSuspended = _ref.onSuspended,
|
|
112
|
-
onPlayError = _ref.onPlayError,
|
|
113
|
-
focusable = _ref.focusable,
|
|
114
|
-
withPoster = _ref.withPoster,
|
|
115
|
-
withLoading = _ref.withLoading,
|
|
116
|
-
disablePictureInPicture = _ref.disablePictureInPicture;
|
|
117
|
-
var _ref2 = media || {},
|
|
118
|
-
_ref2$url = _ref2.url,
|
|
119
|
-
mediaUrl = _ref2$url === void 0 ? null : _ref2$url,
|
|
120
|
-
_ref2$files = _ref2.files,
|
|
121
|
-
files = _ref2$files === void 0 ? null : _ref2$files,
|
|
122
|
-
_ref2$metadata = _ref2.metadata,
|
|
123
|
-
metadata = _ref2$metadata === void 0 ? null : _ref2$metadata;
|
|
124
|
-
var _ref3 = metadata || {},
|
|
125
|
-
_ref3$description = _ref3.description,
|
|
126
|
-
description = _ref3$description === void 0 ? null : _ref3$description,
|
|
127
|
-
_ref3$mime = _ref3.mime,
|
|
128
|
-
mediaMime = _ref3$mime === void 0 ? null : _ref3$mime,
|
|
129
|
-
_ref3$has_audio = _ref3.has_audio,
|
|
130
|
-
hasAudio = _ref3$has_audio === void 0 ? null : _ref3$has_audio;
|
|
131
|
-
var filesArray = React.useMemo(function () {
|
|
132
|
-
return utils.getMediaFilesAsArray(files);
|
|
133
|
-
}, [files]);
|
|
134
|
-
var finalThumbnail = hooks.useMediaThumbnail(media, thumbnail);
|
|
135
|
-
var _ref11 = React.useRef(null);
|
|
136
|
-
var currentTime = hooks.useMediaCurrentTime(_ref11.current, {
|
|
137
|
-
id: mediaUrl,
|
|
138
|
-
disabled: paused || onProgressStep === null
|
|
139
|
-
});
|
|
140
|
-
var duration = hooks.useMediaDuration(_ref11.current, {
|
|
141
|
-
id: mediaUrl
|
|
142
|
-
});
|
|
143
|
-
var _useState = React.useState(false),
|
|
144
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
145
|
-
showLoading = _useState2[0],
|
|
146
|
-
setShowLoading = _useState2[1];
|
|
147
|
-
var ready = hooks.useMediaReady(_ref11.current, {
|
|
148
|
-
id: mediaUrl
|
|
149
|
-
});
|
|
150
|
-
React.useEffect(function () {
|
|
151
|
-
var id = null;
|
|
152
|
-
setShowLoading(false);
|
|
153
|
-
if (mediaUrl && withLoading) {
|
|
154
|
-
id = setTimeout(function () {
|
|
155
|
-
setShowLoading(true);
|
|
156
|
-
}, 2000);
|
|
157
|
-
}
|
|
158
|
-
return function () {
|
|
159
|
-
clearTimeout(id);
|
|
160
|
-
};
|
|
161
|
-
}, [mediaUrl, withLoading]);
|
|
162
|
-
var sourceFiles = React.useMemo(function () {
|
|
163
|
-
if (filesArray.length === 0) {
|
|
164
|
-
return null;
|
|
165
|
-
}
|
|
166
|
-
var supportedMimes = utils.getVideoSupportedMimes();
|
|
167
|
-
if (supportedMimes.length === 0) {
|
|
168
|
-
return null;
|
|
169
|
-
}
|
|
170
|
-
var sourceFilesMap = filesArray.filter(function (file) {
|
|
171
|
-
var _file$mime = file.mime,
|
|
172
|
-
mime = _file$mime === void 0 ? "video/".concat(file.id === 'h264' ? 'mp4' : file.id) : _file$mime;
|
|
173
|
-
return supportedMimes.indexOf(mime) !== -1;
|
|
174
|
-
}).reduce(function (filesMap, file) {
|
|
175
|
-
var _file$mime2 = file.mime,
|
|
176
|
-
mime = _file$mime2 === void 0 ? "video/".concat(file.id === 'h264' ? 'mp4' : file.id) : _file$mime2;
|
|
177
|
-
var currentMimeFile = filesMap[mime] || null;
|
|
178
|
-
var _ref4 = currentMimeFile || {},
|
|
179
|
-
_ref4$id = _ref4.id,
|
|
180
|
-
currentMimeId = _ref4$id === void 0 ? null : _ref4$id;
|
|
181
|
-
return currentMimeFile === null || currentMimeId !== 'original' ? _objectSpread(_objectSpread({}, filesMap), {}, _defineProperty({}, mime, file)) : filesMap;
|
|
182
|
-
}, {});
|
|
183
|
-
return Object.keys(sourceFilesMap).map(function (mime) {
|
|
184
|
-
return sourceFilesMap[mime];
|
|
185
|
-
});
|
|
186
|
-
}, [filesArray]);
|
|
187
|
-
|
|
188
|
-
// @NOTE: Media is an animated image and doesn't have source files in video formats
|
|
189
|
-
var _ref5 = filesArray.find(function (_ref6) {
|
|
190
|
-
var handle = _ref6.handle;
|
|
191
|
-
return handle === 'original';
|
|
192
|
-
}) || {},
|
|
193
|
-
_ref5$type = _ref5.type,
|
|
194
|
-
originalType = _ref5$type === void 0 ? null : _ref5$type,
|
|
195
|
-
_ref5$mime = _ref5.mime,
|
|
196
|
-
originalMime = _ref5$mime === void 0 ? mediaMime : _ref5$mime;
|
|
197
|
-
var originalFileIsImage = originalType === 'image' || originalMime !== null && originalMime.indexOf('image/') === 0;
|
|
198
|
-
var isImageWithoutSourceFile = originalFileIsImage && (sourceFiles === null || sourceFiles.length === 0);
|
|
199
|
-
var withSize = width !== null && height !== null;
|
|
200
|
-
React.useEffect(function () {
|
|
201
|
-
if (duration > 0 && customOnDurationChange !== null) {
|
|
202
|
-
customOnDurationChange(duration);
|
|
203
|
-
}
|
|
204
|
-
}, [duration, customOnDurationChange]);
|
|
205
|
-
var onVolumeChange = React.useCallback(function () {
|
|
206
|
-
var _ref$current = _ref11.current,
|
|
207
|
-
element = _ref$current === void 0 ? null : _ref$current;
|
|
208
|
-
if (element === null) {
|
|
209
|
-
return;
|
|
210
|
-
}
|
|
211
|
-
if (customOnVolumeChange !== null) {
|
|
212
|
-
customOnVolumeChange(element.volume);
|
|
213
|
-
}
|
|
214
|
-
}, [customOnVolumeChange]);
|
|
215
|
-
|
|
216
|
-
// Manage suspend
|
|
217
|
-
var _useState3 = React.useState(false),
|
|
218
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
|
219
|
-
isSuspended = _useState4[0],
|
|
220
|
-
setIsSuspended = _useState4[1];
|
|
221
|
-
var onPlay = React.useCallback(function (e) {
|
|
222
|
-
if (isSuspended) {
|
|
223
|
-
setIsSuspended(false);
|
|
224
|
-
}
|
|
225
|
-
if (customOnPlay !== null) {
|
|
226
|
-
customOnPlay(e);
|
|
227
|
-
}
|
|
228
|
-
}, [isSuspended, setIsSuspended, customOnPlay]);
|
|
229
|
-
var onPlaying = React.useCallback(function () {
|
|
230
|
-
if (isSuspended) {
|
|
231
|
-
setIsSuspended(false);
|
|
232
|
-
}
|
|
233
|
-
}, [isSuspended, setIsSuspended]);
|
|
234
|
-
var onSuspend = React.useCallback(function (e) {
|
|
235
|
-
if (e.currentTarget.paused && !paused && !isSuspended) {
|
|
236
|
-
setIsSuspended(true);
|
|
237
|
-
if (onSuspended !== null) {
|
|
238
|
-
onSuspended();
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
if (customOnSuspend !== null) {
|
|
242
|
-
customOnSuspend(e);
|
|
243
|
-
}
|
|
244
|
-
}, [isSuspended, paused, setIsSuspended, customOnSuspend, onSuspended]);
|
|
245
|
-
React.useEffect(function () {
|
|
246
|
-
if (ready && onReady !== null) {
|
|
247
|
-
onReady();
|
|
248
|
-
}
|
|
249
|
-
}, [ready, onReady]);
|
|
250
|
-
React.useEffect(function () {
|
|
251
|
-
var _ref$current2 = _ref11.current,
|
|
252
|
-
element = _ref$current2 === void 0 ? null : _ref$current2;
|
|
253
|
-
if (element === null) {
|
|
254
|
-
return;
|
|
255
|
-
}
|
|
256
|
-
var isPaused = element.paused;
|
|
257
|
-
if (paused && !isPaused) {
|
|
258
|
-
element.pause();
|
|
259
|
-
} else if (!paused && isPaused) {
|
|
260
|
-
element.play()["catch"](function (e) {
|
|
261
|
-
if (onPlayError !== null) {
|
|
262
|
-
onPlayError(e);
|
|
263
|
-
}
|
|
264
|
-
});
|
|
265
|
-
}
|
|
266
|
-
}, [paused, media, onPlayError]); // test media here for fun
|
|
267
|
-
|
|
268
|
-
hooks.useProgressSteps({
|
|
269
|
-
currentTime: currentTime,
|
|
270
|
-
duration: duration,
|
|
271
|
-
disabled: paused,
|
|
272
|
-
onStep: onProgressStep
|
|
273
|
-
});
|
|
274
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
275
|
-
className: classNames([styles.container, _defineProperty(_defineProperty({}, className, className !== null), styles.withSize, withSize)]),
|
|
276
|
-
style: withSize ? {
|
|
277
|
-
width: width,
|
|
278
|
-
height: height
|
|
279
|
-
} : null
|
|
280
|
-
}, isImageWithoutSourceFile && shouldLoad ? /*#__PURE__*/React.createElement("img", {
|
|
281
|
-
src: mediaUrl,
|
|
282
|
-
alt: description,
|
|
283
|
-
tabIndex: "-1",
|
|
284
|
-
className: classNames([styles.media, _defineProperty({}, innerClassName, innerClassName !== null)])
|
|
285
|
-
}) : null, !isImageWithoutSourceFile ? /*#__PURE__*/React.createElement("video", {
|
|
286
|
-
key: mediaUrl,
|
|
287
|
-
ref: function ref(newRef) {
|
|
288
|
-
_ref11.current = newRef;
|
|
289
|
-
if (mediaRef !== null && isFunction(mediaRef)) {
|
|
290
|
-
mediaRef(newRef);
|
|
291
|
-
} else if (mediaRef !== null) {
|
|
292
|
-
mediaRef.current = newRef;
|
|
293
|
-
}
|
|
294
|
-
},
|
|
295
|
-
src: sourceFiles === null || sourceFiles.length === 0 ? "".concat(mediaUrl, "#t=0.1") : null,
|
|
296
|
-
autoPlay: autoPlay && !paused,
|
|
297
|
-
loop: loop,
|
|
298
|
-
muted: muted,
|
|
299
|
-
poster: shouldLoad && withPoster && finalThumbnail !== null ? finalThumbnail.url || null : null,
|
|
300
|
-
preload: shouldLoad ? preload : 'none',
|
|
301
|
-
playsInline: playsInline,
|
|
302
|
-
crossOrigin: withoutCors ? 'anonymous' : null,
|
|
303
|
-
disablePictureInPicture: disablePictureInPicture,
|
|
304
|
-
tabIndex: focusable ? '0' : '-1',
|
|
305
|
-
className: classNames([styles.media, _defineProperty({}, innerClassName, innerClassName !== null)]),
|
|
306
|
-
onPlay: onPlay,
|
|
307
|
-
onPlaying: onPlaying,
|
|
308
|
-
onPause: onPause,
|
|
309
|
-
onEnded: onEnded,
|
|
310
|
-
onSeeked: onSeeked,
|
|
311
|
-
onVolumeChange: onVolumeChange,
|
|
312
|
-
onTimeUpdate: onTimeUpdate,
|
|
313
|
-
onSuspend: onSuspend,
|
|
314
|
-
"data-has-audio": hasAudio,
|
|
315
|
-
"data-is-suspended": isSuspended,
|
|
316
|
-
"aria-hidden": true
|
|
317
|
-
}, (sourceFiles || []).map(function (_ref10) {
|
|
318
|
-
var sourceUrl = _ref10.url,
|
|
319
|
-
sourceMime = _ref10.mime;
|
|
320
|
-
return /*#__PURE__*/React.createElement("source", {
|
|
321
|
-
key: "".concat(sourceUrl, "-").concat(sourceMime),
|
|
322
|
-
src: sourceUrl !== null ? "".concat(sourceUrl, "#t=0.1") : null,
|
|
323
|
-
type: sourceMime
|
|
324
|
-
});
|
|
325
|
-
})) : null, !isImageWithoutSourceFile && !ready && showLoading ? /*#__PURE__*/React.createElement(components.Spinner, {
|
|
326
|
-
className: styles.spinner
|
|
327
|
-
}) : null);
|
|
328
|
-
};
|
|
329
|
-
Video.propTypes = propTypes;
|
|
330
|
-
Video.defaultProps = defaultProps;
|
|
331
|
-
var Video$1 = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
332
|
-
return /*#__PURE__*/React.createElement(Video, Object.assign({
|
|
333
|
-
mediaRef: ref
|
|
334
|
-
}, props));
|
|
335
|
-
});
|
|
336
|
-
|
|
337
|
-
module.exports = Video$1;
|