@micromag/element-closed-captions 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 +11 -21
- package/package.json +9 -3
package/lib/index.js
CHANGED
|
@@ -11,25 +11,15 @@ require('whatwg-fetch');
|
|
|
11
11
|
var core = require('@micromag/core');
|
|
12
12
|
var utils = require('@micromag/core/utils');
|
|
13
13
|
|
|
14
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
15
|
-
|
|
16
|
-
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
|
|
17
|
-
var _slicedToArray__default = /*#__PURE__*/_interopDefaultLegacy(_slicedToArray);
|
|
18
|
-
var classNames__default = /*#__PURE__*/_interopDefaultLegacy(classNames);
|
|
19
|
-
var fetch__default = /*#__PURE__*/_interopDefaultLegacy(fetch);
|
|
20
|
-
var parseSRT__default = /*#__PURE__*/_interopDefaultLegacy(parseSRT);
|
|
21
|
-
var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
|
|
22
|
-
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
23
|
-
|
|
24
14
|
var styles = {"container":"micromag-element-closed-captions-container","captions":"micromag-element-closed-captions-captions"};
|
|
25
15
|
|
|
26
16
|
var propTypes = {
|
|
27
17
|
media: core.PropTypes.closedCaptionsMedia,
|
|
28
|
-
currentTime:
|
|
18
|
+
currentTime: PropTypes.number,
|
|
29
19
|
// in seconds
|
|
30
|
-
timeOffset:
|
|
20
|
+
timeOffset: PropTypes.string,
|
|
31
21
|
// in srt time format (10:00:01,034)
|
|
32
|
-
className:
|
|
22
|
+
className: PropTypes.string
|
|
33
23
|
};
|
|
34
24
|
var defaultProps = {
|
|
35
25
|
media: null,
|
|
@@ -46,11 +36,11 @@ var ClosedCaptions = function ClosedCaptions(_ref) {
|
|
|
46
36
|
_ref2$url = _ref2.url,
|
|
47
37
|
url = _ref2$url === void 0 ? null : _ref2$url;
|
|
48
38
|
var _useState = React.useState([]),
|
|
49
|
-
_useState2 =
|
|
39
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
50
40
|
lines = _useState2[0],
|
|
51
41
|
setLines = _useState2[1];
|
|
52
42
|
var _useState3 = React.useState(-1),
|
|
53
|
-
_useState4 =
|
|
43
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
54
44
|
lineIndex = _useState4[0],
|
|
55
45
|
setLineIndex = _useState4[1];
|
|
56
46
|
var startOffset = timeOffset !== null ? timeOffset.split(/[\t ]*-->[\t ]*/) : null;
|
|
@@ -59,18 +49,18 @@ var ClosedCaptions = function ClosedCaptions(_ref) {
|
|
|
59
49
|
if (url === null) {
|
|
60
50
|
return;
|
|
61
51
|
}
|
|
62
|
-
|
|
52
|
+
fetch(url, {
|
|
63
53
|
mode: 'cors'
|
|
64
54
|
}).then(function (response) {
|
|
65
55
|
return response.text();
|
|
66
56
|
}).then(function (srt) {
|
|
67
|
-
return
|
|
57
|
+
return parseSRT(srt);
|
|
68
58
|
}).then(function (parsed) {
|
|
69
59
|
setLines(parsed);
|
|
70
60
|
})["catch"](function (e) {
|
|
71
61
|
console.error(e);
|
|
72
62
|
});
|
|
73
|
-
}, [url,
|
|
63
|
+
}, [url, fetch, setLines]);
|
|
74
64
|
var getLineIndexFromTime = React.useCallback(function (t) {
|
|
75
65
|
var currentLineIndex = lines.findIndex(function (line) {
|
|
76
66
|
return t >= line.start - startSeconds && t <= line.end - startSeconds;
|
|
@@ -87,9 +77,9 @@ var ClosedCaptions = function ClosedCaptions(_ref) {
|
|
|
87
77
|
}, [currentTime, lines, getLineIndexFromTime, setLineIndex]);
|
|
88
78
|
var line = lineIndex !== -1 ? lines[lineIndex] : null;
|
|
89
79
|
var active = line !== null;
|
|
90
|
-
return /*#__PURE__*/
|
|
91
|
-
className:
|
|
92
|
-
}, active ? /*#__PURE__*/
|
|
80
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
81
|
+
className: classNames([styles.container, _defineProperty({}, className, className !== null)])
|
|
82
|
+
}, active ? /*#__PURE__*/React.createElement("div", {
|
|
93
83
|
className: styles.captions,
|
|
94
84
|
dangerouslySetInnerHTML: active ? {
|
|
95
85
|
__html: line.text
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@micromag/element-closed-captions",
|
|
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",
|
|
@@ -50,7 +56,7 @@
|
|
|
50
56
|
},
|
|
51
57
|
"dependencies": {
|
|
52
58
|
"@babel/runtime": "^7.13.10",
|
|
53
|
-
"@micromag/core": "^0.3.
|
|
59
|
+
"@micromag/core": "^0.3.430",
|
|
54
60
|
"classnames": "^2.2.6",
|
|
55
61
|
"node-fetch": "^2.6.1",
|
|
56
62
|
"parse-srt": "^1.0.0-alpha",
|
|
@@ -63,5 +69,5 @@
|
|
|
63
69
|
"access": "public",
|
|
64
70
|
"registry": "https://registry.npmjs.org/"
|
|
65
71
|
},
|
|
66
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "da790d76dba9d8e308d9f9c4e51d93a4a0e012a9"
|
|
67
73
|
}
|