From 953afa1d205e352dbbef41f7a5565f28937dae5b Mon Sep 17 00:00:00 2001 From: Carlson Santana Cruz Date: Wed, 9 Aug 2023 19:58:11 -0300 Subject: [PATCH] Don't ignore dist files --- .gitignore | 3 - dist/jepub.js | 1708 +++++++++++++++++++++++++++++++++ dist/jepub.js.map | 1 + dist/jepub.min.js | 2 + dist/jepub.min.js.LICENSE.txt | 1 + 5 files changed, 1712 insertions(+), 3 deletions(-) create mode 100644 dist/jepub.js create mode 100644 dist/jepub.js.map create mode 100644 dist/jepub.min.js create mode 100644 dist/jepub.min.js.LICENSE.txt diff --git a/.gitignore b/.gitignore index dfc4e8f..c07f0c7 100644 --- a/.gitignore +++ b/.gitignore @@ -125,6 +125,3 @@ Icon Network Trash Folder Temporary Items .apdisk - -# Build-related directories -dist/ diff --git a/dist/jepub.js b/dist/jepub.js new file mode 100644 index 0000000..894ef3b --- /dev/null +++ b/dist/jepub.js @@ -0,0 +1,1708 @@ +(function webpackUniversalModuleDefinition(root, factory) { + if(typeof exports === 'object' && typeof module === 'object') + module.exports = factory(); + else if(typeof define === 'function' && define.amd) + define("jEpub", [], factory); + else if(typeof exports === 'object') + exports["jEpub"] = factory(); + else + root["jEpub"] = factory(); +})(self, () => { +return /******/ (() => { // webpackBootstrap +/******/ var __webpack_modules__ = ({ + +/***/ "./node_modules/@babel/runtime/helpers/interopRequireDefault.js": +/*!**********************************************************************!*\ + !*** ./node_modules/@babel/runtime/helpers/interopRequireDefault.js ***! + \**********************************************************************/ +/***/ ((module) => { + +function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { + "default": obj + }; +} + +module.exports = _interopRequireDefault; + +/***/ }), + +/***/ "./node_modules/@babel/runtime/helpers/interopRequireWildcard.js": +/*!***********************************************************************!*\ + !*** ./node_modules/@babel/runtime/helpers/interopRequireWildcard.js ***! + \***********************************************************************/ +/***/ ((module, __unused_webpack_exports, __webpack_require__) => { + +var _typeof = __webpack_require__(/*! ../helpers/typeof */ "./node_modules/@babel/runtime/helpers/typeof.js"); + +function _getRequireWildcardCache() { + if (typeof WeakMap !== "function") return null; + var cache = new WeakMap(); + + _getRequireWildcardCache = function _getRequireWildcardCache() { + return cache; + }; + + return cache; +} + +function _interopRequireWildcard(obj) { + if (obj && obj.__esModule) { + return obj; + } + + if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { + return { + "default": obj + }; + } + + var cache = _getRequireWildcardCache(); + + if (cache && cache.has(obj)) { + return cache.get(obj); + } + + var newObj = {}; + var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; + + for (var key in obj) { + if (Object.prototype.hasOwnProperty.call(obj, key)) { + var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; + + if (desc && (desc.get || desc.set)) { + Object.defineProperty(newObj, key, desc); + } else { + newObj[key] = obj[key]; + } + } + } + + newObj["default"] = obj; + + if (cache) { + cache.set(obj, newObj); + } + + return newObj; +} + +module.exports = _interopRequireWildcard; + +/***/ }), + +/***/ "./node_modules/@babel/runtime/helpers/typeof.js": +/*!*******************************************************!*\ + !*** ./node_modules/@babel/runtime/helpers/typeof.js ***! + \*******************************************************/ +/***/ ((module) => { + +function _typeof(obj) { + "@babel/helpers - typeof"; + + if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { + module.exports = _typeof = function _typeof(obj) { + return typeof obj; + }; + } else { + module.exports = _typeof = function _typeof(obj) { + return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; + }; + } + + return _typeof(obj); +} + +module.exports = _typeof; + +/***/ }), + +/***/ "./src/jepub.js": +/*!**********************!*\ + !*** ./src/jepub.js ***! + \**********************/ +/***/ ((module, exports, __webpack_require__) => { + +"use strict"; + + +var _interopRequireDefault = __webpack_require__(/*! @babel/runtime/helpers/interopRequireDefault */ "./node_modules/@babel/runtime/helpers/interopRequireDefault.js"); + +var _interopRequireWildcard = __webpack_require__(/*! @babel/runtime/helpers/interopRequireWildcard */ "./node_modules/@babel/runtime/helpers/interopRequireWildcard.js"); + +Object.defineProperty(exports, "__esModule", ({ + value: true +})); +exports["default"] = void 0; + +var utils = _interopRequireWildcard(__webpack_require__(/*! ./utils */ "./src/utils.js")); + +var _imageType = _interopRequireDefault(__webpack_require__(/*! image-type */ "./node_modules/image-type/index.js")); + +var _i18n = _interopRequireDefault(__webpack_require__(/*! ./i18n.json */ "./src/i18n.json")); + +var _container = _interopRequireDefault(__webpack_require__(/*! ./tpl/epub/META-INF/container.xml */ "./src/tpl/epub/META-INF/container.xml")); + +var _frontCover = _interopRequireDefault(__webpack_require__(/*! ./tpl/epub/OEBPS/front-cover.html */ "./src/tpl/epub/OEBPS/front-cover.html.ejs")); + +var _notes = _interopRequireDefault(__webpack_require__(/*! ./tpl/epub/OEBPS/notes.html */ "./src/tpl/epub/OEBPS/notes.html.ejs")); + +var _page = _interopRequireDefault(__webpack_require__(/*! ./tpl/epub/OEBPS/page.html */ "./src/tpl/epub/OEBPS/page.html.ejs")); + +var _tableOfContents = _interopRequireDefault(__webpack_require__(/*! ./tpl/epub/OEBPS/table-of-contents.html */ "./src/tpl/epub/OEBPS/table-of-contents.html.ejs")); + +var _titlePage = _interopRequireDefault(__webpack_require__(/*! ./tpl/epub/OEBPS/title-page.html */ "./src/tpl/epub/OEBPS/title-page.html.ejs")); + +var _book = _interopRequireDefault(__webpack_require__(/*! ./tpl/epub/book.opf */ "./src/tpl/epub/book.opf.ejs")); + +var _mimetype = _interopRequireDefault(__webpack_require__(/*! ./tpl/epub/mimetype */ "./src/tpl/epub/mimetype")); + +var _toc = _interopRequireDefault(__webpack_require__(/*! ./tpl/epub/toc.ncx */ "./src/tpl/epub/toc.ncx.ejs")); + +class jEpub { + constructor() { + this._I18n = {}; + this._Info = {}; + this._Uuid = {}; + this._Date = null; + this._Cover = null; + this._Pages = []; + this._Images = []; + this._Zip = {}; + } + + init(details) { + if (details instanceof JSZip) { + this._Zip = details; + return this; + } + + this._Info = Object.assign({}, { + i18n: 'en', + title: 'undefined', + author: 'undefined', + publisher: 'undefined', + description: '', + tags: [] + }, details); + this._Uuid = { + scheme: 'uuid', + id: utils.uuidv4() + }; + this._Date = utils.getISODate(); + if (!_i18n.default[this._Info.i18n]) throw "Unknown Language: ".concat(this._Info.i18n); + this._I18n = _i18n.default[this._Info.i18n]; + this._Zip = new JSZip(); + + this._Zip.file('mimetype', _mimetype.default); + + this._Zip.file('META-INF/container.xml', _container.default); + + this._Zip.file('OEBPS/title-page.html', ejs.render(_titlePage.default, { + i18n: this._I18n, + title: this._Info.title, + author: this._Info.author, + publisher: this._Info.publisher, + description: utils.parseDOM(this._Info.description), + tags: this._Info.tags + }, { + client: true + })); + + return this; + } + + static html2text(html, noBr = false) { + return utils.html2text(html, noBr); + } + + date(date) { + if (date instanceof Date) { + this._Date = utils.getISODate(date); + return this; + } else { + throw 'Date object is not valid'; + } + } + + uuid(id) { + if (utils.isEmpty(id)) { + throw 'UUID value is empty'; + } else { + let scheme = 'uuid'; + if (utils.validateUrl(id)) scheme = 'URI'; + this._Uuid = { + scheme: scheme, + id: id + }; + return this; + } + } + + cover(data) { + let ext, mime; + + if (data instanceof Blob) { + mime = data.type; + ext = utils.mime2ext(mime); + } else if (data instanceof ArrayBuffer) { + ext = (0, _imageType.default)(new Uint8Array(data)); + + if (ext) { + mime = ext.mime; + ext = utils.mime2ext(mime); + } + } else { + throw 'Cover data is not valid'; + } + + if (!ext) throw 'Cover data is not allowed'; + this._Cover = { + type: mime, + path: "OEBPS/cover-image.".concat(ext) + }; + + this._Zip.file(this._Cover.path, data); + + this._Zip.file('OEBPS/front-cover.html', ejs.render(_frontCover.default, { + i18n: this._I18n, + cover: this._Cover + }, { + client: true + })); + + return this; + } + + image(data, name) { + let ext, mime; + + if (data instanceof Blob) { + mime = data.type; + ext = utils.mime2ext(mime); + } else if (data instanceof ArrayBuffer) { + ext = (0, _imageType.default)(new Uint8Array(data)); + mime = ext.mime; + if (ext) ext = utils.mime2ext(mime); + } else { + throw 'Image data is not valid'; + } + + if (!ext) throw 'Image data is not allowed'; + const filePath = "assets/".concat(name, ".").concat(ext); + this._Images[name] = { + type: mime, + path: filePath + }; + + this._Zip.file("OEBPS/".concat(filePath), data); + + return this; + } + + notes(content) { + if (utils.isEmpty(content)) { + throw 'Notes is empty'; + } else { + this._Zip.file('OEBPS/notes.html', ejs.render(_notes.default, { + i18n: this._I18n, + notes: utils.parseDOM(content) + }, { + client: true + })); + + return this; + } + } + + add(title, content, index = this._Pages.length) { + if (utils.isEmpty(title)) { + throw 'Title is empty'; + } else if (utils.isEmpty(content)) { + throw "Content of ".concat(title, " is empty"); + } else { + if (!Array.isArray(content)) { + const template = ejs.compile(content, { + client: true + }); + content = template({ + image: this._Images + }, data => { + return " { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", ({ + value: true +})); +exports.uuidv4 = uuidv4; +exports.isObject = isObject; +exports.isEmpty = isEmpty; +exports.getISODate = getISODate; +exports.parseDOM = parseDOM; +exports.html2text = html2text; +exports.validateUrl = validateUrl; +exports.mime2ext = mime2ext; + +/** + * Generates a UUID + * @see https://stackoverflow.com/a/2117523 + * @returns {string} uuid + */ +function uuidv4() { + return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c => (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)); +} +/** + * Checks if a value is object + * @see https://stackoverflow.com/a/14706877 + * @returns {boolean} + */ + + +function isObject(obj) { + const type = typeof obj; + return type === 'function' || type === 'object' && !!obj; +} +/** + * Checks if a value is empty + * @returns {boolean} + */ + + +function isEmpty(val) { + if (val === null) { + return true; + } else if (typeof val === 'string') { + return !val.trim(); + } + + return false; +} +/** + * Get current moment in ISO format + * @param {Object} date + * @returns {string} ISO date + */ + + +function getISODate(date = new Date()) { + return date.toISOString(); +} +/** + * Convert convert HTML to valid XHTML + * @param {String} html + * @param {String} outText return as plain text + */ + + +function parseDOM(html, outText = false) { + let doc = new DOMParser().parseFromString("".concat(html), 'text/html'); + if (outText) return doc.body.textContent.trim(); + doc = new XMLSerializer().serializeToString(doc.body); + doc = doc.replace(/(^]*>|<\/body>$)/g, ''); + return doc; +} +/** + * Convert HTML to plain text + * @param {String} html + */ + + +function html2text(html, noBr = false) { + html = html.replace(//gi, ''); + html = html.replace(//gi, ''); + html = html.replace(/<\/(div|p|li|dd|h[1-6])>/gi, '\n'); + html = html.replace(/<(br|hr)\s*[/]?>/gi, '\n'); + html = html.replace(/
  • /ig, '+ '); + html = html.replace(/<[^>]+>/g, ''); + html = html.replace(/\n{3,}/g, '\n\n'); + html = parseDOM(html, true); + if (noBr) html = html.replace(/\n+/g, ' '); + return html; +} +/** + * @see https://gist.github.com/dperini/729294 + * @param {String} value + */ + + +function validateUrl(value) { + return /^(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,}))\.?)(?::\d{2,5})?(?:[/?#]\S*)?$/i.test(value); +} +/** + * Convert MIME type to extension + * @param {String} mime + */ + + +function mime2ext(mime) { + let ext = null; + + switch (mime) { + case 'image/jpg': + case 'image/jpeg': + ext = 'jpg'; + break; + + case 'image/svg+xml': + ext = 'svg'; + break; + + case 'image/gif': + case 'image/apng': + case 'image/png': + case 'image/webp': + case 'image/bmp': + ext = mime.split('/')[1]; + break; + + default: + ext = null; + break; + } + + return ext; +} // TODO: kepub +// Wrap text, image text +// https://github.com/pgaskin/kepubify/blob/871aa0bb2047b5ba171bc608024bdb180cb29d70/kepub/transform.go#L173 +//UnescapeString +// var htmlEscaper = strings.NewReplacer( +// `&`, "&", +// `'`, "'", // "'" is shorter than "'" and apos was not in HTML until HTML5. +// `<`, "<", +// `>`, ">", +// `"`, """, // """ is shorter than """. +// ) + +/***/ }), + +/***/ "./node_modules/file-type/index.js": +/*!*****************************************!*\ + !*** ./node_modules/file-type/index.js ***! + \*****************************************/ +/***/ ((module) => { + +"use strict"; + +const toBytes = s => [...s].map(c => c.charCodeAt(0)); +const xpiZipFilename = toBytes('META-INF/mozilla.rsa'); +const oxmlContentTypes = toBytes('[Content_Types].xml'); +const oxmlRels = toBytes('_rels/.rels'); + +function readUInt64LE(buf, offset = 0) { + let n = buf[offset]; + let mul = 1; + let i = 0; + while (++i < 8) { + mul *= 0x100; + n += buf[offset + i] * mul; + } + + return n; +} + +const fileType = input => { + if (!(input instanceof Uint8Array || input instanceof ArrayBuffer || Buffer.isBuffer(input))) { + throw new TypeError(`Expected the \`input\` argument to be of type \`Uint8Array\` or \`Buffer\` or \`ArrayBuffer\`, got \`${typeof input}\``); + } + + const buf = input instanceof Uint8Array ? input : new Uint8Array(input); + + if (!(buf && buf.length > 1)) { + return null; + } + + const check = (header, options) => { + options = Object.assign({ + offset: 0 + }, options); + + for (let i = 0; i < header.length; i++) { + // If a bitmask is set + if (options.mask) { + // If header doesn't equal `buf` with bits masked off + if (header[i] !== (options.mask[i] & buf[i + options.offset])) { + return false; + } + } else if (header[i] !== buf[i + options.offset]) { + return false; + } + } + + return true; + }; + + const checkString = (header, options) => check(toBytes(header), options); + + if (check([0xFF, 0xD8, 0xFF])) { + return { + ext: 'jpg', + mime: 'image/jpeg' + }; + } + + if (check([0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A])) { + return { + ext: 'png', + mime: 'image/png' + }; + } + + if (check([0x47, 0x49, 0x46])) { + return { + ext: 'gif', + mime: 'image/gif' + }; + } + + if (check([0x57, 0x45, 0x42, 0x50], {offset: 8})) { + return { + ext: 'webp', + mime: 'image/webp' + }; + } + + if (check([0x46, 0x4C, 0x49, 0x46])) { + return { + ext: 'flif', + mime: 'image/flif' + }; + } + + // Needs to be before `tif` check + if ( + (check([0x49, 0x49, 0x2A, 0x0]) || check([0x4D, 0x4D, 0x0, 0x2A])) && + check([0x43, 0x52], {offset: 8}) + ) { + return { + ext: 'cr2', + mime: 'image/x-canon-cr2' + }; + } + + if ( + check([0x49, 0x49, 0x2A, 0x0]) || + check([0x4D, 0x4D, 0x0, 0x2A]) + ) { + return { + ext: 'tif', + mime: 'image/tiff' + }; + } + + if (check([0x42, 0x4D])) { + return { + ext: 'bmp', + mime: 'image/bmp' + }; + } + + if (check([0x49, 0x49, 0xBC])) { + return { + ext: 'jxr', + mime: 'image/vnd.ms-photo' + }; + } + + if (check([0x38, 0x42, 0x50, 0x53])) { + return { + ext: 'psd', + mime: 'image/vnd.adobe.photoshop' + }; + } + + // Zip-based file formats + // Need to be before the `zip` check + if (check([0x50, 0x4B, 0x3, 0x4])) { + if ( + check([0x6D, 0x69, 0x6D, 0x65, 0x74, 0x79, 0x70, 0x65, 0x61, 0x70, 0x70, 0x6C, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6F, 0x6E, 0x2F, 0x65, 0x70, 0x75, 0x62, 0x2B, 0x7A, 0x69, 0x70], {offset: 30}) + ) { + return { + ext: 'epub', + mime: 'application/epub+zip' + }; + } + + // Assumes signed `.xpi` from addons.mozilla.org + if (check(xpiZipFilename, {offset: 30})) { + return { + ext: 'xpi', + mime: 'application/x-xpinstall' + }; + } + + if (checkString('mimetypeapplication/vnd.oasis.opendocument.text', {offset: 30})) { + return { + ext: 'odt', + mime: 'application/vnd.oasis.opendocument.text' + }; + } + + if (checkString('mimetypeapplication/vnd.oasis.opendocument.spreadsheet', {offset: 30})) { + return { + ext: 'ods', + mime: 'application/vnd.oasis.opendocument.spreadsheet' + }; + } + + if (checkString('mimetypeapplication/vnd.oasis.opendocument.presentation', {offset: 30})) { + return { + ext: 'odp', + mime: 'application/vnd.oasis.opendocument.presentation' + }; + } + + // The docx, xlsx and pptx file types extend the Office Open XML file format: + // https://en.wikipedia.org/wiki/Office_Open_XML_file_formats + // We look for: + // - one entry named '[Content_Types].xml' or '_rels/.rels', + // - one entry indicating specific type of file. + // MS Office, OpenOffice and LibreOffice may put the parts in different order, so the check should not rely on it. + const findNextZipHeaderIndex = (arr, startAt = 0) => arr.findIndex((el, i, arr) => i >= startAt && arr[i] === 0x50 && arr[i + 1] === 0x4B && arr[i + 2] === 0x3 && arr[i + 3] === 0x4); + + let zipHeaderIndex = 0; // The first zip header was already found at index 0 + let oxmlFound = false; + let type = null; + + do { + const offset = zipHeaderIndex + 30; + + if (!oxmlFound) { + oxmlFound = (check(oxmlContentTypes, {offset}) || check(oxmlRels, {offset})); + } + + if (!type) { + if (checkString('word/', {offset})) { + type = { + ext: 'docx', + mime: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' + }; + } else if (checkString('ppt/', {offset})) { + type = { + ext: 'pptx', + mime: 'application/vnd.openxmlformats-officedocument.presentationml.presentation' + }; + } else if (checkString('xl/', {offset})) { + type = { + ext: 'xlsx', + mime: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' + }; + } + } + + if (oxmlFound && type) { + return type; + } + + zipHeaderIndex = findNextZipHeaderIndex(buf, offset); + } while (zipHeaderIndex >= 0); + + // No more zip parts available in the buffer, but maybe we are almost certain about the type? + if (type) { + return type; + } + } + + if ( + check([0x50, 0x4B]) && + (buf[2] === 0x3 || buf[2] === 0x5 || buf[2] === 0x7) && + (buf[3] === 0x4 || buf[3] === 0x6 || buf[3] === 0x8) + ) { + return { + ext: 'zip', + mime: 'application/zip' + }; + } + + if (check([0x75, 0x73, 0x74, 0x61, 0x72], {offset: 257})) { + return { + ext: 'tar', + mime: 'application/x-tar' + }; + } + + if ( + check([0x52, 0x61, 0x72, 0x21, 0x1A, 0x7]) && + (buf[6] === 0x0 || buf[6] === 0x1) + ) { + return { + ext: 'rar', + mime: 'application/x-rar-compressed' + }; + } + + if (check([0x1F, 0x8B, 0x8])) { + return { + ext: 'gz', + mime: 'application/gzip' + }; + } + + if (check([0x42, 0x5A, 0x68])) { + return { + ext: 'bz2', + mime: 'application/x-bzip2' + }; + } + + if (check([0x37, 0x7A, 0xBC, 0xAF, 0x27, 0x1C])) { + return { + ext: '7z', + mime: 'application/x-7z-compressed' + }; + } + + if (check([0x78, 0x01])) { + return { + ext: 'dmg', + mime: 'application/x-apple-diskimage' + }; + } + + if (check([0x33, 0x67, 0x70, 0x35]) || // 3gp5 + ( + check([0x0, 0x0, 0x0]) && check([0x66, 0x74, 0x79, 0x70], {offset: 4}) && + ( + check([0x6D, 0x70, 0x34, 0x31], {offset: 8}) || // MP41 + check([0x6D, 0x70, 0x34, 0x32], {offset: 8}) || // MP42 + check([0x69, 0x73, 0x6F, 0x6D], {offset: 8}) || // ISOM + check([0x69, 0x73, 0x6F, 0x32], {offset: 8}) || // ISO2 + check([0x6D, 0x6D, 0x70, 0x34], {offset: 8}) || // MMP4 + check([0x4D, 0x34, 0x56], {offset: 8}) || // M4V + check([0x64, 0x61, 0x73, 0x68], {offset: 8}) // DASH + ) + )) { + return { + ext: 'mp4', + mime: 'video/mp4' + }; + } + + if (check([0x4D, 0x54, 0x68, 0x64])) { + return { + ext: 'mid', + mime: 'audio/midi' + }; + } + + // https://github.com/threatstack/libmagic/blob/master/magic/Magdir/matroska + if (check([0x1A, 0x45, 0xDF, 0xA3])) { + const sliced = buf.subarray(4, 4 + 4096); + const idPos = sliced.findIndex((el, i, arr) => arr[i] === 0x42 && arr[i + 1] === 0x82); + + if (idPos !== -1) { + const docTypePos = idPos + 3; + const findDocType = type => [...type].every((c, i) => sliced[docTypePos + i] === c.charCodeAt(0)); + + if (findDocType('matroska')) { + return { + ext: 'mkv', + mime: 'video/x-matroska' + }; + } + + if (findDocType('webm')) { + return { + ext: 'webm', + mime: 'video/webm' + }; + } + } + } + + if (check([0x0, 0x0, 0x0, 0x14, 0x66, 0x74, 0x79, 0x70, 0x71, 0x74, 0x20, 0x20]) || + check([0x66, 0x72, 0x65, 0x65], {offset: 4}) || // Type: `free` + check([0x66, 0x74, 0x79, 0x70, 0x71, 0x74, 0x20, 0x20], {offset: 4}) || + check([0x6D, 0x64, 0x61, 0x74], {offset: 4}) || // MJPEG + check([0x6D, 0x6F, 0x6F, 0x76], {offset: 4}) || // Type: `moov` + check([0x77, 0x69, 0x64, 0x65], {offset: 4})) { + return { + ext: 'mov', + mime: 'video/quicktime' + }; + } + + // RIFF file format which might be AVI, WAV, QCP, etc + if (check([0x52, 0x49, 0x46, 0x46])) { + if (check([0x41, 0x56, 0x49], {offset: 8})) { + return { + ext: 'avi', + mime: 'video/vnd.avi' + }; + } + + if (check([0x57, 0x41, 0x56, 0x45], {offset: 8})) { + return { + ext: 'wav', + mime: 'audio/vnd.wave' + }; + } + + // QLCM, QCP file + if (check([0x51, 0x4C, 0x43, 0x4D], {offset: 8})) { + return { + ext: 'qcp', + mime: 'audio/qcelp' + }; + } + } + + // ASF_Header_Object first 80 bytes + if (check([0x30, 0x26, 0xB2, 0x75, 0x8E, 0x66, 0xCF, 0x11, 0xA6, 0xD9])) { + // Search for header should be in first 1KB of file. + + let offset = 30; + do { + const objectSize = readUInt64LE(buf, offset + 16); + if (check([0x91, 0x07, 0xDC, 0xB7, 0xB7, 0xA9, 0xCF, 0x11, 0x8E, 0xE6, 0x00, 0xC0, 0x0C, 0x20, 0x53, 0x65], {offset})) { + // Sync on Stream-Properties-Object (B7DC0791-A9B7-11CF-8EE6-00C00C205365) + if (check([0x40, 0x9E, 0x69, 0xF8, 0x4D, 0x5B, 0xCF, 0x11, 0xA8, 0xFD, 0x00, 0x80, 0x5F, 0x5C, 0x44, 0x2B], {offset: offset + 24})) { + // Found audio: + return { + ext: 'wma', + mime: 'audio/x-ms-wma' + }; + } + + if (check([0xC0, 0xEF, 0x19, 0xBC, 0x4D, 0x5B, 0xCF, 0x11, 0xA8, 0xFD, 0x00, 0x80, 0x5F, 0x5C, 0x44, 0x2B], {offset: offset + 24})) { + // Found video: + return { + ext: 'wmv', + mime: 'video/x-ms-asf' + }; + } + + break; + } + + offset += objectSize; + } while (offset + 24 <= buf.length); + + // Default to ASF generic extension + return { + ext: 'asf', + mime: 'application/vnd.ms-asf' + }; + } + + if ( + check([0x0, 0x0, 0x1, 0xBA]) || + check([0x0, 0x0, 0x1, 0xB3]) + ) { + return { + ext: 'mpg', + mime: 'video/mpeg' + }; + } + + if (check([0x66, 0x74, 0x79, 0x70, 0x33, 0x67], {offset: 4})) { + return { + ext: '3gp', + mime: 'video/3gpp' + }; + } + + // Check for MPEG header at different starting offsets + for (let start = 0; start < 2 && start < (buf.length - 16); start++) { + if ( + check([0x49, 0x44, 0x33], {offset: start}) || // ID3 header + check([0xFF, 0xE2], {offset: start, mask: [0xFF, 0xE2]}) // MPEG 1 or 2 Layer 3 header + ) { + return { + ext: 'mp3', + mime: 'audio/mpeg' + }; + } + + if ( + check([0xFF, 0xE4], {offset: start, mask: [0xFF, 0xE4]}) // MPEG 1 or 2 Layer 2 header + ) { + return { + ext: 'mp2', + mime: 'audio/mpeg' + }; + } + + if ( + check([0xFF, 0xF8], {offset: start, mask: [0xFF, 0xFC]}) // MPEG 2 layer 0 using ADTS + ) { + return { + ext: 'mp2', + mime: 'audio/mpeg' + }; + } + + if ( + check([0xFF, 0xF0], {offset: start, mask: [0xFF, 0xFC]}) // MPEG 4 layer 0 using ADTS + ) { + return { + ext: 'mp4', + mime: 'audio/mpeg' + }; + } + } + + if ( + check([0x66, 0x74, 0x79, 0x70, 0x4D, 0x34, 0x41], {offset: 4}) + ) { + return { // MPEG-4 layer 3 (audio) + ext: 'm4a', + mime: 'audio/mp4' // RFC 4337 + }; + } + + // Needs to be before `ogg` check + if (check([0x4F, 0x70, 0x75, 0x73, 0x48, 0x65, 0x61, 0x64], {offset: 28})) { + return { + ext: 'opus', + mime: 'audio/opus' + }; + } + + // If 'OggS' in first bytes, then OGG container + if (check([0x4F, 0x67, 0x67, 0x53])) { + // This is a OGG container + + // If ' theora' in header. + if (check([0x80, 0x74, 0x68, 0x65, 0x6F, 0x72, 0x61], {offset: 28})) { + return { + ext: 'ogv', + mime: 'video/ogg' + }; + } + + // If '\x01video' in header. + if (check([0x01, 0x76, 0x69, 0x64, 0x65, 0x6F, 0x00], {offset: 28})) { + return { + ext: 'ogm', + mime: 'video/ogg' + }; + } + + // If ' FLAC' in header https://xiph.org/flac/faq.html + if (check([0x7F, 0x46, 0x4C, 0x41, 0x43], {offset: 28})) { + return { + ext: 'oga', + mime: 'audio/ogg' + }; + } + + // 'Speex ' in header https://en.wikipedia.org/wiki/Speex + if (check([0x53, 0x70, 0x65, 0x65, 0x78, 0x20, 0x20], {offset: 28})) { + return { + ext: 'spx', + mime: 'audio/ogg' + }; + } + + // If '\x01vorbis' in header + if (check([0x01, 0x76, 0x6F, 0x72, 0x62, 0x69, 0x73], {offset: 28})) { + return { + ext: 'ogg', + mime: 'audio/ogg' + }; + } + + // Default OGG container https://www.iana.org/assignments/media-types/application/ogg + return { + ext: 'ogx', + mime: 'application/ogg' + }; + } + + if (check([0x66, 0x4C, 0x61, 0x43])) { + return { + ext: 'flac', + mime: 'audio/x-flac' + }; + } + + if (check([0x4D, 0x41, 0x43, 0x20])) { // 'MAC ' + return { + ext: 'ape', + mime: 'audio/ape' + }; + } + + if (check([0x77, 0x76, 0x70, 0x6B])) { // 'wvpk' + return { + ext: 'wv', + mime: 'audio/wavpack' + }; + } + + if (check([0x23, 0x21, 0x41, 0x4D, 0x52, 0x0A])) { + return { + ext: 'amr', + mime: 'audio/amr' + }; + } + + if (check([0x25, 0x50, 0x44, 0x46])) { + return { + ext: 'pdf', + mime: 'application/pdf' + }; + } + + if (check([0x4D, 0x5A])) { + return { + ext: 'exe', + mime: 'application/x-msdownload' + }; + } + + if ( + (buf[0] === 0x43 || buf[0] === 0x46) && + check([0x57, 0x53], {offset: 1}) + ) { + return { + ext: 'swf', + mime: 'application/x-shockwave-flash' + }; + } + + if (check([0x7B, 0x5C, 0x72, 0x74, 0x66])) { + return { + ext: 'rtf', + mime: 'application/rtf' + }; + } + + if (check([0x00, 0x61, 0x73, 0x6D])) { + return { + ext: 'wasm', + mime: 'application/wasm' + }; + } + + if ( + check([0x77, 0x4F, 0x46, 0x46]) && + ( + check([0x00, 0x01, 0x00, 0x00], {offset: 4}) || + check([0x4F, 0x54, 0x54, 0x4F], {offset: 4}) + ) + ) { + return { + ext: 'woff', + mime: 'font/woff' + }; + } + + if ( + check([0x77, 0x4F, 0x46, 0x32]) && + ( + check([0x00, 0x01, 0x00, 0x00], {offset: 4}) || + check([0x4F, 0x54, 0x54, 0x4F], {offset: 4}) + ) + ) { + return { + ext: 'woff2', + mime: 'font/woff2' + }; + } + + if ( + check([0x4C, 0x50], {offset: 34}) && + ( + check([0x00, 0x00, 0x01], {offset: 8}) || + check([0x01, 0x00, 0x02], {offset: 8}) || + check([0x02, 0x00, 0x02], {offset: 8}) + ) + ) { + return { + ext: 'eot', + mime: 'application/vnd.ms-fontobject' + }; + } + + if (check([0x00, 0x01, 0x00, 0x00, 0x00])) { + return { + ext: 'ttf', + mime: 'font/ttf' + }; + } + + if (check([0x4F, 0x54, 0x54, 0x4F, 0x00])) { + return { + ext: 'otf', + mime: 'font/otf' + }; + } + + if (check([0x00, 0x00, 0x01, 0x00])) { + return { + ext: 'ico', + mime: 'image/x-icon' + }; + } + + if (check([0x00, 0x00, 0x02, 0x00])) { + return { + ext: 'cur', + mime: 'image/x-icon' + }; + } + + if (check([0x46, 0x4C, 0x56, 0x01])) { + return { + ext: 'flv', + mime: 'video/x-flv' + }; + } + + if (check([0x25, 0x21])) { + return { + ext: 'ps', + mime: 'application/postscript' + }; + } + + if (check([0xFD, 0x37, 0x7A, 0x58, 0x5A, 0x00])) { + return { + ext: 'xz', + mime: 'application/x-xz' + }; + } + + if (check([0x53, 0x51, 0x4C, 0x69])) { + return { + ext: 'sqlite', + mime: 'application/x-sqlite3' + }; + } + + if (check([0x4E, 0x45, 0x53, 0x1A])) { + return { + ext: 'nes', + mime: 'application/x-nintendo-nes-rom' + }; + } + + if (check([0x43, 0x72, 0x32, 0x34])) { + return { + ext: 'crx', + mime: 'application/x-google-chrome-extension' + }; + } + + if ( + check([0x4D, 0x53, 0x43, 0x46]) || + check([0x49, 0x53, 0x63, 0x28]) + ) { + return { + ext: 'cab', + mime: 'application/vnd.ms-cab-compressed' + }; + } + + // Needs to be before `ar` check + if (check([0x21, 0x3C, 0x61, 0x72, 0x63, 0x68, 0x3E, 0x0A, 0x64, 0x65, 0x62, 0x69, 0x61, 0x6E, 0x2D, 0x62, 0x69, 0x6E, 0x61, 0x72, 0x79])) { + return { + ext: 'deb', + mime: 'application/x-deb' + }; + } + + if (check([0x21, 0x3C, 0x61, 0x72, 0x63, 0x68, 0x3E])) { + return { + ext: 'ar', + mime: 'application/x-unix-archive' + }; + } + + if (check([0xED, 0xAB, 0xEE, 0xDB])) { + return { + ext: 'rpm', + mime: 'application/x-rpm' + }; + } + + if ( + check([0x1F, 0xA0]) || + check([0x1F, 0x9D]) + ) { + return { + ext: 'Z', + mime: 'application/x-compress' + }; + } + + if (check([0x4C, 0x5A, 0x49, 0x50])) { + return { + ext: 'lz', + mime: 'application/x-lzip' + }; + } + + if (check([0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1])) { + return { + ext: 'msi', + mime: 'application/x-msi' + }; + } + + if (check([0x06, 0x0E, 0x2B, 0x34, 0x02, 0x05, 0x01, 0x01, 0x0D, 0x01, 0x02, 0x01, 0x01, 0x02])) { + return { + ext: 'mxf', + mime: 'application/mxf' + }; + } + + if (check([0x47], {offset: 4}) && (check([0x47], {offset: 192}) || check([0x47], {offset: 196}))) { + return { + ext: 'mts', + mime: 'video/mp2t' + }; + } + + if (check([0x42, 0x4C, 0x45, 0x4E, 0x44, 0x45, 0x52])) { + return { + ext: 'blend', + mime: 'application/x-blender' + }; + } + + if (check([0x42, 0x50, 0x47, 0xFB])) { + return { + ext: 'bpg', + mime: 'image/bpg' + }; + } + + if (check([0x00, 0x00, 0x00, 0x0C, 0x6A, 0x50, 0x20, 0x20, 0x0D, 0x0A, 0x87, 0x0A])) { + // JPEG-2000 family + + if (check([0x6A, 0x70, 0x32, 0x20], {offset: 20})) { + return { + ext: 'jp2', + mime: 'image/jp2' + }; + } + + if (check([0x6A, 0x70, 0x78, 0x20], {offset: 20})) { + return { + ext: 'jpx', + mime: 'image/jpx' + }; + } + + if (check([0x6A, 0x70, 0x6D, 0x20], {offset: 20})) { + return { + ext: 'jpm', + mime: 'image/jpm' + }; + } + + if (check([0x6D, 0x6A, 0x70, 0x32], {offset: 20})) { + return { + ext: 'mj2', + mime: 'image/mj2' + }; + } + } + + if (check([0x46, 0x4F, 0x52, 0x4D])) { + return { + ext: 'aif', + mime: 'audio/aiff' + }; + } + + if (checkString(' new Promise((resolve, reject) => { + // Using `eval` to work around issues when bundling with Webpack + const stream = eval('require')('stream'); // eslint-disable-line no-eval + + readableStream.once('readable', () => { + const pass = new stream.PassThrough(); + const chunk = readableStream.read(module.exports.minimumBytes) || readableStream.read(); + try { + pass.fileType = fileType(chunk); + } catch (error) { + reject(error); + } + + readableStream.unshift(chunk); + + if (stream.pipeline) { + resolve(stream.pipeline(readableStream, pass, () => {})); + } else { + resolve(readableStream.pipe(pass)); + } + }); +}); + + +/***/ }), + +/***/ "./node_modules/image-type/index.js": +/*!******************************************!*\ + !*** ./node_modules/image-type/index.js ***! + \******************************************/ +/***/ ((module, __unused_webpack_exports, __webpack_require__) => { + +"use strict"; + +const fileType = __webpack_require__(/*! file-type */ "./node_modules/file-type/index.js"); + +const imageExts = new Set([ + 'jpg', + 'png', + 'gif', + 'webp', + 'flif', + 'cr2', + 'tif', + 'bmp', + 'jxr', + 'psd', + 'ico', + 'bpg', + 'jp2', + 'jpm', + 'jpx', + 'heic', + 'cur', + 'dcm' +]); + +const imageType = input => { + const ret = fileType(input); + return imageExts.has(ret && ret.ext) ? ret : null; +}; + +module.exports = imageType; +// TODO: Remove this for the next major release +module.exports["default"] = imageType; + +Object.defineProperty(imageType, 'minimumBytes', {value: fileType.minimumBytes}); + + +/***/ }), + +/***/ "./src/tpl/epub/META-INF/container.xml": +/*!*********************************************!*\ + !*** ./src/tpl/epub/META-INF/container.xml ***! + \*********************************************/ +/***/ ((module) => { + +module.exports = "\n\n\t\n\t\t\n\t\n" + +/***/ }), + +/***/ "./src/tpl/epub/OEBPS/front-cover.html.ejs": +/*!*************************************************!*\ + !*** ./src/tpl/epub/OEBPS/front-cover.html.ejs ***! + \*************************************************/ +/***/ ((module) => { + +module.exports = "\n\n\">\n\n\n\t<%= i18n.cover %>\n\t\n\n\n\n\t
    \n\t\t\" alt=\"<%= i18n.cover %>\" />\n\t
    \n\n\n\n" + +/***/ }), + +/***/ "./src/tpl/epub/OEBPS/notes.html.ejs": +/*!*******************************************!*\ + !*** ./src/tpl/epub/OEBPS/notes.html.ejs ***! + \*******************************************/ +/***/ ((module) => { + +module.exports = "\n\n\">\n\n\n\t<%= i18n.note %>\n\t\n\n\n\n\t
    \n\t\t
    \n <%- notes %>\n\t\t
    \n\t
    \n\n\n\n" + +/***/ }), + +/***/ "./src/tpl/epub/OEBPS/page.html.ejs": +/*!******************************************!*\ + !*** ./src/tpl/epub/OEBPS/page.html.ejs ***! + \******************************************/ +/***/ ((module) => { + +module.exports = "\n\n\">\n\n\n\t<%= title %>\n\t\n\n\n\n\t
    \n\t\t
    \n\t\t\t

    <%= title %>

    \n\t\t
    \n\t\t
    \n <% if (Array.isArray(content)) { %>\n <% content.forEach(item => { %>\n

    <%= item %>

    \n <% }); %>\n <% } else { %>\n <%- content %>\n <% } %>\n\t\t
    \n\t
    \n\n\n\n" + +/***/ }), + +/***/ "./src/tpl/epub/OEBPS/table-of-contents.html.ejs": +/*!*******************************************************!*\ + !*** ./src/tpl/epub/OEBPS/table-of-contents.html.ejs ***! + \*******************************************************/ +/***/ ((module) => { + +module.exports = "\n\n\">\n\n\n\t<%= i18n.toc %>\n\t\n\n\n\n\t
    \n\t\t

    <%= i18n.toc %>

    \n\t\t\n\t
    \n\n\n\n" + +/***/ }), + +/***/ "./src/tpl/epub/OEBPS/title-page.html.ejs": +/*!************************************************!*\ + !*** ./src/tpl/epub/OEBPS/title-page.html.ejs ***! + \************************************************/ +/***/ ((module) => { + +module.exports = "\n\n\">\n\n\n\t<%= i18n.info %>\n\t\n\n\n\n\t
    \n\t\t

    <%= title %>

    \n\t\t

    \n\t\t

    <%= author %>

    \n\t\t

    <%= publisher %>

    \n\t
    \n <% if (Array.isArray(tags) && tags.length) { %>\n
    \n <% tags = tags.join(', '); %>\n <%- tags %>\n
    \n <% } %>\n <% if (description) { %>\n
    \n <%- description %>\n
    \n <% } %>\n\n\n\n" + +/***/ }), + +/***/ "./src/tpl/epub/book.opf.ejs": +/*!***********************************!*\ + !*** ./src/tpl/epub/book.opf.ejs ***! + \***********************************/ +/***/ ((module) => { + +module.exports = "\n\n\n\t\n\t\t<%= title %>\n\t\t<%= i18n.code %>\n\t\t\"><%= uuid.id %>\n <%= date %>\n <% if (description) { %>\n\t\t <%= description %>\n <% } %>\n\t\t<%= author %>\n\t\t<%= publisher %>\n <% if (cover) { %>\n\t\t \n <% } %>\n <% if (Array.isArray(tags) && tags.length) tags.forEach(tag => { %>\n <%= tag %>\n <% }); %>\n\t\n\n\t\n <% if (cover) { %>\n\t\t \n <% } %>\n\t\t\n\t\t\n\t\t\n <% pages.forEach((page, index) => { %>\n \" href=\"OEBPS/page-<%= index %>.html\" media-type=\"application/xhtml+xml\" />\n <% }); %>\n <% if (cover) { %>\n\t\t \" media-type=\"<%= cover.type %>\" properties=\"cover-image\" />\n <% } %>\n\t\t\n <% Object.keys(images).forEach(name => { %>\n \" href=\"OEBPS/<%= images[name].path %>\" media-type=\"<%= images[name].type %>\" />\n <% }); %>\n\t\n\n\t\n <% if (cover) { %>\n\t\t \n <% } %>\n\t\t\n\t\t\n <% pages.forEach((page, index) => { %>\n \" linear=\"yes\" />\n <% }); %>\n <% if (notes) { %>\n \n <% } %>\n\t\n\n\t\n <% if (cover) { %>\n\t\t \" href=\"OEBPS/front-cover.html\" />\n <% } %>\n\t\t\" href=\"OEBPS/table-of-contents.html\" />\n\t\n\n\n" + +/***/ }), + +/***/ "./src/tpl/epub/mimetype": +/*!*******************************!*\ + !*** ./src/tpl/epub/mimetype ***! + \*******************************/ +/***/ ((module) => { + +module.exports = "application/epub+zip" + +/***/ }), + +/***/ "./src/tpl/epub/toc.ncx.ejs": +/*!**********************************!*\ + !*** ./src/tpl/epub/toc.ncx.ejs ***! + \**********************************/ +/***/ ((module) => { + +module.exports = "\n\n\n\" xmlns=\"http://www.daisy.org/z3986/2005/ncx/\">\n\t\n\t\t\" />\n\t\t\n\t\t\n\t\t\n\t\n\n\t\n\t\t<%= title %>\n\t\n\n\t\n\t\t<%= author %>\n\t\n\n\t\n\t\t\n\t\t\t\n\t\t\t\t<%= i18n.info %>\n\t\t\t\n\t\t\t\n\t\t\n\t\t\n\t\t\t\n\t\t\t\t<%= i18n.toc %>\n\t\t\t\n\t\t\t\n\t\t\n <% pages.forEach((title, index) => { %>\n \" playOrder=\"<%= (index + 3) %>\">\n \n <%= title %>\n \n .html\" />\n \n <% }); %>\n <% if (notes) { %>\n \n \n <%= i18n.note %>\n \n \n \n <% } %>\n\t\n\n" + +/***/ }), + +/***/ "./src/i18n.json": +/*!***********************!*\ + !*** ./src/i18n.json ***! + \***********************/ +/***/ ((module) => { + +"use strict"; +module.exports = JSON.parse('{"en":{"code":"en","cover":"Cover","toc":"Table of Contents","info":"Information","note":"Notes"},"vi":{"code":"vi","cover":"Bìa sách","toc":"Mục lục","info":"Giới thiệu","note":"Ghi chú"},"hi":{"code":"hi","cover":"आवरण","toc":"विषय - सूची","info":"जानकारी","note":"टिप्पणियाँ"}}'); + +/***/ }) + +/******/ }); +/************************************************************************/ +/******/ // The module cache +/******/ var __webpack_module_cache__ = {}; +/******/ +/******/ // The require function +/******/ function __webpack_require__(moduleId) { +/******/ // Check if module is in cache +/******/ var cachedModule = __webpack_module_cache__[moduleId]; +/******/ if (cachedModule !== undefined) { +/******/ return cachedModule.exports; +/******/ } +/******/ // Create a new module (and put it into the cache) +/******/ var module = __webpack_module_cache__[moduleId] = { +/******/ // no module.id needed +/******/ // no module.loaded needed +/******/ exports: {} +/******/ }; +/******/ +/******/ // Execute the module function +/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/************************************************************************/ +/******/ +/******/ // startup +/******/ // Load entry module and return exports +/******/ // This entry module is referenced by other modules so it can't be inlined +/******/ var __webpack_exports__ = __webpack_require__("./src/jepub.js"); +/******/ +/******/ return __webpack_exports__; +/******/ })() +; +}); +//# sourceMappingURL=jepub.js.map \ No newline at end of file diff --git a/dist/jepub.js.map b/dist/jepub.js.map new file mode 100644 index 0000000..437c018 --- /dev/null +++ b/dist/jepub.js.map @@ -0,0 +1 @@ +{"version":3,"file":"jepub.js","mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AACD,O;;;;;;;;;ACVA;AACA;AACA;AACA;AACA;;AAEA;;;;;;;;;;ACNA,cAAc,mBAAO,CAAC,0EAAmB;;AAEzC;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA,QAAQ;AACR;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA;;;;;;;;;;ACtDA;AACA;;AAEA;AACA;AACA;AACA;AACA,IAAI;AACJ;AACA;AACA;AACA;;AAEA;AACA;;AAEA;;;;;;;;;;;AChBa;;;;;;;;;;;AAEb;;AACA;;AAEA;;AAEA;;AACA;;AAC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AAG;;AAEH,kBAAkB,mBAAmB;AACrC;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;;AAEA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA,sCAAsC,UAAU;AAChD;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,uBAAuB,UAAU;AACjC;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,oLAAoL,WAAW;AAC/L;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,6BAA6B,WAAW;AACxC;AACA;AACA;AACA;AACA;;AAEA,sEAAsE,WAAW;AACjF;AACA;AACA;AACA;AACA;;AAEA,6EAA6E,WAAW;AACxF;AACA;AACA;AACA;AACA;;AAEA,8EAA8E,WAAW;AACzF;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,0BAA0B;AAC1B;AACA;;AAEA;AACA;;AAEA;AACA,0CAA0C,OAAO,sBAAsB,OAAO;AAC9E;;AAEA;AACA,8BAA8B,OAAO;AACrC;AACA;AACA;AACA;AACA,MAAM,8BAA8B,OAAO;AAC3C;AACA;AACA;AACA;AACA,MAAM,6BAA6B,OAAO;AAC1C;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA,IAAI;;AAEJ;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,4CAA4C,YAAY;AACxD;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,8DAA8D,UAAU;AACxE;AACA,sCAAsC,UAAU;AAChD,sCAAsC,UAAU;AAChD,sCAAsC,UAAU;AAChD,sCAAsC,UAAU;AAChD,sCAAsC,UAAU;AAChD,gCAAgC,UAAU;AAC1C,sCAAsC,UAAU;AAChD;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,mCAAmC,UAAU;AAC7C,2DAA2D,UAAU;AACrE,mCAAmC,UAAU;AAC7C,mCAAmC,UAAU;AAC7C,mCAAmC,UAAU;AAC7C;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,iCAAiC,UAAU;AAC3C;AACA;AACA;AACA;AACA;;AAEA,uCAAuC,UAAU;AACjD;AACA;AACA;AACA;AACA;;AAEA;AACA,uCAAuC,UAAU;AACjD;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA,gHAAgH,OAAO;AACvH;AACA,iHAAiH,oBAAoB;AACrI;AACA;AACA;AACA;AACA;AACA;;AAEA,iHAAiH,oBAAoB;AACrI;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA,IAAI;;AAEJ;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,kDAAkD,UAAU;AAC5D;AACA;AACA;AACA;AACA;;AAEA;AACA,qBAAqB,wCAAwC;AAC7D;AACA,8BAA8B,cAAc;AAC5C,wBAAwB,kCAAkC;AAC1D;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,wBAAwB,kCAAkC;AAC1D;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,wBAAwB,kCAAkC;AAC1D;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,wBAAwB,kCAAkC;AAC1D;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,qDAAqD,UAAU;AAC/D;AACA,WAAW;AACX;AACA;AACA;AACA;;AAEA;AACA,8DAA8D,WAAW;AACzE;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA,yDAAyD,WAAW;AACpE;AACA;AACA;AACA;AACA;;AAEA;AACA,yDAAyD,WAAW;AACpE;AACA;AACA;AACA;AACA;;AAEA;AACA,6CAA6C,WAAW;AACxD;AACA;AACA;AACA;AACA;;AAEA;AACA,yDAAyD,WAAW;AACpE;AACA;AACA;AACA;AACA;;AAEA;AACA,yDAAyD,WAAW;AACpE;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA,wCAAwC;AACxC;AACA;AACA;AACA;AACA;;AAEA,wCAAwC;AACxC;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,uBAAuB,UAAU;AACjC;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,oCAAoC,UAAU;AAC9C,oCAAoC,UAAU;AAC9C;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,oCAAoC,UAAU;AAC9C,oCAAoC,UAAU;AAC9C;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,uBAAuB,WAAW;AAClC;AACA,8BAA8B,UAAU;AACxC,8BAA8B,UAAU;AACxC,8BAA8B,UAAU;AACxC;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA,oBAAoB,UAAU,qBAAqB,YAAY,oBAAoB,YAAY;AAC/F;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA,uCAAuC,WAAW;AAClD;AACA;AACA;AACA;AACA;;AAEA,uCAAuC,WAAW;AAClD;AACA;AACA;AACA;AACA;;AAEA,uCAAuC,WAAW;AAClD;AACA;AACA;AACA;AACA;;AAEA,uCAAuC,WAAW;AAClD;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA,8DAA8D,WAAW;AACzE;AACA;AACA;AACA;AACA;;AAEA;AACA,sCAAsC,UAAU;AAChD,uCAAuC,UAAU;AACjD;AACA;AACA;AACA;AACA;;AAEA,uCAAuC,UAAU;AACjD;AACA;AACA;AACA;AACA;;AAEA,uCAAuC,UAAU,sCAAsC,UAAU;AACjG;AACA;AACA;AACA;AACA;;AA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EAAyE,qDAAqD,mHAAmH;;;;;;;;;;ACA/sF;;;;;;;;;;ACAA,skCAAskC,qSAAqS,GAAG,4BAA4B,sQAAsQ;;;;;;;;;;;;;;;;;UCAhpD;UACA;;UAEA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;;UAEA;UACA;;UAEA;UACA;UACA;;;;UEtBA;UACA;UACA;UACA","sources":["webpack://jEpub/webpack/universalModuleDefinition","webpack://jEpub/./node_modules/@babel/runtime/helpers/interopRequireDefault.js","webpack://jEpub/./node_modules/@babel/runtime/helpers/interopRequireWildcard.js","webpack://jEpub/./node_modules/@babel/runtime/helpers/typeof.js","webpack://jEpub/./src/jepub.js","webpack://jEpub/./src/utils.js","webpack://jEpub/./node_modules/file-type/index.js","webpack://jEpub/./node_modules/image-type/index.js","webpack://jEpub/./src/tpl/epub/META-INF/container.xml","webpack://jEpub/./src/tpl/epub/OEBPS/front-cover.html.ejs","webpack://jEpub/./src/tpl/epub/OEBPS/notes.html.ejs","webpack://jEpub/./src/tpl/epub/OEBPS/page.html.ejs","webpack://jEpub/./src/tpl/epub/OEBPS/table-of-contents.html.ejs","webpack://jEpub/./src/tpl/epub/OEBPS/title-page.html.ejs","webpack://jEpub/./src/tpl/epub/book.opf.ejs","webpack://jEpub/./src/tpl/epub/mimetype","webpack://jEpub/./src/tpl/epub/toc.ncx.ejs","webpack://jEpub/webpack/bootstrap","webpack://jEpub/webpack/before-startup","webpack://jEpub/webpack/startup","webpack://jEpub/webpack/after-startup"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine(\"jEpub\", [], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"jEpub\"] = factory();\n\telse\n\t\troot[\"jEpub\"] = factory();\n})(self, () => {\nreturn ","function _interopRequireDefault(obj) {\n return obj && obj.__esModule ? obj : {\n \"default\": obj\n };\n}\n\nmodule.exports = _interopRequireDefault;","var _typeof = require(\"../helpers/typeof\");\n\nfunction _getRequireWildcardCache() {\n if (typeof WeakMap !== \"function\") return null;\n var cache = new WeakMap();\n\n _getRequireWildcardCache = function _getRequireWildcardCache() {\n return cache;\n };\n\n return cache;\n}\n\nfunction _interopRequireWildcard(obj) {\n if (obj && obj.__esModule) {\n return obj;\n }\n\n if (obj === null || _typeof(obj) !== \"object\" && typeof obj !== \"function\") {\n return {\n \"default\": obj\n };\n }\n\n var cache = _getRequireWildcardCache();\n\n if (cache && cache.has(obj)) {\n return cache.get(obj);\n }\n\n var newObj = {};\n var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;\n\n for (var key in obj) {\n if (Object.prototype.hasOwnProperty.call(obj, key)) {\n var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;\n\n if (desc && (desc.get || desc.set)) {\n Object.defineProperty(newObj, key, desc);\n } else {\n newObj[key] = obj[key];\n }\n }\n }\n\n newObj[\"default\"] = obj;\n\n if (cache) {\n cache.set(obj, newObj);\n }\n\n return newObj;\n}\n\nmodule.exports = _interopRequireWildcard;","function _typeof(obj) {\n \"@babel/helpers - typeof\";\n\n if (typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\") {\n module.exports = _typeof = function _typeof(obj) {\n return typeof obj;\n };\n } else {\n module.exports = _typeof = function _typeof(obj) {\n return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj;\n };\n }\n\n return _typeof(obj);\n}\n\nmodule.exports = _typeof;","'use strict';\n\nimport * as utils from './utils';\nimport imageType from 'image-type';\n\nimport language from './i18n.json';\n\nimport container from './tpl/epub/META-INF/container.xml';\nimport cover from './tpl/epub/OEBPS/front-cover.html';\nimport notes from './tpl/epub/OEBPS/notes.html';\nimport page from './tpl/epub/OEBPS/page.html';\nimport tocInBook from './tpl/epub/OEBPS/table-of-contents.html';\nimport info from './tpl/epub/OEBPS/title-page.html';\nimport bookConfig from './tpl/epub/book.opf';\nimport mime from './tpl/epub/mimetype';\nimport toc from './tpl/epub/toc.ncx';\n\nexport default class jEpub {\n constructor() {\n this._I18n = {};\n this._Info = {};\n this._Uuid = {};\n this._Date = null;\n this._Cover = null;\n\n this._Pages = [];\n this._Images = [];\n\n this._Zip = {};\n }\n\n init(details) {\n if (details instanceof JSZip) {\n this._Zip = details;\n return this;\n }\n\n this._Info = Object.assign({}, {\n i18n: 'en',\n title: 'undefined',\n author: 'undefined',\n publisher: 'undefined',\n description: '',\n tags: []\n }, details);\n\n this._Uuid = {\n scheme: 'uuid',\n id: utils.uuidv4()\n };\n\n this._Date = utils.getISODate();\n\n if (!language[this._Info.i18n]) throw `Unknown Language: ${this._Info.i18n}`;\n this._I18n = language[this._Info.i18n];\n\n this._Zip = new JSZip();\n this._Zip.file('mimetype', mime);\n this._Zip.file('META-INF/container.xml', container);\n this._Zip.file('OEBPS/title-page.html', ejs.render(info, {\n i18n: this._I18n,\n title: this._Info.title,\n author: this._Info.author,\n publisher: this._Info.publisher,\n description: utils.parseDOM(this._Info.description),\n tags: this._Info.tags,\n }, {\n client: true\n }));\n\n return this;\n }\n\n static html2text(html, noBr = false) {\n return utils.html2text(html, noBr);\n }\n\n date(date) {\n if (date instanceof Date) {\n this._Date = utils.getISODate(date);\n return this;\n } else {\n throw 'Date object is not valid';\n }\n }\n\n uuid(id) {\n if (utils.isEmpty(id)) {\n throw 'UUID value is empty';\n } else {\n let scheme = 'uuid';\n if (utils.validateUrl(id))\n scheme = 'URI';\n this._Uuid = {\n scheme: scheme,\n id: id\n };\n return this;\n }\n }\n\n cover(data) {\n let ext, mime;\n if (data instanceof Blob) {\n mime = data.type;\n ext = utils.mime2ext(mime);\n } else if (data instanceof ArrayBuffer) {\n ext = imageType(new Uint8Array(data));\n if (ext) {\n mime = ext.mime;\n ext = utils.mime2ext(mime);\n }\n } else {\n throw 'Cover data is not valid';\n }\n if (!ext) throw 'Cover data is not allowed';\n\n this._Cover = {\n type: mime,\n path: `OEBPS/cover-image.${ext}`\n };\n this._Zip.file(this._Cover.path, data);\n this._Zip.file('OEBPS/front-cover.html', ejs.render(cover, {\n i18n: this._I18n,\n cover: this._Cover\n }, {\n client: true\n }));\n return this;\n }\n\n image(data, name) {\n let ext, mime;\n if (data instanceof Blob) {\n mime = data.type;\n ext = utils.mime2ext(mime);\n } else if (data instanceof ArrayBuffer) {\n ext = imageType(new Uint8Array(data));\n mime = ext.mime;\n if (ext) ext = utils.mime2ext(mime);\n } else {\n throw 'Image data is not valid';\n }\n if (!ext) throw 'Image data is not allowed';\n\n const filePath = `assets/${name}.${ext}`;\n this._Images[name] = {\n type: mime,\n path: filePath\n };\n this._Zip.file(`OEBPS/${filePath}`, data);\n return this;\n }\n\n notes(content) {\n if (utils.isEmpty(content)) {\n throw 'Notes is empty';\n } else {\n this._Zip.file('OEBPS/notes.html', ejs.render(notes, {\n i18n: this._I18n,\n notes: utils.parseDOM(content)\n }, {\n client: true\n }));\n return this;\n }\n }\n\n add(title, content, index = this._Pages.length) {\n if (utils.isEmpty(title)) {\n throw 'Title is empty';\n } else if (utils.isEmpty(content)) {\n throw `Content of ${title} is empty`;\n } else {\n if (!Array.isArray(content)) {\n const template = ejs.compile(content, {\n client: true\n });\n content = template({\n image: this._Images\n }, data => {\n return `\n (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)\n );\n}\n\n/**\n * Checks if a value is object\n * @see https://stackoverflow.com/a/14706877\n * @returns {boolean}\n */\nexport function isObject(obj) {\n const type = typeof obj;\n return type === 'function' || type === 'object' && !!obj;\n}\n\n/**\n * Checks if a value is empty\n * @returns {boolean}\n */\nexport function isEmpty(val) {\n if (val === null) {\n return true;\n } else if (typeof val === 'string') {\n return !val.trim();\n }\n return false;\n}\n\n/**\n * Get current moment in ISO format\n * @param {Object} date\n * @returns {string} ISO date\n */\nexport function getISODate(date = new Date()) {\n return date.toISOString();\n}\n\n/**\n * Convert convert HTML to valid XHTML\n * @param {String} html\n * @param {String} outText return as plain text\n */\nexport function parseDOM(html, outText = false) {\n let doc = (new DOMParser).parseFromString(\n `${html}`,\n 'text/html');\n if (outText) return doc.body.textContent.trim();\n doc = (new XMLSerializer).serializeToString(doc.body);\n doc = doc.replace(/(^]*>|<\\/body>$)/g, '');\n return doc;\n}\n\n/**\n * Convert HTML to plain text\n * @param {String} html\n */\nexport function html2text(html, noBr = false) {\n html = html.replace(//gi, '');\n html = html.replace(//gi, '');\n html = html.replace(/<\\/(div|p|li|dd|h[1-6])>/gi, '\\n');\n html = html.replace(/<(br|hr)\\s*[/]?>/gi, '\\n');\n html = html.replace(/
  • /ig, '+ ');\n html = html.replace(/<[^>]+>/g, '');\n html = html.replace(/\\n{3,}/g, '\\n\\n');\n html = parseDOM(html, true);\n if (noBr) html = html.replace(/\\n+/g, ' ');\n return html;\n}\n\n/**\n * @see https://gist.github.com/dperini/729294\n * @param {String} value\n */\nexport function validateUrl(value) {\n return /^(?:(?:https?|ftp):\\/\\/)(?:\\S+(?::\\S*)?@)?(?:(?!(?:10|127)(?:\\.\\d{1,3}){3})(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))\\.?)(?::\\d{2,5})?(?:[/?#]\\S*)?$/i.test(value);\n}\n\n/**\n * Convert MIME type to extension\n * @param {String} mime\n */\nexport function mime2ext(mime) {\n let ext = null;\n switch (mime) {\n case 'image/jpg':\n case 'image/jpeg':\n ext = 'jpg';\n break;\n case 'image/svg+xml':\n ext = 'svg';\n break;\n case 'image/gif':\n case 'image/apng':\n case 'image/png':\n case 'image/webp':\n case 'image/bmp':\n ext = mime.split('/')[1];\n break;\n default:\n ext = null;\n break;\n }\n return ext;\n}\n\n// TODO: kepub\n// Wrap text, image text\n// https://github.com/pgaskin/kepubify/blob/871aa0bb2047b5ba171bc608024bdb180cb29d70/kepub/transform.go#L173\n\n//UnescapeString\n// var htmlEscaper = strings.NewReplacer(\n// \t`&`, \"&\",\n// \t`'`, \"'\", // \"'\" is shorter than \"'\" and apos was not in HTML until HTML5.\n// \t`<`, \"<\",\n// \t`>`, \">\",\n// \t`\"`, \""\", // \""\" is shorter than \""\".\n// )\n","'use strict';\nconst toBytes = s => [...s].map(c => c.charCodeAt(0));\nconst xpiZipFilename = toBytes('META-INF/mozilla.rsa');\nconst oxmlContentTypes = toBytes('[Content_Types].xml');\nconst oxmlRels = toBytes('_rels/.rels');\n\nfunction readUInt64LE(buf, offset = 0) {\n\tlet n = buf[offset];\n\tlet mul = 1;\n\tlet i = 0;\n\twhile (++i < 8) {\n\t\tmul *= 0x100;\n\t\tn += buf[offset + i] * mul;\n\t}\n\n\treturn n;\n}\n\nconst fileType = input => {\n\tif (!(input instanceof Uint8Array || input instanceof ArrayBuffer || Buffer.isBuffer(input))) {\n\t\tthrow new TypeError(`Expected the \\`input\\` argument to be of type \\`Uint8Array\\` or \\`Buffer\\` or \\`ArrayBuffer\\`, got \\`${typeof input}\\``);\n\t}\n\n\tconst buf = input instanceof Uint8Array ? input : new Uint8Array(input);\n\n\tif (!(buf && buf.length > 1)) {\n\t\treturn null;\n\t}\n\n\tconst check = (header, options) => {\n\t\toptions = Object.assign({\n\t\t\toffset: 0\n\t\t}, options);\n\n\t\tfor (let i = 0; i < header.length; i++) {\n\t\t\t// If a bitmask is set\n\t\t\tif (options.mask) {\n\t\t\t\t// If header doesn't equal `buf` with bits masked off\n\t\t\t\tif (header[i] !== (options.mask[i] & buf[i + options.offset])) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t} else if (header[i] !== buf[i + options.offset]) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\treturn true;\n\t};\n\n\tconst checkString = (header, options) => check(toBytes(header), options);\n\n\tif (check([0xFF, 0xD8, 0xFF])) {\n\t\treturn {\n\t\t\text: 'jpg',\n\t\t\tmime: 'image/jpeg'\n\t\t};\n\t}\n\n\tif (check([0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A])) {\n\t\treturn {\n\t\t\text: 'png',\n\t\t\tmime: 'image/png'\n\t\t};\n\t}\n\n\tif (check([0x47, 0x49, 0x46])) {\n\t\treturn {\n\t\t\text: 'gif',\n\t\t\tmime: 'image/gif'\n\t\t};\n\t}\n\n\tif (check([0x57, 0x45, 0x42, 0x50], {offset: 8})) {\n\t\treturn {\n\t\t\text: 'webp',\n\t\t\tmime: 'image/webp'\n\t\t};\n\t}\n\n\tif (check([0x46, 0x4C, 0x49, 0x46])) {\n\t\treturn {\n\t\t\text: 'flif',\n\t\t\tmime: 'image/flif'\n\t\t};\n\t}\n\n\t// Needs to be before `tif` check\n\tif (\n\t\t(check([0x49, 0x49, 0x2A, 0x0]) || check([0x4D, 0x4D, 0x0, 0x2A])) &&\n\t\tcheck([0x43, 0x52], {offset: 8})\n\t) {\n\t\treturn {\n\t\t\text: 'cr2',\n\t\t\tmime: 'image/x-canon-cr2'\n\t\t};\n\t}\n\n\tif (\n\t\tcheck([0x49, 0x49, 0x2A, 0x0]) ||\n\t\tcheck([0x4D, 0x4D, 0x0, 0x2A])\n\t) {\n\t\treturn {\n\t\t\text: 'tif',\n\t\t\tmime: 'image/tiff'\n\t\t};\n\t}\n\n\tif (check([0x42, 0x4D])) {\n\t\treturn {\n\t\t\text: 'bmp',\n\t\t\tmime: 'image/bmp'\n\t\t};\n\t}\n\n\tif (check([0x49, 0x49, 0xBC])) {\n\t\treturn {\n\t\t\text: 'jxr',\n\t\t\tmime: 'image/vnd.ms-photo'\n\t\t};\n\t}\n\n\tif (check([0x38, 0x42, 0x50, 0x53])) {\n\t\treturn {\n\t\t\text: 'psd',\n\t\t\tmime: 'image/vnd.adobe.photoshop'\n\t\t};\n\t}\n\n\t// Zip-based file formats\n\t// Need to be before the `zip` check\n\tif (check([0x50, 0x4B, 0x3, 0x4])) {\n\t\tif (\n\t\t\tcheck([0x6D, 0x69, 0x6D, 0x65, 0x74, 0x79, 0x70, 0x65, 0x61, 0x70, 0x70, 0x6C, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6F, 0x6E, 0x2F, 0x65, 0x70, 0x75, 0x62, 0x2B, 0x7A, 0x69, 0x70], {offset: 30})\n\t\t) {\n\t\t\treturn {\n\t\t\t\text: 'epub',\n\t\t\t\tmime: 'application/epub+zip'\n\t\t\t};\n\t\t}\n\n\t\t// Assumes signed `.xpi` from addons.mozilla.org\n\t\tif (check(xpiZipFilename, {offset: 30})) {\n\t\t\treturn {\n\t\t\t\text: 'xpi',\n\t\t\t\tmime: 'application/x-xpinstall'\n\t\t\t};\n\t\t}\n\n\t\tif (checkString('mimetypeapplication/vnd.oasis.opendocument.text', {offset: 30})) {\n\t\t\treturn {\n\t\t\t\text: 'odt',\n\t\t\t\tmime: 'application/vnd.oasis.opendocument.text'\n\t\t\t};\n\t\t}\n\n\t\tif (checkString('mimetypeapplication/vnd.oasis.opendocument.spreadsheet', {offset: 30})) {\n\t\t\treturn {\n\t\t\t\text: 'ods',\n\t\t\t\tmime: 'application/vnd.oasis.opendocument.spreadsheet'\n\t\t\t};\n\t\t}\n\n\t\tif (checkString('mimetypeapplication/vnd.oasis.opendocument.presentation', {offset: 30})) {\n\t\t\treturn {\n\t\t\t\text: 'odp',\n\t\t\t\tmime: 'application/vnd.oasis.opendocument.presentation'\n\t\t\t};\n\t\t}\n\n\t\t// The docx, xlsx and pptx file types extend the Office Open XML file format:\n\t\t// https://en.wikipedia.org/wiki/Office_Open_XML_file_formats\n\t\t// We look for:\n\t\t// - one entry named '[Content_Types].xml' or '_rels/.rels',\n\t\t// - one entry indicating specific type of file.\n\t\t// MS Office, OpenOffice and LibreOffice may put the parts in different order, so the check should not rely on it.\n\t\tconst findNextZipHeaderIndex = (arr, startAt = 0) => arr.findIndex((el, i, arr) => i >= startAt && arr[i] === 0x50 && arr[i + 1] === 0x4B && arr[i + 2] === 0x3 && arr[i + 3] === 0x4);\n\n\t\tlet zipHeaderIndex = 0; // The first zip header was already found at index 0\n\t\tlet oxmlFound = false;\n\t\tlet type = null;\n\n\t\tdo {\n\t\t\tconst offset = zipHeaderIndex + 30;\n\n\t\t\tif (!oxmlFound) {\n\t\t\t\toxmlFound = (check(oxmlContentTypes, {offset}) || check(oxmlRels, {offset}));\n\t\t\t}\n\n\t\t\tif (!type) {\n\t\t\t\tif (checkString('word/', {offset})) {\n\t\t\t\t\ttype = {\n\t\t\t\t\t\text: 'docx',\n\t\t\t\t\t\tmime: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'\n\t\t\t\t\t};\n\t\t\t\t} else if (checkString('ppt/', {offset})) {\n\t\t\t\t\ttype = {\n\t\t\t\t\t\text: 'pptx',\n\t\t\t\t\t\tmime: 'application/vnd.openxmlformats-officedocument.presentationml.presentation'\n\t\t\t\t\t};\n\t\t\t\t} else if (checkString('xl/', {offset})) {\n\t\t\t\t\ttype = {\n\t\t\t\t\t\text: 'xlsx',\n\t\t\t\t\t\tmime: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (oxmlFound && type) {\n\t\t\t\treturn type;\n\t\t\t}\n\n\t\t\tzipHeaderIndex = findNextZipHeaderIndex(buf, offset);\n\t\t} while (zipHeaderIndex >= 0);\n\n\t\t// No more zip parts available in the buffer, but maybe we are almost certain about the type?\n\t\tif (type) {\n\t\t\treturn type;\n\t\t}\n\t}\n\n\tif (\n\t\tcheck([0x50, 0x4B]) &&\n\t\t(buf[2] === 0x3 || buf[2] === 0x5 || buf[2] === 0x7) &&\n\t\t(buf[3] === 0x4 || buf[3] === 0x6 || buf[3] === 0x8)\n\t) {\n\t\treturn {\n\t\t\text: 'zip',\n\t\t\tmime: 'application/zip'\n\t\t};\n\t}\n\n\tif (check([0x75, 0x73, 0x74, 0x61, 0x72], {offset: 257})) {\n\t\treturn {\n\t\t\text: 'tar',\n\t\t\tmime: 'application/x-tar'\n\t\t};\n\t}\n\n\tif (\n\t\tcheck([0x52, 0x61, 0x72, 0x21, 0x1A, 0x7]) &&\n\t\t(buf[6] === 0x0 || buf[6] === 0x1)\n\t) {\n\t\treturn {\n\t\t\text: 'rar',\n\t\t\tmime: 'application/x-rar-compressed'\n\t\t};\n\t}\n\n\tif (check([0x1F, 0x8B, 0x8])) {\n\t\treturn {\n\t\t\text: 'gz',\n\t\t\tmime: 'application/gzip'\n\t\t};\n\t}\n\n\tif (check([0x42, 0x5A, 0x68])) {\n\t\treturn {\n\t\t\text: 'bz2',\n\t\t\tmime: 'application/x-bzip2'\n\t\t};\n\t}\n\n\tif (check([0x37, 0x7A, 0xBC, 0xAF, 0x27, 0x1C])) {\n\t\treturn {\n\t\t\text: '7z',\n\t\t\tmime: 'application/x-7z-compressed'\n\t\t};\n\t}\n\n\tif (check([0x78, 0x01])) {\n\t\treturn {\n\t\t\text: 'dmg',\n\t\t\tmime: 'application/x-apple-diskimage'\n\t\t};\n\t}\n\n\tif (check([0x33, 0x67, 0x70, 0x35]) || // 3gp5\n\t\t(\n\t\t\tcheck([0x0, 0x0, 0x0]) && check([0x66, 0x74, 0x79, 0x70], {offset: 4}) &&\n\t\t\t\t(\n\t\t\t\t\tcheck([0x6D, 0x70, 0x34, 0x31], {offset: 8}) || // MP41\n\t\t\t\t\tcheck([0x6D, 0x70, 0x34, 0x32], {offset: 8}) || // MP42\n\t\t\t\t\tcheck([0x69, 0x73, 0x6F, 0x6D], {offset: 8}) || // ISOM\n\t\t\t\t\tcheck([0x69, 0x73, 0x6F, 0x32], {offset: 8}) || // ISO2\n\t\t\t\t\tcheck([0x6D, 0x6D, 0x70, 0x34], {offset: 8}) || // MMP4\n\t\t\t\t\tcheck([0x4D, 0x34, 0x56], {offset: 8}) || // M4V\n\t\t\t\t\tcheck([0x64, 0x61, 0x73, 0x68], {offset: 8}) // DASH\n\t\t\t\t)\n\t\t)) {\n\t\treturn {\n\t\t\text: 'mp4',\n\t\t\tmime: 'video/mp4'\n\t\t};\n\t}\n\n\tif (check([0x4D, 0x54, 0x68, 0x64])) {\n\t\treturn {\n\t\t\text: 'mid',\n\t\t\tmime: 'audio/midi'\n\t\t};\n\t}\n\n\t// https://github.com/threatstack/libmagic/blob/master/magic/Magdir/matroska\n\tif (check([0x1A, 0x45, 0xDF, 0xA3])) {\n\t\tconst sliced = buf.subarray(4, 4 + 4096);\n\t\tconst idPos = sliced.findIndex((el, i, arr) => arr[i] === 0x42 && arr[i + 1] === 0x82);\n\n\t\tif (idPos !== -1) {\n\t\t\tconst docTypePos = idPos + 3;\n\t\t\tconst findDocType = type => [...type].every((c, i) => sliced[docTypePos + i] === c.charCodeAt(0));\n\n\t\t\tif (findDocType('matroska')) {\n\t\t\t\treturn {\n\t\t\t\t\text: 'mkv',\n\t\t\t\t\tmime: 'video/x-matroska'\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tif (findDocType('webm')) {\n\t\t\t\treturn {\n\t\t\t\t\text: 'webm',\n\t\t\t\t\tmime: 'video/webm'\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t}\n\n\tif (check([0x0, 0x0, 0x0, 0x14, 0x66, 0x74, 0x79, 0x70, 0x71, 0x74, 0x20, 0x20]) ||\n\t\tcheck([0x66, 0x72, 0x65, 0x65], {offset: 4}) || // Type: `free`\n\t\tcheck([0x66, 0x74, 0x79, 0x70, 0x71, 0x74, 0x20, 0x20], {offset: 4}) ||\n\t\tcheck([0x6D, 0x64, 0x61, 0x74], {offset: 4}) || // MJPEG\n\t\tcheck([0x6D, 0x6F, 0x6F, 0x76], {offset: 4}) || // Type: `moov`\n\t\tcheck([0x77, 0x69, 0x64, 0x65], {offset: 4})) {\n\t\treturn {\n\t\t\text: 'mov',\n\t\t\tmime: 'video/quicktime'\n\t\t};\n\t}\n\n\t// RIFF file format which might be AVI, WAV, QCP, etc\n\tif (check([0x52, 0x49, 0x46, 0x46])) {\n\t\tif (check([0x41, 0x56, 0x49], {offset: 8})) {\n\t\t\treturn {\n\t\t\t\text: 'avi',\n\t\t\t\tmime: 'video/vnd.avi'\n\t\t\t};\n\t\t}\n\n\t\tif (check([0x57, 0x41, 0x56, 0x45], {offset: 8})) {\n\t\t\treturn {\n\t\t\t\text: 'wav',\n\t\t\t\tmime: 'audio/vnd.wave'\n\t\t\t};\n\t\t}\n\n\t\t// QLCM, QCP file\n\t\tif (check([0x51, 0x4C, 0x43, 0x4D], {offset: 8})) {\n\t\t\treturn {\n\t\t\t\text: 'qcp',\n\t\t\t\tmime: 'audio/qcelp'\n\t\t\t};\n\t\t}\n\t}\n\n\t// ASF_Header_Object first 80 bytes\n\tif (check([0x30, 0x26, 0xB2, 0x75, 0x8E, 0x66, 0xCF, 0x11, 0xA6, 0xD9])) {\n\t\t// Search for header should be in first 1KB of file.\n\n\t\tlet offset = 30;\n\t\tdo {\n\t\t\tconst objectSize = readUInt64LE(buf, offset + 16);\n\t\t\tif (check([0x91, 0x07, 0xDC, 0xB7, 0xB7, 0xA9, 0xCF, 0x11, 0x8E, 0xE6, 0x00, 0xC0, 0x0C, 0x20, 0x53, 0x65], {offset})) {\n\t\t\t\t// Sync on Stream-Properties-Object (B7DC0791-A9B7-11CF-8EE6-00C00C205365)\n\t\t\t\tif (check([0x40, 0x9E, 0x69, 0xF8, 0x4D, 0x5B, 0xCF, 0x11, 0xA8, 0xFD, 0x00, 0x80, 0x5F, 0x5C, 0x44, 0x2B], {offset: offset + 24})) {\n\t\t\t\t\t// Found audio:\n\t\t\t\t\treturn {\n\t\t\t\t\t\text: 'wma',\n\t\t\t\t\t\tmime: 'audio/x-ms-wma'\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tif (check([0xC0, 0xEF, 0x19, 0xBC, 0x4D, 0x5B, 0xCF, 0x11, 0xA8, 0xFD, 0x00, 0x80, 0x5F, 0x5C, 0x44, 0x2B], {offset: offset + 24})) {\n\t\t\t\t\t// Found video:\n\t\t\t\t\treturn {\n\t\t\t\t\t\text: 'wmv',\n\t\t\t\t\t\tmime: 'video/x-ms-asf'\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\toffset += objectSize;\n\t\t} while (offset + 24 <= buf.length);\n\n\t\t// Default to ASF generic extension\n\t\treturn {\n\t\t\text: 'asf',\n\t\t\tmime: 'application/vnd.ms-asf'\n\t\t};\n\t}\n\n\tif (\n\t\tcheck([0x0, 0x0, 0x1, 0xBA]) ||\n\t\tcheck([0x0, 0x0, 0x1, 0xB3])\n\t) {\n\t\treturn {\n\t\t\text: 'mpg',\n\t\t\tmime: 'video/mpeg'\n\t\t};\n\t}\n\n\tif (check([0x66, 0x74, 0x79, 0x70, 0x33, 0x67], {offset: 4})) {\n\t\treturn {\n\t\t\text: '3gp',\n\t\t\tmime: 'video/3gpp'\n\t\t};\n\t}\n\n\t// Check for MPEG header at different starting offsets\n\tfor (let start = 0; start < 2 && start < (buf.length - 16); start++) {\n\t\tif (\n\t\t\tcheck([0x49, 0x44, 0x33], {offset: start}) || // ID3 header\n\t\t\tcheck([0xFF, 0xE2], {offset: start, mask: [0xFF, 0xE2]}) // MPEG 1 or 2 Layer 3 header\n\t\t) {\n\t\t\treturn {\n\t\t\t\text: 'mp3',\n\t\t\t\tmime: 'audio/mpeg'\n\t\t\t};\n\t\t}\n\n\t\tif (\n\t\t\tcheck([0xFF, 0xE4], {offset: start, mask: [0xFF, 0xE4]}) // MPEG 1 or 2 Layer 2 header\n\t\t) {\n\t\t\treturn {\n\t\t\t\text: 'mp2',\n\t\t\t\tmime: 'audio/mpeg'\n\t\t\t};\n\t\t}\n\n\t\tif (\n\t\t\tcheck([0xFF, 0xF8], {offset: start, mask: [0xFF, 0xFC]}) // MPEG 2 layer 0 using ADTS\n\t\t) {\n\t\t\treturn {\n\t\t\t\text: 'mp2',\n\t\t\t\tmime: 'audio/mpeg'\n\t\t\t};\n\t\t}\n\n\t\tif (\n\t\t\tcheck([0xFF, 0xF0], {offset: start, mask: [0xFF, 0xFC]}) // MPEG 4 layer 0 using ADTS\n\t\t) {\n\t\t\treturn {\n\t\t\t\text: 'mp4',\n\t\t\t\tmime: 'audio/mpeg'\n\t\t\t};\n\t\t}\n\t}\n\n\tif (\n\t\tcheck([0x66, 0x74, 0x79, 0x70, 0x4D, 0x34, 0x41], {offset: 4})\n\t) {\n\t\treturn { // MPEG-4 layer 3 (audio)\n\t\t\text: 'm4a',\n\t\t\tmime: 'audio/mp4' // RFC 4337\n\t\t};\n\t}\n\n\t// Needs to be before `ogg` check\n\tif (check([0x4F, 0x70, 0x75, 0x73, 0x48, 0x65, 0x61, 0x64], {offset: 28})) {\n\t\treturn {\n\t\t\text: 'opus',\n\t\t\tmime: 'audio/opus'\n\t\t};\n\t}\n\n\t// If 'OggS' in first bytes, then OGG container\n\tif (check([0x4F, 0x67, 0x67, 0x53])) {\n\t\t// This is a OGG container\n\n\t\t// If ' theora' in header.\n\t\tif (check([0x80, 0x74, 0x68, 0x65, 0x6F, 0x72, 0x61], {offset: 28})) {\n\t\t\treturn {\n\t\t\t\text: 'ogv',\n\t\t\t\tmime: 'video/ogg'\n\t\t\t};\n\t\t}\n\n\t\t// If '\\x01video' in header.\n\t\tif (check([0x01, 0x76, 0x69, 0x64, 0x65, 0x6F, 0x00], {offset: 28})) {\n\t\t\treturn {\n\t\t\t\text: 'ogm',\n\t\t\t\tmime: 'video/ogg'\n\t\t\t};\n\t\t}\n\n\t\t// If ' FLAC' in header https://xiph.org/flac/faq.html\n\t\tif (check([0x7F, 0x46, 0x4C, 0x41, 0x43], {offset: 28})) {\n\t\t\treturn {\n\t\t\t\text: 'oga',\n\t\t\t\tmime: 'audio/ogg'\n\t\t\t};\n\t\t}\n\n\t\t// 'Speex ' in header https://en.wikipedia.org/wiki/Speex\n\t\tif (check([0x53, 0x70, 0x65, 0x65, 0x78, 0x20, 0x20], {offset: 28})) {\n\t\t\treturn {\n\t\t\t\text: 'spx',\n\t\t\t\tmime: 'audio/ogg'\n\t\t\t};\n\t\t}\n\n\t\t// If '\\x01vorbis' in header\n\t\tif (check([0x01, 0x76, 0x6F, 0x72, 0x62, 0x69, 0x73], {offset: 28})) {\n\t\t\treturn {\n\t\t\t\text: 'ogg',\n\t\t\t\tmime: 'audio/ogg'\n\t\t\t};\n\t\t}\n\n\t\t// Default OGG container https://www.iana.org/assignments/media-types/application/ogg\n\t\treturn {\n\t\t\text: 'ogx',\n\t\t\tmime: 'application/ogg'\n\t\t};\n\t}\n\n\tif (check([0x66, 0x4C, 0x61, 0x43])) {\n\t\treturn {\n\t\t\text: 'flac',\n\t\t\tmime: 'audio/x-flac'\n\t\t};\n\t}\n\n\tif (check([0x4D, 0x41, 0x43, 0x20])) { // 'MAC '\n\t\treturn {\n\t\t\text: 'ape',\n\t\t\tmime: 'audio/ape'\n\t\t};\n\t}\n\n\tif (check([0x77, 0x76, 0x70, 0x6B])) { // 'wvpk'\n\t\treturn {\n\t\t\text: 'wv',\n\t\t\tmime: 'audio/wavpack'\n\t\t};\n\t}\n\n\tif (check([0x23, 0x21, 0x41, 0x4D, 0x52, 0x0A])) {\n\t\treturn {\n\t\t\text: 'amr',\n\t\t\tmime: 'audio/amr'\n\t\t};\n\t}\n\n\tif (check([0x25, 0x50, 0x44, 0x46])) {\n\t\treturn {\n\t\t\text: 'pdf',\n\t\t\tmime: 'application/pdf'\n\t\t};\n\t}\n\n\tif (check([0x4D, 0x5A])) {\n\t\treturn {\n\t\t\text: 'exe',\n\t\t\tmime: 'application/x-msdownload'\n\t\t};\n\t}\n\n\tif (\n\t\t(buf[0] === 0x43 || buf[0] === 0x46) &&\n\t\tcheck([0x57, 0x53], {offset: 1})\n\t) {\n\t\treturn {\n\t\t\text: 'swf',\n\t\t\tmime: 'application/x-shockwave-flash'\n\t\t};\n\t}\n\n\tif (check([0x7B, 0x5C, 0x72, 0x74, 0x66])) {\n\t\treturn {\n\t\t\text: 'rtf',\n\t\t\tmime: 'application/rtf'\n\t\t};\n\t}\n\n\tif (check([0x00, 0x61, 0x73, 0x6D])) {\n\t\treturn {\n\t\t\text: 'wasm',\n\t\t\tmime: 'application/wasm'\n\t\t};\n\t}\n\n\tif (\n\t\tcheck([0x77, 0x4F, 0x46, 0x46]) &&\n\t\t(\n\t\t\tcheck([0x00, 0x01, 0x00, 0x00], {offset: 4}) ||\n\t\t\tcheck([0x4F, 0x54, 0x54, 0x4F], {offset: 4})\n\t\t)\n\t) {\n\t\treturn {\n\t\t\text: 'woff',\n\t\t\tmime: 'font/woff'\n\t\t};\n\t}\n\n\tif (\n\t\tcheck([0x77, 0x4F, 0x46, 0x32]) &&\n\t\t(\n\t\t\tcheck([0x00, 0x01, 0x00, 0x00], {offset: 4}) ||\n\t\t\tcheck([0x4F, 0x54, 0x54, 0x4F], {offset: 4})\n\t\t)\n\t) {\n\t\treturn {\n\t\t\text: 'woff2',\n\t\t\tmime: 'font/woff2'\n\t\t};\n\t}\n\n\tif (\n\t\tcheck([0x4C, 0x50], {offset: 34}) &&\n\t\t(\n\t\t\tcheck([0x00, 0x00, 0x01], {offset: 8}) ||\n\t\t\tcheck([0x01, 0x00, 0x02], {offset: 8}) ||\n\t\t\tcheck([0x02, 0x00, 0x02], {offset: 8})\n\t\t)\n\t) {\n\t\treturn {\n\t\t\text: 'eot',\n\t\t\tmime: 'application/vnd.ms-fontobject'\n\t\t};\n\t}\n\n\tif (check([0x00, 0x01, 0x00, 0x00, 0x00])) {\n\t\treturn {\n\t\t\text: 'ttf',\n\t\t\tmime: 'font/ttf'\n\t\t};\n\t}\n\n\tif (check([0x4F, 0x54, 0x54, 0x4F, 0x00])) {\n\t\treturn {\n\t\t\text: 'otf',\n\t\t\tmime: 'font/otf'\n\t\t};\n\t}\n\n\tif (check([0x00, 0x00, 0x01, 0x00])) {\n\t\treturn {\n\t\t\text: 'ico',\n\t\t\tmime: 'image/x-icon'\n\t\t};\n\t}\n\n\tif (check([0x00, 0x00, 0x02, 0x00])) {\n\t\treturn {\n\t\t\text: 'cur',\n\t\t\tmime: 'image/x-icon'\n\t\t};\n\t}\n\n\tif (check([0x46, 0x4C, 0x56, 0x01])) {\n\t\treturn {\n\t\t\text: 'flv',\n\t\t\tmime: 'video/x-flv'\n\t\t};\n\t}\n\n\tif (check([0x25, 0x21])) {\n\t\treturn {\n\t\t\text: 'ps',\n\t\t\tmime: 'application/postscript'\n\t\t};\n\t}\n\n\tif (check([0xFD, 0x37, 0x7A, 0x58, 0x5A, 0x00])) {\n\t\treturn {\n\t\t\text: 'xz',\n\t\t\tmime: 'application/x-xz'\n\t\t};\n\t}\n\n\tif (check([0x53, 0x51, 0x4C, 0x69])) {\n\t\treturn {\n\t\t\text: 'sqlite',\n\t\t\tmime: 'application/x-sqlite3'\n\t\t};\n\t}\n\n\tif (check([0x4E, 0x45, 0x53, 0x1A])) {\n\t\treturn {\n\t\t\text: 'nes',\n\t\t\tmime: 'application/x-nintendo-nes-rom'\n\t\t};\n\t}\n\n\tif (check([0x43, 0x72, 0x32, 0x34])) {\n\t\treturn {\n\t\t\text: 'crx',\n\t\t\tmime: 'application/x-google-chrome-extension'\n\t\t};\n\t}\n\n\tif (\n\t\tcheck([0x4D, 0x53, 0x43, 0x46]) ||\n\t\tcheck([0x49, 0x53, 0x63, 0x28])\n\t) {\n\t\treturn {\n\t\t\text: 'cab',\n\t\t\tmime: 'application/vnd.ms-cab-compressed'\n\t\t};\n\t}\n\n\t// Needs to be before `ar` check\n\tif (check([0x21, 0x3C, 0x61, 0x72, 0x63, 0x68, 0x3E, 0x0A, 0x64, 0x65, 0x62, 0x69, 0x61, 0x6E, 0x2D, 0x62, 0x69, 0x6E, 0x61, 0x72, 0x79])) {\n\t\treturn {\n\t\t\text: 'deb',\n\t\t\tmime: 'application/x-deb'\n\t\t};\n\t}\n\n\tif (check([0x21, 0x3C, 0x61, 0x72, 0x63, 0x68, 0x3E])) {\n\t\treturn {\n\t\t\text: 'ar',\n\t\t\tmime: 'application/x-unix-archive'\n\t\t};\n\t}\n\n\tif (check([0xED, 0xAB, 0xEE, 0xDB])) {\n\t\treturn {\n\t\t\text: 'rpm',\n\t\t\tmime: 'application/x-rpm'\n\t\t};\n\t}\n\n\tif (\n\t\tcheck([0x1F, 0xA0]) ||\n\t\tcheck([0x1F, 0x9D])\n\t) {\n\t\treturn {\n\t\t\text: 'Z',\n\t\t\tmime: 'application/x-compress'\n\t\t};\n\t}\n\n\tif (check([0x4C, 0x5A, 0x49, 0x50])) {\n\t\treturn {\n\t\t\text: 'lz',\n\t\t\tmime: 'application/x-lzip'\n\t\t};\n\t}\n\n\tif (check([0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1])) {\n\t\treturn {\n\t\t\text: 'msi',\n\t\t\tmime: 'application/x-msi'\n\t\t};\n\t}\n\n\tif (check([0x06, 0x0E, 0x2B, 0x34, 0x02, 0x05, 0x01, 0x01, 0x0D, 0x01, 0x02, 0x01, 0x01, 0x02])) {\n\t\treturn {\n\t\t\text: 'mxf',\n\t\t\tmime: 'application/mxf'\n\t\t};\n\t}\n\n\tif (check([0x47], {offset: 4}) && (check([0x47], {offset: 192}) || check([0x47], {offset: 196}))) {\n\t\treturn {\n\t\t\text: 'mts',\n\t\t\tmime: 'video/mp2t'\n\t\t};\n\t}\n\n\tif (check([0x42, 0x4C, 0x45, 0x4E, 0x44, 0x45, 0x52])) {\n\t\treturn {\n\t\t\text: 'blend',\n\t\t\tmime: 'application/x-blender'\n\t\t};\n\t}\n\n\tif (check([0x42, 0x50, 0x47, 0xFB])) {\n\t\treturn {\n\t\t\text: 'bpg',\n\t\t\tmime: 'image/bpg'\n\t\t};\n\t}\n\n\tif (check([0x00, 0x00, 0x00, 0x0C, 0x6A, 0x50, 0x20, 0x20, 0x0D, 0x0A, 0x87, 0x0A])) {\n\t\t// JPEG-2000 family\n\n\t\tif (check([0x6A, 0x70, 0x32, 0x20], {offset: 20})) {\n\t\t\treturn {\n\t\t\t\text: 'jp2',\n\t\t\t\tmime: 'image/jp2'\n\t\t\t};\n\t\t}\n\n\t\tif (check([0x6A, 0x70, 0x78, 0x20], {offset: 20})) {\n\t\t\treturn {\n\t\t\t\text: 'jpx',\n\t\t\t\tmime: 'image/jpx'\n\t\t\t};\n\t\t}\n\n\t\tif (check([0x6A, 0x70, 0x6D, 0x20], {offset: 20})) {\n\t\t\treturn {\n\t\t\t\text: 'jpm',\n\t\t\t\tmime: 'image/jpm'\n\t\t\t};\n\t\t}\n\n\t\tif (check([0x6D, 0x6A, 0x70, 0x32], {offset: 20})) {\n\t\t\treturn {\n\t\t\t\text: 'mj2',\n\t\t\t\tmime: 'image/mj2'\n\t\t\t};\n\t\t}\n\t}\n\n\tif (check([0x46, 0x4F, 0x52, 0x4D])) {\n\t\treturn {\n\t\t\text: 'aif',\n\t\t\tmime: 'audio/aiff'\n\t\t};\n\t}\n\n\tif (checkString(' new Promise((resolve, reject) => {\n\t// Using `eval` to work around issues when bundling with Webpack\n\tconst stream = eval('require')('stream'); // eslint-disable-line no-eval\n\n\treadableStream.once('readable', () => {\n\t\tconst pass = new stream.PassThrough();\n\t\tconst chunk = readableStream.read(module.exports.minimumBytes) || readableStream.read();\n\t\ttry {\n\t\t\tpass.fileType = fileType(chunk);\n\t\t} catch (error) {\n\t\t\treject(error);\n\t\t}\n\n\t\treadableStream.unshift(chunk);\n\n\t\tif (stream.pipeline) {\n\t\t\tresolve(stream.pipeline(readableStream, pass, () => {}));\n\t\t} else {\n\t\t\tresolve(readableStream.pipe(pass));\n\t\t}\n\t});\n});\n","'use strict';\nconst fileType = require('file-type');\n\nconst imageExts = new Set([\n\t'jpg',\n\t'png',\n\t'gif',\n\t'webp',\n\t'flif',\n\t'cr2',\n\t'tif',\n\t'bmp',\n\t'jxr',\n\t'psd',\n\t'ico',\n\t'bpg',\n\t'jp2',\n\t'jpm',\n\t'jpx',\n\t'heic',\n\t'cur',\n\t'dcm'\n]);\n\nconst imageType = input => {\n\tconst ret = fileType(input);\n\treturn imageExts.has(ret && ret.ext) ? ret : null;\n};\n\nmodule.exports = imageType;\n// TODO: Remove this for the next major release\nmodule.exports.default = imageType;\n\nObject.defineProperty(imageType, 'minimumBytes', {value: fileType.minimumBytes});\n","module.exports = \"\\n\\n\\t\\n\\t\\t\\n\\t\\n\"","module.exports = \"\\n\\n\\\">\\n\\n\\n\\t<%= i18n.cover %>\\n\\t\\n\\n\\n\\n\\t
    \\n\\t\\t\\\" alt=\\\"<%= i18n.cover %>\\\" />\\n\\t
    \\n\\n\\n\\n\"","module.exports = \"\\n\\n\\\">\\n\\n\\n\\t<%= i18n.note %>\\n\\t\\n\\n\\n\\n\\t
    \\n\\t\\t
    \\n <%- notes %>\\n\\t\\t
    \\n\\t
    \\n\\n\\n\\n\"","module.exports = \"\\n\\n\\\">\\n\\n\\n\\t<%= title %>\\n\\t\\n\\n\\n\\n\\t
    \\n\\t\\t
    \\n\\t\\t\\t

    <%= title %>

    \\n\\t\\t
    \\n\\t\\t
    \\n <% if (Array.isArray(content)) { %>\\n <% content.forEach(item => { %>\\n

    <%= item %>

    \\n <% }); %>\\n <% } else { %>\\n <%- content %>\\n <% } %>\\n\\t\\t
    \\n\\t
    \\n\\n\\n\\n\"","module.exports = \"\\n\\n\\\">\\n\\n\\n\\t<%= i18n.toc %>\\n\\t\\n\\n\\n\\n\\t
    \\n\\t\\t

    <%= i18n.toc %>

    \\n\\t\\t\\n\\t
    \\n\\n\\n\\n\"","module.exports = \"\\n\\n\\\">\\n\\n\\n\\t<%= i18n.info %>\\n\\t\\n\\n\\n\\n\\t
    \\n\\t\\t

    <%= title %>

    \\n\\t\\t

    \\n\\t\\t

    <%= author %>

    \\n\\t\\t

    <%= publisher %>

    \\n\\t
    \\n <% if (Array.isArray(tags) && tags.length) { %>\\n
    \\n <% tags = tags.join(', '); %>\\n <%- tags %>\\n
    \\n <% } %>\\n <% if (description) { %>\\n
    \\n <%- description %>\\n
    \\n <% } %>\\n\\n\\n\\n\"","module.exports = \"\\n\\n\\n\\t\\n\\t\\t<%= title %>\\n\\t\\t<%= i18n.code %>\\n\\t\\t\\\"><%= uuid.id %>\\n <%= date %>\\n <% if (description) { %>\\n\\t\\t <%= description %>\\n <% } %>\\n\\t\\t<%= author %>\\n\\t\\t<%= publisher %>\\n <% if (cover) { %>\\n\\t\\t \\n <% } %>\\n <% if (Array.isArray(tags) && tags.length) tags.forEach(tag => { %>\\n <%= tag %>\\n <% }); %>\\n\\t\\n\\n\\t\\n <% if (cover) { %>\\n\\t\\t \\n <% } %>\\n\\t\\t\\n\\t\\t\\n\\t\\t\\n <% pages.forEach((page, index) => { %>\\n \\\" href=\\\"OEBPS/page-<%= index %>.html\\\" media-type=\\\"application/xhtml+xml\\\" />\\n <% }); %>\\n <% if (cover) { %>\\n\\t\\t \\\" media-type=\\\"<%= cover.type %>\\\" properties=\\\"cover-image\\\" />\\n <% } %>\\n\\t\\t\\n <% Object.keys(images).forEach(name => { %>\\n \\\" href=\\\"OEBPS/<%= images[name].path %>\\\" media-type=\\\"<%= images[name].type %>\\\" />\\n <% }); %>\\n\\t\\n\\n\\t\\n <% if (cover) { %>\\n\\t\\t \\n <% } %>\\n\\t\\t\\n\\t\\t\\n <% pages.forEach((page, index) => { %>\\n \\\" linear=\\\"yes\\\" />\\n <% }); %>\\n <% if (notes) { %>\\n \\n <% } %>\\n\\t\\n\\n\\t\\n <% if (cover) { %>\\n\\t\\t \\\" href=\\\"OEBPS/front-cover.html\\\" />\\n <% } %>\\n\\t\\t\\\" href=\\\"OEBPS/table-of-contents.html\\\" />\\n\\t\\n\\n\\n\"","module.exports = \"application/epub+zip\"","module.exports = \"\\n\\n\\n\\\" xmlns=\\\"http://www.daisy.org/z3986/2005/ncx/\\\">\\n\\t\\n\\t\\t\\\" />\\n\\t\\t\\n\\t\\t\\n\\t\\t\\n\\t\\n\\n\\t\\n\\t\\t<%= title %>\\n\\t\\n\\n\\t\\n\\t\\t<%= author %>\\n\\t\\n\\n\\t\\n\\t\\t\\n\\t\\t\\t\\n\\t\\t\\t\\t<%= i18n.info %>\\n\\t\\t\\t\\n\\t\\t\\t\\n\\t\\t\\n\\t\\t\\n\\t\\t\\t\\n\\t\\t\\t\\t<%= i18n.toc %>\\n\\t\\t\\t\\n\\t\\t\\t\\n\\t\\t\\n <% pages.forEach((title, index) => { %>\\n \\\" playOrder=\\\"<%= (index + 3) %>\\\">\\n \\n <%= title %>\\n \\n .html\\\" />\\n \\n <% }); %>\\n <% if (notes) { %>\\n \\n \\n <%= i18n.note %>\\n \\n \\n \\n <% } %>\\n\\t\\n\\n\"","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","","// startup\n// Load entry module and return exports\n// This entry module is referenced by other modules so it can't be inlined\nvar __webpack_exports__ = __webpack_require__(\"./src/jepub.js\");\n",""],"names":["jEpub","constructor","_I18n","_Info","_Uuid","_Date","_Cover","_Pages","_Images","_Zip","init","details","JSZip","Object","assign","i18n","title","author","publisher","description","tags","scheme","id","utils","uuidv4","getISODate","language","file","mime","container","ejs","render","info","parseDOM","client","html2text","html","noBr","date","Date","uuid","isEmpty","validateUrl","cover","data","ext","Blob","type","mime2ext","ArrayBuffer","Uint8Array","path","image","name","filePath","notes","content","add","index","length","Array","isArray","template","compile","page","generate","onUpdate","support","bookConfig","pages","images","tocInBook","toc","generateAsync","mimeType","compression","compressionOptions","level","replace","c","crypto","getRandomValues","toString","isObject","obj","val","trim","toISOString","outText","doc","DOMParser","parseFromString","body","textContent","XMLSerializer","serializeToString","value","test","split"],"sourceRoot":""} \ No newline at end of file diff --git a/dist/jepub.min.js b/dist/jepub.min.js new file mode 100644 index 0000000..e03f040 --- /dev/null +++ b/dist/jepub.min.js @@ -0,0 +1,2 @@ +/*! For license information please see jepub.min.js.LICENSE.txt */ +!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("jEpub",[],t):"object"==typeof exports?exports.jEpub=t():e.jEpub=t()}(self,(()=>(()=>{var __webpack_modules__={318:e=>{e.exports=function(e){return e&&e.__esModule?e:{default:e}}},862:(e,t,i)=>{var n=i(8);function o(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return o=function(){return e},e}e.exports=function(e){if(e&&e.__esModule)return e;if(null===e||"object"!==n(e)&&"function"!=typeof e)return{default:e};var t=o();if(t&&t.has(e))return t.get(e);var i={},r=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var a in e)if(Object.prototype.hasOwnProperty.call(e,a)){var m=r?Object.getOwnPropertyDescriptor(e,a):null;m&&(m.get||m.set)?Object.defineProperty(i,a,m):i[a]=e[a]}return i.default=e,t&&t.set(e,i),i}},8:e=>{function t(i){return"function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?e.exports=t=function(e){return typeof e}:e.exports=t=function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},t(i)}e.exports=t},406:(e,t,i)=>{"use strict";var n=i(318),o=i(862);Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var r=o(i(853)),a=n(i(184)),m=n(i(282)),s=n(i(860)),f=n(i(650)),p=n(i(638)),l=n(i(170)),c=n(i(994)),d=n(i(87)),u=n(i(532)),x=n(i(191)),h=n(i(631));t.default=class{constructor(){this._I18n={},this._Info={},this._Uuid={},this._Date=null,this._Cover=null,this._Pages=[],this._Images=[],this._Zip={}}init(e){if(e instanceof JSZip)return this._Zip=e,this;if(this._Info=Object.assign({},{i18n:"en",title:"undefined",author:"undefined",publisher:"undefined",description:"",tags:[]},e),this._Uuid={scheme:"uuid",id:r.uuidv4()},this._Date=r.getISODate(),!m.default[this._Info.i18n])throw"Unknown Language: ".concat(this._Info.i18n);return this._I18n=m.default[this._Info.i18n],this._Zip=new JSZip,this._Zip.file("mimetype",x.default),this._Zip.file("META-INF/container.xml",s.default),this._Zip.file("OEBPS/title-page.html",ejs.render(d.default,{i18n:this._I18n,title:this._Info.title,author:this._Info.author,publisher:this._Info.publisher,description:r.parseDOM(this._Info.description),tags:this._Info.tags},{client:!0})),this}static html2text(e,t=!1){return r.html2text(e,t)}date(e){if(e instanceof Date)return this._Date=r.getISODate(e),this;throw"Date object is not valid"}uuid(e){if(r.isEmpty(e))throw"UUID value is empty";{let t="uuid";return r.validateUrl(e)&&(t="URI"),this._Uuid={scheme:t,id:e},this}}cover(e){let t,i;if(e instanceof Blob)i=e.type,t=r.mime2ext(i);else{if(!(e instanceof ArrayBuffer))throw"Cover data is not valid";t=(0,a.default)(new Uint8Array(e)),t&&(i=t.mime,t=r.mime2ext(i))}if(!t)throw"Cover data is not allowed";return this._Cover={type:i,path:"OEBPS/cover-image.".concat(t)},this._Zip.file(this._Cover.path,e),this._Zip.file("OEBPS/front-cover.html",ejs.render(f.default,{i18n:this._I18n,cover:this._Cover},{client:!0})),this}image(e,t){let i,n;if(e instanceof Blob)n=e.type,i=r.mime2ext(n);else{if(!(e instanceof ArrayBuffer))throw"Image data is not valid";i=(0,a.default)(new Uint8Array(e)),n=i.mime,i&&(i=r.mime2ext(n))}if(!i)throw"Image data is not allowed";const o="assets/".concat(t,".").concat(i);return this._Images[t]={type:n,path:o},this._Zip.file("OEBPS/".concat(o),e),this}notes(e){if(r.isEmpty(e))throw"Notes is empty";return this._Zip.file("OEBPS/notes.html",ejs.render(p.default,{i18n:this._I18n,notes:r.parseDOM(e)},{client:!0})),this}add(e,t,i=this._Pages.length){if(r.isEmpty(e))throw"Title is empty";if(r.isEmpty(t))throw"Content of ".concat(e," is empty");return Array.isArray(t)||(t=ejs.compile(t,{client:!0})({image:this._Images},(e=>''))),t=r.parseDOM(t)),this._Zip.file("OEBPS/page-".concat(i,".html"),ejs.render(l.default,{i18n:this._I18n,title:e,content:t},{client:!0})),this._Pages[i]=e,this}generate(e="blob",t){if(!JSZip.support[e])throw"This browser does not support ".concat(e);let i=this._Zip.file("OEBPS/notes.html");return i=!!i,this._Zip.file("book.opf",ejs.render(u.default,{i18n:this._I18n,uuid:this._Uuid,date:this._Date,title:this._Info.title,author:this._Info.author,publisher:this._Info.publisher,description:r.html2text(this._Info.description,!0),tags:this._Info.tags,cover:this._Cover,pages:this._Pages,notes:i,images:this._Images},{client:!0})),this._Zip.file("OEBPS/table-of-contents.html",ejs.render(c.default,{i18n:this._I18n,pages:this._Pages},{client:!0})),this._Zip.file("toc.ncx",ejs.render(h.default,{i18n:this._I18n,uuid:this._Uuid,title:this._Info.title,author:this._Info.author,pages:this._Pages,notes:i},{client:!0})),this._Zip.generateAsync({type:e,mimeType:x.default,compression:"DEFLATE",compressionOptions:{level:9}},t)}},e.exports=t.default},853:(e,t)=>{"use strict";function i(e,t=!1){let i=(new DOMParser).parseFromString("".concat(e),"text/html");return t?i.body.textContent.trim():(i=(new XMLSerializer).serializeToString(i.body),i=i.replace(/(^]*>|<\/body>$)/g,""),i)}Object.defineProperty(t,"__esModule",{value:!0}),t.uuidv4=function(){return([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,(e=>(e^crypto.getRandomValues(new Uint8Array(1))[0]&15>>e/4).toString(16)))},t.isObject=function(e){const t=typeof e;return"function"===t||"object"===t&&!!e},t.isEmpty=function(e){return null===e||"string"==typeof e&&!e.trim()},t.getISODate=function(e=new Date){return e.toISOString()},t.parseDOM=i,t.html2text=function(e,t=!1){return e=i(e=(e=(e=(e=(e=(e=(e=e.replace(//gi,"")).replace(//gi,"")).replace(/<\/(div|p|li|dd|h[1-6])>/gi,"\n")).replace(/<(br|hr)\s*[/]?>/gi,"\n")).replace(/
  • /gi,"+ ")).replace(/<[^>]+>/g,"")).replace(/\n{3,}/g,"\n\n"),!0),t&&(e=e.replace(/\n+/g," ")),e},t.validateUrl=function(e){return/^(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,}))\.?)(?::\d{2,5})?(?:[/?#]\S*)?$/i.test(e)},t.mime2ext=function(e){let t=null;switch(e){case"image/jpg":case"image/jpeg":t="jpg";break;case"image/svg+xml":t="svg";break;case"image/gif":case"image/apng":case"image/png":case"image/webp":case"image/bmp":t=e.split("/")[1];break;default:t=null}return t}},769:module=>{"use strict";const toBytes=e=>[...e].map((e=>e.charCodeAt(0))),xpiZipFilename=toBytes("META-INF/mozilla.rsa"),oxmlContentTypes=toBytes("[Content_Types].xml"),oxmlRels=toBytes("_rels/.rels");function readUInt64LE(e,t=0){let i=e[t],n=1,o=0;for(;++o<8;)n*=256,i+=e[t+o]*n;return i}const fileType=e=>{if(!(e instanceof Uint8Array||e instanceof ArrayBuffer||Buffer.isBuffer(e)))throw new TypeError(`Expected the \`input\` argument to be of type \`Uint8Array\` or \`Buffer\` or \`ArrayBuffer\`, got \`${typeof e}\``);const t=e instanceof Uint8Array?e:new Uint8Array(e);if(!(t&&t.length>1))return null;const i=(e,i)=>{i=Object.assign({offset:0},i);for(let n=0;ni(toBytes(e),t);if(i([255,216,255]))return{ext:"jpg",mime:"image/jpeg"};if(i([137,80,78,71,13,10,26,10]))return{ext:"png",mime:"image/png"};if(i([71,73,70]))return{ext:"gif",mime:"image/gif"};if(i([87,69,66,80],{offset:8}))return{ext:"webp",mime:"image/webp"};if(i([70,76,73,70]))return{ext:"flif",mime:"image/flif"};if((i([73,73,42,0])||i([77,77,0,42]))&&i([67,82],{offset:8}))return{ext:"cr2",mime:"image/x-canon-cr2"};if(i([73,73,42,0])||i([77,77,0,42]))return{ext:"tif",mime:"image/tiff"};if(i([66,77]))return{ext:"bmp",mime:"image/bmp"};if(i([73,73,188]))return{ext:"jxr",mime:"image/vnd.ms-photo"};if(i([56,66,80,83]))return{ext:"psd",mime:"image/vnd.adobe.photoshop"};if(i([80,75,3,4])){if(i([109,105,109,101,116,121,112,101,97,112,112,108,105,99,97,116,105,111,110,47,101,112,117,98,43,122,105,112],{offset:30}))return{ext:"epub",mime:"application/epub+zip"};if(i(xpiZipFilename,{offset:30}))return{ext:"xpi",mime:"application/x-xpinstall"};if(n("mimetypeapplication/vnd.oasis.opendocument.text",{offset:30}))return{ext:"odt",mime:"application/vnd.oasis.opendocument.text"};if(n("mimetypeapplication/vnd.oasis.opendocument.spreadsheet",{offset:30}))return{ext:"ods",mime:"application/vnd.oasis.opendocument.spreadsheet"};if(n("mimetypeapplication/vnd.oasis.opendocument.presentation",{offset:30}))return{ext:"odp",mime:"application/vnd.oasis.opendocument.presentation"};const e=(e,t=0)=>e.findIndex(((e,i,n)=>i>=t&&80===n[i]&&75===n[i+1]&&3===n[i+2]&&4===n[i+3]));let o=0,r=!1,a=null;do{const m=o+30;if(r||(r=i(oxmlContentTypes,{offset:m})||i(oxmlRels,{offset:m})),a||(n("word/",{offset:m})?a={ext:"docx",mime:"application/vnd.openxmlformats-officedocument.wordprocessingml.document"}:n("ppt/",{offset:m})?a={ext:"pptx",mime:"application/vnd.openxmlformats-officedocument.presentationml.presentation"}:n("xl/",{offset:m})&&(a={ext:"xlsx",mime:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"})),r&&a)return a;o=e(t,m)}while(o>=0);if(a)return a}if(i([80,75])&&(3===t[2]||5===t[2]||7===t[2])&&(4===t[3]||6===t[3]||8===t[3]))return{ext:"zip",mime:"application/zip"};if(i([117,115,116,97,114],{offset:257}))return{ext:"tar",mime:"application/x-tar"};if(i([82,97,114,33,26,7])&&(0===t[6]||1===t[6]))return{ext:"rar",mime:"application/x-rar-compressed"};if(i([31,139,8]))return{ext:"gz",mime:"application/gzip"};if(i([66,90,104]))return{ext:"bz2",mime:"application/x-bzip2"};if(i([55,122,188,175,39,28]))return{ext:"7z",mime:"application/x-7z-compressed"};if(i([120,1]))return{ext:"dmg",mime:"application/x-apple-diskimage"};if(i([51,103,112,53])||i([0,0,0])&&i([102,116,121,112],{offset:4})&&(i([109,112,52,49],{offset:8})||i([109,112,52,50],{offset:8})||i([105,115,111,109],{offset:8})||i([105,115,111,50],{offset:8})||i([109,109,112,52],{offset:8})||i([77,52,86],{offset:8})||i([100,97,115,104],{offset:8})))return{ext:"mp4",mime:"video/mp4"};if(i([77,84,104,100]))return{ext:"mid",mime:"audio/midi"};if(i([26,69,223,163])){const e=t.subarray(4,4100),i=e.findIndex(((e,t,i)=>66===i[t]&&130===i[t+1]));if(-1!==i){const t=i+3,n=i=>[...i].every(((i,n)=>e[t+n]===i.charCodeAt(0)));if(n("matroska"))return{ext:"mkv",mime:"video/x-matroska"};if(n("webm"))return{ext:"webm",mime:"video/webm"}}}if(i([0,0,0,20,102,116,121,112,113,116,32,32])||i([102,114,101,101],{offset:4})||i([102,116,121,112,113,116,32,32],{offset:4})||i([109,100,97,116],{offset:4})||i([109,111,111,118],{offset:4})||i([119,105,100,101],{offset:4}))return{ext:"mov",mime:"video/quicktime"};if(i([82,73,70,70])){if(i([65,86,73],{offset:8}))return{ext:"avi",mime:"video/vnd.avi"};if(i([87,65,86,69],{offset:8}))return{ext:"wav",mime:"audio/vnd.wave"};if(i([81,76,67,77],{offset:8}))return{ext:"qcp",mime:"audio/qcelp"}}if(i([48,38,178,117,142,102,207,17,166,217])){let e=30;do{const n=readUInt64LE(t,e+16);if(i([145,7,220,183,183,169,207,17,142,230,0,192,12,32,83,101],{offset:e})){if(i([64,158,105,248,77,91,207,17,168,253,0,128,95,92,68,43],{offset:e+24}))return{ext:"wma",mime:"audio/x-ms-wma"};if(i([192,239,25,188,77,91,207,17,168,253,0,128,95,92,68,43],{offset:e+24}))return{ext:"wmv",mime:"video/x-ms-asf"};break}e+=n}while(e+24<=t.length);return{ext:"asf",mime:"application/vnd.ms-asf"}}if(i([0,0,1,186])||i([0,0,1,179]))return{ext:"mpg",mime:"video/mpeg"};if(i([102,116,121,112,51,103],{offset:4}))return{ext:"3gp",mime:"video/3gpp"};for(let e=0;e<2&&enew Promise(((resolve,reject)=>{const stream=eval("require")("stream");readableStream.once("readable",(()=>{const e=new stream.PassThrough,t=readableStream.read(module.exports.minimumBytes)||readableStream.read();try{e.fileType=fileType(t)}catch(e){reject(e)}readableStream.unshift(t),stream.pipeline?resolve(stream.pipeline(readableStream,e,(()=>{}))):resolve(readableStream.pipe(e))}))}))},184:(e,t,i)=>{"use strict";const n=i(769),o=new Set(["jpg","png","gif","webp","flif","cr2","tif","bmp","jxr","psd","ico","bpg","jp2","jpm","jpx","heic","cur","dcm"]),r=e=>{const t=n(e);return o.has(t&&t.ext)?t:null};e.exports=r,e.exports.default=r,Object.defineProperty(r,"minimumBytes",{value:n.minimumBytes})},860:e=>{e.exports='\n\n\t\n\t\t\n\t\n'},650:e=>{e.exports='\n\n\n\n\n\t<%= i18n.cover %>\n\t\n\n\n\n\t
    \n\t\t<%= i18n.cover %>\n\t
    \n\n\n\n'},638:e=>{e.exports='\n\n\n\n\n\t<%= i18n.note %>\n\t\n\n\n\n\t
    \n\t\t
    \n <%- notes %>\n\t\t
    \n\t
    \n\n\n\n'},170:e=>{e.exports='\n\n\n\n\n\t<%= title %>\n\t\n\n\n\n\t
    \n\t\t
    \n\t\t\t

    <%= title %>

    \n\t\t
    \n\t\t
    \n <% if (Array.isArray(content)) { %>\n <% content.forEach(item => { %>\n

    <%= item %>

    \n <% }); %>\n <% } else { %>\n <%- content %>\n <% } %>\n\t\t
    \n\t
    \n\n\n\n'},994:e=>{e.exports='\n\n\n\n\n\t<%= i18n.toc %>\n\t\n\n\n\n\t
    \n\t\t

    <%= i18n.toc %>

    \n\t\t\n\t
    \n\n\n\n'},87:e=>{e.exports='\n\n\n\n\n\t<%= i18n.info %>\n\t\n\n\n\n\t
    \n\t\t

    <%= title %>

    \n\t\t

    \n\t\t

    <%= author %>

    \n\t\t

    <%= publisher %>

    \n\t
    \n <% if (Array.isArray(tags) && tags.length) { %>\n
    \n <% tags = tags.join(\', \'); %>\n <%- tags %>\n
    \n <% } %>\n <% if (description) { %>\n
    \n <%- description %>\n
    \n <% } %>\n\n\n\n'},532:e=>{e.exports='\n\n\n\t\n\t\t<%= title %>\n\t\t<%= i18n.code %>\n\t\t<%= uuid.id %>\n <%= date %>\n <% if (description) { %>\n\t\t <%= description %>\n <% } %>\n\t\t<%= author %>\n\t\t<%= publisher %>\n <% if (cover) { %>\n\t\t \n <% } %>\n <% if (Array.isArray(tags) && tags.length) tags.forEach(tag => { %>\n <%= tag %>\n <% }); %>\n\t\n\n\t\n <% if (cover) { %>\n\t\t \n <% } %>\n\t\t\n\t\t\n\t\t\n <% pages.forEach((page, index) => { %>\n \n <% }); %>\n <% if (cover) { %>\n\t\t \n <% } %>\n\t\t\n <% Object.keys(images).forEach(name => { %>\n \n <% }); %>\n\t\n\n\t\n <% if (cover) { %>\n\t\t \n <% } %>\n\t\t\n\t\t\n <% pages.forEach((page, index) => { %>\n \n <% }); %>\n <% if (notes) { %>\n \n <% } %>\n\t\n\n\t\n <% if (cover) { %>\n\t\t \n <% } %>\n\t\t\n\t\n\n\n'},191:e=>{e.exports="application/epub+zip"},631:e=>{e.exports='\n\n\n\n\t\n\t\t\n\t\t\n\t\t\n\t\t\n\t\n\n\t\n\t\t<%= title %>\n\t\n\n\t\n\t\t<%= author %>\n\t\n\n\t\n\t\t\n\t\t\t\n\t\t\t\t<%= i18n.info %>\n\t\t\t\n\t\t\t\n\t\t\n\t\t\n\t\t\t\n\t\t\t\t<%= i18n.toc %>\n\t\t\t\n\t\t\t\n\t\t\n <% pages.forEach((title, index) => { %>\n \n \n <%= title %>\n \n \n \n <% }); %>\n <% if (notes) { %>\n \n \n <%= i18n.note %>\n \n \n \n <% } %>\n\t\n\n'},282:e=>{"use strict";e.exports=JSON.parse('{"en":{"code":"en","cover":"Cover","toc":"Table of Contents","info":"Information","note":"Notes"},"vi":{"code":"vi","cover":"Bìa sách","toc":"Mục lục","info":"Giới thiệu","note":"Ghi chú"},"hi":{"code":"hi","cover":"आवरण","toc":"विषय - सूची","info":"जानकारी","note":"टिप्पणियाँ"}}')}},__webpack_module_cache__={};function __webpack_require__(e){var t=__webpack_module_cache__[e];if(void 0!==t)return t.exports;var i=__webpack_module_cache__[e]={exports:{}};return __webpack_modules__[e](i,i.exports,__webpack_require__),i.exports}var __webpack_exports__=__webpack_require__(406);return __webpack_exports__})())); \ No newline at end of file diff --git a/dist/jepub.min.js.LICENSE.txt b/dist/jepub.min.js.LICENSE.txt new file mode 100644 index 0000000..6d9fe9d --- /dev/null +++ b/dist/jepub.min.js.LICENSE.txt @@ -0,0 +1 @@ +/*! jepub - 2.1.4 | (c) 2018 lelinhtinh | ISC | https://lelinhtinh.github.io/jEpub/ */