@canopycanopycanopy/b-ber-grammar-vimeo 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 +3 -34
- package/dist/index.js +7 -30
- package/package.json +9 -8
package/dist/helpers.js
CHANGED
|
@@ -1,33 +1,22 @@
|
|
|
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.bBerAttributes = void 0;
|
|
12
9
|
exports.createUnsupportedInline = createUnsupportedInline;
|
|
13
10
|
exports.createVimeo = createVimeo;
|
|
14
11
|
exports.createVimeoInline = createVimeoInline;
|
|
15
12
|
exports.vimeoAttributesTransformer = exports.validatePosterImage = exports.transformAttributes = exports.renderPosterImage = exports.renderCaption = exports.getMediaType = void 0;
|
|
16
|
-
|
|
17
13
|
var _reduce = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/reduce"));
|
|
18
|
-
|
|
19
14
|
var _entries = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/entries"));
|
|
20
|
-
|
|
21
15
|
var _indexOf = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/index-of"));
|
|
22
|
-
|
|
23
16
|
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
24
|
-
|
|
25
17
|
var _bBerLogger = _interopRequireDefault(require("@canopycanopycanopy/b-ber-logger"));
|
|
26
|
-
|
|
27
18
|
var _State = _interopRequireDefault(require("@canopycanopycanopy/b-ber-lib/State"));
|
|
28
|
-
|
|
29
19
|
var _lodash = _interopRequireDefault(require("lodash.isundefined"));
|
|
30
|
-
|
|
31
20
|
// `bBerAttributes` and the `vimeoAttributesTransformer` below are used to
|
|
32
21
|
// filter when building the query string for Vimeo embeds, and for filtering the
|
|
33
22
|
// vimeo/vimeo-inline's directive attributes that appear in the rendered HTML
|
|
@@ -37,20 +26,15 @@ const bBerAttributes = {
|
|
|
37
26
|
aspectratio: true
|
|
38
27
|
};
|
|
39
28
|
exports.bBerAttributes = bBerAttributes;
|
|
40
|
-
|
|
41
29
|
const ensureBoolean = val => val === 'yes';
|
|
42
|
-
|
|
43
30
|
const ensureMatch = (name, re) => val => {
|
|
44
31
|
if (!re.test(val)) {
|
|
45
32
|
let message = `Invalid Vimeo attribute. [${name}] must match [${re}]`;
|
|
46
33
|
message += 'See the Vimeo Player Parameters documentation for more information https://vimeo.zendesk.com/hc/en-us/articles/360001494447-Using-Player-Parameters';
|
|
47
|
-
|
|
48
34
|
_bBerLogger.default.error(message);
|
|
49
35
|
}
|
|
50
|
-
|
|
51
36
|
return val;
|
|
52
37
|
};
|
|
53
|
-
|
|
54
38
|
const vimeoAttributesTransformer = {
|
|
55
39
|
autopause: ensureBoolean,
|
|
56
40
|
autoplay: ensureBoolean,
|
|
@@ -72,10 +56,8 @@ const vimeoAttributesTransformer = {
|
|
|
72
56
|
transparent: ensureBoolean
|
|
73
57
|
};
|
|
74
58
|
exports.vimeoAttributesTransformer = vimeoAttributesTransformer;
|
|
75
|
-
|
|
76
59
|
const transformAttributes = (obj, transformer) => {
|
|
77
60
|
var _context;
|
|
78
|
-
|
|
79
61
|
const nextObj = (0, _reduce.default)(_context = (0, _entries.default)(obj)).call(_context, (acc, [key, val]) => {
|
|
80
62
|
if ((0, _lodash.default)(transformer[key])) return acc;
|
|
81
63
|
acc[key] = transformer[key](val);
|
|
@@ -83,36 +65,24 @@ const transformAttributes = (obj, transformer) => {
|
|
|
83
65
|
}, {});
|
|
84
66
|
return nextObj;
|
|
85
67
|
};
|
|
86
|
-
|
|
87
68
|
exports.transformAttributes = transformAttributes;
|
|
88
|
-
|
|
89
69
|
const validatePosterImage = (asset, type) => {
|
|
90
70
|
const assetPath = _State.default.src.images(asset);
|
|
91
|
-
|
|
92
71
|
if (!_fsExtra.default.existsSync(assetPath)) {
|
|
93
72
|
_bBerLogger.default.error(`bber-directives: Poster image for [${type}] does not exist`);
|
|
94
73
|
}
|
|
95
|
-
|
|
96
74
|
return asset;
|
|
97
75
|
};
|
|
98
|
-
|
|
99
76
|
exports.validatePosterImage = validatePosterImage;
|
|
100
|
-
|
|
101
77
|
const renderPosterImage = poster => poster ? `<img src="${poster}" alt="Poster Image"/>` : '';
|
|
102
|
-
|
|
103
78
|
exports.renderPosterImage = renderPosterImage;
|
|
104
|
-
|
|
105
79
|
const renderCaption = (caption, mediaType) => caption ? `<p class="caption caption__${mediaType}">${caption}</p>` : '';
|
|
106
|
-
|
|
107
80
|
exports.renderCaption = renderCaption;
|
|
108
|
-
|
|
109
81
|
const getMediaType = type => {
|
|
110
82
|
const index = (0, _indexOf.default)(type).call(type, '-');
|
|
111
83
|
return index > -1 ? type.substring(0, index) : type;
|
|
112
84
|
};
|
|
113
|
-
|
|
114
85
|
exports.getMediaType = getMediaType;
|
|
115
|
-
|
|
116
86
|
function createVimeo({
|
|
117
87
|
id,
|
|
118
88
|
href,
|
|
@@ -127,7 +97,6 @@ function createVimeo({
|
|
|
127
97
|
</figure>
|
|
128
98
|
</div>`;
|
|
129
99
|
}
|
|
130
|
-
|
|
131
100
|
function createVimeoInline({
|
|
132
101
|
id,
|
|
133
102
|
commentStart,
|
|
@@ -160,12 +129,12 @@ function createVimeoInline({
|
|
|
160
129
|
${renderCaption(caption, mediaType)}
|
|
161
130
|
</section>
|
|
162
131
|
${commentEnd}`;
|
|
163
|
-
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Only render unsupported HTML for inline embeds since the unsupported figure
|
|
164
135
|
// in the LOI is handled by b-ber-templates. Not great UI to have to click to
|
|
165
136
|
// the LOI to see that something is unsupported, but vimeo directives should
|
|
166
137
|
// mostly be managed by media.yml which supports fallbacks.
|
|
167
|
-
|
|
168
|
-
|
|
169
138
|
function createUnsupportedInline({
|
|
170
139
|
id,
|
|
171
140
|
commentStart,
|
package/dist/index.js
CHANGED
|
@@ -1,42 +1,26 @@
|
|
|
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 _trim = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/trim"));
|
|
14
|
-
|
|
15
10
|
var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));
|
|
16
|
-
|
|
17
11
|
var _path = _interopRequireDefault(require("path"));
|
|
18
|
-
|
|
19
12
|
var _bBerLib = require("@canopycanopycanopy/b-ber-lib");
|
|
20
|
-
|
|
21
13
|
var _State = _interopRequireDefault(require("@canopycanopycanopy/b-ber-lib/State"));
|
|
22
|
-
|
|
23
14
|
var _bBerLogger = _interopRequireDefault(require("@canopycanopycanopy/b-ber-logger"));
|
|
24
|
-
|
|
25
15
|
var _bBerShapesDirectives = require("@canopycanopycanopy/b-ber-shapes-directives");
|
|
26
|
-
|
|
27
16
|
var _bBerParserFigure = _interopRequireDefault(require("@canopycanopycanopy/b-ber-parser-figure"));
|
|
28
|
-
|
|
29
17
|
var _bBerGrammarAttributes = require("@canopycanopycanopy/b-ber-grammar-attributes");
|
|
30
|
-
|
|
31
18
|
var _helpers = require("./helpers");
|
|
32
|
-
|
|
33
19
|
const MARKER_RE = /^(vimeo)/;
|
|
34
20
|
const DIRECTIVE_RE = /(vimeo(?:-inline)?)(?::([^\s]+)(\s+.*)?)?$/;
|
|
35
|
-
|
|
36
21
|
function supported(build) {
|
|
37
22
|
return build === 'reader' || build === 'web';
|
|
38
23
|
}
|
|
39
|
-
|
|
40
24
|
function prepare({
|
|
41
25
|
token,
|
|
42
26
|
marker,
|
|
@@ -52,20 +36,22 @@ function prepare({
|
|
|
52
36
|
lineNumber
|
|
53
37
|
});
|
|
54
38
|
const caption = token.children ? instance.renderInline(token.children) : '';
|
|
55
|
-
if (!attrsObject.source) _bBerLogger.default.error(`Directive [${type}] requires a [source] attribute at [${fileName}:${lineNumber}]`);
|
|
39
|
+
if (!attrsObject.source) _bBerLogger.default.error(`Directive [${type}] requires a [source] attribute at [${fileName}:${lineNumber}]`);
|
|
56
40
|
|
|
41
|
+
// Set update poster image path or set to empty string if one wasn't specified
|
|
57
42
|
if (attrsObject.poster) {
|
|
58
43
|
(0, _helpers.validatePosterImage)(attrsObject.poster, type);
|
|
59
44
|
attrsObject.poster = `../images/${encodeURIComponent(_path.default.basename(attrsObject.poster))}`;
|
|
60
45
|
} else {
|
|
61
46
|
attrsObject.poster = '';
|
|
62
|
-
}
|
|
63
|
-
|
|
47
|
+
}
|
|
64
48
|
|
|
49
|
+
// Add mediaType to classes
|
|
65
50
|
if (!attrsObject.classes) attrsObject.classes = '';
|
|
66
51
|
const supportedPrefix = supported(_State.default.build) ? '' : 'un';
|
|
67
|
-
attrsObject.classes += ` embed ${supportedPrefix}supported`;
|
|
52
|
+
attrsObject.classes += ` embed ${supportedPrefix}supported`;
|
|
68
53
|
|
|
54
|
+
// Ensure an aspect ratio is set, default to 16:9
|
|
69
55
|
let aspectRatio = '16x9';
|
|
70
56
|
const {
|
|
71
57
|
aspectratio
|
|
@@ -77,11 +63,8 @@ function prepare({
|
|
|
77
63
|
const attrString = (0, _bBerGrammarAttributes.attributesString)(attrsObject, _helpers.bBerAttributes);
|
|
78
64
|
const vimeoAttributesObject = (0, _helpers.transformAttributes)(attrsObject, _helpers.vimeoAttributesTransformer);
|
|
79
65
|
const attrQuery = (0, _bBerGrammarAttributes.attributesQueryString)(vimeoAttributesObject);
|
|
80
|
-
|
|
81
66
|
const commentStart = _bBerLib.Html.comment(`START: ${mediaType}:${type}#${figureId};`);
|
|
82
|
-
|
|
83
67
|
const commentEnd = _bBerLib.Html.comment(`END: ${mediaType}:${type}#${figureId};`);
|
|
84
|
-
|
|
85
68
|
const page = `figure-${figureId}.xhtml`;
|
|
86
69
|
const href = _State.default.build === 'reader' ? 'figures-titlepage.xhtml' : page;
|
|
87
70
|
return {
|
|
@@ -104,13 +87,11 @@ function prepare({
|
|
|
104
87
|
type
|
|
105
88
|
};
|
|
106
89
|
}
|
|
107
|
-
|
|
108
90
|
const render = ({
|
|
109
91
|
instance,
|
|
110
92
|
context
|
|
111
93
|
}) => (tokens, index) => {
|
|
112
94
|
var _context;
|
|
113
|
-
|
|
114
95
|
const token = tokens[index];
|
|
115
96
|
const marker = (0, _trim.default)(_context = token.info).call(_context).match(DIRECTIVE_RE);
|
|
116
97
|
if (!marker) return '';
|
|
@@ -125,25 +106,21 @@ const render = ({
|
|
|
125
106
|
fileName,
|
|
126
107
|
lineNumber
|
|
127
108
|
});
|
|
128
|
-
|
|
129
109
|
switch (type) {
|
|
130
110
|
// Render the linked image and add the figure to state so that it's rendered
|
|
131
111
|
// in the LOI
|
|
132
112
|
case 'vimeo':
|
|
133
113
|
_State.default.add('figures', args);
|
|
134
|
-
|
|
135
114
|
return (0, _helpers.createVimeo)(args);
|
|
115
|
+
|
|
136
116
|
// Render an inline Vimeo embed, or an unsupported message if not running a
|
|
137
117
|
// reader or web build
|
|
138
|
-
|
|
139
118
|
case 'vimeo-inline':
|
|
140
119
|
return supported(_State.default.build) ? (0, _helpers.createVimeoInline)(args) : (0, _helpers.createUnsupportedInline)(args);
|
|
141
|
-
|
|
142
120
|
default:
|
|
143
121
|
throw new Error(`Something went wrong parsing [${args.source}] in [${context.fileName}]`);
|
|
144
122
|
}
|
|
145
123
|
};
|
|
146
|
-
|
|
147
124
|
var _default = {
|
|
148
125
|
plugin: _bBerParserFigure.default,
|
|
149
126
|
name: 'vimeo',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@canopycanopycanopy/b-ber-grammar-vimeo",
|
|
3
|
-
"version": "
|
|
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.
|
|
25
|
+
"rimraf": "^2.7.1"
|
|
25
26
|
},
|
|
26
27
|
"dependencies": {
|
|
27
|
-
"@canopycanopycanopy/b-ber-grammar-attributes": "
|
|
28
|
-
"@canopycanopycanopy/b-ber-lib": "
|
|
29
|
-
"@canopycanopycanopy/b-ber-logger": "
|
|
30
|
-
"@canopycanopycanopy/b-ber-parser-figure": "
|
|
31
|
-
"@canopycanopycanopy/b-ber-shapes-directives": "
|
|
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.isundefined": "^3.0.1",
|
|
@@ -51,5 +52,5 @@
|
|
|
51
52
|
"url": "https://maxwellsimmer.com"
|
|
52
53
|
}
|
|
53
54
|
],
|
|
54
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "9b13185f21f602f8a2bf3a4cf503b1fd644d6432"
|
|
55
56
|
}
|