@canopycanopycanopy/b-ber-grammar-audio-video 2.0.0 → 2.0.3

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,
@@ -57,37 +40,32 @@ function prepare({
57
40
  let sources = [];
58
41
  let sourceElements = '';
59
42
  let err = null;
60
- let poster = ''; // let provider = null
61
-
43
+ let poster = '';
44
+ // let provider = null
62
45
  let aspectRatio = '16x9';
63
46
  let aspectRatioClassName = '';
64
-
65
47
  if (attrsObject.poster) {
66
48
  poster = (0, _helpers.validatePosterImage)(attrsObject.poster, type);
67
49
  poster = `../images/${encodeURIComponent(_path.default.basename(poster))}`;
68
50
  attrsObject.poster = poster;
69
51
  }
70
-
71
52
  const {
72
53
  source
73
54
  } = attrsObject;
74
55
  if (!source) _bBerLogger.default.error(`Directive [${type}] requires a [source] attribute at [${fileName}:${lineNumber}]`);
75
-
76
56
  if (!(0, _lodash.default)(attrsObject, 'controls')) {
77
57
  // Add controls attr by default for audio and video
78
58
  attrsObject.controls = 'controls';
79
- } // 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
80
62
  // string, all other builds set to `controls=controls` for epub validation.
81
63
  // The value `controls=no` gets stripped out in b-ber-grammar-attributes.
82
-
83
-
84
64
  if (_State.default.build !== 'reader' && _State.default.build !== 'web') {
85
65
  attrsObject.controls = attrsObject.controls === 'no' ? attrsObject.controls : 'controls';
86
66
  }
87
-
88
67
  if ((0, _helpers.isHostedRemotely)(source)) {
89
68
  const supportedThirdParty = (0, _helpers.isHostedBySupportedThirdParty)(source);
90
-
91
69
  if (supportedThirdParty) {
92
70
  // ;[, provider] = supportedThirdParty
93
71
  type = type.replace(/(audio|video)/, 'iframe'); // iframe, iframe-inline
@@ -95,21 +73,16 @@ function prepare({
95
73
  sources = [source];
96
74
  sourceElements = (0, _helpers.createRemoteMediaSource)(sources);
97
75
  }
98
-
99
76
  _State.default.add('remoteAssets', source);
100
77
  } else if ((0, _helpers.validateLocalMediaSource)(source, mediaType)) {
101
78
  sources = (0, _filter.default)(media).call(media, a => (0, _bBerGrammarAttributes.toAlias)(a) === source);
102
79
  sourceElements = (0, _helpers.createLocalMediaSources)(sources);
103
80
  }
104
-
105
81
  if (!sources.length && type !== 'iframe' && type !== 'iframe-inline') {
106
82
  err = new Error(`bber-directives: Could not find matching [${mediaType}] with the basename [${source}]`);
107
-
108
83
  _bBerLogger.default.error(err);
109
84
  }
110
-
111
85
  delete attrsObject.source; // otherwise we get a `src` tag on our video element
112
-
113
86
  if (mediaType === 'audio') {
114
87
  delete attrsObject.poster; // invalid attr for audio elements
115
88
  }
@@ -121,6 +94,7 @@ function prepare({
121
94
  // const aspectRatioClassName = isHostedRemotely(source)
122
95
  // ? getVideoAspectRatio()
123
96
  // : getVideoAspectRatio(path.resolve(state.src.media(head(sources))))
97
+
124
98
  // Ensure an aspect ratio is set, default to 16:9
125
99
  const {
126
100
  aspectratio
@@ -129,15 +103,11 @@ function prepare({
129
103
  aspectRatioClassName = `video--${aspectRatio}`;
130
104
  delete attrsObject.aspectratio;
131
105
  }
132
-
133
106
  const figureId = (0, _bBerGrammarAttributes.htmlId)(id);
134
107
  const attrString = (0, _bBerGrammarAttributes.attributesString)(attrsObject);
135
108
  const webOnlyAttrString = (0, _helpers.getWebOnlyAttributesString)();
136
-
137
109
  const commentStart = _bBerLib.Html.comment(`START: ${mediaType}:${type}#${figureId};`);
138
-
139
110
  const commentEnd = _bBerLib.Html.comment(`END: ${mediaType}:${type}#${figureId};`);
140
-
141
111
  const page = `figure-${figureId}.xhtml`;
142
112
  const href = _State.default.build === 'reader' ? 'figures-titlepage.xhtml' : page;
143
113
  return {
@@ -162,13 +132,11 @@ function prepare({
162
132
  controls: attrsObject.controls
163
133
  };
164
134
  }
165
-
166
135
  const render = ({
167
136
  instance,
168
137
  context
169
138
  }) => (tokens, index) => {
170
139
  var _context;
171
-
172
140
  const token = tokens[index];
173
141
  const marker = (0, _trim.default)(_context = token.info).call(_context).match(DIRECTIVE_RE);
174
142
  if (!marker) return '';
@@ -183,28 +151,22 @@ const render = ({
183
151
  fileName,
184
152
  lineNumber
185
153
  });
186
-
187
154
  switch (type) {
188
155
  case 'iframe':
189
156
  case 'audio':
190
157
  case 'video':
191
158
  // Add it to state so that it's rendered as a `figure`
192
159
  _State.default.add('figures', args);
193
-
194
160
  return (0, _helpers.createMedia)(args);
195
-
196
161
  case 'iframe-inline':
197
162
  return (0, _helpers.createIFrame)(args);
198
-
199
163
  case 'audio-inline':
200
164
  case 'video-inline':
201
165
  return (0, _helpers.createMediaInline)(args);
202
-
203
166
  default:
204
167
  throw new Error(`Something went wrong parsing [${args.source}] in [${context.fileName}]`);
205
168
  }
206
169
  };
207
-
208
170
  var _default = {
209
171
  plugin: _bBerParserFigure.default,
210
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": "2.0.0",
3
+ "version": "2.0.3",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -25,11 +25,11 @@
25
25
  "rimraf": "^2.7.1"
26
26
  },
27
27
  "dependencies": {
28
- "@canopycanopycanopy/b-ber-grammar-attributes": "2.0.0",
29
- "@canopycanopycanopy/b-ber-lib": "2.0.0",
30
- "@canopycanopycanopy/b-ber-logger": "2.0.0",
31
- "@canopycanopycanopy/b-ber-parser-figure": "2.0.0",
32
- "@canopycanopycanopy/b-ber-shapes-directives": "2.0.0",
28
+ "@canopycanopycanopy/b-ber-grammar-attributes": "2.0.3",
29
+ "@canopycanopycanopy/b-ber-lib": "2.0.3",
30
+ "@canopycanopycanopy/b-ber-logger": "2.0.3",
31
+ "@canopycanopycanopy/b-ber-parser-figure": "2.0.3",
32
+ "@canopycanopycanopy/b-ber-shapes-directives": "2.0.3",
33
33
  "fs-extra": "^8.1.0",
34
34
  "lodash": "^4.17.21",
35
35
  "lodash.has": "latest",
@@ -53,5 +53,5 @@
53
53
  "url": "https://maxwellsimmer.com"
54
54
  }
55
55
  ],
56
- "gitHead": "dbeae192709705f5bc211195ff343cbd999f9caf"
56
+ "gitHead": "f5e6f419af00c5d0c28e7ee202b8184273ca81e3"
57
57
  }