@canopycanopycanopy/b-ber-grammar-audio-video 1.2.16 → 2.0.2

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/dist/helpers.js CHANGED
@@ -1,13 +1,10 @@
1
1
  "use strict";
2
2
 
3
3
  var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
4
-
5
4
  var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
6
-
7
5
  _Object$defineProperty(exports, "__esModule", {
8
6
  value: true
9
7
  });
10
-
11
8
  exports.createIFrame = createIFrame;
12
9
  exports.createLocalMediaSources = void 0;
13
10
  exports.createMedia = createMedia;
@@ -15,83 +12,52 @@ exports.createMediaInline = createMediaInline;
15
12
  exports.getMediaType = exports.createRemoteMediaSource = void 0;
16
13
  exports.getWebOnlyAttributesString = getWebOnlyAttributesString;
17
14
  exports.validatePosterImage = exports.validateLocalMediaSource = exports.isHostedRemotely = exports.isHostedBySupportedThirdParty = void 0;
18
-
19
15
  var _indexOf = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/index-of"));
20
-
21
16
  var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));
22
-
23
17
  var _reduce = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/reduce"));
24
-
25
18
  var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/concat"));
26
-
27
19
  var _fsExtra = _interopRequireDefault(require("fs-extra"));
28
-
29
20
  var _path = _interopRequireDefault(require("path"));
30
-
31
21
  var _mimeTypes = _interopRequireDefault(require("mime-types"));
32
-
33
22
  var _bBerLib = require("@canopycanopycanopy/b-ber-lib");
34
-
35
23
  var _bBerLogger = _interopRequireDefault(require("@canopycanopycanopy/b-ber-logger"));
36
-
37
24
  var _State = _interopRequireDefault(require("@canopycanopycanopy/b-ber-lib/State"));
38
-
39
25
  var _bBerGrammarAttributes = require("@canopycanopycanopy/b-ber-grammar-attributes");
40
-
41
26
  // import { getVideoAspectRatio } from '@canopycanopycanopy/b-ber-lib/utils'
27
+
42
28
  const getMediaType = type => {
43
29
  const index = (0, _indexOf.default)(type).call(type, '-');
44
30
  return index > -1 ? type.substring(0, index) : type;
45
31
  };
46
-
47
32
  exports.getMediaType = getMediaType;
48
-
49
33
  const isHostedRemotely = asset => /^http/.test(asset);
50
-
51
34
  exports.isHostedRemotely = isHostedRemotely;
52
-
53
35
  const isHostedBySupportedThirdParty = asset => asset.match(/(vimeo|youtube)\.com/);
54
-
55
36
  exports.isHostedBySupportedThirdParty = isHostedBySupportedThirdParty;
56
-
57
37
  const validatePosterImage = (_asset, type) => {
58
38
  const asset = _State.default.src.images(_asset);
59
-
60
39
  if (!_fsExtra.default.existsSync(asset)) {
61
40
  _bBerLogger.default.error(`bber-directives: Poster image for [${type}] does not exist`);
62
41
  }
63
-
64
42
  return asset;
65
43
  };
66
-
67
44
  exports.validatePosterImage = validatePosterImage;
68
-
69
45
  const validateLocalMediaSource = (asset, mediaType) => {
70
46
  var _context;
71
-
72
47
  const media = (0, _map.default)(_context = [..._State.default[mediaType]]).call(_context, file => (0, _bBerGrammarAttributes.toAlias)(file));
73
-
74
48
  if (!asset.length || (0, _indexOf.default)(media).call(media, asset) < 0) {
75
49
  _bBerLogger.default.error(`Could not find [${mediaType}] matching [${asset}], make sure it's included in the [_media] directory`);
76
50
  }
77
-
78
51
  return asset;
79
52
  };
80
-
81
53
  exports.validateLocalMediaSource = validateLocalMediaSource;
82
-
83
54
  const createLocalMediaSources = sources => (0, _reduce.default)(sources).call(sources, (acc, curr) => (0, _concat.default)(acc).call(acc, `<source src="../media/${_path.default.basename(curr)}" type="${_mimeTypes.default.lookup(curr)}"/>`), '');
84
-
85
55
  exports.createLocalMediaSources = createLocalMediaSources;
86
-
87
56
  const createRemoteMediaSource = sources => `<source src="${sources[0]}" type="${_mimeTypes.default.lookup(sources[0])}"/>`;
88
-
89
57
  exports.createRemoteMediaSource = createRemoteMediaSource;
90
-
91
58
  function getWebOnlyAttributesString() {
92
59
  return _State.default.build === 'web' || _State.default.build === 'reader' ? ' webkit-playsinline="webkit-playsinline" playsinline="playsinline"' : '';
93
60
  }
94
-
95
61
  function createMedia({
96
62
  id,
97
63
  href,
@@ -106,7 +72,6 @@ function createMedia({
106
72
  </figure>
107
73
  </div>`;
108
74
  }
109
-
110
75
  function createIFrame({
111
76
  commentStart,
112
77
  commentEnd,
@@ -123,7 +88,6 @@ function createIFrame({
123
88
  </section>
124
89
  ${commentEnd}`;
125
90
  }
126
-
127
91
  function createMediaInline({
128
92
  commentStart,
129
93
  commentEnd,
package/dist/index.js CHANGED
@@ -1,42 +1,25 @@
1
1
  "use strict";
2
2
 
3
3
  var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
4
-
5
4
  var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
6
-
7
5
  _Object$defineProperty(exports, "__esModule", {
8
6
  value: true
9
7
  });
10
-
11
8
  exports.default = void 0;
12
-
13
9
  var _filter = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/filter"));
14
-
15
10
  var _trim = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/trim"));
16
-
17
11
  var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));
18
-
19
12
  var _path = _interopRequireDefault(require("path"));
20
-
21
13
  var _lodash = _interopRequireDefault(require("lodash.has"));
22
-
23
14
  var _bBerLib = require("@canopycanopycanopy/b-ber-lib");
24
-
25
15
  var _State = _interopRequireDefault(require("@canopycanopycanopy/b-ber-lib/State"));
26
-
27
16
  var _bBerLogger = _interopRequireDefault(require("@canopycanopycanopy/b-ber-logger"));
28
-
29
17
  var _bBerShapesDirectives = require("@canopycanopycanopy/b-ber-shapes-directives");
30
-
31
18
  var _bBerParserFigure = _interopRequireDefault(require("@canopycanopycanopy/b-ber-parser-figure"));
32
-
33
19
  var _bBerGrammarAttributes = require("@canopycanopycanopy/b-ber-grammar-attributes");
34
-
35
20
  var _helpers = require("./helpers");
36
-
37
21
  const MARKER_RE = /^(video|audio)/;
38
22
  const DIRECTIVE_RE = /(audio(?:-inline)?|video(?:-inline)?)(?::([^\s]+)(\s+.*)?)?$/;
39
-
40
23
  function prepare({
41
24
  token,
42
25
  marker,
@@ -58,60 +41,48 @@ function prepare({
58
41
  let sourceElements = '';
59
42
  let err = null;
60
43
  let poster = '';
61
- let provider = null; // eslint-disable-line no-unused-vars
62
-
44
+ // let provider = null
63
45
  let aspectRatio = '16x9';
64
46
  let aspectRatioClassName = '';
65
-
66
47
  if (attrsObject.poster) {
67
48
  poster = (0, _helpers.validatePosterImage)(attrsObject.poster, type);
68
49
  poster = `../images/${encodeURIComponent(_path.default.basename(poster))}`;
69
50
  attrsObject.poster = poster;
70
51
  }
71
-
72
52
  const {
73
53
  source
74
54
  } = attrsObject;
75
55
  if (!source) _bBerLogger.default.error(`Directive [${type}] requires a [source] attribute at [${fileName}:${lineNumber}]`);
76
-
77
56
  if (!(0, _lodash.default)(attrsObject, 'controls')) {
78
57
  // Add controls attr by default for audio and video
79
58
  attrsObject.controls = 'controls';
80
- } // Allow for custom controls for reader and web builds where the value is a
59
+ }
60
+
61
+ // Allow for custom controls for reader and web builds where the value is a
81
62
  // string, all other builds set to `controls=controls` for epub validation.
82
63
  // The value `controls=no` gets stripped out in b-ber-grammar-attributes.
83
-
84
-
85
64
  if (_State.default.build !== 'reader' && _State.default.build !== 'web') {
86
65
  attrsObject.controls = attrsObject.controls === 'no' ? attrsObject.controls : 'controls';
87
66
  }
88
-
89
67
  if ((0, _helpers.isHostedRemotely)(source)) {
90
68
  const supportedThirdParty = (0, _helpers.isHostedBySupportedThirdParty)(source);
91
-
92
69
  if (supportedThirdParty) {
93
- ;
94
- [, provider] = supportedThirdParty;
70
+ // ;[, provider] = supportedThirdParty
95
71
  type = type.replace(/(audio|video)/, 'iframe'); // iframe, iframe-inline
96
72
  } else {
97
73
  sources = [source];
98
74
  sourceElements = (0, _helpers.createRemoteMediaSource)(sources);
99
75
  }
100
-
101
76
  _State.default.add('remoteAssets', source);
102
77
  } else if ((0, _helpers.validateLocalMediaSource)(source, mediaType)) {
103
78
  sources = (0, _filter.default)(media).call(media, a => (0, _bBerGrammarAttributes.toAlias)(a) === source);
104
79
  sourceElements = (0, _helpers.createLocalMediaSources)(sources);
105
80
  }
106
-
107
81
  if (!sources.length && type !== 'iframe' && type !== 'iframe-inline') {
108
82
  err = new Error(`bber-directives: Could not find matching [${mediaType}] with the basename [${source}]`);
109
-
110
83
  _bBerLogger.default.error(err);
111
84
  }
112
-
113
85
  delete attrsObject.source; // otherwise we get a `src` tag on our video element
114
-
115
86
  if (mediaType === 'audio') {
116
87
  delete attrsObject.poster; // invalid attr for audio elements
117
88
  }
@@ -123,6 +94,7 @@ function prepare({
123
94
  // const aspectRatioClassName = isHostedRemotely(source)
124
95
  // ? getVideoAspectRatio()
125
96
  // : getVideoAspectRatio(path.resolve(state.src.media(head(sources))))
97
+
126
98
  // Ensure an aspect ratio is set, default to 16:9
127
99
  const {
128
100
  aspectratio
@@ -131,15 +103,11 @@ function prepare({
131
103
  aspectRatioClassName = `video--${aspectRatio}`;
132
104
  delete attrsObject.aspectratio;
133
105
  }
134
-
135
106
  const figureId = (0, _bBerGrammarAttributes.htmlId)(id);
136
107
  const attrString = (0, _bBerGrammarAttributes.attributesString)(attrsObject);
137
108
  const webOnlyAttrString = (0, _helpers.getWebOnlyAttributesString)();
138
-
139
109
  const commentStart = _bBerLib.Html.comment(`START: ${mediaType}:${type}#${figureId};`);
140
-
141
110
  const commentEnd = _bBerLib.Html.comment(`END: ${mediaType}:${type}#${figureId};`);
142
-
143
111
  const page = `figure-${figureId}.xhtml`;
144
112
  const href = _State.default.build === 'reader' ? 'figures-titlepage.xhtml' : page;
145
113
  return {
@@ -164,13 +132,11 @@ function prepare({
164
132
  controls: attrsObject.controls
165
133
  };
166
134
  }
167
-
168
135
  const render = ({
169
136
  instance,
170
137
  context
171
138
  }) => (tokens, index) => {
172
139
  var _context;
173
-
174
140
  const token = tokens[index];
175
141
  const marker = (0, _trim.default)(_context = token.info).call(_context).match(DIRECTIVE_RE);
176
142
  if (!marker) return '';
@@ -185,28 +151,22 @@ const render = ({
185
151
  fileName,
186
152
  lineNumber
187
153
  });
188
-
189
154
  switch (type) {
190
155
  case 'iframe':
191
156
  case 'audio':
192
157
  case 'video':
193
158
  // Add it to state so that it's rendered as a `figure`
194
159
  _State.default.add('figures', args);
195
-
196
160
  return (0, _helpers.createMedia)(args);
197
-
198
161
  case 'iframe-inline':
199
162
  return (0, _helpers.createIFrame)(args);
200
-
201
163
  case 'audio-inline':
202
164
  case 'video-inline':
203
165
  return (0, _helpers.createMediaInline)(args);
204
-
205
166
  default:
206
167
  throw new Error(`Something went wrong parsing [${args.source}] in [${context.fileName}]`);
207
168
  }
208
169
  };
209
-
210
170
  var _default = {
211
171
  plugin: _bBerParserFigure.default,
212
172
  name: 'audio-video',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canopycanopycanopy/b-ber-grammar-audio-video",
3
- "version": "1.2.16",
3
+ "version": "2.0.2",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -20,15 +20,16 @@
20
20
  "@babel/cli": "^7.10.5",
21
21
  "@babel/core": "^7.10.5",
22
22
  "@babel/preset-env": "^7.10.4",
23
+ "browserslist": "^4.17.4",
23
24
  "jest": "^26.6.3",
24
- "rimraf": "^2.6.3"
25
+ "rimraf": "^2.7.1"
25
26
  },
26
27
  "dependencies": {
27
- "@canopycanopycanopy/b-ber-grammar-attributes": "1.2.16",
28
- "@canopycanopycanopy/b-ber-lib": "1.2.16",
29
- "@canopycanopycanopy/b-ber-logger": "1.2.16",
30
- "@canopycanopycanopy/b-ber-parser-figure": "1.2.16",
31
- "@canopycanopycanopy/b-ber-shapes-directives": "1.2.16",
28
+ "@canopycanopycanopy/b-ber-grammar-attributes": "2.0.2",
29
+ "@canopycanopycanopy/b-ber-lib": "2.0.2",
30
+ "@canopycanopycanopy/b-ber-logger": "2.0.2",
31
+ "@canopycanopycanopy/b-ber-parser-figure": "2.0.2",
32
+ "@canopycanopycanopy/b-ber-shapes-directives": "2.0.2",
32
33
  "fs-extra": "^8.1.0",
33
34
  "lodash": "^4.17.21",
34
35
  "lodash.has": "latest",
@@ -52,5 +53,5 @@
52
53
  "url": "https://maxwellsimmer.com"
53
54
  }
54
55
  ],
55
- "gitHead": "b4d9c563beb349a32c19e0f65447f7c7dbc8ea52"
56
+ "gitHead": "9b13185f21f602f8a2bf3a4cf503b1fd644d6432"
56
57
  }