@canopycanopycanopy/b-ber-lib 3.0.8-next.61 → 3.0.8-next.97
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/EbookConvert.js +2 -75
- package/Html.js +2 -24
- package/HtmlToXml.js +2 -252
- package/ManifestItemProperties.js +2 -88
- package/State.js +2 -398
- package/Theme.js +2 -171
- package/YamlAdaptor.js +2 -41
- package/dist/index.d.ts +364 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1372 -0
- package/package.json +24 -31
- package/utils.js +2 -0
- package/Config.js +0 -58
- package/GuideItem.js +0 -19
- package/Spine.js +0 -133
- package/SpineItem.js +0 -53
- package/Template.js +0 -20
- package/Url.js +0 -42
- package/Yaml.js +0 -174
- package/index.js +0 -98
- package/utils/index.js +0 -286
package/EbookConvert.js
CHANGED
|
@@ -1,75 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var _Object$keys = require("@babel/runtime-corejs3/core-js-stable/object/keys");
|
|
4
|
-
var _Object$getOwnPropertySymbols = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols");
|
|
5
|
-
var _filterInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/filter");
|
|
6
|
-
var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor");
|
|
7
|
-
var _forEachInstanceProperty2 = require("@babel/runtime-corejs3/core-js-stable/instance/for-each");
|
|
8
|
-
var _Object$getOwnPropertyDescriptors = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors");
|
|
9
|
-
var _Object$defineProperties = require("@babel/runtime-corejs3/core-js-stable/object/define-properties");
|
|
10
|
-
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
|
11
|
-
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
|
12
|
-
_Object$defineProperty(exports, "__esModule", {
|
|
13
|
-
value: true
|
|
14
|
-
});
|
|
15
|
-
exports.default = void 0;
|
|
16
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
|
|
17
|
-
var _promise = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/promise"));
|
|
18
|
-
var _forEach = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/for-each"));
|
|
19
|
-
var _path = _interopRequireDefault(require("path"));
|
|
20
|
-
var _has = _interopRequireDefault(require("lodash/has"));
|
|
21
|
-
var _child_process = require("child_process");
|
|
22
|
-
var _commandExists = _interopRequireDefault(require("command-exists"));
|
|
23
|
-
var _bBerLogger = _interopRequireDefault(require("@canopycanopycanopy/b-ber-logger"));
|
|
24
|
-
function ownKeys(e, r) { var t = _Object$keys(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = _filterInstanceProperty(o).call(o, function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
25
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _context, _context2; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty2(_context = ownKeys(Object(t), !0)).call(_context, function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : _forEachInstanceProperty2(_context2 = ownKeys(Object(t))).call(_context2, function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
26
|
-
const command = 'ebook-convert';
|
|
27
|
-
const defaults = {
|
|
28
|
-
inputPath: null,
|
|
29
|
-
outputPath: null,
|
|
30
|
-
fileType: null,
|
|
31
|
-
// any format supported by `ebook-convert`
|
|
32
|
-
fileName: new Date().toISOString().replace(/:/g, '-'),
|
|
33
|
-
flags: []
|
|
34
|
-
};
|
|
35
|
-
function checkForCalibre() {
|
|
36
|
-
return new _promise.default((resolve, reject) => {
|
|
37
|
-
(0, _commandExists.default)(command, (err, ok) => {
|
|
38
|
-
if (err || !ok) {
|
|
39
|
-
return reject(new Error("Error: calibre's ebook-convert must be installed. Download calibre here: https://calibre-ebook.com/"));
|
|
40
|
-
}
|
|
41
|
-
resolve();
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
function convertDocument({
|
|
46
|
-
inputPath,
|
|
47
|
-
bookPath,
|
|
48
|
-
flags
|
|
49
|
-
}) {
|
|
50
|
-
return new _promise.default((resolve, reject) => {
|
|
51
|
-
(0, _child_process.exec)(`${command} ${inputPath} ${bookPath} ${flags.join(' ')}`, {
|
|
52
|
-
cwd: process.cwd()
|
|
53
|
-
}, (err, stdout, stderr) => {
|
|
54
|
-
if (err) return reject(err);
|
|
55
|
-
if (stderr !== '') process.stdout.write(stderr);
|
|
56
|
-
if (stdout !== '') process.stdout.write(stdout);
|
|
57
|
-
resolve();
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
function convert(options) {
|
|
62
|
-
const props = ['inputPath', 'outputPath', 'fileType'];
|
|
63
|
-
(0, _forEach.default)(props).call(props, prop => {
|
|
64
|
-
if (!(0, _has.default)(options, prop)) {
|
|
65
|
-
throw new Error(`Missing required option [${prop}]`);
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
const settings = _objectSpread(_objectSpread({}, defaults), options);
|
|
69
|
-
const bookName = `${settings.fileName}.${settings.fileType.replace(/^\./, '')}`;
|
|
70
|
-
settings.bookPath = `"${_path.default.resolve(settings.outputPath, bookName)}"`;
|
|
71
|
-
return checkForCalibre().then(() => convertDocument(settings)).catch(_bBerLogger.default.error);
|
|
72
|
-
}
|
|
73
|
-
var _default = exports.default = {
|
|
74
|
-
convert
|
|
75
|
-
};
|
|
1
|
+
'use strict';
|
|
2
|
+
module.exports = require('./dist/index.js').EbookConvert;
|
package/Html.js
CHANGED
|
@@ -1,24 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
|
4
|
-
_Object$defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.default = void 0;
|
|
8
|
-
class Html {
|
|
9
|
-
static comment(str) {
|
|
10
|
-
return `\n<!-- ${str} -->\n`;
|
|
11
|
-
}
|
|
12
|
-
static escape(str) {
|
|
13
|
-
const str_ = typeof str !== 'string' ? String(str) : str;
|
|
14
|
-
const map = {
|
|
15
|
-
'&': '&',
|
|
16
|
-
'<': '<',
|
|
17
|
-
'>': '>',
|
|
18
|
-
'"': '"',
|
|
19
|
-
"'": '''
|
|
20
|
-
};
|
|
21
|
-
return str_.replace(/[&<>"']/g, m => map[m]);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
var _default = exports.default = Html;
|
|
1
|
+
'use strict';
|
|
2
|
+
module.exports = require('./dist/index.js').Html;
|
package/HtmlToXml.js
CHANGED
|
@@ -1,252 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
|
4
|
-
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
|
5
|
-
_Object$defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.default = void 0;
|
|
9
|
-
var _bind = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/bind"));
|
|
10
|
-
var _reduce = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/reduce"));
|
|
11
|
-
var _entries = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/entries"));
|
|
12
|
-
var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/concat"));
|
|
13
|
-
var _set = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/set"));
|
|
14
|
-
var _trim = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/trim"));
|
|
15
|
-
var _path = _interopRequireDefault(require("path"));
|
|
16
|
-
var _htmlparser = require("htmlparser2");
|
|
17
|
-
var _State = _interopRequireDefault(require("./State"));
|
|
18
|
-
class HtmlToXmlParser {
|
|
19
|
-
constructor({
|
|
20
|
-
content,
|
|
21
|
-
onEndCallback
|
|
22
|
-
}) {
|
|
23
|
-
var _context, _context2, _context3, _context4;
|
|
24
|
-
this.customElementNames = {
|
|
25
|
-
pullquote: true,
|
|
26
|
-
blockquote: true,
|
|
27
|
-
epigraph: true,
|
|
28
|
-
dialogue: true,
|
|
29
|
-
gallery: true,
|
|
30
|
-
spread: true,
|
|
31
|
-
colophon: true,
|
|
32
|
-
appendix: true,
|
|
33
|
-
subtitle: true,
|
|
34
|
-
frontmatter: true,
|
|
35
|
-
backmatter: true,
|
|
36
|
-
'meta-content': true,
|
|
37
|
-
bibliography: true,
|
|
38
|
-
masthead: true,
|
|
39
|
-
figcaption: true,
|
|
40
|
-
subchapter: true
|
|
41
|
-
};
|
|
42
|
-
this.inlineElementNames = {
|
|
43
|
-
pagebreak: true,
|
|
44
|
-
a: false,
|
|
45
|
-
abbr: true,
|
|
46
|
-
acronym: true,
|
|
47
|
-
audio: false,
|
|
48
|
-
b: true,
|
|
49
|
-
bdi: true,
|
|
50
|
-
bdo: true,
|
|
51
|
-
big: true,
|
|
52
|
-
br: false,
|
|
53
|
-
button: false,
|
|
54
|
-
canvas: true,
|
|
55
|
-
cite: true,
|
|
56
|
-
code: true,
|
|
57
|
-
data: true,
|
|
58
|
-
datalist: true,
|
|
59
|
-
del: true,
|
|
60
|
-
dfn: true,
|
|
61
|
-
em: true,
|
|
62
|
-
embed: false,
|
|
63
|
-
i: true,
|
|
64
|
-
iframe: false,
|
|
65
|
-
img: false,
|
|
66
|
-
input: false,
|
|
67
|
-
ins: true,
|
|
68
|
-
kbd: true,
|
|
69
|
-
label: false,
|
|
70
|
-
map: true,
|
|
71
|
-
mark: true,
|
|
72
|
-
meter: true,
|
|
73
|
-
noscript: false,
|
|
74
|
-
object: false,
|
|
75
|
-
output: true,
|
|
76
|
-
picture: false,
|
|
77
|
-
progress: false,
|
|
78
|
-
q: true,
|
|
79
|
-
ruby: true,
|
|
80
|
-
s: true,
|
|
81
|
-
samp: true,
|
|
82
|
-
script: false,
|
|
83
|
-
select: false,
|
|
84
|
-
slot: true,
|
|
85
|
-
small: true,
|
|
86
|
-
span: true,
|
|
87
|
-
strong: true,
|
|
88
|
-
sub: true,
|
|
89
|
-
sup: true,
|
|
90
|
-
svg: true,
|
|
91
|
-
template: true,
|
|
92
|
-
textarea: false,
|
|
93
|
-
time: true,
|
|
94
|
-
u: true,
|
|
95
|
-
tt: true,
|
|
96
|
-
var: true,
|
|
97
|
-
video: false,
|
|
98
|
-
wbr: true
|
|
99
|
-
};
|
|
100
|
-
this.whitelistedAttributes = {
|
|
101
|
-
src: true,
|
|
102
|
-
href: true,
|
|
103
|
-
'xlink:href': true,
|
|
104
|
-
xmlns: true,
|
|
105
|
-
'xmlns:xlink': true,
|
|
106
|
-
class: true
|
|
107
|
-
};
|
|
108
|
-
this.blacklistedTagNames = {
|
|
109
|
-
html: true,
|
|
110
|
-
head: true,
|
|
111
|
-
title: true,
|
|
112
|
-
meta: true,
|
|
113
|
-
link: true,
|
|
114
|
-
script: true,
|
|
115
|
-
body: true,
|
|
116
|
-
video: true,
|
|
117
|
-
audio: true
|
|
118
|
-
};
|
|
119
|
-
this.containingTagNames = {
|
|
120
|
-
div: true,
|
|
121
|
-
span: true,
|
|
122
|
-
section: true
|
|
123
|
-
};
|
|
124
|
-
this.elementAttributeNames = {
|
|
125
|
-
img: {
|
|
126
|
-
src: 'href'
|
|
127
|
-
},
|
|
128
|
-
source: {
|
|
129
|
-
src: 'href'
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
this.elementAttributeTransformers = {
|
|
133
|
-
img: {
|
|
134
|
-
src: value => `file://${_path.default.resolve(_State.default.dist.images(_path.default.basename(value)))}`
|
|
135
|
-
},
|
|
136
|
-
source: {
|
|
137
|
-
src: value => `file://${_path.default.resolve(_State.default.dist.media(_path.default.basename(value)))}`
|
|
138
|
-
}
|
|
139
|
-
};
|
|
140
|
-
this.content = content;
|
|
141
|
-
this.onEndCallback = onEndCallback;
|
|
142
|
-
this.output = '';
|
|
143
|
-
this.tagList = [];
|
|
144
|
-
this.onopentag = (0, _bind.default)(_context = this.onopentag).call(_context, this);
|
|
145
|
-
this.ontext = (0, _bind.default)(_context2 = this.ontext).call(_context2, this);
|
|
146
|
-
this.onclosetag = (0, _bind.default)(_context3 = this.onclosetag).call(_context3, this);
|
|
147
|
-
this.onend = (0, _bind.default)(_context4 = this.onend).call(_context4, this);
|
|
148
|
-
}
|
|
149
|
-
writePageBreak() {
|
|
150
|
-
this.output += '<pagebreak></pagebreak>';
|
|
151
|
-
}
|
|
152
|
-
writeXMLDeclaration() {
|
|
153
|
-
this.output += '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
|
|
154
|
-
}
|
|
155
|
-
renameAttribute(name, attribute) {
|
|
156
|
-
if (!this.elementAttributeNames[name]) return attribute;
|
|
157
|
-
return this.elementAttributeNames[name][attribute] || attribute;
|
|
158
|
-
}
|
|
159
|
-
transformAttributeValue(name, attribute, value) {
|
|
160
|
-
if (!this.elementAttributeTransformers[name] || !this.elementAttributeTransformers[name][attribute]) {
|
|
161
|
-
return value;
|
|
162
|
-
}
|
|
163
|
-
return this.elementAttributeTransformers[name][attribute](value);
|
|
164
|
-
}
|
|
165
|
-
writeTagOpen(name, attributes = {}) {
|
|
166
|
-
var _context5;
|
|
167
|
-
let tag = [name];
|
|
168
|
-
tag = (0, _reduce.default)(_context5 = (0, _entries.default)(attributes)).call(_context5, (acc, [key, val]) => this.whitelistedAttributes[key] ? (0, _concat.default)(acc).call(acc, `${this.renameAttribute(name, key)}="${this.transformAttributeValue(name, key, val)}"`) : acc, tag);
|
|
169
|
-
if (attributes.class) {
|
|
170
|
-
const classNames = new _set.default(attributes.class.split(' '));
|
|
171
|
-
if (classNames.has('figure__large') && classNames.has('figure__inline') || classNames.has('gallery__item')) {
|
|
172
|
-
this.writePageBreak();
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
tag = tag.join(' ');
|
|
176
|
-
this.output += `<${tag}>`;
|
|
177
|
-
}
|
|
178
|
-
writeTagClose(name) {
|
|
179
|
-
this.output += `</${name}>`;
|
|
180
|
-
if (!this.inlineElementNames[name]) this.output += '\n';
|
|
181
|
-
}
|
|
182
|
-
addTag(name) {
|
|
183
|
-
this.tagList.push(name);
|
|
184
|
-
}
|
|
185
|
-
removeTag() {
|
|
186
|
-
return this.tagList.pop();
|
|
187
|
-
}
|
|
188
|
-
getTag() {
|
|
189
|
-
if (!this.tagList.length) return null;
|
|
190
|
-
return this.tagList[this.tagList.length - 1];
|
|
191
|
-
}
|
|
192
|
-
onopentag(name, attributes = {}) {
|
|
193
|
-
if (this.blacklistedTagNames[name]) return;
|
|
194
|
-
if (name === 'body') {
|
|
195
|
-
// Special case for body
|
|
196
|
-
if (attributes.class) {
|
|
197
|
-
// eslint-disable-next-line no-param-reassign
|
|
198
|
-
name = attributes.class.replace(/\s+/g, '-');
|
|
199
|
-
}
|
|
200
|
-
} else if (name === 'source') {
|
|
201
|
-
// Handle both audio and video elements' source tags. The audio and video
|
|
202
|
-
// elements themselves are blacklisted, so the child sources are used as
|
|
203
|
-
// the XML tags for the mp3/mp4s. Only allow mp3/mp4 file extensions since
|
|
204
|
-
// those are the only formats supported by INDD.
|
|
205
|
-
if (!attributes.src || !/\.mp[34]$/i.test(attributes.src)) {
|
|
206
|
-
return;
|
|
207
|
-
}
|
|
208
|
-
} else if (this.containingTagNames[name]) {
|
|
209
|
-
// Generic tag
|
|
210
|
-
if (attributes.class) {
|
|
211
|
-
const classNames = attributes.class.split(' ');
|
|
212
|
-
for (let i = 0; i < classNames.length; i++) {
|
|
213
|
-
if (this.customElementNames[classNames[i]]) {
|
|
214
|
-
// eslint-disable-next-line no-param-reassign
|
|
215
|
-
name = classNames[i];
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
this.addTag(name);
|
|
221
|
-
this.writeTagOpen(name, attributes);
|
|
222
|
-
}
|
|
223
|
-
ontext(text) {
|
|
224
|
-
if (!(0, _trim.default)(text).call(text)) return;
|
|
225
|
-
const name = this.getTag();
|
|
226
|
-
if (!name || this.blacklistedTagNames[name]) return;
|
|
227
|
-
this.output += text;
|
|
228
|
-
}
|
|
229
|
-
onclosetag() {
|
|
230
|
-
const name = this.removeTag();
|
|
231
|
-
if (name) this.writeTagClose(name);
|
|
232
|
-
}
|
|
233
|
-
onend() {
|
|
234
|
-
this.writeTagClose('body');
|
|
235
|
-
this.onEndCallback(this.output);
|
|
236
|
-
}
|
|
237
|
-
parse() {
|
|
238
|
-
this.writeXMLDeclaration();
|
|
239
|
-
this.writeTagOpen('body');
|
|
240
|
-
const parser = new _htmlparser.Parser({
|
|
241
|
-
onclosetag: this.onclosetag,
|
|
242
|
-
onopentag: this.onopentag,
|
|
243
|
-
ontext: this.ontext,
|
|
244
|
-
onend: this.onend
|
|
245
|
-
}, {
|
|
246
|
-
decodeEntities: false
|
|
247
|
-
});
|
|
248
|
-
parser.write(this.content);
|
|
249
|
-
parser.end();
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
var _default = exports.default = HtmlToXmlParser;
|
|
1
|
+
'use strict';
|
|
2
|
+
module.exports = require('./dist/index.js').HtmlToXml;
|
|
@@ -1,88 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
|
4
|
-
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
|
5
|
-
_Object$defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.default = void 0;
|
|
9
|
-
var _includes = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/includes"));
|
|
10
|
-
var _indexOf = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/index-of"));
|
|
11
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
|
|
12
|
-
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
13
|
-
var _mimeTypes = _interopRequireDefault(require("mime-types"));
|
|
14
|
-
var _has = _interopRequireDefault(require("lodash/has"));
|
|
15
|
-
var _bBerShapesDublinCore = require("@canopycanopycanopy/b-ber-shapes-dublin-core");
|
|
16
|
-
// Class to detect XML media-type properties based on the content of XHTML documents
|
|
17
|
-
class ManifestItemProperties {
|
|
18
|
-
// Detect if a file is an (X)HTML document
|
|
19
|
-
static isHTML(file) {
|
|
20
|
-
var _context;
|
|
21
|
-
return (0, _includes.default)(_context = ManifestItemProperties.HTMLMimeTypes).call(_context, _mimeTypes.default.lookup(file.absolutePath));
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// Detect if a file is an ePub navigation document
|
|
25
|
-
static isNav(file) {
|
|
26
|
-
return ManifestItemProperties.isHTML(file) && /^toc\./.test(file.name);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// Detect if an XHTML file contains JavaScript
|
|
30
|
-
static isScripted(file) {
|
|
31
|
-
if (!ManifestItemProperties.isHTML(file)) return false;
|
|
32
|
-
|
|
33
|
-
// TODO: fixme; we need to check if the toc.xhtml is scripted, but it
|
|
34
|
-
// hasn't been written to disk yet. checking right now against the
|
|
35
|
-
// results from `state.template.dynamicTail` for now, since we know
|
|
36
|
-
// that the toc was written using that
|
|
37
|
-
// @issue: https://github.com/triplecanopy/b-ber/issues/206
|
|
38
|
-
if (ManifestItemProperties.isNav(file)) return true;
|
|
39
|
-
const contents = _fsExtra.default.readFileSync(file.absolutePath, 'utf8');
|
|
40
|
-
return contents.match(/<script/) !== null;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// Detect if an XHTML file contains SVG
|
|
44
|
-
static isSVG(file) {
|
|
45
|
-
if (!ManifestItemProperties.isHTML(file)) return false;
|
|
46
|
-
const contents = _fsExtra.default.readFileSync(file.absolutePath, 'utf8');
|
|
47
|
-
return contents.match(/<svg/) !== null;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// Detect if a term is a Dublin Core `element`
|
|
51
|
-
static isDCElement(data) {
|
|
52
|
-
return (0, _has.default)(data, 'term') && (0, _indexOf.default)(_bBerShapesDublinCore.elements).call(_bBerShapesDublinCore.elements, data.term) > -1;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// Detect if a term is a Dublin Core `term`
|
|
56
|
-
static isDCTerm(data) {
|
|
57
|
-
return (0, _has.default)(data, 'term') && (0, _indexOf.default)(_bBerShapesDublinCore.terms).call(_bBerShapesDublinCore.terms, data.term) > -1;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// Detect if an XHTML file contains remote resources
|
|
61
|
-
static hasRemoteResources(file) {
|
|
62
|
-
if (!ManifestItemProperties.isHTML(file)) return false;
|
|
63
|
-
const contents = _fsExtra.default.readFileSync(file.absolutePath, 'utf8');
|
|
64
|
-
return contents.match(/src=(?:['"]{1})?(?:http|\/\/)/) !== null;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// Test if an XHTML file is a navigation document, contains JavaScript or SVG
|
|
68
|
-
static testHTML(file) {
|
|
69
|
-
const props = [];
|
|
70
|
-
if (ManifestItemProperties.isNav(file)) props.push('nav');
|
|
71
|
-
if (ManifestItemProperties.isScripted(file)) props.push('scripted');
|
|
72
|
-
if (ManifestItemProperties.isSVG(file)) props.push('svg');
|
|
73
|
-
if (ManifestItemProperties.hasRemoteResources(file)) {
|
|
74
|
-
props.push('remote-resources');
|
|
75
|
-
}
|
|
76
|
-
return props;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// Test if an object contains Dublin Core `term`s or `element`s
|
|
80
|
-
static testMeta(data) {
|
|
81
|
-
return {
|
|
82
|
-
term: ManifestItemProperties.isDCTerm(data),
|
|
83
|
-
element: ManifestItemProperties.isDCElement(data)
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
(0, _defineProperty2.default)(ManifestItemProperties, "HTMLMimeTypes", ['text/html', 'application/xhtml+xml']);
|
|
88
|
-
var _default = exports.default = ManifestItemProperties;
|
|
1
|
+
'use strict';
|
|
2
|
+
module.exports = require('./dist/index.js').ManifestItemProperties;
|