@micromag/element-closed-captions 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.
Files changed (2) hide show
  1. package/package.json +5 -6
  2. package/lib/index.js +0 -100
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@micromag/element-closed-captions",
3
- "version": "0.3.541",
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
- "main": "lib/index.js",
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.541",
64
- "@micromag/element-text": "^0.3.541",
62
+ "@micromag/core": "^0.3.569",
63
+ "@micromag/element-text": "^0.3.569",
65
64
  "classnames": "^2.2.6",
66
65
  "parse-srt": "^1.0.0-alpha",
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": "6c04a7e327b5fbc096785c11320b3fbd3c5751c8"
74
+ "gitHead": "ceb71f23a32ab8df4a1563a1e5cd5598e539de4d"
76
75
  }
package/lib/index.js DELETED
@@ -1,100 +0,0 @@
1
- 'use strict';
2
-
3
- var _defineProperty = require('@babel/runtime/helpers/defineProperty');
4
- var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
5
- var classNames = require('classnames');
6
- var parseSRT = require('parse-srt');
7
- var PropTypes = require('prop-types');
8
- var React = require('react');
9
- var core = require('@micromag/core');
10
- var utils = require('@micromag/core/utils');
11
- var TextElement = require('@micromag/element-text');
12
-
13
- var styles = {"container":"micromag-element-closed-captions-container","captions":"micromag-element-closed-captions-captions"};
14
-
15
- var propTypes = {
16
- media: core.PropTypes.closedCaptionsMedia,
17
- currentTime: PropTypes.number,
18
- // in seconds
19
- timeOffset: PropTypes.string,
20
- // in srt time format (10:00:01,034)
21
- textStyle: core.PropTypes.textStyle,
22
- boxStyle: core.PropTypes.boxStyle,
23
- className: PropTypes.string
24
- };
25
- var defaultProps = {
26
- media: null,
27
- currentTime: 0,
28
- timeOffset: null,
29
- textStyle: null,
30
- boxStyle: null,
31
- className: null
32
- };
33
- var ClosedCaptions = function ClosedCaptions(_ref) {
34
- var currentTime = _ref.currentTime,
35
- timeOffset = _ref.timeOffset,
36
- media = _ref.media,
37
- textStyle = _ref.textStyle,
38
- boxStyle = _ref.boxStyle,
39
- className = _ref.className;
40
- var _ref2 = media || {},
41
- _ref2$url = _ref2.url,
42
- url = _ref2$url === void 0 ? null : _ref2$url;
43
- var _useState = React.useState([]),
44
- _useState2 = _slicedToArray(_useState, 2),
45
- lines = _useState2[0],
46
- setLines = _useState2[1];
47
- var _useState3 = React.useState(-1),
48
- _useState4 = _slicedToArray(_useState3, 2),
49
- lineIndex = _useState4[0],
50
- setLineIndex = _useState4[1];
51
- var startOffset = timeOffset !== null ? timeOffset.split(/[\t ]*-->[\t ]*/) : null;
52
- var startSeconds = startOffset !== null && startOffset.length ? utils.getSecondsFromTime(startOffset[0]) : 0;
53
- React.useEffect(function () {
54
- if (url === null) {
55
- return;
56
- }
57
- fetch(url, {
58
- mode: 'cors'
59
- }).then(function (response) {
60
- return response.text();
61
- }).then(function (srt) {
62
- return parseSRT(srt);
63
- }).then(function (parsed) {
64
- setLines(parsed);
65
- })["catch"](function (e) {
66
- console.error(e);
67
- });
68
- }, [url, fetch, setLines]);
69
- var getLineIndexFromTime = React.useCallback(function (t) {
70
- var currentLineIndex = lines.findIndex(function (line) {
71
- return t >= line.start - startSeconds && t <= line.end - startSeconds;
72
- });
73
- return currentLineIndex;
74
- }, [lines, startSeconds]);
75
- React.useEffect(function () {
76
- if (lines.length > 0) {
77
- var nextLineIndex = getLineIndexFromTime(currentTime);
78
- if (nextLineIndex !== lineIndex) {
79
- setLineIndex(nextLineIndex);
80
- }
81
- }
82
- }, [currentTime, lines, getLineIndexFromTime, setLineIndex]);
83
- var line = lineIndex !== -1 ? lines[lineIndex] : null;
84
- var active = line !== null;
85
- var finalBoxStyles = boxStyle !== null ? utils.getStyleFromBox(boxStyle) : null;
86
- return /*#__PURE__*/React.createElement("div", {
87
- className: classNames([styles.container, _defineProperty({}, className, className !== null)])
88
- }, active ? /*#__PURE__*/React.createElement("div", {
89
- className: styles.captions,
90
- style: finalBoxStyles
91
- }, /*#__PURE__*/React.createElement(TextElement, {
92
- textStyle: textStyle,
93
- body: line.text
94
- })) : null);
95
- };
96
- ClosedCaptions.propTypes = propTypes;
97
- ClosedCaptions.defaultProps = defaultProps;
98
- var ClosedCaptions$1 = ClosedCaptions;
99
-
100
- module.exports = ClosedCaptions$1;