@canopycanopycanopy/b-ber-lib 1.2.13-react-reader.5 → 1.2.16
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/package.json +7 -7
- package/utils/index.js +90 -17
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@canopycanopycanopy/b-ber-lib",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.16",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -27,11 +27,11 @@
|
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@babel/runtime-corejs3": "^7.10.5",
|
|
30
|
-
"@canopycanopycanopy/b-ber-logger": "1.2.
|
|
31
|
-
"@canopycanopycanopy/b-ber-shapes-dublin-core": "1.2.
|
|
32
|
-
"@canopycanopycanopy/b-ber-shapes-sequences": "1.2.
|
|
33
|
-
"@canopycanopycanopy/b-ber-theme-sans": "1.2.
|
|
34
|
-
"@canopycanopycanopy/b-ber-theme-serif": "1.2.
|
|
30
|
+
"@canopycanopycanopy/b-ber-logger": "1.2.16",
|
|
31
|
+
"@canopycanopycanopy/b-ber-shapes-dublin-core": "1.2.16",
|
|
32
|
+
"@canopycanopycanopy/b-ber-shapes-sequences": "1.2.16",
|
|
33
|
+
"@canopycanopycanopy/b-ber-theme-sans": "1.2.16",
|
|
34
|
+
"@canopycanopycanopy/b-ber-theme-serif": "1.2.16",
|
|
35
35
|
"command-exists": "^1.2.2",
|
|
36
36
|
"fs-extra": "^8.1.0",
|
|
37
37
|
"glob": "^7.1.4",
|
|
@@ -76,5 +76,5 @@
|
|
|
76
76
|
"url": "https://maxwellsimmer.com"
|
|
77
77
|
}
|
|
78
78
|
],
|
|
79
|
-
"gitHead": "
|
|
79
|
+
"gitHead": "b4d9c563beb349a32c19e0f65447f7c7dbc8ea52"
|
|
80
80
|
}
|
package/utils/index.js
CHANGED
|
@@ -13,7 +13,7 @@ exports.ensure = void 0;
|
|
|
13
13
|
exports.ensurePoster = ensurePoster;
|
|
14
14
|
exports.ensureSource = ensureSource;
|
|
15
15
|
exports.ensureSupportedClassNames = ensureSupportedClassNames;
|
|
16
|
-
exports.validatePosterImage = exports.safeWrite = exports.renderPosterImage = exports.renderCaption = exports.opsPath = exports.getTitle = exports.getMediaType = exports.getImageOrientation = exports.getBookMetadata = exports.generateWebpubManifest = exports.forOf = exports.fileId = exports.fail = void 0;
|
|
16
|
+
exports.validatePosterImage = exports.safeWrite = exports.resolveIntersectingUrl = exports.renderPosterImage = exports.renderCaption = exports.opsPath = exports.getTitle = exports.getMediaType = exports.getImageOrientation = exports.getBookMetadata = exports.generateWebpubManifest = exports.forOf = exports.fileId = exports.fail = void 0;
|
|
17
17
|
|
|
18
18
|
var _forEach = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/for-each"));
|
|
19
19
|
|
|
@@ -29,6 +29,12 @@ var _reduce = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-sta
|
|
|
29
29
|
|
|
30
30
|
var _filter = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/filter"));
|
|
31
31
|
|
|
32
|
+
var _url = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/url"));
|
|
33
|
+
|
|
34
|
+
var _slice = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/slice"));
|
|
35
|
+
|
|
36
|
+
var _map2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/map"));
|
|
37
|
+
|
|
32
38
|
var _indexOf = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/index-of"));
|
|
33
39
|
|
|
34
40
|
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
@@ -163,24 +169,91 @@ const ensure = ({
|
|
|
163
169
|
|
|
164
170
|
exports.ensure = ensure;
|
|
165
171
|
|
|
166
|
-
const
|
|
172
|
+
const trimLeadingSlash = s => s.replace(/^\//, '');
|
|
173
|
+
|
|
174
|
+
const resolveIntersectingUrl = (u, p) => {
|
|
167
175
|
var _context7, _context8;
|
|
168
176
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
const
|
|
180
|
-
|
|
181
|
-
|
|
177
|
+
let url = '';
|
|
178
|
+
|
|
179
|
+
try {
|
|
180
|
+
url = new _url.default(u);
|
|
181
|
+
} catch (err) {
|
|
182
|
+
_bBerLogger.default.warn(err);
|
|
183
|
+
|
|
184
|
+
return url;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const {
|
|
188
|
+
pathname
|
|
189
|
+
} = url;
|
|
190
|
+
let urlParts = (0, _filter.default)(_context7 = pathname.split('/')).call(_context7, Boolean);
|
|
191
|
+
let pathParts = (0, _filter.default)(_context8 = p.split('/')).call(_context8, Boolean); // Remove filename if there is one
|
|
192
|
+
|
|
193
|
+
if (/\./.test(urlParts[urlParts.length - 1])) {
|
|
194
|
+
urlParts.pop();
|
|
195
|
+
} // Find indices where to slice arrays
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
let intersectionIndices = [];
|
|
199
|
+
|
|
200
|
+
for (let i = 0; i < urlParts.length; i++) {
|
|
201
|
+
for (let j = 0; j < pathParts.length; j++) {
|
|
202
|
+
if (urlParts[i] === pathParts[j]) {
|
|
203
|
+
intersectionIndices = [i, j];
|
|
204
|
+
break;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const [uIdx, pIdx] = intersectionIndices;
|
|
210
|
+
urlParts = (0, _slice.default)(urlParts).call(urlParts, 0, uIdx);
|
|
211
|
+
pathParts = (0, _slice.default)(pathParts).call(pathParts, pIdx);
|
|
212
|
+
const intersection = (0, _concat.default)(urlParts).call(urlParts, pathParts);
|
|
213
|
+
url.pathname = intersection.join('/');
|
|
214
|
+
return url.href;
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
exports.resolveIntersectingUrl = resolveIntersectingUrl;
|
|
218
|
+
|
|
219
|
+
const webpubManifestResource = base => file => {
|
|
220
|
+
const href = resolveIntersectingUrl(base, file);
|
|
221
|
+
return {
|
|
222
|
+
href,
|
|
182
223
|
type: _mimeTypes.default.lookup(file)
|
|
183
|
-
}
|
|
224
|
+
};
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
const webpubManifestReadingOrderItem = base => ({
|
|
228
|
+
title,
|
|
229
|
+
file
|
|
230
|
+
}) => {
|
|
231
|
+
const href = resolveIntersectingUrl(base, file);
|
|
232
|
+
return {
|
|
233
|
+
href,
|
|
234
|
+
title,
|
|
235
|
+
type: 'text/xhtml'
|
|
236
|
+
};
|
|
237
|
+
}; // https://github.com/readium/webpub-manifest
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
const generateWebpubManifest = files => {
|
|
241
|
+
var _context9, _context10;
|
|
242
|
+
|
|
243
|
+
const remoteURL = _.Url.trimSlashes(_.State.config.remote_url); // Build a map to sort the files according to the position in the spine
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
const fileMap = new _map2.default((0, _map.default)(files).call(files, f => [_path.default.basename(f), f])); // Create the items for the manifest's reading order
|
|
247
|
+
|
|
248
|
+
const readingOrderItems = (0, _reduce.default)(_context9 = _.State.spine.flattened).call(_context9, (acc, curr) => {
|
|
249
|
+
const file = fileMap.get(`${curr.fileName}.xhtml`);
|
|
250
|
+
return !file ? acc : (0, _concat.default)(acc).call(acc, {
|
|
251
|
+
file,
|
|
252
|
+
title: curr.title
|
|
253
|
+
});
|
|
254
|
+
}, []);
|
|
255
|
+
const readingOrder = (0, _map.default)(readingOrderItems).call(readingOrderItems, webpubManifestReadingOrderItem(remoteURL));
|
|
256
|
+
const resources = (0, _map.default)(_context10 = (0, _filter.default)(files).call(files, file => _path.default.basename(file).charAt(0) !== '.')).call(_context10, webpubManifestResource(remoteURL));
|
|
184
257
|
const manifest = {
|
|
185
258
|
'@context': 'https://readium.org/webpub-manifest/context.jsonld',
|
|
186
259
|
metadata: {
|
|
@@ -194,7 +267,7 @@ const generateWebpubManifest = files => {
|
|
|
194
267
|
},
|
|
195
268
|
links: [{
|
|
196
269
|
rel: 'self',
|
|
197
|
-
href: `${remoteURL}/manifest.json`,
|
|
270
|
+
href: `${remoteURL}/${trimLeadingSlash(_.State.distDir)}/manifest.json`,
|
|
198
271
|
type: 'application/webpub+json'
|
|
199
272
|
} // { rel: 'alternate', href: `${remoteURL}/publication.epub`, type: 'application/epub+zip' },
|
|
200
273
|
// { rel: 'search', href: `${remoteURL}/search{?query}`, type: 'text/html', templated: true },
|