diff options
-rw-r--r-- | js/read.js | 6 | ||||
-rw-r--r-- | lib/epub.js | 9225 | ||||
-rw-r--r-- | lib/smartimages.js | 73 | ||||
-rw-r--r-- | lib/zip.min.js | 11 | ||||
-rw-r--r-- | read.html | 147 |
5 files changed, 113 insertions, 9349 deletions
@@ -56,14 +56,14 @@ function open_lastread() { function next_page() { _store_position = 1; - window.book.nextPage(); + window.book.rendition.next(); show_ui(false); request_fullscreen(); } function prev_page() { - window.book.prevPage(); + window.book.rendition.prev(); show_ui(false); request_fullscreen(); @@ -276,7 +276,7 @@ function apply_theme() { $("#theme_css").attr("href", theme_url); - $(book.renderer.doc).find("#theme_css").text(_res_data[theme_url]); + //$(book.renderer.doc).find("#theme_css").text(_res_data[theme_url]); }); } diff --git a/lib/epub.js b/lib/epub.js index 277d998..f52a7d2 100644 --- a/lib/epub.js +++ b/lib/epub.js @@ -1,9224 +1 @@ -/*! - * @overview RSVP - a tiny implementation of Promises/A+. - * @copyright Copyright (c) 2016 Yehuda Katz, Tom Dale, Stefan Penner and contributors - * @license Licensed under MIT license - * See https://raw.githubusercontent.com/tildeio/rsvp.js/master/LICENSE - * @version 3.5.0 - */ - -(function (global, factory) { - typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : - typeof define === 'function' && define.amd ? define(['exports'], factory) : - (factory((global.RSVP = global.RSVP || {}))); -}(this, (function (exports) { 'use strict'; - -function indexOf(callbacks, callback) { - for (var i = 0, l = callbacks.length; i < l; i++) { - if (callbacks[i] === callback) { - return i; - } - } - - return -1; -} - -function callbacksFor(object) { - var callbacks = object._promiseCallbacks; - - if (!callbacks) { - callbacks = object._promiseCallbacks = {}; - } - - return callbacks; -} - -/** - @class RSVP.EventTarget -*/ -var EventTarget = { - - /** - `RSVP.EventTarget.mixin` extends an object with EventTarget methods. For - Example: - ```javascript - let object = {}; - RSVP.EventTarget.mixin(object); - object.on('finished', function(event) { - // handle event - }); - object.trigger('finished', { detail: value }); - ``` - `EventTarget.mixin` also works with prototypes: - ```javascript - let Person = function() {}; - RSVP.EventTarget.mixin(Person.prototype); - let yehuda = new Person(); - let tom = new Person(); - yehuda.on('poke', function(event) { - console.log('Yehuda says OW'); - }); - tom.on('poke', function(event) { - console.log('Tom says OW'); - }); - yehuda.trigger('poke'); - tom.trigger('poke'); - ``` - @method mixin - @for RSVP.EventTarget - @private - @param {Object} object object to extend with EventTarget methods - */ - mixin: function mixin(object) { - object['on'] = this['on']; - object['off'] = this['off']; - object['trigger'] = this['trigger']; - object._promiseCallbacks = undefined; - return object; - }, - - /** - Registers a callback to be executed when `eventName` is triggered - ```javascript - object.on('event', function(eventInfo){ - // handle the event - }); - object.trigger('event'); - ``` - @method on - @for RSVP.EventTarget - @private - @param {String} eventName name of the event to listen for - @param {Function} callback function to be called when the event is triggered. - */ - on: function on(eventName, callback) { - if (typeof callback !== 'function') { - throw new TypeError('Callback must be a function'); - } - - var allCallbacks = callbacksFor(this), - callbacks = undefined; - - callbacks = allCallbacks[eventName]; - - if (!callbacks) { - callbacks = allCallbacks[eventName] = []; - } - - if (indexOf(callbacks, callback) === -1) { - callbacks.push(callback); - } - }, - - /** - You can use `off` to stop firing a particular callback for an event: - ```javascript - function doStuff() { // do stuff! } - object.on('stuff', doStuff); - object.trigger('stuff'); // doStuff will be called - // Unregister ONLY the doStuff callback - object.off('stuff', doStuff); - object.trigger('stuff'); // doStuff will NOT be called - ``` - If you don't pass a `callback` argument to `off`, ALL callbacks for the - event will not be executed when the event fires. For example: - ```javascript - let callback1 = function(){}; - let callback2 = function(){}; - object.on('stuff', callback1); - object.on('stuff', callback2); - object.trigger('stuff'); // callback1 and callback2 will be executed. - object.off('stuff'); - object.trigger('stuff'); // callback1 and callback2 will not be executed! - ``` - @method off - @for RSVP.EventTarget - @private - @param {String} eventName event to stop listening to - @param {Function} callback optional argument. If given, only the function - given will be removed from the event's callback queue. If no `callback` - argument is given, all callbacks will be removed from the event's callback - queue. - */ - off: function off(eventName, callback) { - var allCallbacks = callbacksFor(this), - callbacks = undefined, - index = undefined; - - if (!callback) { - allCallbacks[eventName] = []; - return; - } - - callbacks = allCallbacks[eventName]; - - index = indexOf(callbacks, callback); - - if (index !== -1) { - callbacks.splice(index, 1); - } - }, - - /** - Use `trigger` to fire custom events. For example: - ```javascript - object.on('foo', function(){ - console.log('foo event happened!'); - }); - object.trigger('foo'); - // 'foo event happened!' logged to the console - ``` - You can also pass a value as a second argument to `trigger` that will be - passed as an argument to all event listeners for the event: - ```javascript - object.on('foo', function(value){ - console.log(value.name); - }); - object.trigger('foo', { name: 'bar' }); - // 'bar' logged to the console - ``` - @method trigger - @for RSVP.EventTarget - @private - @param {String} eventName name of the event to be triggered - @param {*} options optional value to be passed to any event handlers for - the given `eventName` - */ - trigger: function trigger(eventName, options, label) { - var allCallbacks = callbacksFor(this), - callbacks = undefined, - callback = undefined; - - if (callbacks = allCallbacks[eventName]) { - // Don't cache the callbacks.length since it may grow - for (var i = 0; i < callbacks.length; i++) { - callback = callbacks[i]; - - callback(options, label); - } - } - } -}; - -var config = { - instrument: false -}; - -EventTarget['mixin'](config); - -function configure(name, value) { - if (name === 'onerror') { - // handle for legacy users that expect the actual - // error to be passed to their function added via - // `RSVP.configure('onerror', someFunctionHere);` - config['on']('error', value); - return; - } - - if (arguments.length === 2) { - config[name] = value; - } else { - return config[name]; - } -} - -function objectOrFunction(x) { - return typeof x === 'function' || typeof x === 'object' && x !== null; -} - -function isFunction(x) { - return typeof x === 'function'; -} - -function isMaybeThenable(x) { - return typeof x === 'object' && x !== null; -} - -var _isArray = undefined; -if (!Array.isArray) { - _isArray = function (x) { - return Object.prototype.toString.call(x) === '[object Array]'; - }; -} else { - _isArray = Array.isArray; -} - -var isArray = _isArray; - -// Date.now is not available in browsers < IE9 -// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/now#Compatibility -var now = Date.now || function () { - return new Date().getTime(); -}; - -function F() {} - -var o_create = Object.create || function (o) { - if (arguments.length > 1) { - throw new Error('Second argument not supported'); - } - if (typeof o !== 'object') { - throw new TypeError('Argument must be an object'); - } - F.prototype = o; - return new F(); -}; - -var queue = []; - -function scheduleFlush() { - setTimeout(function () { - for (var i = 0; i < queue.length; i++) { - var entry = queue[i]; - - var payload = entry.payload; - - payload.guid = payload.key + payload.id; - payload.childGuid = payload.key + payload.childId; - if (payload.error) { - payload.stack = payload.error.stack; - } - - config['trigger'](entry.name, entry.payload); - } - queue.length = 0; - }, 50); -} -function instrument$1(eventName, promise, child) { - if (1 === queue.push({ - name: eventName, - payload: { - key: promise._guidKey, - id: promise._id, - eventName: eventName, - detail: promise._result, - childId: child && child._id, - label: promise._label, - timeStamp: now(), - error: config["instrument-with-stack"] ? new Error(promise._label) : null - } })) { - scheduleFlush(); - } -} - -/** - `RSVP.Promise.resolve` returns a promise that will become resolved with the - passed `value`. It is shorthand for the following: - - ```javascript - let promise = new RSVP.Promise(function(resolve, reject){ - resolve(1); - }); - - promise.then(function(value){ - // value === 1 - }); - ``` - - Instead of writing the above, your code now simply becomes the following: - - ```javascript - let promise = RSVP.Promise.resolve(1); - - promise.then(function(value){ - // value === 1 - }); - ``` - - @method resolve - @static - @param {*} object value that the returned promise will be resolved with - @param {String} label optional string for identifying the returned promise. - Useful for tooling. - @return {Promise} a promise that will become fulfilled with the given - `value` -*/ -function resolve$1(object, label) { - /*jshint validthis:true */ - var Constructor = this; - - if (object && typeof object === 'object' && object.constructor === Constructor) { - return object; - } - - var promise = new Constructor(noop, label); - resolve(promise, object); - return promise; -} - -function withOwnPromise() { - return new TypeError('A promises callback cannot return that same promise.'); -} - -function noop() {} - -var PENDING = void 0; -var FULFILLED = 1; -var REJECTED = 2; - -var GET_THEN_ERROR = new ErrorObject(); - -function getThen(promise) { - try { - return promise.then; - } catch (error) { - GET_THEN_ERROR.error = error; - return GET_THEN_ERROR; - } -} - -function tryThen(then$$1, value, fulfillmentHandler, rejectionHandler) { - try { - then$$1.call(value, fulfillmentHandler, rejectionHandler); - } catch (e) { - return e; - } -} - -function handleForeignThenable(promise, thenable, then$$1) { - config.async(function (promise) { - var sealed = false; - var error = tryThen(then$$1, thenable, function (value) { - if (sealed) { - return; - } - sealed = true; - if (thenable !== value) { - resolve(promise, value, undefined); - } else { - fulfill(promise, value); - } - }, function (reason) { - if (sealed) { - return; - } - sealed = true; - - reject(promise, reason); - }, 'Settle: ' + (promise._label || ' unknown promise')); - - if (!sealed && error) { - sealed = true; - reject(promise, error); - } - }, promise); -} - -function handleOwnThenable(promise, thenable) { - if (thenable._state === FULFILLED) { - fulfill(promise, thenable._result); - } else if (thenable._state === REJECTED) { - thenable._onError = null; - reject(promise, thenable._result); - } else { - subscribe(thenable, undefined, function (value) { - if (thenable !== value) { - resolve(promise, value, undefined); - } else { - fulfill(promise, value); - } - }, function (reason) { - return reject(promise, reason); - }); - } -} - -function handleMaybeThenable(promise, maybeThenable, then$$1) { - if (maybeThenable.constructor === promise.constructor && then$$1 === then && promise.constructor.resolve === resolve$1) { - handleOwnThenable(promise, maybeThenable); - } else { - if (then$$1 === GET_THEN_ERROR) { - reject(promise, GET_THEN_ERROR.error); - GET_THEN_ERROR.error = null; - } else if (then$$1 === undefined) { - fulfill(promise, maybeThenable); - } else if (isFunction(then$$1)) { - handleForeignThenable(promise, maybeThenable, then$$1); - } else { - fulfill(promise, maybeThenable); - } - } -} - -function resolve(promise, value) { - if (promise === value) { - fulfill(promise, value); - } else if (objectOrFunction(value)) { - handleMaybeThenable(promise, value, getThen(value)); - } else { - fulfill(promise, value); - } -} - -function publishRejection(promise) { - if (promise._onError) { - promise._onError(promise._result); - } - - publish(promise); -} - -function fulfill(promise, value) { - if (promise._state !== PENDING) { - return; - } - - promise._result = value; - promise._state = FULFILLED; - - if (promise._subscribers.length === 0) { - if (config.instrument) { - instrument$1('fulfilled', promise); - } - } else { - config.async(publish, promise); - } -} - -function reject(promise, reason) { - if (promise._state !== PENDING) { - return; - } - promise._state = REJECTED; - promise._result = reason; - config.async(publishRejection, promise); -} - -function subscribe(parent, child, onFulfillment, onRejection) { - var subscribers = parent._subscribers; - var length = subscribers.length; - - parent._onError = null; - - subscribers[length] = child; - subscribers[length + FULFILLED] = onFulfillment; - subscribers[length + REJECTED] = onRejection; - - if (length === 0 && parent._state) { - config.async(publish, parent); - } -} - -function publish(promise) { - var subscribers = promise._subscribers; - var settled = promise._state; - - if (config.instrument) { - instrument$1(settled === FULFILLED ? 'fulfilled' : 'rejected', promise); - } - - if (subscribers.length === 0) { - return; - } - - var child = undefined, - callback = undefined, - detail = promise._result; - - for (var i = 0; i < subscribers.length; i += 3) { - child = subscribers[i]; - callback = subscribers[i + settled]; - - if (child) { - invokeCallback(settled, child, callback, detail); - } else { - callback(detail); - } - } - - promise._subscribers.length = 0; -} - -function ErrorObject() { - this.error = null; -} - -var TRY_CATCH_ERROR = new ErrorObject(); - -function tryCatch(callback, detail) { - try { - return callback(detail); - } catch (e) { - TRY_CATCH_ERROR.error = e; - return TRY_CATCH_ERROR; - } -} - -function invokeCallback(settled, promise, callback, detail) { - var hasCallback = isFunction(callback), - value = undefined, - error = undefined, - succeeded = undefined, - failed = undefined; - - if (hasCallback) { - value = tryCatch(callback, detail); - - if (value === TRY_CATCH_ERROR) { - failed = true; - error = value.error; - value.error = null; // release - } else { - succeeded = true; - } - - if (promise === value) { - reject(promise, withOwnPromise()); - return; - } - } else { - value = detail; - succeeded = true; - } - - if (promise._state !== PENDING) { - // noop - } else if (hasCallback && succeeded) { - resolve(promise, value); - } else if (failed) { - reject(promise, error); - } else if (settled === FULFILLED) { - fulfill(promise, value); - } else if (settled === REJECTED) { - reject(promise, value); - } -} - -function initializePromise(promise, resolver) { - var resolved = false; - try { - resolver(function (value) { - if (resolved) { - return; - } - resolved = true; - resolve(promise, value); - }, function (reason) { - if (resolved) { - return; - } - resolved = true; - reject(promise, reason); - }); - } catch (e) { - reject(promise, e); - } -} - -function then(onFulfillment, onRejection, label) { - var _arguments = arguments; - - var parent = this; - var state = parent._state; - - if (state === FULFILLED && !onFulfillment || state === REJECTED && !onRejection) { - config.instrument && instrument$1('chained', parent, parent); - return parent; - } - - parent._onError = null; - - var child = new parent.constructor(noop, label); - var result = parent._result; - - config.instrument && instrument$1('chained', parent, child); - - if (state) { - (function () { - var callback = _arguments[state - 1]; - config.async(function () { - return invokeCallback(state, child, callback, result); - }); - })(); - } else { - subscribe(parent, child, onFulfillment, onRejection); - } - - return child; -} - -function makeSettledResult(state, position, value) { - if (state === FULFILLED) { - return { - state: 'fulfilled', - value: value - }; - } else { - return { - state: 'rejected', - reason: value - }; - } -} - -function Enumerator(Constructor, input, abortOnReject, label) { - this._instanceConstructor = Constructor; - this.promise = new Constructor(noop, label); - this._abortOnReject = abortOnReject; - - if (this._validateInput(input)) { - this._input = input; - this.length = input.length; - this._remaining = input.length; - - this._init(); - - if (this.length === 0) { - fulfill(this.promise, this._result); - } else { - this.length = this.length || 0; - this._enumerate(); - if (this._remaining === 0) { - fulfill(this.promise, this._result); - } - } - } else { - reject(this.promise, this._validationError()); - } -} - -Enumerator.prototype._validateInput = function (input) { - return isArray(input); -}; - -Enumerator.prototype._validationError = function () { - return new Error('Array Methods must be provided an Array'); -}; - -Enumerator.prototype._init = function () { - this._result = new Array(this.length); -}; - -Enumerator.prototype._enumerate = function () { - var length = this.length; - var promise = this.promise; - var input = this._input; - - for (var i = 0; promise._state === PENDING && i < length; i++) { - this._eachEntry(input[i], i); - } -}; - -Enumerator.prototype._settleMaybeThenable = function (entry, i) { - var c = this._instanceConstructor; - var resolve$$1 = c.resolve; - - if (resolve$$1 === resolve$1) { - var then$$1 = getThen(entry); - - if (then$$1 === then && entry._state !== PENDING) { - entry._onError = null; - this._settledAt(entry._state, i, entry._result); - } else if (typeof then$$1 !== 'function') { - this._remaining--; - this._result[i] = this._makeResult(FULFILLED, i, entry); - } else if (c === Promise$1) { - var promise = new c(noop); - handleMaybeThenable(promise, entry, then$$1); - this._willSettleAt(promise, i); - } else { - this._willSettleAt(new c(function (resolve$$1) { - return resolve$$1(entry); - }), i); - } - } else { - this._willSettleAt(resolve$$1(entry), i); - } -}; - -Enumerator.prototype._eachEntry = function (entry, i) { - if (isMaybeThenable(entry)) { - this._settleMaybeThenable(entry, i); - } else { - this._remaining--; - this._result[i] = this._makeResult(FULFILLED, i, entry); - } -}; - -Enumerator.prototype._settledAt = function (state, i, value) { - var promise = this.promise; - - if (promise._state === PENDING) { - this._remaining--; - - if (this._abortOnReject && state === REJECTED) { - reject(promise, value); - } else { - this._result[i] = this._makeResult(state, i, value); - } - } - - if (this._remaining === 0) { - fulfill(promise, this._result); - } -}; - -Enumerator.prototype._makeResult = function (state, i, value) { - return value; -}; - -Enumerator.prototype._willSettleAt = function (promise, i) { - var enumerator = this; - - subscribe(promise, undefined, function (value) { - return enumerator._settledAt(FULFILLED, i, value); - }, function (reason) { - return enumerator._settledAt(REJECTED, i, reason); - }); -}; - -/** - `RSVP.Promise.all` accepts an array of promises, and returns a new promise which - is fulfilled with an array of fulfillment values for the passed promises, or - rejected with the reason of the first passed promise to be rejected. It casts all - elements of the passed iterable to promises as it runs this algorithm. - - Example: - - ```javascript - let promise1 = RSVP.resolve(1); - let promise2 = RSVP.resolve(2); - let promise3 = RSVP.resolve(3); - let promises = [ promise1, promise2, promise3 ]; - - RSVP.Promise.all(promises).then(function(array){ - // The array here would be [ 1, 2, 3 ]; - }); - ``` - - If any of the `promises` given to `RSVP.all` are rejected, the first promise - that is rejected will be given as an argument to the returned promises's - rejection handler. For example: - - Example: - - ```javascript - let promise1 = RSVP.resolve(1); - let promise2 = RSVP.reject(new Error("2")); - let promise3 = RSVP.reject(new Error("3")); - let promises = [ promise1, promise2, promise3 ]; - - RSVP.Promise.all(promises).then(function(array){ - // Code here never runs because there are rejected promises! - }, function(error) { - // error.message === "2" - }); - ``` - - @method all - @static - @param {Array} entries array of promises - @param {String} label optional string for labeling the promise. - Useful for tooling. - @return {Promise} promise that is fulfilled when all `promises` have been - fulfilled, or rejected if any of them become rejected. - @static -*/ -function all$1(entries, label) { - return new Enumerator(this, entries, true, /* abort on reject */label).promise; -} - -/** - `RSVP.Promise.race` returns a new promise which is settled in the same way as the - first passed promise to settle. - - Example: - - ```javascript - let promise1 = new RSVP.Promise(function(resolve, reject){ - setTimeout(function(){ - resolve('promise 1'); - }, 200); - }); - - let promise2 = new RSVP.Promise(function(resolve, reject){ - setTimeout(function(){ - resolve('promise 2'); - }, 100); - }); - - RSVP.Promise.race([promise1, promise2]).then(function(result){ - // result === 'promise 2' because it was resolved before promise1 - // was resolved. - }); - ``` - - `RSVP.Promise.race` is deterministic in that only the state of the first - settled promise matters. For example, even if other promises given to the - `promises` array argument are resolved, but the first settled promise has - become rejected before the other promises became fulfilled, the returned - promise will become rejected: - - ```javascript - let promise1 = new RSVP.Promise(function(resolve, reject){ - setTimeout(function(){ - resolve('promise 1'); - }, 200); - }); - - let promise2 = new RSVP.Promise(function(resolve, reject){ - setTimeout(function(){ - reject(new Error('promise 2')); - }, 100); - }); - - RSVP.Promise.race([promise1, promise2]).then(function(result){ - // Code here never runs - }, function(reason){ - // reason.message === 'promise 2' because promise 2 became rejected before - // promise 1 became fulfilled - }); - ``` - - An example real-world use case is implementing timeouts: - - ```javascript - RSVP.Promise.race([ajax('foo.json'), timeout(5000)]) - ``` - - @method race - @static - @param {Array} entries array of promises to observe - @param {String} label optional string for describing the promise returned. - Useful for tooling. - @return {Promise} a promise which settles in the same way as the first passed - promise to settle. -*/ -function race$1(entries, label) { - /*jshint validthis:true */ - var Constructor = this; - - var promise = new Constructor(noop, label); - - if (!isArray(entries)) { - reject(promise, new TypeError('You must pass an array to race.')); - return promise; - } - - for (var i = 0; promise._state === PENDING && i < entries.length; i++) { - subscribe(Constructor.resolve(entries[i]), undefined, function (value) { - return resolve(promise, value); - }, function (reason) { - return reject(promise, reason); - }); - } - - return promise; -} - -/** - `RSVP.Promise.reject` returns a promise rejected with the passed `reason`. - It is shorthand for the following: - - ```javascript - let promise = new RSVP.Promise(function(resolve, reject){ - reject(new Error('WHOOPS')); - }); - - promise.then(function(value){ - // Code here doesn't run because the promise is rejected! - }, function(reason){ - // reason.message === 'WHOOPS' - }); - ``` - - Instead of writing the above, your code now simply becomes the following: - - ```javascript - let promise = RSVP.Promise.reject(new Error('WHOOPS')); - - promise.then(function(value){ - // Code here doesn't run because the promise is rejected! - }, function(reason){ - // reason.message === 'WHOOPS' - }); - ``` - - @method reject - @static - @param {*} reason value that the returned promise will be rejected with. - @param {String} label optional string for identifying the returned promise. - Useful for tooling. - @return {Promise} a promise rejected with the given `reason`. -*/ -function reject$1(reason, label) { - /*jshint validthis:true */ - var Constructor = this; - var promise = new Constructor(noop, label); - reject(promise, reason); - return promise; -} - -var guidKey = 'rsvp_' + now() + '-'; -var counter = 0; - -function needsResolver() { - throw new TypeError('You must pass a resolver function as the first argument to the promise constructor'); -} - -function needsNew() { - throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function."); -} - -/** - Promise objects represent the eventual result of an asynchronous operation. The - primary way of interacting with a promise is through its `then` method, which - registers callbacks to receive either a promise’s eventual value or the reason - why the promise cannot be fulfilled. - - Terminology - ----------- - - - `promise` is an object or function with a `then` method whose behavior conforms to this specification. - - `thenable` is an object or function that defines a `then` method. - - `value` is any legal JavaScript value (including undefined, a thenable, or a promise). - - `exception` is a value that is thrown using the throw statement. - - `reason` is a value that indicates why a promise was rejected. - - `settled` the final resting state of a promise, fulfilled or rejected. - - A promise can be in one of three states: pending, fulfilled, or rejected. - - Promises that are fulfilled have a fulfillment value and are in the fulfilled - state. Promises that are rejected have a rejection reason and are in the - rejected state. A fulfillment value is never a thenable. - - Promises can also be said to *resolve* a value. If this value is also a - promise, then the original promise's settled state will match the value's - settled state. So a promise that *resolves* a promise that rejects will - itself reject, and a promise that *resolves* a promise that fulfills will - itself fulfill. - - - Basic Usage: - ------------ - - ```js - let promise = new Promise(function(resolve, reject) { - // on success - resolve(value); - - // on failure - reject(reason); - }); - - promise.then(function(value) { - // on fulfillment - }, function(reason) { - // on rejection - }); - ``` - - Advanced Usage: - --------------- - - Promises shine when abstracting away asynchronous interactions such as - `XMLHttpRequest`s. - - ```js - function getJSON(url) { - return new Promise(function(resolve, reject){ - let xhr = new XMLHttpRequest(); - - xhr.open('GET', url); - xhr.onreadystatechange = handler; - xhr.responseType = 'json'; - xhr.setRequestHeader('Accept', 'application/json'); - xhr.send(); - - function handler() { - if (this.readyState === this.DONE) { - if (this.status === 200) { - resolve(this.response); - } else { - reject(new Error('getJSON: `' + url + '` failed with status: [' + this.status + ']')); - } - } - }; - }); - } - - getJSON('/posts.json').then(function(json) { - // on fulfillment - }, function(reason) { - // on rejection - }); - ``` - - Unlike callbacks, promises are great composable primitives. - - ```js - Promise.all([ - getJSON('/posts'), - getJSON('/comments') - ]).then(function(values){ - values[0] // => postsJSON - values[1] // => commentsJSON - - return values; - }); - ``` - - @class RSVP.Promise - @param {function} resolver - @param {String} label optional string for labeling the promise. - Useful for tooling. - @constructor -*/ -function Promise$1(resolver, label) { - this._id = counter++; - this._label = label; - this._state = undefined; - this._result = undefined; - this._subscribers = []; - - config.instrument && instrument$1('created', this); - - if (noop !== resolver) { - typeof resolver !== 'function' && needsResolver(); - this instanceof Promise$1 ? initializePromise(this, resolver) : needsNew(); - } -} - -Promise$1.cast = resolve$1; // deprecated -Promise$1.all = all$1; -Promise$1.race = race$1; -Promise$1.resolve = resolve$1; -Promise$1.reject = reject$1; - -Promise$1.prototype = { - constructor: Promise$1, - - _guidKey: guidKey, - - _onError: function _onError(reason) { - var promise = this; - config.after(function () { - if (promise._onError) { - config['trigger']('error', reason, promise._label); - } - }); - }, - - /** - The primary way of interacting with a promise is through its `then` method, - which registers callbacks to receive either a promise's eventual value or the - reason why the promise cannot be fulfilled. - - ```js - findUser().then(function(user){ - // user is available - }, function(reason){ - // user is unavailable, and you are given the reason why - }); - ``` - - Chaining - -------- - - The return value of `then` is itself a promise. This second, 'downstream' - promise is resolved with the return value of the first promise's fulfillment - or rejection handler, or rejected if the handler throws an exception. - - ```js - findUser().then(function (user) { - return user.name; - }, function (reason) { - return 'default name'; - }).then(function (userName) { - // If `findUser` fulfilled, `userName` will be the user's name, otherwise it - // will be `'default name'` - }); - - findUser().then(function (user) { - throw new Error('Found user, but still unhappy'); - }, function (reason) { - throw new Error('`findUser` rejected and we\'re unhappy'); - }).then(function (value) { - // never reached - }, function (reason) { - // if `findUser` fulfilled, `reason` will be 'Found user, but still unhappy'. - // If `findUser` rejected, `reason` will be '`findUser` rejected and we\'re unhappy'. - }); - ``` - If the downstream promise does not specify a rejection handler, rejection reasons will be propagated further downstream. - - ```js - findUser().then(function (user) { - throw new PedagogicalException('Upstream error'); - }).then(function (value) { - // never reached - }).then(function (value) { - // never reached - }, function (reason) { - // The `PedgagocialException` is propagated all the way down to here - }); - ``` - - Assimilation - ------------ - - Sometimes the value you want to propagate to a downstream promise can only be - retrieved asynchronously. This can be achieved by returning a promise in the - fulfillment or rejection handler. The downstream promise will then be pending - until the returned promise is settled. This is called *assimilation*. - - ```js - findUser().then(function (user) { - return findCommentsByAuthor(user); - }).then(function (comments) { - // The user's comments are now available - }); - ``` - - If the assimliated promise rejects, then the downstream promise will also reject. - - ```js - findUser().then(function (user) { - return findCommentsByAuthor(user); - }).then(function (comments) { - // If `findCommentsByAuthor` fulfills, we'll have the value here - }, function (reason) { - // If `findCommentsByAuthor` rejects, we'll have the reason here - }); - ``` - - Simple Example - -------------- - - Synchronous Example - - ```javascript - let result; - - try { - result = findResult(); - // success - } catch(reason) { - // failure - } - ``` - - Errback Example - - ```js - findResult(function(result, err){ - if (err) { - // failure - } else { - // success - } - }); - ``` - - Promise Example; - - ```javascript - findResult().then(function(result){ - // success - }, function(reason){ - // failure - }); - ``` - - Advanced Example - -------------- - - Synchronous Example - - ```javascript - let author, books; - - try { - author = findAuthor(); - books = findBooksByAuthor(author); - // success - } catch(reason) { - // failure - } - ``` - - Errback Example - - ```js - - function foundBooks(books) { - - } - - function failure(reason) { - - } - - findAuthor(function(author, err){ - if (err) { - failure(err); - // failure - } else { - try { - findBoooksByAuthor(author, function(books, err) { - if (err) { - failure(err); - } else { - try { - foundBooks(books); - } catch(reason) { - failure(reason); - } - } - }); - } catch(error) { - failure(err); - } - // success - } - }); - ``` - - Promise Example; - - ```javascript - findAuthor(). - then(findBooksByAuthor). - then(function(books){ - // found books - }).catch(function(reason){ - // something went wrong - }); - ``` - - @method then - @param {Function} onFulfillment - @param {Function} onRejection - @param {String} label optional string for labeling the promise. - Useful for tooling. - @return {Promise} - */ - then: then, - - /** - `catch` is simply sugar for `then(undefined, onRejection)` which makes it the same - as the catch block of a try/catch statement. - - ```js - function findAuthor(){ - throw new Error('couldn\'t find that author'); - } - - // synchronous - try { - findAuthor(); - } catch(reason) { - // something went wrong - } - - // async with promises - findAuthor().catch(function(reason){ - // something went wrong - }); - ``` - - @method catch - @param {Function} onRejection - @param {String} label optional string for labeling the promise. - Useful for tooling. - @return {Promise} - */ - 'catch': function _catch(onRejection, label) { - return this.then(undefined, onRejection, label); - }, - - /** - `finally` will be invoked regardless of the promise's fate just as native - try/catch/finally behaves - - Synchronous example: - - ```js - findAuthor() { - if (Math.random() > 0.5) { - throw new Error(); - } - return new Author(); - } - - try { - return findAuthor(); // succeed or fail - } catch(error) { - return findOtherAuthor(); - } finally { - // always runs - // doesn't affect the return value - } - ``` - - Asynchronous example: - - ```js - findAuthor().catch(function(reason){ - return findOtherAuthor(); - }).finally(function(){ - // author was either found, or not - }); - ``` - - @method finally - @param {Function} callback - @param {String} label optional string for labeling the promise. - Useful for tooling. - @return {Promise} - */ - 'finally': function _finally(callback, label) { - var promise = this; - var constructor = promise.constructor; - - return promise.then(function (value) { - return constructor.resolve(callback()).then(function () { - return value; - }); - }, function (reason) { - return constructor.resolve(callback()).then(function () { - throw reason; - }); - }, label); - } -}; - -function Result() { - this.value = undefined; -} - -var ERROR = new Result(); -var GET_THEN_ERROR$1 = new Result(); - -function getThen$1(obj) { - try { - return obj.then; - } catch (error) { - ERROR.value = error; - return ERROR; - } -} - -function tryApply(f, s, a) { - try { - f.apply(s, a); - } catch (error) { - ERROR.value = error; - return ERROR; - } -} - -function makeObject(_, argumentNames) { - var obj = {}; - var length = _.length; - var args = new Array(length); - - for (var x = 0; x < length; x++) { - args[x] = _[x]; - } - - for (var i = 0; i < argumentNames.length; i++) { - var _name = argumentNames[i]; - obj[_name] = args[i + 1]; - } - - return obj; -} - -function arrayResult(_) { - var length = _.length; - var args = new Array(length - 1); - - for (var i = 1; i < length; i++) { - args[i - 1] = _[i]; - } - - return args; -} - -function wrapThenable(_then, promise) { - return { - then: function then(onFulFillment, onRejection) { - return _then.call(promise, onFulFillment, onRejection); - } - }; -} - -/** - `RSVP.denodeify` takes a 'node-style' function and returns a function that - will return an `RSVP.Promise`. You can use `denodeify` in Node.js or the - browser when you'd prefer to use promises over using callbacks. For example, - `denodeify` transforms the following: - - ```javascript - let fs = require('fs'); - - fs.readFile('myfile.txt', function(err, data){ - if (err) return handleError(err); - handleData(data); - }); - ``` - - into: - - ```javascript - let fs = require('fs'); - let readFile = RSVP.denodeify(fs.readFile); - - readFile('myfile.txt').then(handleData, handleError); - ``` - - If the node function has multiple success parameters, then `denodeify` - just returns the first one: - - ```javascript - let request = RSVP.denodeify(require('request')); - - request('http://example.com').then(function(res) { - // ... - }); - ``` - - However, if you need all success parameters, setting `denodeify`'s - second parameter to `true` causes it to return all success parameters - as an array: - - ```javascript - let request = RSVP.denodeify(require('request'), true); - - request('http://example.com').then(function(result) { - // result[0] -> res - // result[1] -> body - }); - ``` - - Or if you pass it an array with names it returns the parameters as a hash: - - ```javascript - let request = RSVP.denodeify(require('request'), ['res', 'body']); - - request('http://example.com').then(function(result) { - // result.res - // result.body - }); - ``` - - Sometimes you need to retain the `this`: - - ```javascript - let app = require('express')(); - let render = RSVP.denodeify(app.render.bind(app)); - ``` - - The denodified function inherits from the original function. It works in all - environments, except IE 10 and below. Consequently all properties of the original - function are available to you. However, any properties you change on the - denodeified function won't be changed on the original function. Example: - - ```javascript - let request = RSVP.denodeify(require('request')), - cookieJar = request.jar(); // <- Inheritance is used here - - request('http://example.com', {jar: cookieJar}).then(function(res) { - // cookieJar.cookies holds now the cookies returned by example.com - }); - ``` - - Using `denodeify` makes it easier to compose asynchronous operations instead - of using callbacks. For example, instead of: - - ```javascript - let fs = require('fs'); - - fs.readFile('myfile.txt', function(err, data){ - if (err) { ... } // Handle error - fs.writeFile('myfile2.txt', data, function(err){ - if (err) { ... } // Handle error - console.log('done') - }); - }); - ``` - - you can chain the operations together using `then` from the returned promise: - - ```javascript - let fs = require('fs'); - let readFile = RSVP.denodeify(fs.readFile); - let writeFile = RSVP.denodeify(fs.writeFile); - - readFile('myfile.txt').then(function(data){ - return writeFile('myfile2.txt', data); - }).then(function(){ - console.log('done') - }).catch(function(error){ - // Handle error - }); - ``` - - @method denodeify - @static - @for RSVP - @param {Function} nodeFunc a 'node-style' function that takes a callback as - its last argument. The callback expects an error to be passed as its first - argument (if an error occurred, otherwise null), and the value from the - operation as its second argument ('function(err, value){ }'). - @param {Boolean|Array} [options] An optional paramter that if set - to `true` causes the promise to fulfill with the callback's success arguments - as an array. This is useful if the node function has multiple success - paramters. If you set this paramter to an array with names, the promise will - fulfill with a hash with these names as keys and the success parameters as - values. - @return {Function} a function that wraps `nodeFunc` to return an - `RSVP.Promise` - @static -*/ -function denodeify$1(nodeFunc, options) { - var fn = function fn() { - var self = this; - var l = arguments.length; - var args = new Array(l + 1); - var promiseInput = false; - - for (var i = 0; i < l; ++i) { - var arg = arguments[i]; - - if (!promiseInput) { - // TODO: clean this up - promiseInput = needsPromiseInput(arg); - if (promiseInput === GET_THEN_ERROR$1) { - var p = new Promise$1(noop); - reject(p, GET_THEN_ERROR$1.value); - return p; - } else if (promiseInput && promiseInput !== true) { - arg = wrapThenable(promiseInput, arg); - } - } - args[i] = arg; - } - - var promise = new Promise$1(noop); - - args[l] = function (err, val) { - if (err) reject(promise, err);else if (options === undefined) resolve(promise, val);else if (options === true) resolve(promise, arrayResult(arguments));else if (isArray(options)) resolve(promise, makeObject(arguments, options));else resolve(promise, val); - }; - - if (promiseInput) { - return handlePromiseInput(promise, args, nodeFunc, self); - } else { - return handleValueInput(promise, args, nodeFunc, self); - } - }; - - fn.__proto__ = nodeFunc; - - return fn; -} - -function handleValueInput(promise, args, nodeFunc, self) { - var result = tryApply(nodeFunc, self, args); - if (result === ERROR) { - reject(promise, result.value); - } - return promise; -} - -function handlePromiseInput(promise, args, nodeFunc, self) { - return Promise$1.all(args).then(function (args) { - var result = tryApply(nodeFunc, self, args); - if (result === ERROR) { - reject(promise, result.value); - } - return promise; - }); -} - -function needsPromiseInput(arg) { - if (arg && typeof arg === 'object') { - if (arg.constructor === Promise$1) { - return true; - } else { - return getThen$1(arg); - } - } else { - return false; - } -} - -/** - This is a convenient alias for `RSVP.Promise.all`. - - @method all - @static - @for RSVP - @param {Array} array Array of promises. - @param {String} label An optional label. This is useful - for tooling. -*/ -function all$3(array, label) { - return Promise$1.all(array, label); -} - -function AllSettled(Constructor, entries, label) { - this._superConstructor(Constructor, entries, false, /* don't abort on reject */label); -} - -AllSettled.prototype = o_create(Enumerator.prototype); -AllSettled.prototype._superConstructor = Enumerator; -AllSettled.prototype._makeResult = makeSettledResult; -AllSettled.prototype._validationError = function () { - return new Error('allSettled must be called with an array'); -}; - -/** - `RSVP.allSettled` is similar to `RSVP.all`, but instead of implementing - a fail-fast method, it waits until all the promises have returned and - shows you all the results. This is useful if you want to handle multiple - promises' failure states together as a set. - - Returns a promise that is fulfilled when all the given promises have been - settled. The return promise is fulfilled with an array of the states of - the promises passed into the `promises` array argument. - - Each state object will either indicate fulfillment or rejection, and - provide the corresponding value or reason. The states will take one of - the following formats: - - ```javascript - { state: 'fulfilled', value: value } - or - { state: 'rejected', reason: reason } - ``` - - Example: - - ```javascript - let promise1 = RSVP.Promise.resolve(1); - let promise2 = RSVP.Promise.reject(new Error('2')); - let promise3 = RSVP.Promise.reject(new Error('3')); - let promises = [ promise1, promise2, promise3 ]; - - RSVP.allSettled(promises).then(function(array){ - // array == [ - // { state: 'fulfilled', value: 1 }, - // { state: 'rejected', reason: Error }, - // { state: 'rejected', reason: Error } - // ] - // Note that for the second item, reason.message will be '2', and for the - // third item, reason.message will be '3'. - }, function(error) { - // Not run. (This block would only be called if allSettled had failed, - // for instance if passed an incorrect argument type.) - }); - ``` - - @method allSettled - @static - @for RSVP - @param {Array} entries - @param {String} label - optional string that describes the promise. - Useful for tooling. - @return {Promise} promise that is fulfilled with an array of the settled - states of the constituent promises. -*/ -function allSettled$1(entries, label) { - return new AllSettled(Promise$1, entries, label).promise; -} - -/** - This is a convenient alias for `RSVP.Promise.race`. - - @method race - @static - @for RSVP - @param {Array} array Array of promises. - @param {String} label An optional label. This is useful - for tooling. - */ -function race$3(array, label) { - return Promise$1.race(array, label); -} - -function PromiseHash(Constructor, object, label) { - this._superConstructor(Constructor, object, true, label); -} - -PromiseHash.prototype = o_create(Enumerator.prototype); -PromiseHash.prototype._superConstructor = Enumerator; -PromiseHash.prototype._init = function () { - this._result = {}; -}; - -PromiseHash.prototype._validateInput = function (input) { - return input && typeof input === 'object'; -}; - -PromiseHash.prototype._validationError = function () { - return new Error('Promise.hash must be called with an object'); -}; - -PromiseHash.prototype._enumerate = function () { - var enumerator = this; - var promise = enumerator.promise; - var input = enumerator._input; - var results = []; - - for (var key in input) { - if (promise._state === PENDING && Object.prototype.hasOwnProperty.call(input, key)) { - results.push({ - position: key, - entry: input[key] - }); - } - } - - var length = results.length; - enumerator._remaining = length; - var result = undefined; - - for (var i = 0; promise._state === PENDING && i < length; i++) { - result = results[i]; - enumerator._eachEntry(result.entry, result.position); - } -}; - -/** - `RSVP.hash` is similar to `RSVP.all`, but takes an object instead of an array - for its `promises` argument. - - Returns a promise that is fulfilled when all the given promises have been - fulfilled, or rejected if any of them become rejected. The returned promise - is fulfilled with a hash that has the same key names as the `promises` object - argument. If any of the values in the object are not promises, they will - simply be copied over to the fulfilled object. - - Example: - - ```javascript - let promises = { - myPromise: RSVP.resolve(1), - yourPromise: RSVP.resolve(2), - theirPromise: RSVP.resolve(3), - notAPromise: 4 - }; - - RSVP.hash(promises).then(function(hash){ - // hash here is an object that looks like: - // { - // myPromise: 1, - // yourPromise: 2, - // theirPromise: 3, - // notAPromise: 4 - // } - }); - ```` - - If any of the `promises` given to `RSVP.hash` are rejected, the first promise - that is rejected will be given as the reason to the rejection handler. - - Example: - - ```javascript - let promises = { - myPromise: RSVP.resolve(1), - rejectedPromise: RSVP.reject(new Error('rejectedPromise')), - anotherRejectedPromise: RSVP.reject(new Error('anotherRejectedPromise')), - }; - - RSVP.hash(promises).then(function(hash){ - // Code here never runs because there are rejected promises! - }, function(reason) { - // reason.message === 'rejectedPromise' - }); - ``` - - An important note: `RSVP.hash` is intended for plain JavaScript objects that - are just a set of keys and values. `RSVP.hash` will NOT preserve prototype - chains. - - Example: - - ```javascript - function MyConstructor(){ - this.example = RSVP.resolve('Example'); - } - - MyConstructor.prototype = { - protoProperty: RSVP.resolve('Proto Property') - }; - - let myObject = new MyConstructor(); - - RSVP.hash(myObject).then(function(hash){ - // protoProperty will not be present, instead you will just have an - // object that looks like: - // { - // example: 'Example' - // } - // - // hash.hasOwnProperty('protoProperty'); // false - // 'undefined' === typeof hash.protoProperty - }); - ``` - - @method hash - @static - @for RSVP - @param {Object} object - @param {String} label optional string that describes the promise. - Useful for tooling. - @return {Promise} promise that is fulfilled when all properties of `promises` - have been fulfilled, or rejected if any of them become rejected. -*/ -function hash$1(object, label) { - return new PromiseHash(Promise$1, object, label).promise; -} - -function HashSettled(Constructor, object, label) { - this._superConstructor(Constructor, object, false, label); -} - -HashSettled.prototype = o_create(PromiseHash.prototype); -HashSettled.prototype._superConstructor = Enumerator; -HashSettled.prototype._makeResult = makeSettledResult; - -HashSettled.prototype._validationError = function () { - return new Error('hashSettled must be called with an object'); -}; - -/** - `RSVP.hashSettled` is similar to `RSVP.allSettled`, but takes an object - instead of an array for its `promises` argument. - - Unlike `RSVP.all` or `RSVP.hash`, which implement a fail-fast method, - but like `RSVP.allSettled`, `hashSettled` waits until all the - constituent promises have returned and then shows you all the results - with their states and values/reasons. This is useful if you want to - handle multiple promises' failure states together as a set. - - Returns a promise that is fulfilled when all the given promises have been - settled, or rejected if the passed parameters are invalid. - - The returned promise is fulfilled with a hash that has the same key names as - the `promises` object argument. If any of the values in the object are not - promises, they will be copied over to the fulfilled object and marked with state - 'fulfilled'. - - Example: - - ```javascript - let promises = { - myPromise: RSVP.Promise.resolve(1), - yourPromise: RSVP.Promise.resolve(2), - theirPromise: RSVP.Promise.resolve(3), - notAPromise: 4 - }; - - RSVP.hashSettled(promises).then(function(hash){ - // hash here is an object that looks like: - // { - // myPromise: { state: 'fulfilled', value: 1 }, - // yourPromise: { state: 'fulfilled', value: 2 }, - // theirPromise: { state: 'fulfilled', value: 3 }, - // notAPromise: { state: 'fulfilled', value: 4 } - // } - }); - ``` - - If any of the `promises` given to `RSVP.hash` are rejected, the state will - be set to 'rejected' and the reason for rejection provided. - - Example: - - ```javascript - let promises = { - myPromise: RSVP.Promise.resolve(1), - rejectedPromise: RSVP.Promise.reject(new Error('rejection')), - anotherRejectedPromise: RSVP.Promise.reject(new Error('more rejection')), - }; - - RSVP.hashSettled(promises).then(function(hash){ - // hash here is an object that looks like: - // { - // myPromise: { state: 'fulfilled', value: 1 }, - // rejectedPromise: { state: 'rejected', reason: Error }, - // anotherRejectedPromise: { state: 'rejected', reason: Error }, - // } - // Note that for rejectedPromise, reason.message == 'rejection', - // and for anotherRejectedPromise, reason.message == 'more rejection'. - }); - ``` - - An important note: `RSVP.hashSettled` is intended for plain JavaScript objects that - are just a set of keys and values. `RSVP.hashSettled` will NOT preserve prototype - chains. - - Example: - - ```javascript - function MyConstructor(){ - this.example = RSVP.Promise.resolve('Example'); - } - - MyConstructor.prototype = { - protoProperty: RSVP.Promise.resolve('Proto Property') - }; - - let myObject = new MyConstructor(); - - RSVP.hashSettled(myObject).then(function(hash){ - // protoProperty will not be present, instead you will just have an - // object that looks like: - // { - // example: { state: 'fulfilled', value: 'Example' } - // } - // - // hash.hasOwnProperty('protoProperty'); // false - // 'undefined' === typeof hash.protoProperty - }); - ``` - - @method hashSettled - @for RSVP - @param {Object} object - @param {String} label optional string that describes the promise. - Useful for tooling. - @return {Promise} promise that is fulfilled when when all properties of `promises` - have been settled. - @static -*/ -function hashSettled$1(object, label) { - return new HashSettled(Promise$1, object, label).promise; -} - -/** - `RSVP.rethrow` will rethrow an error on the next turn of the JavaScript event - loop in order to aid debugging. - - Promises A+ specifies that any exceptions that occur with a promise must be - caught by the promises implementation and bubbled to the last handler. For - this reason, it is recommended that you always specify a second rejection - handler function to `then`. However, `RSVP.rethrow` will throw the exception - outside of the promise, so it bubbles up to your console if in the browser, - or domain/cause uncaught exception in Node. `rethrow` will also throw the - error again so the error can be handled by the promise per the spec. - - ```javascript - function throws(){ - throw new Error('Whoops!'); - } - - let promise = new RSVP.Promise(function(resolve, reject){ - throws(); - }); - - promise.catch(RSVP.rethrow).then(function(){ - // Code here doesn't run because the promise became rejected due to an - // error! - }, function (err){ - // handle the error here - }); - ``` - - The 'Whoops' error will be thrown on the next turn of the event loop - and you can watch for it in your console. You can also handle it using a - rejection handler given to `.then` or `.catch` on the returned promise. - - @method rethrow - @static - @for RSVP - @param {Error} reason reason the promise became rejected. - @throws Error - @static -*/ -function rethrow$1(reason) { - setTimeout(function () { - throw reason; - }); - throw reason; -} - -/** - `RSVP.defer` returns an object similar to jQuery's `$.Deferred`. - `RSVP.defer` should be used when porting over code reliant on `$.Deferred`'s - interface. New code should use the `RSVP.Promise` constructor instead. - - The object returned from `RSVP.defer` is a plain object with three properties: - - * promise - an `RSVP.Promise`. - * reject - a function that causes the `promise` property on this object to - become rejected - * resolve - a function that causes the `promise` property on this object to - become fulfilled. - - Example: - - ```javascript - let deferred = RSVP.defer(); - - deferred.resolve("Success!"); - - deferred.promise.then(function(value){ - // value here is "Success!" - }); - ``` - - @method defer - @static - @for RSVP - @param {String} label optional string for labeling the promise. - Useful for tooling. - @return {Object} - */ -function defer$1(label) { - var deferred = { resolve: undefined, reject: undefined }; - - deferred.promise = new Promise$1(function (resolve, reject) { - deferred.resolve = resolve; - deferred.reject = reject; - }, label); - - return deferred; -} - -/** - `RSVP.map` is similar to JavaScript's native `map` method, except that it - waits for all promises to become fulfilled before running the `mapFn` on - each item in given to `promises`. `RSVP.map` returns a promise that will - become fulfilled with the result of running `mapFn` on the values the promises - become fulfilled with. - - For example: - - ```javascript - - let promise1 = RSVP.resolve(1); - let promise2 = RSVP.resolve(2); - let promise3 = RSVP.resolve(3); - let promises = [ promise1, promise2, promise3 ]; - - let mapFn = function(item){ - return item + 1; - }; - - RSVP.map(promises, mapFn).then(function(result){ - // result is [ 2, 3, 4 ] - }); - ``` - - If any of the `promises` given to `RSVP.map` are rejected, the first promise - that is rejected will be given as an argument to the returned promise's - rejection handler. For example: - - ```javascript - let promise1 = RSVP.resolve(1); - let promise2 = RSVP.reject(new Error('2')); - let promise3 = RSVP.reject(new Error('3')); - let promises = [ promise1, promise2, promise3 ]; - - let mapFn = function(item){ - return item + 1; - }; - - RSVP.map(promises, mapFn).then(function(array){ - // Code here never runs because there are rejected promises! - }, function(reason) { - // reason.message === '2' - }); - ``` - - `RSVP.map` will also wait if a promise is returned from `mapFn`. For example, - say you want to get all comments from a set of blog posts, but you need - the blog posts first because they contain a url to those comments. - - ```javscript - - let mapFn = function(blogPost){ - // getComments does some ajax and returns an RSVP.Promise that is fulfilled - // with some comments data - return getComments(blogPost.comments_url); - }; - - // getBlogPosts does some ajax and returns an RSVP.Promise that is fulfilled - // with some blog post data - RSVP.map(getBlogPosts(), mapFn).then(function(comments){ - // comments is the result of asking the server for the comments - // of all blog posts returned from getBlogPosts() - }); - ``` - - @method map - @static - @for RSVP - @param {Array} promises - @param {Function} mapFn function to be called on each fulfilled promise. - @param {String} label optional string for labeling the promise. - Useful for tooling. - @return {Promise} promise that is fulfilled with the result of calling - `mapFn` on each fulfilled promise or value when they become fulfilled. - The promise will be rejected if any of the given `promises` become rejected. - @static -*/ -function map$1(promises, mapFn, label) { - return Promise$1.all(promises, label).then(function (values) { - if (!isFunction(mapFn)) { - throw new TypeError("You must pass a function as map's second argument."); - } - - var length = values.length; - var results = new Array(length); - - for (var i = 0; i < length; i++) { - results[i] = mapFn(values[i]); - } - - return Promise$1.all(results, label); - }); -} - -/** - This is a convenient alias for `RSVP.Promise.resolve`. - - @method resolve - @static - @for RSVP - @param {*} value value that the returned promise will be resolved with - @param {String} label optional string for identifying the returned promise. - Useful for tooling. - @return {Promise} a promise that will become fulfilled with the given - `value` -*/ -function resolve$3(value, label) { - return Promise$1.resolve(value, label); -} - -/** - This is a convenient alias for `RSVP.Promise.reject`. - - @method reject - @static - @for RSVP - @param {*} reason value that the returned promise will be rejected with. - @param {String} label optional string for identifying the returned promise. - Useful for tooling. - @return {Promise} a promise rejected with the given `reason`. -*/ -function reject$3(reason, label) { - return Promise$1.reject(reason, label); -} - -/** - `RSVP.filter` is similar to JavaScript's native `filter` method, except that it - waits for all promises to become fulfilled before running the `filterFn` on - each item in given to `promises`. `RSVP.filter` returns a promise that will - become fulfilled with the result of running `filterFn` on the values the - promises become fulfilled with. - - For example: - - ```javascript - - let promise1 = RSVP.resolve(1); - let promise2 = RSVP.resolve(2); - let promise3 = RSVP.resolve(3); - - let promises = [promise1, promise2, promise3]; - - let filterFn = function(item){ - return item > 1; - }; - - RSVP.filter(promises, filterFn).then(function(result){ - // result is [ 2, 3 ] - }); - ``` - - If any of the `promises` given to `RSVP.filter` are rejected, the first promise - that is rejected will be given as an argument to the returned promise's - rejection handler. For example: - - ```javascript - let promise1 = RSVP.resolve(1); - let promise2 = RSVP.reject(new Error('2')); - let promise3 = RSVP.reject(new Error('3')); - let promises = [ promise1, promise2, promise3 ]; - - let filterFn = function(item){ - return item > 1; - }; - - RSVP.filter(promises, filterFn).then(function(array){ - // Code here never runs because there are rejected promises! - }, function(reason) { - // reason.message === '2' - }); - ``` - - `RSVP.filter` will also wait for any promises returned from `filterFn`. - For instance, you may want to fetch a list of users then return a subset - of those users based on some asynchronous operation: - - ```javascript - - let alice = { name: 'alice' }; - let bob = { name: 'bob' }; - let users = [ alice, bob ]; - - let promises = users.map(function(user){ - return RSVP.resolve(user); - }); - - let filterFn = function(user){ - // Here, Alice has permissions to create a blog post, but Bob does not. - return getPrivilegesForUser(user).then(function(privs){ - return privs.can_create_blog_post === true; - }); - }; - RSVP.filter(promises, filterFn).then(function(users){ - // true, because the server told us only Alice can create a blog post. - users.length === 1; - // false, because Alice is the only user present in `users` - users[0] === bob; - }); - ``` - - @method filter - @static - @for RSVP - @param {Array} promises - @param {Function} filterFn - function to be called on each resolved value to - filter the final results. - @param {String} label optional string describing the promise. Useful for - tooling. - @return {Promise} -*/ - -function resolveAll(promises, label) { - return Promise$1.all(promises, label); -} - -function resolveSingle(promise, label) { - return Promise$1.resolve(promise, label).then(function (promises) { - return resolveAll(promises, label); - }); -} -function filter$1(promises, filterFn, label) { - var promise = isArray(promises) ? resolveAll(promises, label) : resolveSingle(promises, label); - return promise.then(function (values) { - if (!isFunction(filterFn)) { - throw new TypeError("You must pass a function as filter's second argument."); - } - - var length = values.length; - var filtered = new Array(length); - - for (var i = 0; i < length; i++) { - filtered[i] = filterFn(values[i]); - } - - return resolveAll(filtered, label).then(function (filtered) { - var results = new Array(length); - var newLength = 0; - - for (var i = 0; i < length; i++) { - if (filtered[i]) { - results[newLength] = values[i]; - newLength++; - } - } - - results.length = newLength; - - return results; - }); - }); -} - -var len = 0; -var vertxNext = undefined; -function asap$1(callback, arg) { - queue$1[len] = callback; - queue$1[len + 1] = arg; - len += 2; - if (len === 2) { - // If len is 1, that means that we need to schedule an async flush. - // If additional callbacks are queued before the queue is flushed, they - // will be processed by this flush that we are scheduling. - scheduleFlush$1(); - } -} - -var browserWindow = typeof window !== 'undefined' ? window : undefined; -var browserGlobal = browserWindow || {}; -var BrowserMutationObserver = browserGlobal.MutationObserver || browserGlobal.WebKitMutationObserver; -var isNode = typeof self === 'undefined' && typeof process !== 'undefined' && ({}).toString.call(process) === '[object process]'; - -// test for web worker but not in IE10 -var isWorker = typeof Uint8ClampedArray !== 'undefined' && typeof importScripts !== 'undefined' && typeof MessageChannel !== 'undefined'; - -// node -function useNextTick() { - var nextTick = process.nextTick; - // node version 0.10.x displays a deprecation warning when nextTick is used recursively - // setImmediate should be used instead instead - var version = process.versions.node.match(/^(?:(\d+)\.)?(?:(\d+)\.)?(\*|\d+)$/); - if (Array.isArray(version) && version[1] === '0' && version[2] === '10') { - nextTick = setImmediate; - } - return function () { - return nextTick(flush); - }; -} - -// vertx -function useVertxTimer() { - if (typeof vertxNext !== 'undefined') { - return function () { - vertxNext(flush); - }; - } - return useSetTimeout(); -} - -function useMutationObserver() { - var iterations = 0; - var observer = new BrowserMutationObserver(flush); - var node = document.createTextNode(''); - observer.observe(node, { characterData: true }); - - return function () { - return node.data = iterations = ++iterations % 2; - }; -} - -// web worker -function useMessageChannel() { - var channel = new MessageChannel(); - channel.port1.onmessage = flush; - return function () { - return channel.port2.postMessage(0); - }; -} - -function useSetTimeout() { - return function () { - return setTimeout(flush, 1); - }; -} - -var queue$1 = new Array(1000); - -function flush() { - for (var i = 0; i < len; i += 2) { - var callback = queue$1[i]; - var arg = queue$1[i + 1]; - - callback(arg); - - queue$1[i] = undefined; - queue$1[i + 1] = undefined; - } - - len = 0; -} - -function attemptVertex() { - try { - var r = require; - var vertx = r('vertx'); - vertxNext = vertx.runOnLoop || vertx.runOnContext; - return useVertxTimer(); - } catch (e) { - return useSetTimeout(); - } -} - -var scheduleFlush$1 = undefined; -// Decide what async method to use to triggering processing of queued callbacks: -if (isNode) { - scheduleFlush$1 = useNextTick(); -} else if (BrowserMutationObserver) { - scheduleFlush$1 = useMutationObserver(); -} else if (isWorker) { - scheduleFlush$1 = useMessageChannel(); -} else if (browserWindow === undefined && typeof require === 'function') { - scheduleFlush$1 = attemptVertex(); -} else { - scheduleFlush$1 = useSetTimeout(); -} - -var platform = undefined; - -/* global self */ -if (typeof self === 'object') { - platform = self; - - /* global global */ -} else if (typeof global === 'object') { - platform = global; - } else { - throw new Error('no global: `self` or `global` found'); - } - -var _async$filter; - -function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } - -// defaults - -// the default export here is for backwards compat: -// https://github.com/tildeio/rsvp.js/issues/434 -config.async = asap$1; -config.after = function (cb) { - return setTimeout(cb, 0); -}; -var cast = resolve$3; - -var async = function async(callback, arg) { - return config.async(callback, arg); -}; - -function on() { - config['on'].apply(config, arguments); -} - -function off() { - config['off'].apply(config, arguments); -} - -// Set up instrumentation through `window.__PROMISE_INTRUMENTATION__` -if (typeof window !== 'undefined' && typeof window['__PROMISE_INSTRUMENTATION__'] === 'object') { - var callbacks = window['__PROMISE_INSTRUMENTATION__']; - configure('instrument', true); - for (var eventName in callbacks) { - if (callbacks.hasOwnProperty(eventName)) { - on(eventName, callbacks[eventName]); - } - } -}var rsvp = (_async$filter = { - asap: asap$1, - cast: cast, - Promise: Promise$1, - EventTarget: EventTarget, - all: all$3, - allSettled: allSettled$1, - race: race$3, - hash: hash$1, - hashSettled: hashSettled$1, - rethrow: rethrow$1, - defer: defer$1, - denodeify: denodeify$1, - configure: configure, - on: on, - off: off, - resolve: resolve$3, - reject: reject$3, - map: map$1 -}, _defineProperty(_async$filter, 'async', async), _defineProperty(_async$filter, 'filter', // babel seems to error if async isn't a computed prop here... -filter$1), _async$filter); - -exports['default'] = rsvp; -exports.asap = asap$1; -exports.cast = cast; -exports.Promise = Promise$1; -exports.EventTarget = EventTarget; -exports.all = all$3; -exports.allSettled = allSettled$1; -exports.race = race$3; -exports.hash = hash$1; -exports.hashSettled = hashSettled$1; -exports.rethrow = rethrow$1; -exports.defer = defer$1; -exports.denodeify = denodeify$1; -exports.configure = configure; -exports.on = on; -exports.off = off; -exports.resolve = resolve$3; -exports.reject = reject$3; -exports.map = map$1; -exports.async = async; -exports.filter = filter$1; - -Object.defineProperty(exports, '__esModule', { value: true }); - -}))); - -// - -'use strict'; - -var EPUBJS = EPUBJS || {}; -EPUBJS.VERSION = "0.2.19"; - -EPUBJS.plugins = EPUBJS.plugins || {}; - -EPUBJS.filePath = EPUBJS.filePath || "/epubjs/"; - -EPUBJS.Render = {}; - -(function(root) { - - var previousEpub = root.ePub || {}; - - var ePub = root.ePub = function() { - var bookPath, options; - - //-- var book = ePub("path/to/book.epub", { restore: true }) - if(typeof(arguments[0]) != 'undefined' && - (typeof arguments[0] === 'string' || arguments[0] instanceof ArrayBuffer)) { - - bookPath = arguments[0]; - - if( arguments[1] && typeof arguments[1] === 'object' ) { - options = arguments[1]; - options.bookPath = bookPath; - } else { - options = { 'bookPath' : bookPath }; - } - - } - - /* - * var book = ePub({ bookPath: "path/to/book.epub", restore: true }); - * - * - OR - - * - * var book = ePub({ restore: true }); - * book.open("path/to/book.epub"); - */ - - if( arguments[0] && typeof arguments[0] === 'object' && !(arguments[0] instanceof ArrayBuffer)) { - options = arguments[0]; - } - - - return new EPUBJS.Book(options); - }; - - //exports to multiple environments - if (typeof define === 'function' && define.amd) { - //AMD - define(['rsvp', 'jszip', 'localforage'], function(RSVP, JSZip, localForage){ return ePub; }); - } else if (typeof module != "undefined" && module.exports) { - //Node - global.RSVP = require('rsvp'); - global.JSZip = require('jszip'); - global.localForage = require('localforage'); - module.exports = ePub; - } - -})(window); - -EPUBJS.Book = function(options){ - - var book = this; - - this.settings = EPUBJS.core.defaults(options || {}, { - bookPath : undefined, - bookKey : undefined, - packageUrl : undefined, - storage: false, //-- true (auto) or false (none) | override: 'ram', 'websqldatabase', 'indexeddb', 'filesystem' - fromStorage : false, - saved : false, - online : true, - contained : false, - width : undefined, - height: undefined, - layoutOveride : undefined, // Default: { spread: 'reflowable', layout: 'auto', orientation: 'auto'} - orientation : undefined, - minSpreadWidth: 768, //-- overridden by spread: none (never) / both (always) - gap: "auto", //-- "auto" or int - version: 1, - restore: false, - reload : false, - goto : false, - styles : {}, - classes : [], - headTags : {}, - withCredentials: false, - render_method: "Iframe", - displayLastPage: false - }); - - this.settings.EPUBJSVERSION = EPUBJS.VERSION; - - this.spinePos = 0; - this.stored = false; - - //-- All Book events for listening - /* - book:ready - book:stored - book:online - book:offline - book:pageChanged - book:loadFailed - book:loadChapterFailed - */ - - //-- Adds Hook methods to the Book prototype - // Hooks will all return before triggering the callback. - // EPUBJS.Hooks.mixin(this); - //-- Get pre-registered hooks for events - // this.getHooks("beforeChapterDisplay"); - - this.online = this.settings.online || navigator.onLine; - this.networkListeners(); - - this.ready = { - manifest: new RSVP.defer(), - spine: new RSVP.defer(), - metadata: new RSVP.defer(), - cover: new RSVP.defer(), - toc: new RSVP.defer(), - pageList: new RSVP.defer() - }; - - this.readyPromises = [ - this.ready.manifest.promise, - this.ready.spine.promise, - this.ready.metadata.promise, - this.ready.cover.promise, - this.ready.toc.promise - ]; - - this.pageList = []; - this.pagination = new EPUBJS.Pagination(); - this.pageListReady = this.ready.pageList.promise; - - this.ready.all = RSVP.all(this.readyPromises); - - this.ready.all.then(this._ready.bind(this)); - - // Queue for methods used before rendering - this.isRendered = false; - this._q = EPUBJS.core.queue(this); - // Queue for rendering - this._rendering = false; - this._displayQ = EPUBJS.core.queue(this); - // Queue for going to another location - this._moving = false; - this._gotoQ = EPUBJS.core.queue(this); - - /** - * Creates a new renderer. - * The renderer will handle displaying the content using the method provided in the settings - */ - this.renderer = new EPUBJS.Renderer(this.settings.render_method); - //-- Set the width at which to switch from spreads to single pages - this.renderer.setMinSpreadWidth(this.settings.minSpreadWidth); - this.renderer.setGap(this.settings.gap); - //-- Pass through the renderer events - this.listenToRenderer(this.renderer); - - this.defer_opened = new RSVP.defer(); - this.opened = this.defer_opened.promise; - - this.store = false; //-- False if not using storage; - - //-- Determine storage method - //-- Override options: none | ram | websqldatabase | indexeddb | filesystem - if(this.settings.storage !== false){ - // this.storage = new fileStorage.storage(this.settings.storage); - this.fromStorage(true); - } - - // BookUrl is optional, but if present start loading process - if(typeof this.settings.bookPath === 'string' || this.settings.bookPath instanceof ArrayBuffer) { - this.open(this.settings.bookPath, this.settings.reload); - } - - window.addEventListener("beforeunload", this.unload.bind(this), false); - - //-- Listen for these promises: - //-- book.opened.then() - //-- book.rendered.then() -}; - -//-- Check bookUrl and start parsing book Assets or load them from storage -EPUBJS.Book.prototype.open = function(bookPath, forceReload){ - var book = this, - epubpackage, - opened = new RSVP.defer(); - - this.settings.bookPath = bookPath; - - if(this.settings.contained || this.isContained(bookPath)){ - - this.settings.contained = this.contained = true; - - this.bookUrl = ''; - - epubpackage = this.unarchive(bookPath). - then(function(){ - return book.loadPackage(); - }); - - } else { - //-- Get a absolute URL from the book path - this.bookUrl = this.urlFrom(bookPath); - - epubpackage = this.loadPackage(); - } - - if(this.settings.restore && !forceReload && localStorage){ - //-- Will load previous package json, or re-unpack if error - epubpackage.then(function(packageXml) { - var identifier = book.packageIdentifier(packageXml); - var restored = book.restore(identifier); - - if(!restored) { - book.unpack(packageXml); - } - opened.resolve(); - book.defer_opened.resolve(); - }); - - }else{ - - //-- Get package information from epub opf - epubpackage.then(function(packageXml) { - book.unpack(packageXml); - opened.resolve(); - book.defer_opened.resolve(); - }); - } - - this._registerReplacements(this.renderer); - - return opened.promise; - -}; - -EPUBJS.Book.prototype.loadPackage = function(_containerPath){ - var book = this, - parse = new EPUBJS.Parser(), - containerPath = _containerPath || "META-INF/container.xml", - containerXml, - packageXml; - - if(!this.settings.packageUrl) { //-- provide the packageUrl to skip this step - packageXml = book.loadXml(book.bookUrl + containerPath). - then(function(containerXml){ - return parse.container(containerXml); // Container has path to content - }). - then(function(paths){ - book.settings.contentsPath = book.bookUrl + paths.basePath; - book.settings.packageUrl = book.bookUrl + paths.packagePath; - book.settings.encoding = paths.encoding; - return book.loadXml(book.settings.packageUrl); // Containes manifest, spine and metadata - }); - } else { - packageXml = book.loadXml(book.settings.packageUrl); - } - - packageXml.catch(function(error) { - // handle errors in either of the two requests - console.error("Could not load book at: "+ containerPath); - book.trigger("book:loadFailed", containerPath); - }); - return packageXml; -}; - -EPUBJS.Book.prototype.packageIdentifier = function(packageXml){ - var book = this, - parse = new EPUBJS.Parser(); - - return parse.identifier(packageXml); -}; - -EPUBJS.Book.prototype.unpack = function(packageXml){ - var book = this, - parse = new EPUBJS.Parser(); - - book.contents = parse.packageContents(packageXml, book.settings.contentsPath); // Extract info from contents - - book.manifest = book.contents.manifest; - book.spine = book.contents.spine; - book.spineIndexByURL = book.contents.spineIndexByURL; - book.metadata = book.contents.metadata; - if(!book.settings.bookKey) { - book.settings.bookKey = book.generateBookKey(book.metadata.identifier); - } - - //-- Set Globbal Layout setting based on metadata - book.globalLayoutProperties = book.parseLayoutProperties(book.metadata); - - if(book.contents.coverPath) { - book.cover = book.contents.cover = book.settings.contentsPath + book.contents.coverPath; - } - - book.spineNodeIndex = book.contents.spineNodeIndex; - - book.ready.manifest.resolve(book.contents.manifest); - book.ready.spine.resolve(book.contents.spine); - book.ready.metadata.resolve(book.contents.metadata); - book.ready.cover.resolve(book.contents.cover); - - book.locations = new EPUBJS.Locations(book.spine, book.store, book.settings.withCredentials); - - //-- Load the TOC, optional; either the EPUB3 XHTML Navigation file or the EPUB2 NCX file - if(book.contents.navPath) { - book.settings.navUrl = book.settings.contentsPath + book.contents.navPath; - - book.loadXml(book.settings.navUrl). - then(function(navHtml){ - return parse.nav(navHtml, book.spineIndexByURL, book.spine); // Grab Table of Contents - }).then(function(toc){ - book.toc = book.contents.toc = toc; - book.ready.toc.resolve(book.contents.toc); - }, function(error) { - book.ready.toc.resolve(false); - }); - - // Load the optional pageList - book.loadXml(book.settings.navUrl). - then(function(navHtml){ - return parse.pageList(navHtml, book.spineIndexByURL, book.spine); - }).then(function(pageList){ - var epubcfi = new EPUBJS.EpubCFI(); - var wait = 0; // need to generate a cfi - - // No pageList found - if(pageList.length === 0) { - return; - } - - book.pageList = book.contents.pageList = pageList; - - // Replace HREFs with CFI - book.pageList.forEach(function(pg){ - if(!pg.cfi) { - wait += 1; - epubcfi.generateCfiFromHref(pg.href, book).then(function(cfi){ - pg.cfi = cfi; - pg.packageUrl = book.settings.packageUrl; - - wait -= 1; - if(wait === 0) { - book.pagination.process(book.pageList); - book.ready.pageList.resolve(book.pageList); - } - }); - } - }); - - if(!wait) { - book.pagination.process(book.pageList); - book.ready.pageList.resolve(book.pageList); - } - - }, function(error) { - book.ready.pageList.resolve([]); - }); - } else if(book.contents.tocPath) { - book.settings.tocUrl = book.settings.contentsPath + book.contents.tocPath; - - book.loadXml(book.settings.tocUrl). - then(function(tocXml){ - return parse.toc(tocXml, book.spineIndexByURL, book.spine); // Grab Table of Contents - }, function(err) { - console.error(err); - }).then(function(toc){ - book.toc = book.contents.toc = toc; - book.ready.toc.resolve(book.contents.toc); - }, function(error) { - book.ready.toc.resolve(false); - }); - - } else { - book.ready.toc.resolve(false); - } - -}; - -EPUBJS.Book.prototype.createHiddenRender = function(renderer, _width, _height) { - var box = this.element.getBoundingClientRect(); - var width = _width || this.settings.width || box.width; - var height = _height || this.settings.height || box.height; - var hiddenContainer; - var hiddenEl; - renderer.setMinSpreadWidth(this.settings.minSpreadWidth); - renderer.setGap(this.settings.gap); - - this._registerReplacements(renderer); - if(this.settings.forceSingle) { - renderer.forceSingle(true); - } - - hiddenContainer = document.createElement("div"); - hiddenContainer.style.visibility = "hidden"; - hiddenContainer.style.overflow = "hidden"; - hiddenContainer.style.width = "0"; - hiddenContainer.style.height = "0"; - this.element.appendChild(hiddenContainer); - - hiddenEl = document.createElement("div"); - hiddenEl.style.visibility = "hidden"; - hiddenEl.style.overflow = "hidden"; - hiddenEl.style.width = width + "px";//"0"; - hiddenEl.style.height = height +"px"; //"0"; - hiddenContainer.appendChild(hiddenEl); - - renderer.initialize(hiddenEl, this.settings.width, this.settings.height); - return hiddenContainer; -}; - -// Generates the pageList array by loading every chapter and paging through them -EPUBJS.Book.prototype.generatePageList = function(width, height, flag){ - var pageList = []; - var pager = new EPUBJS.Renderer(this.settings.render_method, false); //hidden - var hiddenContainer = this.createHiddenRender(pager, width, height); - var deferred = new RSVP.defer(); - var spinePos = -1; - var spineLength = this.spine.length; - var totalPages = 0; - var currentPage = 0; - var nextChapter = function(deferred){ - var chapter; - var next = spinePos + 1; - var done = deferred || new RSVP.defer(); - var loaded; - if(next >= spineLength) { - done.resolve(); - } else { - if (flag && flag.cancelled) { - pager.remove(); - this.element.removeChild(hiddenContainer); - done.reject(new Error("User cancelled")); - return; - } - - spinePos = next; - chapter = new EPUBJS.Chapter(this.spine[spinePos], this.store); - pager.displayChapter(chapter, this.globalLayoutProperties).then(function(chap){ - pager.pageMap.forEach(function(item){ - currentPage += 1; - pageList.push({ - "cfi" : item.start, - "page" : currentPage - }); - - }); - - if(pager.pageMap.length % 2 > 0 && - pager.spreads) { - currentPage += 1; // Handle Spreads - pageList.push({ - "cfi" : pager.pageMap[pager.pageMap.length - 1].end, - "page" : currentPage - }); - } - - // Load up the next chapter - setTimeout(function(){ - nextChapter(done); - }, 1); - }); - } - return done.promise; - }.bind(this); - - var finished = nextChapter().then(function(){ - pager.remove(); - this.element.removeChild(hiddenContainer); - deferred.resolve(pageList); - }.bind(this), function(reason) { - deferred.reject(reason); - }); - - return deferred.promise; -}; - -// Render out entire book and generate the pagination -// Width and Height are optional and will default to the current dimensions -EPUBJS.Book.prototype.generatePagination = function(width, height, flag) { - var book = this; - var defered = new RSVP.defer(); - - this.ready.spine.promise.then(function(){ - book.generatePageList(width, height, flag).then(function(pageList){ - book.pageList = book.contents.pageList = pageList; - book.pagination.process(pageList); - book.ready.pageList.resolve(book.pageList); - defered.resolve(book.pageList); - }, function(reason) { - defered.reject(reason); - }); - }); - - return defered.promise; -}; - -// Process the pagination from a JSON array containing the pagelist -EPUBJS.Book.prototype.loadPagination = function(pagelistJSON) { - var pageList; - - if (typeof(pagelistJSON) === "string") { - pageList = JSON.parse(pagelistJSON); - } else { - pageList = pagelistJSON; - } - - if(pageList && pageList.length) { - this.pageList = pageList; - this.pagination.process(this.pageList); - this.ready.pageList.resolve(this.pageList); - } - return this.pageList; -}; - -EPUBJS.Book.prototype.getPageList = function() { - return this.ready.pageList.promise; -}; - -EPUBJS.Book.prototype.getMetadata = function() { - return this.ready.metadata.promise; -}; - -EPUBJS.Book.prototype.getToc = function() { - return this.ready.toc.promise; -}; - -/* Private Helpers */ - -//-- Listeners for browser events -EPUBJS.Book.prototype.networkListeners = function(){ - var book = this; - window.addEventListener("offline", function(e) { - book.online = false; - if (book.settings.storage) { - book.fromStorage(true); - } - book.trigger("book:offline"); - }, false); - - window.addEventListener("online", function(e) { - book.online = true; - if (book.settings.storage) { - book.fromStorage(false); - } - book.trigger("book:online"); - }, false); - -}; - -// Listen to all events the renderer triggers and pass them as book events -EPUBJS.Book.prototype.listenToRenderer = function(renderer){ - var book = this; - renderer.Events.forEach(function(eventName){ - renderer.on(eventName, function(e){ - book.trigger(eventName, e); - }); - }); - - renderer.on("renderer:visibleRangeChanged", function(range) { - var startPage, endPage, percent; - var pageRange = []; - - if(this.pageList.length > 0) { - startPage = this.pagination.pageFromCfi(range.start); - percent = this.pagination.percentageFromPage(startPage); - pageRange.push(startPage); - - if(range.end) { - endPage = this.pagination.pageFromCfi(range.end); - //if(startPage != endPage) { - pageRange.push(endPage); - //} - } - this.trigger("book:pageChanged", { - "anchorPage": startPage, - "percentage": percent, - "pageRange" : pageRange - }); - - // TODO: Add event for first and last page. - // (though last is going to be hard, since it could be several reflowed pages long) - } - }.bind(this)); - - renderer.on("render:loaded", this.loadChange.bind(this)); -}; - -// Listens for load events from the Renderer and checks against the current chapter -// Prevents the Render from loading a different chapter when back button is pressed -EPUBJS.Book.prototype.loadChange = function(url){ - var uri = EPUBJS.core.uri(url); - var chapterUri = EPUBJS.core.uri(this.currentChapter.absolute); - var spinePos, chapter; - - if(uri.path != chapterUri.path){ - console.warn("Miss Match", uri.path, this.currentChapter.absolute); - // this.goto(uri.filename); - - // Set the current chapter to what is being displayed - spinePos = this.spineIndexByURL[uri.filename]; - chapter = new EPUBJS.Chapter(this.spine[spinePos], this.store); - this.currentChapter = chapter; - - // setup the renderer with the displayed chapter - this.renderer.currentChapter = chapter; - this.renderer.afterLoad(this.renderer.render.docEl); - this.renderer.beforeDisplay(function () { - this.renderer.afterDisplay(); - }.bind(this)); - - } else if(!this._rendering) { - this.renderer.reformat(); - } -}; - -EPUBJS.Book.prototype.unlistenToRenderer = function(renderer){ - renderer.Events.forEach(function(eventName){ - renderer.off(eventName); - }); -}; - -//-- Returns the cover -EPUBJS.Book.prototype.coverUrl = function(){ - var retrieved = this.ready.cover.promise - .then(function(url) { - if(this.settings.fromStorage) { - return this.store.getUrl(this.contents.cover); - } else if(this.settings.contained) { - return this.zip.getUrl(this.contents.cover); - }else{ - return this.contents.cover; - } - }.bind(this)); - - retrieved.then(function(url) { - this.cover = url; - }.bind(this)); - - return retrieved; -}; - -//-- Choose between a request from store or a request from network -EPUBJS.Book.prototype.loadXml = function(url){ - if(this.settings.fromStorage) { - return this.store.getXml(url, this.settings.encoding); - } else if(this.settings.contained) { - return this.zip.getXml(url, this.settings.encoding); - }else{ - return EPUBJS.core.request(url, 'xml', this.settings.withCredentials); - } -}; - -//-- Turns a url into a absolute url -EPUBJS.Book.prototype.urlFrom = function(bookPath){ - var uri = EPUBJS.core.uri(bookPath), - absolute = uri.protocol, - fromRoot = uri.path[0] == "/", - location = window.location, - //-- Get URL orgin, try for native or combine - origin = location.origin || location.protocol + "//" + location.host, - baseTag = document.getElementsByTagName('base'), - base; - - - //-- Check is Base tag is set - - if(baseTag.length) { - base = baseTag[0].href; - } - - //-- 1. Check if url is absolute - if(uri.protocol){ - return uri.origin + uri.path; - } - - //-- 2. Check if url starts with /, add base url - if(!absolute && fromRoot){ - return (base || origin) + uri.path; - } - - //-- 3. Or find full path to url and add that - if(!absolute && !fromRoot){ - return EPUBJS.core.resolveUrl(base || location.pathname, uri.path); - } - -}; - - -EPUBJS.Book.prototype.unarchive = function(bookPath){ - var book = this, - unarchived; - - //-- Must use storage - // if(this.settings.storage == false ){ - // this.settings.storage = true; - // this.storage = new fileStorage.storage(); - // } - - this.zip = new EPUBJS.Unarchiver(); - this.store = this.zip; // Use zip storaged in ram - return this.zip.open(bookPath); -}; - -//-- Checks if url has a .epub or .zip extension, or is ArrayBuffer (of zip/epub) -EPUBJS.Book.prototype.isContained = function(bookUrl){ - if (bookUrl instanceof ArrayBuffer) { - return true; - } - var uri = EPUBJS.core.uri(bookUrl); - - if(uri.extension && (uri.extension == "epub" || uri.extension == "zip")){ - return true; - } - - return false; -}; - -//-- Checks if the book can be retrieved from localStorage -EPUBJS.Book.prototype.isSaved = function(bookKey) { - var storedSettings; - - if(!localStorage) { - return false; - } - - storedSettings = localStorage.getItem(bookKey); - - if( !localStorage || - storedSettings === null) { - return false; - } else { - return true; - } -}; - -// Generates the Book Key using the identifer in the manifest or other string provided -EPUBJS.Book.prototype.generateBookKey = function(identifier){ - return "epubjs:" + EPUBJS.VERSION + ":" + window.location.host + ":" + identifier; -}; - -EPUBJS.Book.prototype.saveContents = function(){ - if(!localStorage) { - return false; - } - localStorage.setItem(this.settings.bookKey, JSON.stringify(this.contents)); -}; - -EPUBJS.Book.prototype.removeSavedContents = function() { - if(!localStorage) { - return false; - } - localStorage.removeItem(this.settings.bookKey); -}; - - - -//-- Takes a string or a element -EPUBJS.Book.prototype.renderTo = function(elem){ - var book = this, - rendered; - - if(EPUBJS.core.isElement(elem)) { - this.element = elem; - } else if (typeof elem == "string") { - this.element = EPUBJS.core.getEl(elem); - } else { - console.error("Not an Element"); - return; - } - - rendered = this.opened. - then(function(){ - // book.render = new EPUBJS.Renderer[this.settings.renderer](book); - book.renderer.initialize(book.element, book.settings.width, book.settings.height); - - if(book.metadata.direction) { - book.renderer.setDirection(book.metadata.direction); - } - - book._rendered(); - return book.startDisplay(); - }); - - // rendered.then(null, function(error) { console.error(error); }); - - return rendered; -}; - -EPUBJS.Book.prototype.startDisplay = function(){ - var display; - - if(this.settings.goto) { - display = this.goto(this.settings.goto); - }else if(this.settings.previousLocationCfi) { - display = this.gotoCfi(this.settings.previousLocationCfi); - }else{ - display = this.displayChapter(this.spinePos, this.settings.displayLastPage); - } - - return display; -}; - -EPUBJS.Book.prototype.restore = function(identifier){ - - var book = this, - fetch = ['manifest', 'spine', 'metadata', 'cover', 'toc', 'spineNodeIndex', 'spineIndexByURL', 'globalLayoutProperties'], - reject = false, - bookKey = this.generateBookKey(identifier), - fromStore = localStorage.getItem(bookKey), - len = fetch.length, - i; - - if(this.settings.clearSaved) reject = true; - - if(!reject && fromStore != 'undefined' && fromStore !== null){ - book.contents = JSON.parse(fromStore); - - for(i = 0; i < len; i++) { - var item = fetch[i]; - - if(!book.contents[item]) { - reject = true; - break; - } - book[item] = book.contents[item]; - } - } - - if(reject || !fromStore || !this.contents || !this.settings.contentsPath){ - return false; - }else{ - this.settings.bookKey = bookKey; - this.ready.manifest.resolve(this.manifest); - this.ready.spine.resolve(this.spine); - this.ready.metadata.resolve(this.metadata); - this.ready.cover.resolve(this.cover); - this.ready.toc.resolve(this.toc); - return true; - } - -}; - -EPUBJS.Book.prototype.displayChapter = function(chap, end, deferred){ - var book = this, - render, - cfi, - pos, - store, - defer = deferred || new RSVP.defer(); - - var chapter; - - if(!this.isRendered) { - this._q.enqueue("displayChapter", arguments); - // Reject for now. TODO: pass promise to queue - defer.reject({ - message : "Rendering", - stack : new Error().stack - }); - return defer.promise; - } - - - if(this._rendering || this.renderer._moving) { - // Pass along the current defer - this._displayQ.enqueue("displayChapter", [chap, end, defer]); - return defer.promise; - } - - if(EPUBJS.core.isNumber(chap)){ - pos = chap; - }else{ - cfi = new EPUBJS.EpubCFI(chap); - pos = cfi.spinePos; - } - - if(pos < 0 || pos >= this.spine.length){ - console.warn("Not A Valid Location"); - pos = 0; - end = false; - cfi = false; - } - - //-- Create a new chapter - chapter = new EPUBJS.Chapter(this.spine[pos], this.store); - - this._rendering = true; - - if(this._needsAssetReplacement()) { - - chapter.registerHook("beforeChapterRender", [ - EPUBJS.replace.head, - EPUBJS.replace.resources, - EPUBJS.replace.posters, - EPUBJS.replace.svg - ], true); - - } - - book.currentChapter = chapter; - - render = book.renderer.displayChapter(chapter, this.globalLayoutProperties); - if(cfi) { - book.renderer.gotoCfi(cfi); - } else if(end) { - book.renderer.lastPage(); - } - //-- Success, Clear render queue - render.then(function(rendered){ - // var inwait; - //-- Set the book's spine position - book.spinePos = pos; - - defer.resolve(book.renderer); - - if(book.settings.fromStorage === false && - book.settings.contained === false) { - book.preloadNextChapter(); - } - - book._rendering = false; - book._displayQ.dequeue(); - if(book._displayQ.length() === 0) { - book._gotoQ.dequeue(); - } - - }, function(error) { - // handle errors in either of the two requests - console.error("Could not load Chapter: "+ chapter.absolute, error); - book.trigger("book:chapterLoadFailed", chapter.absolute); - book._rendering = false; - defer.reject(error); - }); - - return defer.promise; -}; - -EPUBJS.Book.prototype.nextPage = function(defer){ - var defer = defer || new RSVP.defer(); - - if (!this.isRendered) { - this._q.enqueue("nextPage", [defer]); - return defer.promise; - } - - var next = this.renderer.nextPage(); - if (!next){ - return this.nextChapter(defer); - } - - defer.resolve(true); - return defer.promise; -}; - -EPUBJS.Book.prototype.prevPage = function(defer) { - var defer = defer || new RSVP.defer(); - - if (!this.isRendered) { - this._q.enqueue("prevPage", [defer]); - return defer.promise; - } - - var prev = this.renderer.prevPage(); - if (!prev){ - return this.prevChapter(defer); - } - - defer.resolve(true); - return defer.promise; -}; - -EPUBJS.Book.prototype.nextChapter = function(defer) { - var defer = defer || new RSVP.defer(); - - if (this.spinePos < this.spine.length - 1) { - var next = this.spinePos + 1; - // Skip non linear chapters - while (this.spine[next] && this.spine[next].linear && this.spine[next].linear == 'no') { - next++; - } - if (next < this.spine.length) { - return this.displayChapter(next, false, defer); - } - } - - this.trigger("book:atEnd"); - defer.resolve(true); - return defer.promise; -}; - -EPUBJS.Book.prototype.prevChapter = function(defer) { - var defer = defer || new RSVP.defer(); - - if (this.spinePos > 0) { - var prev = this.spinePos - 1; - while (this.spine[prev] && this.spine[prev].linear && this.spine[prev].linear == 'no') { - prev--; - } - if (prev >= 0) { - return this.displayChapter(prev, true, defer); - } - } - - this.trigger("book:atStart"); - defer.resolve(true); - return defer.promise; -}; - -EPUBJS.Book.prototype.getCurrentLocationCfi = function() { - if(!this.isRendered) return false; - return this.renderer.currentLocationCfi; -}; - -EPUBJS.Book.prototype.goto = function(target){ - - if(target.indexOf("epubcfi(") === 0) { - return this.gotoCfi(target); - } else if(target.indexOf("%") === target.length-1) { - return this.gotoPercentage(parseInt(target.substring(0, target.length-1))/100); - } else if(typeof target === "number" || isNaN(target) === false){ - return this.gotoPage(target); - } else { - return this.gotoHref(target); - } - -}; - -EPUBJS.Book.prototype.gotoCfi = function(cfiString, defer){ - var cfi, - spinePos, - spineItem, - rendered, - promise, - render, - deferred = defer || new RSVP.defer(); - - if(!this.isRendered) { - console.warn("Not yet Rendered"); - this.settings.previousLocationCfi = cfiString; - return false; - } - - // Currently going to a chapter - if(this._moving || this._rendering) { - console.warn("Renderer is moving"); - this._gotoQ.enqueue("gotoCfi", [cfiString, deferred]); - return false; - } - - cfi = new EPUBJS.EpubCFI(cfiString); - spinePos = cfi.spinePos; - - if(spinePos == -1) { - return false; - } - - spineItem = this.spine[spinePos]; - promise = deferred.promise; - this._moving = true; - //-- If same chapter only stay on current chapter - if(this.currentChapter && this.spinePos === spinePos){ - this.renderer.gotoCfi(cfi); - this._moving = false; - deferred.resolve(this.renderer.currentLocationCfi); - } else { - - if(!spineItem || spinePos == -1) { - spinePos = 0; - spineItem = this.spine[spinePos]; - } - - render = this.displayChapter(cfiString); - - render.then(function(rendered){ - this._moving = false; - deferred.resolve(rendered.currentLocationCfi); - }.bind(this), function() { - this._moving = false; - }.bind(this)); - - } - - promise.then(function(){ - this._gotoQ.dequeue(); - }.bind(this)); - - return promise; -}; - -EPUBJS.Book.prototype.gotoHref = function(url, defer){ - var split, chapter, section, relativeURL, spinePos; - var deferred = defer || new RSVP.defer(); - - if(!this.isRendered) { - this.settings.goto = url; - return false; - } - - // Currently going to a chapter - if(this._moving || this._rendering) { - this._gotoQ.enqueue("gotoHref", [url, deferred]); - return false; - } - - split = url.split("#"); - chapter = split[0]; - section = split[1] || false; - if (chapter.search("://") == -1) { - relativeURL = chapter.replace(EPUBJS.core.uri(this.settings.contentsPath).path, ''); - } else { - relativeURL = chapter.replace(this.settings.contentsPath, ''); - } - spinePos = this.spineIndexByURL[relativeURL]; - - //-- If link fragment only stay on current chapter - if(!chapter){ - spinePos = this.currentChapter ? this.currentChapter.spinePos : 0; - } - - //-- Check that URL is present in the index, or stop - if(typeof(spinePos) != "number") return false; - - if(!this.currentChapter || spinePos != this.currentChapter.spinePos){ - //-- Load new chapter if different than current - return this.displayChapter(spinePos).then(function(){ - if(section){ - this.renderer.section(section); - } - deferred.resolve(this.renderer.currentLocationCfi); - }.bind(this)); - }else{ - //-- Goto section - if(section) { - this.renderer.section(section); - } else { - // Or jump to the start - this.renderer.firstPage(); - } - deferred.resolve(this.renderer.currentLocationCfi); - } - - deferred.promise.then(function(){ - this._gotoQ.dequeue(); - }.bind(this)); - - return deferred.promise; -}; - -EPUBJS.Book.prototype.gotoPage = function(pg){ - var cfi = this.pagination.cfiFromPage(pg); - return this.gotoCfi(cfi); -}; - -EPUBJS.Book.prototype.gotoPercentage = function(percent){ - var pg = this.pagination.pageFromPercentage(percent); - return this.gotoPage(pg); -}; - -EPUBJS.Book.prototype.preloadNextChapter = function() { - var next; - var chap = this.spinePos + 1; - - if(chap >= this.spine.length){ - return false; - } - - next = new EPUBJS.Chapter(this.spine[chap]); - if(next) { - EPUBJS.core.request(next.absolute); - } -}; - -EPUBJS.Book.prototype.storeOffline = function() { - var book = this, - assets = EPUBJS.core.values(this.manifest); - - //-- Creates a queue of all items to load - return this.store.put(assets). - then(function(){ - book.settings.stored = true; - book.trigger("book:stored"); - }); -}; - -EPUBJS.Book.prototype.availableOffline = function() { - return this.settings.stored > 0 ? true : false; -}; - -EPUBJS.Book.prototype.toStorage = function () { - var key = this.settings.bookKey; - this.store.isStored(key).then(function(stored) { - - if (stored === true) { - this.settings.stored = true; - return true; - } - - return this.storeOffline() - .then(function() { - this.store.token(key, true); - }.bind(this)); - - }.bind(this)); - -}; -EPUBJS.Book.prototype.fromStorage = function(stored) { - var hooks = [ - EPUBJS.replace.head, - EPUBJS.replace.resources, - EPUBJS.replace.posters, - EPUBJS.replace.svg - ]; - - if(this.contained || this.settings.contained) return; - - //-- If there is network connection, store the books contents - if(this.online){ - this.opened.then(this.toStorage.bind(this)); - } - - if(this.store && this.settings.fromStorage && stored === false){ - this.settings.fromStorage = false; - this.store.off("offline"); - // this.renderer.removeHook("beforeChapterRender", hooks, true); - this.store = false; - }else if(!this.settings.fromStorage){ - - this.store = new EPUBJS.Storage(this.settings.credentials); - this.store.on("offline", function (offline) { - if (!offline) { - // Online - this.offline = false; - this.settings.fromStorage = false; - // this.renderer.removeHook("beforeChapterRender", hooks, true); - this.trigger("book:online"); - } else { - // Offline - this.offline = true; - this.settings.fromStorage = true; - // this.renderer.registerHook("beforeChapterRender", hooks, true); - this.trigger("book:offline"); - } - }.bind(this)); - - } - -}; - -EPUBJS.Book.prototype.setStyle = function(style, val, prefixed) { - var noreflow = ["color", "background", "background-color"]; - - if(!this.isRendered) return this._q.enqueue("setStyle", arguments); - - this.settings.styles[style] = val; - - this.renderer.setStyle(style, val, prefixed); - - if(noreflow.indexOf(style) === -1) { - // clearTimeout(this.reformatTimeout); - // this.reformatTimeout = setTimeout(function(){ - this.renderer.reformat(); - // }.bind(this), 10); - } -}; - -EPUBJS.Book.prototype.removeStyle = function(style) { - if(!this.isRendered) return this._q.enqueue("removeStyle", arguments); - this.renderer.removeStyle(style); - this.renderer.reformat(); - delete this.settings.styles[style]; -}; - -EPUBJS.Book.prototype.resetClasses = function(classes) { - - if(!this.isRendered) return this._q.enqueue("setClasses", arguments); - - if(classes.constructor === String) classes = [ classes ]; - - this.settings.classes = classes; - - this.renderer.setClasses(this.settings.classes); - this.renderer.reformat(); -}; - -EPUBJS.Book.prototype.addClass = function(aClass) { - - if(!this.isRendered) return this._q.enqueue("addClass", arguments); - - if(this.settings.classes.indexOf(aClass) == -1) { - this.settings.classes.push(aClass); - } - - this.renderer.setClasses(this.settings.classes); - this.renderer.reformat(); -}; - -EPUBJS.Book.prototype.removeClass = function(aClass) { - - if(!this.isRendered) return this._q.enqueue("removeClass", arguments); - - var idx = this.settings.classes.indexOf(aClass); - - if(idx != -1) { - - delete this.settings.classes[idx]; - - this.renderer.setClasses(this.settings.classes); - this.renderer.reformat(); - - } - -}; - -EPUBJS.Book.prototype.addHeadTag = function(tag, attrs) { - if(!this.isRendered) return this._q.enqueue("addHeadTag", arguments); - this.settings.headTags[tag] = attrs; -}; - -EPUBJS.Book.prototype.useSpreads = function(use) { - console.warn("useSpreads is deprecated, use forceSingle or set a layoutOveride instead"); - if(use === false) { - this.forceSingle(true); - } else { - this.forceSingle(false); - } -}; - -EPUBJS.Book.prototype.forceSingle = function(_use) { - var force = typeof _use === "undefined" ? true : _use; - - this.renderer.forceSingle(force); - this.settings.forceSingle = force; - if(this.isRendered) { - this.renderer.reformat(); - } -}; - -EPUBJS.Book.prototype.setMinSpreadWidth = function(width) { - this.settings.minSpreadWidth = width; - if(this.isRendered) { - this.renderer.setMinSpreadWidth(this.settings.minSpreadWidth); - this.renderer.reformat(); - } -}; - -EPUBJS.Book.prototype.setGap = function(gap) { - this.settings.gap = gap; - if(this.isRendered) { - this.renderer.setGap(this.settings.gap); - this.renderer.reformat(); - } -}; - -EPUBJS.Book.prototype.chapter = function(path) { - var spinePos = this.spineIndexByURL[path]; - var spineItem; - var chapter; - - if(spinePos){ - spineItem = this.spine[spinePos]; - chapter = new EPUBJS.Chapter(spineItem, this.store, this.settings.withCredentials); - chapter.load(); - } - return chapter; -}; - -EPUBJS.Book.prototype.unload = function(){ - - if(this.settings.restore && localStorage) { - this.saveContents(); - } - - this.unlistenToRenderer(this.renderer); - - this.trigger("book:unload"); -}; - -EPUBJS.Book.prototype.destroy = function() { - - window.removeEventListener("beforeunload", this.unload); - - if(this.currentChapter) this.currentChapter.unload(); - - this.unload(); - - if(this.renderer) this.renderer.remove(); - -}; - -EPUBJS.Book.prototype._ready = function() { - - this.trigger("book:ready"); - -}; - -EPUBJS.Book.prototype._rendered = function(err) { - var book = this; - - this.isRendered = true; - this.trigger("book:rendered"); - - this._q.flush(); -}; - - -EPUBJS.Book.prototype.applyStyles = function(renderer, callback){ - // if(!this.isRendered) return this._q.enqueue("applyStyles", arguments); - renderer.applyStyles(this.settings.styles); - callback(); -}; - -EPUBJS.Book.prototype.applyClasses = function(renderer, callback){ - // if(!this.isRendered) return this._q.enqueue("applyClasses", arguments); - renderer.setClasses(this.settings.classes); - callback(); -}; - -EPUBJS.Book.prototype.applyHeadTags = function(renderer, callback){ - // if(!this.isRendered) return this._q.enqueue("applyHeadTags", arguments); - renderer.applyHeadTags(this.settings.headTags); - callback(); -}; - -EPUBJS.Book.prototype._registerReplacements = function(renderer){ - renderer.registerHook("beforeChapterDisplay", this.applyStyles.bind(this, renderer), true); - renderer.registerHook("beforeChapterDisplay", this.applyHeadTags.bind(this, renderer), true); - renderer.registerHook("beforeChapterDisplay", this.applyClasses.bind(this, renderer), true); - renderer.registerHook("beforeChapterDisplay", EPUBJS.replace.hrefs.bind(this), true); -}; - -EPUBJS.Book.prototype._needsAssetReplacement = function(){ - if(this.settings.fromStorage) { - - //-- Filesystem api links are relative, so no need to replace them - // if(this.storage.getStorageType() == "filesystem") { - // return false; - // } - - return true; - - } else if(this.settings.contained) { - - return true; - - } else { - - return false; - - } -}; - - -//-- http://www.idpf.org/epub/fxl/ -EPUBJS.Book.prototype.parseLayoutProperties = function(metadata){ - var layout = (this.settings.layoutOveride && this.settings.layoutOveride.layout) || metadata.layout || "reflowable"; - var spread = (this.settings.layoutOveride && this.settings.layoutOveride.spread) || metadata.spread || "auto"; - var orientation = (this.settings.layoutOveride && this.settings.layoutOveride.orientation) || metadata.orientation || "auto"; - return { - layout : layout, - spread : spread, - orientation : orientation - }; -}; - -//-- Enable binding events to book -RSVP.EventTarget.mixin(EPUBJS.Book.prototype); - -//-- Handle RSVP Errors -RSVP.on('error', function(event) { - console.error(event); -}); - -RSVP.configure('instrument', true); //-- true | will logging out all RSVP rejections -// RSVP.on('created', listener); -// RSVP.on('chained', listener); -// RSVP.on('fulfilled', listener); -// RSVP.on('rejected', function(event){ -// console.error(event.detail.message, event.detail.stack); -// }); - -EPUBJS.Chapter = function(spineObject, store, credentials){ - this.href = spineObject.href; - this.absolute = spineObject.url; - this.id = spineObject.id; - this.spinePos = spineObject.index; - this.cfiBase = spineObject.cfiBase; - this.properties = spineObject.properties; - this.manifestProperties = spineObject.manifestProperties; - this.linear = spineObject.linear; - this.pages = 1; - this.store = store; - this.credentials = credentials; - this.epubcfi = new EPUBJS.EpubCFI(); - this.deferred = new RSVP.defer(); - this.loaded = this.deferred.promise; - - EPUBJS.Hooks.mixin(this); - //-- Get pre-registered hooks for events - this.getHooks("beforeChapterRender"); - - // Cached for replacement urls from storage - this.caches = {}; -}; - - -EPUBJS.Chapter.prototype.load = function(_store, _credentials){ - var store = _store || this.store; - var credentials = _credentials || this.credentials; - var promise; - // if(this.store && (!this.book.online || this.book.contained)) - if(store){ - promise = store.getXml(this.absolute); - }else{ - promise = EPUBJS.core.request(this.absolute, false, credentials); - } - - promise.then(function(xml){ - try { - this.setDocument(xml); - this.deferred.resolve(this); - } catch (error) { - this.deferred.reject({ - message : this.absolute + " -> " + error.message, - stack : new Error().stack - }); - } - }.bind(this)); - - return promise; -}; - -EPUBJS.Chapter.prototype.render = function(_store){ - - return this.load().then(function(doc){ - - var head = doc.querySelector('head'); - var base = doc.createElement("base"); - - base.setAttribute("href", this.absolute); - head.insertBefore(base, head.firstChild); - - this.contents = doc; - - return new RSVP.Promise(function (resolve, reject) { - this.triggerHooks("beforeChapterRender", function () { - resolve(doc); - }.bind(this), this); - }.bind(this)); - - }.bind(this)) - .then(function(doc) { - var serializer = new XMLSerializer(); - var contents = serializer.serializeToString(doc); - return contents; - }.bind(this)); -}; - -EPUBJS.Chapter.prototype.url = function(_store){ - var deferred = new RSVP.defer(); - var store = _store || this.store; - var loaded; - var chapter = this; - var url; - - if(store){ - if(!this.tempUrl) { - store.getUrl(this.absolute).then(function(url){ - chapter.tempUrl = url; - deferred.resolve(url); - }); - } else { - url = this.tempUrl; - deferred.resolve(url); - } - }else{ - url = this.absolute; - deferred.resolve(url); - } - - return deferred.promise; -}; - -EPUBJS.Chapter.prototype.setPages = function(num){ - this.pages = num; -}; - -EPUBJS.Chapter.prototype.getPages = function(num){ - return this.pages; -}; - -EPUBJS.Chapter.prototype.getID = function(){ - return this.ID; -}; - -EPUBJS.Chapter.prototype.unload = function(store){ - this.document = null; - if(this.tempUrl && store) { - store.revokeUrl(this.tempUrl); - this.tempUrl = false; - } -}; - -EPUBJS.Chapter.prototype.setDocument = function(_document){ - // var uri = _document.namespaceURI; - // var doctype = _document.doctype; - // - // // Creates an empty document - // this.document = _document.implementation.createDocument( - // uri, - // null, - // null - // ); - // this.contents = this.document.importNode( - // _document.documentElement, //node to import - // true //clone its descendants - // ); - // - // this.document.appendChild(this.contents); - this.document = _document; - this.contents = _document.documentElement; - - // Fix to apply wgxpath to new document in IE - if(!this.document.evaluate && document.evaluate) { - this.document.evaluate = document.evaluate; - } - - // this.deferred.resolve(this.contents); -}; - -EPUBJS.Chapter.prototype.cfiFromRange = function(_range) { - var range; - var startXpath, endXpath; - var startContainer, endContainer; - var cleanTextContent, cleanStartTextContent, cleanEndTextContent; - - // Check for Contents - if(!this.document) return; - - if(typeof document.evaluate != 'undefined') { - - startXpath = EPUBJS.core.getElementXPath(_range.startContainer); - // console.log(startContainer) - endXpath = EPUBJS.core.getElementXPath(_range.endContainer); - - startContainer = this.document.evaluate(startXpath, this.document, EPUBJS.core.nsResolver, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; - - if(!_range.collapsed) { - endContainer = this.document.evaluate(endXpath, this.document, EPUBJS.core.nsResolver, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; - } - - range = this.document.createRange(); - // Find Exact Range in original document - if(startContainer) { - try { - range.setStart(startContainer, _range.startOffset); - if(!_range.collapsed && endContainer) { - range.setEnd(endContainer, _range.endOffset); - } - } catch (e) { - console.log("missed"); - startContainer = false; - } - - } - - // Fuzzy Match - if(!startContainer) { - console.log("not found, try fuzzy match"); - cleanStartTextContent = EPUBJS.core.cleanStringForXpath(_range.startContainer.textContent); - startXpath = "//text()[contains(.," + cleanStartTextContent + ")]"; - - startContainer = this.document.evaluate(startXpath, this.document, EPUBJS.core.nsResolver, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; - - if(startContainer){ - // console.log("Found with Fuzzy"); - range.setStart(startContainer, _range.startOffset); - - if(!_range.collapsed) { - cleanEndTextContent = EPUBJS.core.cleanStringForXpath(_range.endContainer.textContent); - endXpath = "//text()[contains(.," + cleanEndTextContent + ")]"; - endContainer = this.document.evaluate(endXpath, this.document, EPUBJS.core.nsResolver, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; - if(endContainer) { - range.setEnd(endContainer, _range.endOffset); - } - } - - } - } - } else { - range = _range; // Just evaluate the current documents range - } - - // Generate the Cfi - return this.epubcfi.generateCfiFromRange(range, this.cfiBase); -}; - -EPUBJS.Chapter.prototype.find = function(_query){ - var chapter = this; - var matches = []; - var query = _query.toLowerCase(); - //var xpath = this.document.evaluate(".//text()[contains(translate(., '"+query.toUpperCase()+"', '"+query+"'),'"+query+"')]", this.document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); - var find = function(node){ - // Search String - var text = node.textContent.toLowerCase(); - var range = chapter.document.createRange(); - var cfi; - var pos; - var last = -1; - var excerpt; - var limit = 150; - - while (pos != -1) { - pos = text.indexOf(query, last + 1); - - if(pos != -1) { - // If Found, Create Range - range = chapter.document.createRange(); - range.setStart(node, pos); - range.setEnd(node, pos + query.length); - - //Generate CFI - cfi = chapter.cfiFromRange(range); - - // Generate Excerpt - if(node.textContent.length < limit) { - excerpt = node.textContent; - } else { - excerpt = node.textContent.substring(pos-limit/2,pos+limit/2); - excerpt = "..." + excerpt + "..."; - } - - //Add CFI to list - matches.push({ - cfi: cfi, - excerpt: excerpt - }); - } - - last = pos; - } - - }; - - // Grab text nodes - - /* - for ( var i=0 ; i < xpath.snapshotLength; i++ ) { - find(xpath.snapshotItem(i)); - } - */ - - this.textSprint(this.document, function(node){ - find(node); - }); - - - // Return List of CFIs - return matches; -}; - - -EPUBJS.Chapter.prototype.textSprint = function(root, func) { - var treeWalker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT, { - acceptNode: function (node) { - if (node.data && ! /^\s*$/.test(node.data) ) { - return NodeFilter.FILTER_ACCEPT; - } else { - return NodeFilter.FILTER_REJECT; - } - } - }, false); - var node; - while ((node = treeWalker.nextNode())) { - func(node); - } - -}; - -EPUBJS.Chapter.prototype.replace = function(query, func, finished, progress){ - var items = this.contents.querySelectorAll(query), - resources = Array.prototype.slice.call(items), - count = resources.length; - - - if(count === 0) { - finished(false); - return; - } - resources.forEach(function(item){ - var called = false; - var after = function(result, full){ - if(called === false) { - count--; - if(progress) progress(result, full, count); - if(count <= 0 && finished) finished(true); - called = true; - } - }; - - func(item, after); - - }.bind(this)); - -}; - -EPUBJS.Chapter.prototype.replaceWithStored = function(query, attr, func, callback) { - var _oldUrls, - _newUrls = {}, - _store = this.store, - _cache = this.caches[query], - _uri = EPUBJS.core.uri(this.absolute), - _chapterBase = _uri.base, - _attr = attr, - _wait = 5, - progress = function(url, full, count) { - _newUrls[full] = url; - }, - finished = function(notempty) { - if(callback) callback(); - EPUBJS.core.values(_oldUrls).forEach(function(url){ - _store.revokeUrl(url); - }); - - _cache = _newUrls; - }; - - if(!_store) return; - - if(!_cache) _cache = {}; - _oldUrls = EPUBJS.core.clone(_cache); - - this.replace(query, function(link, done){ - var src = link.getAttribute(_attr), - full = EPUBJS.core.resolveUrl(_chapterBase, src); - - var replaceUrl = function(url) { - var timeout; - link.onload = function(){ - clearTimeout(timeout); - done(url, full); - }; - - /* - link.onerror = function(e){ - clearTimeout(timeout); - done(url, full); - console.error(e); - }; - */ - - if(query == "svg image") { - //-- SVG needs this to trigger a load event - link.setAttribute("externalResourcesRequired", "true"); - } - - if(query == "link[href]" && link.getAttribute("rel") !== "stylesheet") { - //-- Only Stylesheet links seem to have a load events, just continue others - done(url, full); - } else { - timeout = setTimeout(function(){ - done(url, full); - }, _wait); - } - - if (url) { - link.setAttribute(_attr, url); - } - - }; - - if(full in _oldUrls){ - replaceUrl(_oldUrls[full]); - _newUrls[full] = _oldUrls[full]; - delete _oldUrls[full]; - }else{ - func(_store, full, replaceUrl, link); - } - - }, finished, progress); -}; - -var EPUBJS = EPUBJS || {}; -EPUBJS.core = {}; - -var ELEMENT_NODE = 1; -var TEXT_NODE = 3; -var COMMENT_NODE = 8; -var DOCUMENT_NODE = 9; - -//-- Get a element for an id -EPUBJS.core.getEl = function(elem) { - return document.getElementById(elem); -}; - -//-- Get all elements for a class -EPUBJS.core.getEls = function(classes) { - return document.getElementsByClassName(classes); -}; - -EPUBJS.core.request = function(url, type, withCredentials) { - var supportsURL = window.URL; - var BLOB_RESPONSE = supportsURL ? "blob" : "arraybuffer"; - var deferred = new RSVP.defer(); - var xhr = new XMLHttpRequest(); - var uri; - - //-- Check from PDF.js: - // https://github.com/mozilla/pdf.js/blob/master/web/compatibility.js - var xhrPrototype = XMLHttpRequest.prototype; - - var handler = function() { - var r; - - if (this.readyState != this.DONE) return; - - if ((this.status === 200 || this.status === 0) && this.response) { // Android & Firefox reporting 0 for local & blob urls - if (type == 'xml'){ - // If this.responseXML wasn't set, try to parse using a DOMParser from text - if(!this.responseXML) { - r = new DOMParser().parseFromString(this.response, "application/xml"); - } else { - r = this.responseXML; - } - } else if (type == 'xhtml') { - if (!this.responseXML){ - r = new DOMParser().parseFromString(this.response, "application/xhtml+xml"); - } else { - r = this.responseXML; - } - } else if (type == 'html') { - if (!this.responseXML){ - r = new DOMParser().parseFromString(this.response, "text/html"); - } else { - r = this.responseXML; - } - } else if (type == 'json') { - r = JSON.parse(this.response); - } else if (type == 'blob') { - if (supportsURL) { - r = this.response; - } else { - //-- Safari doesn't support responseType blob, so create a blob from arraybuffer - r = new Blob([this.response]); - } - } else { - r = this.response; - } - - deferred.resolve(r); - } else { - deferred.reject({ - message : this.response, - stack : new Error().stack - }); - } - }; - - if (!('overrideMimeType' in xhrPrototype)) { - // IE10 might have response, but not overrideMimeType - Object.defineProperty(xhrPrototype, 'overrideMimeType', { - value: function xmlHttpRequestOverrideMimeType(mimeType) {} - }); - } - - xhr.onreadystatechange = handler; - xhr.open("GET", url, true); - - if(withCredentials) { - xhr.withCredentials = true; - } - - // If type isn't set, determine it from the file extension - if(!type) { - uri = EPUBJS.core.uri(url); - type = uri.extension; - type = { - 'htm': 'html' - }[type] || type; - } - - if(type == 'blob'){ - xhr.responseType = BLOB_RESPONSE; - } - - if(type == "json") { - xhr.setRequestHeader("Accept", "application/json"); - } - - if(type == 'xml') { - xhr.responseType = "document"; - xhr.overrideMimeType('text/xml'); // for OPF parsing - } - - if(type == 'xhtml') { - xhr.responseType = "document"; - } - - if(type == 'html') { - xhr.responseType = "document"; - } - - if(type == "binary") { - xhr.responseType = "arraybuffer"; - } - - xhr.send(); - - return deferred.promise; -}; - -EPUBJS.core.toArray = function(obj) { - var arr = []; - - for (var member in obj) { - var newitm; - if ( obj.hasOwnProperty(member) ) { - newitm = obj[member]; - newitm.ident = member; - arr.push(newitm); - } - } - - return arr; -}; - -//-- Parse the different parts of a url, returning a object -EPUBJS.core.uri = function(url){ - var uri = { - protocol : '', - host : '', - path : '', - origin : '', - directory : '', - base : '', - filename : '', - extension : '', - fragment : '', - href : url - }, - blob = url.indexOf('blob:'), - doubleSlash = url.indexOf('://'), - search = url.indexOf('?'), - fragment = url.indexOf("#"), - withoutProtocol, - dot, - firstSlash; - - if(blob === 0) { - uri.protocol = "blob"; - uri.base = url.indexOf(0, fragment); - return uri; - } - - if(fragment != -1) { - uri.fragment = url.slice(fragment + 1); - url = url.slice(0, fragment); - } - - if(search != -1) { - uri.search = url.slice(search + 1); - url = url.slice(0, search); - href = uri.href; - } - - if(doubleSlash != -1) { - uri.protocol = url.slice(0, doubleSlash); - withoutProtocol = url.slice(doubleSlash+3); - firstSlash = withoutProtocol.indexOf('/'); - - if(firstSlash === -1) { - uri.host = uri.path; - uri.path = ""; - } else { - uri.host = withoutProtocol.slice(0, firstSlash); - uri.path = withoutProtocol.slice(firstSlash); - } - - - uri.origin = uri.protocol + "://" + uri.host; - - uri.directory = EPUBJS.core.folder(uri.path); - - uri.base = uri.origin + uri.directory; - // return origin; - } else { - uri.path = url; - uri.directory = EPUBJS.core.folder(url); - uri.base = uri.directory; - } - - //-- Filename - uri.filename = url.replace(uri.base, ''); - dot = uri.filename.lastIndexOf('.'); - if(dot != -1) { - uri.extension = uri.filename.slice(dot+1); - } - return uri; -}; - -//-- Parse out the folder, will return everything before the last slash - -EPUBJS.core.folder = function(url){ - - var lastSlash = url.lastIndexOf('/'); - - if(lastSlash == -1) var folder = ''; - - folder = url.slice(0, lastSlash + 1); - - return folder; - -}; - -//-- https://github.com/ebidel/filer.js/blob/master/src/filer.js#L128 -EPUBJS.core.dataURLToBlob = function(dataURL) { - var BASE64_MARKER = ';base64,', - parts, contentType, raw, rawLength, uInt8Array; - - if (dataURL.indexOf(BASE64_MARKER) == -1) { - parts = dataURL.split(','); - contentType = parts[0].split(':')[1]; - raw = parts[1]; - - return new Blob([raw], {type: contentType}); - } - - parts = dataURL.split(BASE64_MARKER); - contentType = parts[0].split(':')[1]; - raw = window.atob(parts[1]); - rawLength = raw.length; - - uInt8Array = new Uint8Array(rawLength); - - for (var i = 0; i < rawLength; ++i) { - uInt8Array[i] = raw.charCodeAt(i); - } - - return new Blob([uInt8Array], {type: contentType}); -}; - -//-- Load scripts async: http://stackoverflow.com/questions/7718935/load-scripts-asynchronously -EPUBJS.core.addScript = function(src, callback, target) { - var s, r; - r = false; - s = document.createElement('script'); - s.type = 'text/javascript'; - s.async = false; - s.src = src; - s.onload = s.onreadystatechange = function() { - if ( !r && (!this.readyState || this.readyState == 'complete') ) { - r = true; - if(callback) callback(); - } - }; - target = target || document.body; - target.appendChild(s); -}; - -EPUBJS.core.addScripts = function(srcArr, callback, target) { - var total = srcArr.length, - curr = 0, - cb = function(){ - curr++; - if(total == curr){ - if(callback) callback(); - }else{ - EPUBJS.core.addScript(srcArr[curr], cb, target); - } - }; - - EPUBJS.core.addScript(srcArr[curr], cb, target); -}; - -EPUBJS.core.addCss = function(src, callback, target) { - var s, r; - r = false; - s = document.createElement('link'); - s.type = 'text/css'; - s.rel = "stylesheet"; - s.href = src; - s.onload = s.onreadystatechange = function() { - if ( !r && (!this.readyState || this.readyState == 'complete') ) { - r = true; - if(callback) callback(); - } - }; - target = target || document.body; - target.appendChild(s); -}; - -EPUBJS.core.prefixed = function(unprefixed) { - var vendors = ["Webkit", "Moz", "O", "ms" ], - prefixes = ['-Webkit-', '-moz-', '-o-', '-ms-'], - upper = unprefixed[0].toUpperCase() + unprefixed.slice(1), - length = vendors.length; - - if (typeof(document.documentElement.style[unprefixed]) != 'undefined') { - return unprefixed; - } - - for ( var i=0; i < length; i++ ) { - if (typeof(document.documentElement.style[vendors[i] + upper]) != 'undefined') { - return vendors[i] + upper; - } - } - - return unprefixed; -}; - -EPUBJS.core.resolveUrl = function(base, path) { - var url, - segments = [], - uri = EPUBJS.core.uri(path), - folders = base.split("/"), - paths; - - if(uri.host) { - return path; - } - - folders.pop(); - - paths = path.split("/"); - paths.forEach(function(p){ - if(p === ".."){ - folders.pop(); - }else{ - segments.push(p); - } - }); - - url = folders.concat(segments); - - return url.join("/"); -}; - -// http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript -EPUBJS.core.uuid = function() { - var d = new Date().getTime(); - var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { - var r = (d + Math.random()*16)%16 | 0; - d = Math.floor(d/16); - return (c=='x' ? r : (r&0x7|0x8)).toString(16); - }); - return uuid; -}; - -// Fast quicksort insert for sorted array -- based on: -// http://stackoverflow.com/questions/1344500/efficient-way-to-insert-a-number-into-a-sorted-array-of-numbers -EPUBJS.core.insert = function(item, array, compareFunction) { - var location = EPUBJS.core.locationOf(item, array, compareFunction); - array.splice(location, 0, item); - - return location; -}; - -EPUBJS.core.locationOf = function(item, array, compareFunction, _start, _end) { - var start = _start || 0; - var end = _end || array.length; - var pivot = parseInt(start + (end - start) / 2); - var compared; - if(!compareFunction){ - compareFunction = function(a, b) { - if(a > b) return 1; - if(a < b) return -1; - if(a = b) return 0; - }; - } - if(end-start <= 0) { - return pivot; - } - - compared = compareFunction(array[pivot], item); - if(end-start === 1) { - return compared > 0 ? pivot : pivot + 1; - } - - if(compared === 0) { - return pivot; - } - if(compared === -1) { - return EPUBJS.core.locationOf(item, array, compareFunction, pivot, end); - } else{ - return EPUBJS.core.locationOf(item, array, compareFunction, start, pivot); - } -}; - -EPUBJS.core.indexOfSorted = function(item, array, compareFunction, _start, _end) { - var start = _start || 0; - var end = _end || array.length; - var pivot = parseInt(start + (end - start) / 2); - var compared; - if(!compareFunction){ - compareFunction = function(a, b) { - if(a > b) return 1; - if(a < b) return -1; - if(a = b) return 0; - }; - } - if(end-start <= 0) { - return -1; // Not found - } - - compared = compareFunction(array[pivot], item); - if(end-start === 1) { - return compared === 0 ? pivot : -1; - } - if(compared === 0) { - return pivot; // Found - } - if(compared === -1) { - return EPUBJS.core.indexOfSorted(item, array, compareFunction, pivot, end); - } else{ - return EPUBJS.core.indexOfSorted(item, array, compareFunction, start, pivot); - } -}; - - -EPUBJS.core.queue = function(_scope){ - var _q = []; - var scope = _scope; - // Add an item to the queue - var enqueue = function(funcName, args, context) { - _q.push({ - "funcName" : funcName, - "args" : args, - "context" : context - }); - return _q; - }; - // Run one item - var dequeue = function(){ - var inwait; - if(_q.length) { - inwait = _q.shift(); - // Defer to any current tasks - // setTimeout(function(){ - scope[inwait.funcName].apply(inwait.context || scope, inwait.args); - // }, 0); - } - }; - - // Run All - var flush = function(){ - while(_q.length) { - dequeue(); - } - }; - // Clear all items in wait - var clear = function(){ - _q = []; - }; - - var length = function(){ - return _q.length; - }; - - return { - "enqueue" : enqueue, - "dequeue" : dequeue, - "flush" : flush, - "clear" : clear, - "length" : length - }; -}; - -// From: https://code.google.com/p/fbug/source/browse/branches/firebug1.10/content/firebug/lib/xpath.js -/** - * Gets an XPath for an element which describes its hierarchical location. - */ -EPUBJS.core.getElementXPath = function(element) { - if (element && element.id) { - return '//*[@id="' + element.id + '"]'; - } else { - return EPUBJS.core.getElementTreeXPath(element); - } -}; - -EPUBJS.core.getElementTreeXPath = function(element) { - var paths = []; - var isXhtml = (element.ownerDocument.documentElement.getAttribute('xmlns') === "http://www.w3.org/1999/xhtml"); - var index, nodeName, tagName, pathIndex; - - if(element.nodeType === Node.TEXT_NODE){ - // index = Array.prototype.indexOf.call(element.parentNode.childNodes, element) + 1; - index = EPUBJS.core.indexOfTextNode(element) + 1; - - paths.push("text()["+index+"]"); - element = element.parentNode; - } - - // Use nodeName (instead of localName) so namespace prefix is included (if any). - for (; element && element.nodeType == 1; element = element.parentNode) - { - index = 0; - for (var sibling = element.previousSibling; sibling; sibling = sibling.previousSibling) - { - // Ignore document type declaration. - if (sibling.nodeType == Node.DOCUMENT_TYPE_NODE) { - continue; - } - if (sibling.nodeName == element.nodeName) { - ++index; - } - } - nodeName = element.nodeName.toLowerCase(); - tagName = (isXhtml ? "xhtml:" + nodeName : nodeName); - pathIndex = (index ? "[" + (index+1) + "]" : ""); - paths.splice(0, 0, tagName + pathIndex); - } - - return paths.length ? "./" + paths.join("/") : null; -}; - -EPUBJS.core.nsResolver = function(prefix) { - var ns = { - 'xhtml' : 'http://www.w3.org/1999/xhtml', - 'epub': 'http://www.idpf.org/2007/ops' - }; - return ns[prefix] || null; -}; - -//https://stackoverflow.com/questions/13482352/xquery-looking-for-text-with-single-quote/13483496#13483496 -EPUBJS.core.cleanStringForXpath = function(str) { - var parts = str.match(/[^'"]+|['"]/g); - parts = parts.map(function(part){ - if (part === "'") { - return '\"\'\"'; // output "'" - } - - if (part === '"') { - return "\'\"\'"; // output '"' - } - return "\'" + part + "\'"; - }); - return "concat(\'\'," + parts.join(",") + ")"; -}; - -EPUBJS.core.indexOfTextNode = function(textNode){ - var parent = textNode.parentNode; - var children = parent.childNodes; - var sib; - var index = -1; - for (var i = 0; i < children.length; i++) { - sib = children[i]; - if(sib.nodeType === Node.TEXT_NODE){ - index++; - } - if(sib == textNode) break; - } - - return index; -}; - -// Underscore -EPUBJS.core.defaults = function(obj) { - for (var i = 1, length = arguments.length; i < length; i++) { - var source = arguments[i]; - for (var prop in source) { - if (obj[prop] === void 0) obj[prop] = source[prop]; - } - } - return obj; -}; - -EPUBJS.core.extend = function(target) { - var sources = [].slice.call(arguments, 1); - sources.forEach(function (source) { - if(!source) return; - Object.getOwnPropertyNames(source).forEach(function(propName) { - Object.defineProperty(target, propName, Object.getOwnPropertyDescriptor(source, propName)); - }); - }); - return target; -}; - -EPUBJS.core.clone = function(obj) { - return EPUBJS.core.isArray(obj) ? obj.slice() : EPUBJS.core.extend({}, obj); -}; - -EPUBJS.core.isElement = function(obj) { - return !!(obj && obj.nodeType == 1); -}; - -EPUBJS.core.isNumber = function(n) { - return !isNaN(parseFloat(n)) && isFinite(n); -}; - -EPUBJS.core.isString = function(str) { - return (typeof str === 'string' || str instanceof String); -}; - -EPUBJS.core.isArray = Array.isArray || function(obj) { - return Object.prototype.toString.call(obj) === '[object Array]'; -}; - -// Lodash -EPUBJS.core.values = function(object) { - var index = -1; - var props, length, result; - - if(!object) return []; - - props = Object.keys(object); - length = props.length; - result = Array(length); - - while (++index < length) { - result[index] = object[props[index]]; - } - return result; -}; - -EPUBJS.core.indexOfNode = function(node, typeId) { - var parent = node.parentNode; - var children = parent.childNodes; - var sib; - var index = -1; - for (var i = 0; i < children.length; i++) { - sib = children[i]; - if (sib.nodeType === typeId) { - index++; - } - if (sib == node) break; - } - - return index; -} - -EPUBJS.core.indexOfTextNode = function(textNode) { - return EPUBJS.core.indexOfNode(textNode, TEXT_NODE); -} - -EPUBJS.core.indexOfElementNode = function(elementNode) { - return EPUBJS.core.indexOfNode(elementNode, ELEMENT_NODE); -} - -EPUBJS.EpubCFI = function(cfiStr){ - if(cfiStr) return this.parse(cfiStr); -}; - -EPUBJS.EpubCFI.prototype.generateChapterComponent = function(_spineNodeIndex, _pos, id) { - var pos = parseInt(_pos), - spineNodeIndex = (_spineNodeIndex + 1) * 2, - cfi = '/'+spineNodeIndex+'/'; - - cfi += (pos + 1) * 2; - - if(id) cfi += "[" + id + "]"; - - //cfi += "!"; - - return cfi; -}; - -EPUBJS.EpubCFI.prototype.generatePathComponent = function(steps) { - return steps.map(function(part) { - return (part.index + 1) * 2 + (part.id ? '[' + part.id + ']' : ''); - }).join('/'); -}; - -EPUBJS.EpubCFI.prototype.generateCfiFromElement = function(element, chapter) { - var steps = this.pathTo(element); - var path = this.generatePathComponent(steps); - if(!path.length) { - // Start of Chapter - return "epubcfi(" + chapter + "!/4/)"; - } else { - // First Text Node - return "epubcfi(" + chapter + "!/" + path + "/1:0)"; - } -}; - -EPUBJS.EpubCFI.prototype.pathTo = function(node) { - var stack = [], - children; - - while(node && node.parentNode !== null && node.parentNode.nodeType != 9) { - children = node.parentNode.children; - - stack.unshift({ - 'id' : node.id, - // 'classList' : node.classList, - 'tagName' : node.tagName, - 'index' : children ? Array.prototype.indexOf.call(children, node) : 0 - }); - - node = node.parentNode; - } - - return stack; -}; - -EPUBJS.EpubCFI.prototype.getChapterComponent = function(cfiStr) { - - var splitStr = cfiStr.split("!"); - - return splitStr[0]; -}; - -EPUBJS.EpubCFI.prototype.getPathComponent = function(cfiStr) { - - var splitStr = cfiStr.split("!"); - var pathComponent = splitStr[1] ? splitStr[1].split(":") : ''; - - return pathComponent[0]; -}; - -EPUBJS.EpubCFI.prototype.getCharecterOffsetComponent = // backwards-compat -EPUBJS.EpubCFI.prototype.getCharacterOffsetComponent = function(cfiStr) { - var splitStr = cfiStr.split(":"); - return splitStr[1] || ''; -}; - - -EPUBJS.EpubCFI.prototype.parse = function(cfiStr) { - var cfi = {}, - chapSegment, - chapterComponent, - pathComponent, - characterOffsetComponent, - assertion, - chapId, - path, - end, - endInt, - text, - parseStep = function(part){ - var type, index, has_brackets, id; - - type = "element"; - index = parseInt(part) / 2 - 1; - has_brackets = part.match(/\[(.*)\]/); - if(has_brackets && has_brackets[1]){ - id = has_brackets[1]; - } - - return { - "type" : type, - 'index' : index, - 'id' : id || false - }; - }; - - if(typeof cfiStr !== "string") { - return {spinePos: -1}; - } - - cfi.str = cfiStr; - - if(cfiStr.indexOf("epubcfi(") === 0 && cfiStr[cfiStr.length-1] === ")") { - // Remove intial epubcfi( and ending ) - cfiStr = cfiStr.slice(8, cfiStr.length-1); - } - - chapterComponent = this.getChapterComponent(cfiStr); - pathComponent = this.getPathComponent(cfiStr) || ''; - characterOffsetComponent = this.getCharacterOffsetComponent(cfiStr); - // Make sure this is a valid cfi or return - if(!chapterComponent) { - return {spinePos: -1}; - } - - // Chapter segment is always the second one - chapSegment = chapterComponent.split("/")[2] || ''; - if(!chapSegment) return {spinePos:-1}; - - cfi.spinePos = (parseInt(chapSegment) / 2 - 1 ) || 0; - - chapId = chapSegment.match(/\[(.*)\]/); - - cfi.spineId = chapId ? chapId[1] : false; - - if(pathComponent.indexOf(',') != -1) { - // Handle ranges -- not supported yet - console.warn("CFI Ranges are not supported"); - } - - path = pathComponent.split('/'); - end = path.pop(); - - cfi.steps = []; - - path.forEach(function(part){ - var step; - - if(part) { - step = parseStep(part); - cfi.steps.push(step); - } - }); - - //-- Check if END is a text node or element - endInt = parseInt(end); - if(!isNaN(endInt)) { - - if(endInt % 2 === 0) { // Even = is an element - cfi.steps.push(parseStep(end)); - } else { - cfi.steps.push({ - "type" : "text", - 'index' : (endInt - 1 ) / 2 - }); - } - - } - - assertion = characterOffsetComponent.match(/\[(.*)\]/); - if(assertion && assertion[1]){ - cfi.characterOffset = parseInt(characterOffsetComponent.split('[')[0]); - // We arent handling these assertions yet - cfi.textLocationAssertion = assertion[1]; - } else { - cfi.characterOffset = parseInt(characterOffsetComponent); - } - - return cfi; -}; - -EPUBJS.EpubCFI.prototype.addMarker = function(cfi, _doc, _marker) { - var doc = _doc || document; - var marker = _marker || this.createMarker(doc); - var parent; - var lastStep; - var text; - var split; - - if(typeof cfi === 'string') { - cfi = this.parse(cfi); - } - // Get the terminal step - lastStep = cfi.steps[cfi.steps.length-1]; - - // check spinePos - if(cfi.spinePos === -1) { - // Not a valid CFI - return false; - } - - // Find the CFI elements parent - parent = this.findParent(cfi, doc); - - if(!parent) { - // CFI didn't return an element - // Maybe it isnt in the current chapter? - return false; - } - - if(lastStep && lastStep.type === "text") { - text = parent.childNodes[lastStep.index]; - if(cfi.characterOffset){ - split = text.splitText(cfi.characterOffset); - marker.classList.add("EPUBJS-CFI-SPLIT"); - parent.insertBefore(marker, split); - } else { - parent.insertBefore(marker, text); - } - } else { - parent.insertBefore(marker, parent.firstChild); - } - - return marker; -}; - -EPUBJS.EpubCFI.prototype.createMarker = function(_doc) { - var doc = _doc || document; - var element = doc.createElement('span'); - element.id = "EPUBJS-CFI-MARKER:"+ EPUBJS.core.uuid(); - element.classList.add("EPUBJS-CFI-MARKER"); - - return element; -}; - -EPUBJS.EpubCFI.prototype.removeMarker = function(marker, _doc) { - var doc = _doc || document; - // var id = marker.id; - - // Cleanup textnodes if they were split - if(marker.classList.contains("EPUBJS-CFI-SPLIT")){ - nextSib = marker.nextSibling; - prevSib = marker.previousSibling; - if(nextSib && - prevSib && - nextSib.nodeType === 3 && - prevSib.nodeType === 3){ - - prevSib.textContent += nextSib.textContent; - marker.parentNode.removeChild(nextSib); - } - marker.parentNode.removeChild(marker); - } else if(marker.classList.contains("EPUBJS-CFI-MARKER")) { - // Remove only elements added as markers - marker.parentNode.removeChild(marker); - } - -}; - -EPUBJS.EpubCFI.prototype.findParent = function(cfi, _doc) { - var doc = _doc || document, - element = doc.getElementsByTagName('html')[0], - children = Array.prototype.slice.call(element.children), - num, index, part, sections, - text, textBegin, textEnd; - - if(typeof cfi === 'string') { - cfi = this.parse(cfi); - } - - sections = cfi.steps.slice(0); // Clone steps array - if(!sections.length) { - return doc.getElementsByTagName('body')[0]; - } - - while(sections && sections.length > 0) { - part = sections.shift(); - // Find textNodes Parent - if(part.type === "text") { - text = element.childNodes[part.index]; - element = text.parentNode || element; - // Find element by id if present - } else if(part.id){ - element = doc.getElementById(part.id); - // Find element in parent - }else{ - element = children[part.index]; - } - // Element can't be found - if(!element || typeof element === "undefined") { - console.error("No Element For", part, cfi.str); - return false; - } - // Get current element children and continue through steps - children = Array.prototype.slice.call(element.children); - } - - return element; -}; - -EPUBJS.EpubCFI.prototype.compare = function(cfiOne, cfiTwo) { - if(typeof cfiOne === 'string') { - cfiOne = new EPUBJS.EpubCFI(cfiOne); - } - if(typeof cfiTwo === 'string') { - cfiTwo = new EPUBJS.EpubCFI(cfiTwo); - } - // Compare Spine Positions - if(cfiOne.spinePos > cfiTwo.spinePos) { - return 1; - } - if(cfiOne.spinePos < cfiTwo.spinePos) { - return -1; - } - - - // Compare Each Step in the First item - for (var i = 0; i < cfiOne.steps.length; i++) { - if(!cfiTwo.steps[i]) { - return 1; - } - if(cfiOne.steps[i].index > cfiTwo.steps[i].index) { - return 1; - } - if(cfiOne.steps[i].index < cfiTwo.steps[i].index) { - return -1; - } - // Otherwise continue checking - } - - // All steps in First present in Second - if(cfiOne.steps.length < cfiTwo.steps.length) { - return -1; - } - - // Compare the character offset of the text node - if(cfiOne.characterOffset > cfiTwo.characterOffset) { - return 1; - } - if(cfiOne.characterOffset < cfiTwo.characterOffset) { - return -1; - } - - // CFI's are equal - return 0; -}; - -EPUBJS.EpubCFI.prototype.generateCfiFromHref = function(href, book) { - var uri = EPUBJS.core.uri(href); - var path = uri.path; - var fragment = uri.fragment; - var spinePos = book.spineIndexByURL[path]; - var loaded; - var deferred = new RSVP.defer(); - var epubcfi = new EPUBJS.EpubCFI(); - var spineItem; - - if(typeof spinePos !== "undefined"){ - spineItem = book.spine[spinePos]; - loaded = book.loadXml(spineItem.url); - loaded.then(function(doc){ - var element = doc.getElementById(fragment); - var cfi; - cfi = epubcfi.generateCfiFromElement(element, spineItem.cfiBase); - deferred.resolve(cfi); - }); - } - - return deferred.promise; -}; - -EPUBJS.EpubCFI.prototype.generateCfiFromTextNode = function(anchor, offset, base) { - var parent = anchor.parentNode; - var steps = this.pathTo(parent); - var path = this.generatePathComponent(steps); - var index = 1 + (2 * Array.prototype.indexOf.call(parent.childNodes, anchor)); - return "epubcfi(" + base + "!/" + path + "/"+index+":"+(offset || 0)+")"; -}; - -EPUBJS.EpubCFI.prototype.generateCfiFromRangeAnchor = function(range, base) { - var anchor = range.anchorNode; - var offset = range.anchorOffset; - return this.generateCfiFromTextNode(anchor, offset, base); -}; - -EPUBJS.EpubCFI.prototype.generateCfiFromRange = function(range, base) { - var start, startElement, startSteps, startPath, startOffset, startIndex; - var end, endElement, endSteps, endPath, endOffset, endIndex; - - start = range.startContainer; - - if(start.nodeType === 3) { // text node - startElement = start.parentNode; - //startIndex = 1 + (2 * Array.prototype.indexOf.call(startElement.childNodes, start)); - startIndex = 1 + (2 * EPUBJS.core.indexOfTextNode(start)); - startSteps = this.pathTo(startElement); - } else if(range.collapsed) { - return this.generateCfiFromElement(start, base); // single element - } else { - startSteps = this.pathTo(start); - } - - startPath = this.generatePathComponent(startSteps); - startOffset = range.startOffset; - - if(!range.collapsed) { - end = range.endContainer; - - if(end.nodeType === 3) { // text node - endElement = end.parentNode; - // endIndex = 1 + (2 * Array.prototype.indexOf.call(endElement.childNodes, end)); - endIndex = 1 + (2 * EPUBJS.core.indexOfTextNode(end)); - - endSteps = this.pathTo(endElement); - } else { - endSteps = this.pathTo(end); - } - - endPath = this.generatePathComponent(endSteps); - endOffset = range.endOffset; - - // Remove steps present in startPath - endPath = endPath.replace(startPath, ''); - - if (endPath.length) { - endPath = endPath + "/"; - } - - return "epubcfi(" + base + "!/" + startPath + "/" + startIndex + ":" + startOffset + "," + endPath + endIndex + ":" + endOffset + ")"; - - } else { - return "epubcfi(" + base + "!/" + startPath + "/"+ startIndex +":"+ startOffset +")"; - } -}; - -EPUBJS.EpubCFI.prototype.generateXpathFromSteps = function(steps) { - var xpath = [".", "*"]; - - steps.forEach(function(step){ - var position = step.index + 1; - - if(step.id){ - xpath.push("*[position()=" + position + " and @id='" + step.id + "']"); - } else if(step.type === "text") { - xpath.push("text()[" + position + "]"); - } else { - xpath.push("*[" + position + "]"); - } - }); - - return xpath.join("/"); -}; - -EPUBJS.EpubCFI.prototype.generateQueryFromSteps = function(steps) { - var query = ["html"]; - - steps.forEach(function(step){ - var position = step.index + 1; - - if(step.id){ - query.push("#" + step.id); - } else if(step.type === "text") { - // unsupported in querySelector - // query.push("text()[" + position + "]"); - } else { - query.push("*:nth-child(" + position + ")"); - } - }); - - return query.join(">"); -}; - - -EPUBJS.EpubCFI.prototype.generateRangeFromCfi = function(cfi, _doc) { - var doc = _doc || document; - var range = doc.createRange(); - var lastStep; - var xpath; - var startContainer; - var textLength; - var query; - var startContainerParent; - - if(typeof cfi === 'string') { - cfi = this.parse(cfi); - } - - // check spinePos - if(cfi.spinePos === -1) { - // Not a valid CFI - return false; - } - - // Get the terminal step - lastStep = cfi.steps[cfi.steps.length-1]; - - if(typeof document.evaluate != 'undefined') { - xpath = this.generateXpathFromSteps(cfi.steps); - startContainer = doc.evaluate(xpath, doc, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; - } else { - // Get the query string - query = this.generateQueryFromSteps(cfi.steps); - // Find the containing element - startContainerParent = doc.querySelector(query); - // Find the text node within that element - if(startContainerParent && lastStep.type == "text") { - startContainer = startContainerParent.childNodes[lastStep.index]; - } - } - - if(!startContainer) { - return null; - } - - if(startContainer && cfi.characterOffset >= 0) { - textLength = startContainer.length; - - if(cfi.characterOffset < textLength) { - range.setStart(startContainer, cfi.characterOffset); - range.setEnd(startContainer, textLength ); - } else { - console.debug("offset greater than length:", cfi.characterOffset, textLength); - range.setStart(startContainer, textLength - 1 ); - range.setEnd(startContainer, textLength ); - } - } else if(startContainer) { - range.selectNode(startContainer); - } - // doc.defaultView.getSelection().addRange(range); - return range; -}; - -EPUBJS.EpubCFI.prototype.isCfiString = function(target) { - return typeof target === 'string' && target.indexOf('epubcfi(') === 0; -}; - -EPUBJS.Events = function(obj, el){ - - this.events = {}; - - if(!el){ - this.el = document.createElement('div'); - }else{ - this.el = el; - } - - obj.createEvent = this.createEvent; - obj.tell = this.tell; - obj.listen = this.listen; - obj.deafen = this.deafen; - obj.listenUntil = this.listenUntil; - - return this; -}; - -EPUBJS.Events.prototype.createEvent = function(evt){ - var e = new CustomEvent(evt); - this.events[evt] = e; - return e; -}; - -EPUBJS.Events.prototype.tell = function(evt, msg){ - var e; - - if(!this.events[evt]){ - console.warn("No event:", evt, "defined yet, creating."); - e = this.createEvent(evt); - }else{ - e = this.events[evt]; - } - - if(msg) e.msg = msg; - this.el.dispatchEvent(e); - -}; - -EPUBJS.Events.prototype.listen = function(evt, func, bindto){ - if(!this.events[evt]){ - console.warn("No event:", evt, "defined yet, creating."); - this.createEvent(evt); - return; - } - - if(bindto){ - this.el.addEventListener(evt, func.bind(bindto), false); - }else{ - this.el.addEventListener(evt, func, false); - } - -}; - -EPUBJS.Events.prototype.deafen = function(evt, func){ - this.el.removeEventListener(evt, func, false); -}; - -EPUBJS.Events.prototype.listenUntil = function(OnEvt, OffEvt, func, bindto){ - this.listen(OnEvt, func, bindto); - - function unlisten(){ - this.deafen(OnEvt, func); - this.deafen(OffEvt, unlisten); - } - - this.listen(OffEvt, unlisten, this); -}; -EPUBJS.hooks = {}; -EPUBJS.Hooks = (function(){ - function hooks(){} - - //-- Get pre-registered hooks - hooks.prototype.getHooks = function(){ - var plugs; - this.hooks = {}; - Array.prototype.slice.call(arguments).forEach(function(arg){ - this.hooks[arg] = []; - }, this); - - for (var plugType in this.hooks) { - plugs = EPUBJS.core.values(EPUBJS.hooks[plugType]); - - plugs.forEach(function(hook){ - this.registerHook(plugType, hook); - }, this); - } - }; - - //-- Hooks allow for injecting async functions that must all complete before continuing - // Functions must have a callback as their first argument. - hooks.prototype.registerHook = function(type, toAdd, toFront){ - - if(typeof(this.hooks[type]) != "undefined"){ - - if(typeof(toAdd) === "function"){ - if(toFront) { - this.hooks[type].unshift(toAdd); - }else{ - this.hooks[type].push(toAdd); - } - }else if(Array.isArray(toAdd)){ - toAdd.forEach(function(hook){ - if(toFront) { - this.hooks[type].unshift(hook); - }else{ - this.hooks[type].push(hook); - } - }, this); - } - }else{ - //-- Allows for undefined hooks - this.hooks[type] = [toAdd]; - - if(typeof(toAdd) === "function"){ - this.hooks[type] = [toAdd]; - }else if(Array.isArray(toAdd)){ - this.hooks[type] = []; - toAdd.forEach(function(hook){ - this.hooks[type].push(hook); - }, this); - } - - } - }; - - hooks.prototype.removeHook = function(type, toRemove){ - var index; - - if(typeof(this.hooks[type]) != "undefined"){ - - if(typeof(toRemove) === "function"){ - index = this.hooks[type].indexOf(toRemove); - if (index > -1) { - this.hooks[type].splice(index, 1); - } - }else if(Array.isArray(toRemove)){ - toRemove.forEach(function(hook){ - index = this.hooks[type].indexOf(hook); - if (index > -1) { - this.hooks[type].splice(index, 1); - } - }, this); - } - } - }; - - hooks.prototype.triggerHooks = function(type, callback, passed){ - var hooks, count; - - if(typeof(this.hooks[type]) == "undefined") return false; - - hooks = this.hooks[type]; - - count = hooks.length; - if(count === 0 && callback) { - callback(); - } - - function countdown(){ - count--; - if(count <= 0 && callback) callback(); - } - - hooks.forEach(function(hook){ - hook(countdown, passed); - }); - }; - - return { - register: function(name) { - if(EPUBJS.hooks[name] === undefined) { EPUBJS.hooks[name] = {}; } - if(typeof EPUBJS.hooks[name] !== 'object') { throw "Already registered: "+name; } - return EPUBJS.hooks[name]; - }, - mixin: function(object) { - for (var prop in hooks.prototype) { - object[prop] = hooks.prototype[prop]; - } - } - }; -})(); - -EPUBJS.Layout = EPUBJS.Layout || {}; - -// EPUB2 documents won't provide us with "rendition:layout", so this is used to -// duck type the documents instead. -EPUBJS.Layout.isFixedLayout = function (documentElement) { - var viewport = documentElement.querySelector("[name=viewport]"); - if (!viewport || !viewport.hasAttribute("content")) { - return false; - } - var content = viewport.getAttribute("content"); - return (/width=(\d+)/.test(content) && /height=(\d+)/.test(content)); -}; - -EPUBJS.Layout.Reflowable = function(){ - this.documentElement = null; - this.spreadWidth = null; -}; - -EPUBJS.Layout.Reflowable.prototype.format = function(documentElement, _width, _height, _gap){ - // Get the prefixed CSS commands - var columnAxis = EPUBJS.core.prefixed('columnAxis'); - var columnGap = EPUBJS.core.prefixed('columnGap'); - var columnWidth = EPUBJS.core.prefixed('columnWidth'); - var columnFill = EPUBJS.core.prefixed('columnFill'); - - //-- Check the width and create even width columns - var width = Math.floor(_width); - // var width = (fullWidth % 2 === 0) ? fullWidth : fullWidth - 0; // Not needed for single - var section = Math.floor(width / 8); - var gap = (_gap >= 0) ? _gap : ((section % 2 === 0) ? section : section - 1); - this.documentElement = documentElement; - //-- Single Page - this.spreadWidth = (width + gap); - - - documentElement.style.overflow = "hidden"; - - // Must be set to the new calculated width or the columns will be off - documentElement.style.width = width + "px"; - - //-- Adjust height - documentElement.style.height = _height + "px"; - - //-- Add columns - documentElement.style[columnAxis] = "horizontal"; - documentElement.style[columnFill] = "auto"; - documentElement.style[columnWidth] = width+"px"; - documentElement.style[columnGap] = gap+"px"; - this.colWidth = width; - this.gap = gap; - - return { - pageWidth : this.spreadWidth, - pageHeight : _height - }; -}; - -EPUBJS.Layout.Reflowable.prototype.calculatePages = function() { - var totalWidth, displayedPages; - this.documentElement.style.width = "auto"; //-- reset width for calculations - totalWidth = this.documentElement.scrollWidth; - displayedPages = Math.ceil(totalWidth / this.spreadWidth); - - return { - displayedPages : displayedPages, - pageCount : displayedPages - }; -}; - -EPUBJS.Layout.ReflowableSpreads = function(){ - this.documentElement = null; - this.spreadWidth = null; -}; - -EPUBJS.Layout.ReflowableSpreads.prototype.format = function(documentElement, _width, _height, _gap){ - var columnAxis = EPUBJS.core.prefixed('columnAxis'); - var columnGap = EPUBJS.core.prefixed('columnGap'); - var columnWidth = EPUBJS.core.prefixed('columnWidth'); - var columnFill = EPUBJS.core.prefixed('columnFill'); - - var divisor = 2, - cutoff = 800; - - //-- Check the width and create even width columns - var fullWidth = Math.floor(_width); - var width = (fullWidth % 2 === 0) ? fullWidth : fullWidth - 1; - - var section = Math.floor(width / 8); - var gap = (_gap >= 0) ? _gap : ((section % 2 === 0) ? section : section - 1); - - //-- Double Page - var colWidth = Math.floor((width - gap) / divisor); - - this.documentElement = documentElement; - this.spreadWidth = (colWidth + gap) * divisor; - - - documentElement.style.overflow = "hidden"; - - // Must be set to the new calculated width or the columns will be off - documentElement.style.width = width + "px"; - - //-- Adjust height - documentElement.style.height = _height + "px"; - - //-- Add columns - documentElement.style[columnAxis] = "horizontal"; - documentElement.style[columnFill] = "auto"; - documentElement.style[columnGap] = gap+"px"; - documentElement.style[columnWidth] = colWidth+"px"; - - this.colWidth = colWidth; - this.gap = gap; - return { - pageWidth : this.spreadWidth, - pageHeight : _height - }; -}; - -EPUBJS.Layout.ReflowableSpreads.prototype.calculatePages = function() { - var totalWidth = this.documentElement.scrollWidth; - var displayedPages = Math.ceil(totalWidth / this.spreadWidth); - - //-- Add a page to the width of the document to account an for odd number of pages - this.documentElement.style.width = ((displayedPages * this.spreadWidth) - this.gap) + "px"; - - return { - displayedPages : displayedPages, - pageCount : displayedPages * 2 - }; -}; - -EPUBJS.Layout.Fixed = function(){ - this.documentElement = null; -}; - -EPUBJS.Layout.Fixed.prototype.format = function(documentElement, _width, _height, _gap){ - var columnWidth = EPUBJS.core.prefixed('columnWidth'); - var transform = EPUBJS.core.prefixed('transform'); - var transformOrigin = EPUBJS.core.prefixed('transformOrigin'); - var viewport = documentElement.querySelector("[name=viewport]"); - var content; - var contents; - var width, height; - this.documentElement = documentElement; - /** - * check for the viewport size - * <meta name="viewport" content="width=1024,height=697" /> - */ - if(viewport && viewport.hasAttribute("content")) { - content = viewport.getAttribute("content"); - contents = content.split(','); - if(contents[0]){ - width = contents[0].replace("width=", ''); - } - if(contents[1]){ - height = contents[1].replace("height=", ''); - } - } - - //-- Scale fixed documents so their contents don't overflow, and - // vertically and horizontally center the contents - var widthScale = _width / width; - var heightScale = _height / height; - var scale = widthScale < heightScale ? widthScale : heightScale; - documentElement.style.position = "absolute"; - documentElement.style.top = "50%"; - documentElement.style.left = "50%"; - documentElement.style[transform] = "scale(" + scale + ") translate(-50%, -50%)"; - documentElement.style[transformOrigin] = "0px 0px 0px"; - - //-- Adjust width and height - documentElement.style.width = width + "px" || "auto"; - documentElement.style.height = height + "px" || "auto"; - - //-- Remove columns - documentElement.style[columnWidth] = "auto"; - - //-- Scroll - documentElement.style.overflow = "auto"; - - this.colWidth = width; - this.gap = 0; - - return { - pageWidth : width, - pageHeight : height - }; - -}; - -EPUBJS.Layout.Fixed.prototype.calculatePages = function(){ - return { - displayedPages : 1, - pageCount : 1 - }; -}; - -EPUBJS.Locations = function(spine, store, credentials) { - this.spine = spine; - this.store = store; - this.credentials = credentials; - - this.epubcfi = new EPUBJS.EpubCFI(); - - this._locations = []; - this.total = 0; - - this.break = 150; - - this._current = 0; - -}; - -EPUBJS.Locations.prototype.generate = function(chars) { - var deferred = new RSVP.defer(); - var spinePos = -1; - var spineLength = this.spine.length; - var finished; - var nextChapter = function(deferred){ - var chapter; - var next = spinePos + 1; - var done = deferred || new RSVP.defer(); - var loaded; - if(next >= spineLength) { - done.resolve(); - } else { - spinePos = next; - chapter = new EPUBJS.Chapter(this.spine[spinePos], this.store, this.credentials); - - this.process(chapter).then(function() { - // Load up the next chapter - setTimeout(function(){ - nextChapter(done); - }, 1); - - }); - } - return done.promise; - }.bind(this); - - if(typeof chars === 'number') { - this.break = chars; - } - - finished = nextChapter().then(function(){ - this.total = this._locations.length-1; - - if (this._currentCfi) { - this.currentLocation = this._currentCfi; - } - deferred.resolve(this._locations); - }.bind(this)); - - return deferred.promise; -}; - -EPUBJS.Locations.prototype.process = function(chapter) { - return chapter.load() - .then(function(_doc) { - - var range; - var doc = _doc; - var contents = doc.documentElement.querySelector("body"); - var counter = 0; - var prev; - var cfi; - var _break = this.break; - - this.sprint(contents, function(node) { - var len = node.length; - var dist; - var pos = 0; - - if (node.textContent.trim().length === 0) { - return false; // continue - } - - // Start range - if (counter === 0) { - range = doc.createRange(); - range.setStart(node, 0); - } - - dist = _break - counter; - - // Node is smaller than a break - if(dist > len){ - counter += len; - pos = len; - } - - while (pos < len) { - dist = _break - counter; - - if (counter === 0) { - pos += 1; - range = doc.createRange(); - range.setStart(node, pos); - } - - // Gone over - if(pos + dist >= len){ - // Continue counter for next node - counter += len - pos; - // break - pos = len; - // At End - } else { - // Advance pos - pos += dist; - - // End the previous range - range.setEnd(node, pos); - cfi = chapter.cfiFromRange(range); - this._locations.push(cfi); - counter = 0; - } - } - - prev = node; - - }.bind(this)); - - // Close remaining - if (range) { - range.setEnd(prev, prev.length); - cfi = chapter.cfiFromRange(range); - this._locations.push(cfi); - counter = 0; - } - - }.bind(this)); - -}; - -EPUBJS.Locations.prototype.sprint = function(root, func) { - var node; - var treeWalker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT, null, false); - - while ((node = treeWalker.nextNode())) { - func(node); - } - -}; - -EPUBJS.Locations.prototype.locationFromCfi = function(cfi){ - // Check if the location has not been set yet - if(this._locations.length === 0) { - return -1; - } - - return EPUBJS.core.locationOf(cfi, this._locations, this.epubcfi.compare); -}; - -EPUBJS.Locations.prototype.percentageFromCfi = function(cfi) { - // Find closest cfi - var loc = this.locationFromCfi(cfi); - // Get percentage in total - return this.percentageFromLocation(loc); -}; - -EPUBJS.Locations.prototype.percentageFromLocation = function(loc) { - if (!loc || !this.total) { - return 0; - } - return (loc / this.total); -}; - -EPUBJS.Locations.prototype.cfiFromLocation = function(loc){ - var cfi = -1; - // check that pg is an int - if(typeof loc != "number"){ - loc = parseInt(loc); - } - - if(loc >= 0 && loc < this._locations.length) { - cfi = this._locations[loc]; - } - - return cfi; -}; - -EPUBJS.Locations.prototype.cfiFromPercentage = function(value){ - var percentage = (value > 1) ? value / 100 : value; // Normalize value to 0-1 - var loc = Math.ceil(this.total * percentage); - - return this.cfiFromLocation(loc); -}; - -EPUBJS.Locations.prototype.load = function(locations){ - this._locations = JSON.parse(locations); - this.total = this._locations.length-1; - return this._locations; -}; - -EPUBJS.Locations.prototype.save = function(json){ - return JSON.stringify(this._locations); -}; - -EPUBJS.Locations.prototype.getCurrent = function(json){ - return this._current; -}; - -EPUBJS.Locations.prototype.setCurrent = function(curr){ - var loc; - - if(typeof curr == "string"){ - this._currentCfi = curr; - } else if (typeof curr == "number") { - this._current = curr; - } else { - return; - } - - if(this._locations.length === 0) { - return; - } - - if(typeof curr == "string"){ - loc = this.locationFromCfi(curr); - this._current = loc; - } else { - loc = curr; - } - - this.trigger("changed", { - percentage: this.percentageFromLocation(loc) - }); -}; - -Object.defineProperty(EPUBJS.Locations.prototype, 'currentLocation', { - get: function () { - return this._current; - }, - set: function (curr) { - this.setCurrent(curr); - } -}); - -RSVP.EventTarget.mixin(EPUBJS.Locations.prototype); - -EPUBJS.Pagination = function(pageList) { - this.pages = []; - this.locations = []; - this.epubcfi = new EPUBJS.EpubCFI(); - if(pageList && pageList.length) { - this.process(pageList); - } -}; - -EPUBJS.Pagination.prototype.process = function(pageList){ - pageList.forEach(function(item){ - this.pages.push(item.page); - this.locations.push(item.cfi); - }, this); - - this.pageList = pageList; - this.firstPage = parseInt(this.pages[0]); - this.lastPage = parseInt(this.pages[this.pages.length-1]); - this.totalPages = this.lastPage - this.firstPage; -}; - -EPUBJS.Pagination.prototype.pageFromCfi = function(cfi){ - var pg = -1; - - // Check if the pageList has not been set yet - if(this.locations.length === 0) { - return -1; - } - - // TODO: check if CFI is valid? - - // check if the cfi is in the location list - // var index = this.locations.indexOf(cfi); - var index = EPUBJS.core.indexOfSorted(cfi, this.locations, this.epubcfi.compare); - if(index != -1) { - pg = this.pages[index]; - } else { - // Otherwise add it to the list of locations - // Insert it in the correct position in the locations page - //index = EPUBJS.core.insert(cfi, this.locations, this.epubcfi.compare); - index = EPUBJS.core.locationOf(cfi, this.locations, this.epubcfi.compare); - // Get the page at the location just before the new one, or return the first - pg = index-1 >= 0 ? this.pages[index-1] : this.pages[0]; - if(pg !== undefined) { - // Add the new page in so that the locations and page array match up - //this.pages.splice(index, 0, pg); - } else { - pg = -1; - } - - } - return pg; -}; - -EPUBJS.Pagination.prototype.cfiFromPage = function(pg){ - var cfi = -1; - // check that pg is an int - if(typeof pg != "number"){ - pg = parseInt(pg); - } - - // check if the cfi is in the page list - // Pages could be unsorted. - var index = this.pages.indexOf(pg); - if(index != -1) { - cfi = this.locations[index]; - } - // TODO: handle pages not in the list - return cfi; -}; - -EPUBJS.Pagination.prototype.pageFromPercentage = function(percent){ - var pg = Math.round(this.totalPages * percent); - return pg; -}; - -// Returns a value between 0 - 1 corresponding to the location of a page -EPUBJS.Pagination.prototype.percentageFromPage = function(pg){ - var percentage = (pg - this.firstPage) / this.totalPages; - return Math.round(percentage * 1000) / 1000; -}; - -// Returns a value between 0 - 1 corresponding to the location of a cfi -EPUBJS.Pagination.prototype.percentageFromCfi = function(cfi){ - var pg = this.pageFromCfi(cfi); - var percentage = this.percentageFromPage(pg); - return percentage; -}; -EPUBJS.Parser = function(baseUrl){ - this.baseUrl = baseUrl || ''; -}; - -EPUBJS.Parser.prototype.container = function(containerXml){ - //-- <rootfile full-path="OPS/package.opf" media-type="application/oebps-package+xml"/> - var rootfile, fullpath, folder, encoding; - - if(!containerXml) { - console.error("Container File Not Found"); - return; - } - - rootfile = containerXml.querySelector("rootfile"); - - if(!rootfile) { - console.error("No RootFile Found"); - return; - } - - fullpath = rootfile.getAttribute('full-path'); - folder = EPUBJS.core.uri(fullpath).directory; - encoding = containerXml.xmlEncoding; - - //-- Now that we have the path we can parse the contents - return { - 'packagePath' : fullpath, - 'basePath' : folder, - 'encoding' : encoding - }; -}; - -EPUBJS.Parser.prototype.identifier = function(packageXml){ - var metadataNode; - - if(!packageXml) { - console.error("Package File Not Found"); - return; - } - - metadataNode = packageXml.querySelector("metadata"); - - if(!metadataNode) { - console.error("No Metadata Found"); - return; - } - - return this.getElementText(metadataNode, "identifier"); -}; - -EPUBJS.Parser.prototype.packageContents = function(packageXml, baseUrl){ - var parse = this; - var metadataNode, manifestNode, spineNode; - var manifest, navPath, tocPath, coverPath; - var spineNodeIndex; - var spine; - var spineIndexByURL; - var metadata; - - if(baseUrl) this.baseUrl = baseUrl; - - if(!packageXml) { - console.error("Package File Not Found"); - return; - } - - metadataNode = packageXml.querySelector("metadata"); - if(!metadataNode) { - console.error("No Metadata Found"); - return; - } - - manifestNode = packageXml.querySelector("manifest"); - if(!manifestNode) { - console.error("No Manifest Found"); - return; - } - - spineNode = packageXml.querySelector("spine"); - if(!spineNode) { - console.error("No Spine Found"); - return; - } - - manifest = parse.manifest(manifestNode); - navPath = parse.findNavPath(manifestNode); - tocPath = parse.findTocPath(manifestNode, spineNode); - coverPath = parse.findCoverPath(packageXml); - - spineNodeIndex = Array.prototype.indexOf.call(spineNode.parentNode.childNodes, spineNode); - - spine = parse.spine(spineNode, manifest); - - spineIndexByURL = {}; - spine.forEach(function(item){ - spineIndexByURL[item.href] = item.index; - }); - - metadata = parse.metadata(metadataNode); - - metadata.direction = spineNode.getAttribute("page-progression-direction"); - - return { - 'metadata' : metadata, - 'spine' : spine, - 'manifest' : manifest, - 'navPath' : navPath, - 'tocPath' : tocPath, - 'coverPath': coverPath, - 'spineNodeIndex' : spineNodeIndex, - 'spineIndexByURL' : spineIndexByURL - }; -}; - -//-- Find TOC NAV -EPUBJS.Parser.prototype.findNavPath = function(manifestNode){ - // Find item with property 'nav' - // Should catch nav irregardless of order - var node = manifestNode.querySelector("item[properties$='nav'], item[properties^='nav '], item[properties*=' nav ']"); - return node ? node.getAttribute('href') : false; -}; - -//-- Find TOC NCX: media-type="application/x-dtbncx+xml" href="toc.ncx" -EPUBJS.Parser.prototype.findTocPath = function(manifestNode, spineNode){ - var node = manifestNode.querySelector("item[media-type='application/x-dtbncx+xml']"); - var tocId; - - // If we can't find the toc by media-type then try to look for id of the item in the spine attributes as - // according to http://www.idpf.org/epub/20/spec/OPF_2.0.1_draft.htm#Section2.4.1.2, - // "The item that describes the NCX must be referenced by the spine toc attribute." - if (!node) { - tocId = spineNode.getAttribute("toc"); - if(tocId) { - node = manifestNode.querySelector("item[id='" + tocId + "']"); - } - } - - return node ? node.getAttribute('href') : false; -}; - -//-- Expanded to match Readium web components -EPUBJS.Parser.prototype.metadata = function(xml){ - var metadata = {}, - p = this; - - metadata.bookTitle = p.getElementText(xml, 'title'); - metadata.creator = p.getElementText(xml, 'creator'); - metadata.description = p.getElementText(xml, 'description'); - - metadata.pubdate = p.getElementText(xml, 'date'); - - metadata.publisher = p.getElementText(xml, 'publisher'); - - metadata.identifier = p.getElementText(xml, "identifier"); - metadata.language = p.getElementText(xml, "language"); - metadata.rights = p.getElementText(xml, "rights"); - - metadata.modified_date = p.querySelectorText(xml, "meta[property='dcterms:modified']"); - metadata.layout = p.querySelectorText(xml, "meta[property='rendition:layout']"); - metadata.orientation = p.querySelectorText(xml, "meta[property='rendition:orientation']"); - metadata.spread = p.querySelectorText(xml, "meta[property='rendition:spread']"); - - return metadata; -}; - -//-- Find Cover: <item properties="cover-image" id="ci" href="cover.svg" media-type="image/svg+xml" /> -//-- Fallback for Epub 2.0 -EPUBJS.Parser.prototype.findCoverPath = function(packageXml){ - - var epubVersion = packageXml.querySelector('package').getAttribute('version'); - if (epubVersion === '2.0') { - var metaCover = packageXml.querySelector('meta[name="cover"]'); - if (metaCover) { - var coverId = metaCover.getAttribute('content'); - var cover = packageXml.querySelector("item[id='" + coverId + "']"); - return cover ? cover.getAttribute('href') : false; - } - else { - return false; - } - } - else { - var node = packageXml.querySelector("item[properties='cover-image']"); - return node ? node.getAttribute('href') : false; - } -}; - -EPUBJS.Parser.prototype.getElementText = function(xml, tag){ - var found = xml.getElementsByTagNameNS("http://purl.org/dc/elements/1.1/", tag), - el; - - if(!found || found.length === 0) return ''; - - el = found[0]; - - if(el.childNodes.length){ - return el.childNodes[0].nodeValue; - } - - return ''; - -}; - -EPUBJS.Parser.prototype.querySelectorText = function(xml, q){ - var el = xml.querySelector(q); - - if(el && el.childNodes.length){ - return el.childNodes[0].nodeValue; - } - - return ''; -}; - -EPUBJS.Parser.prototype.manifest = function(manifestXml){ - var baseUrl = this.baseUrl, - manifest = {}; - - //-- Turn items into an array - var selected = manifestXml.querySelectorAll("item"), - items = Array.prototype.slice.call(selected); - - //-- Create an object with the id as key - items.forEach(function(item){ - var id = item.getAttribute('id'), - href = item.getAttribute('href') || '', - type = item.getAttribute('media-type') || '', - properties = item.getAttribute('properties') || ''; - - manifest[id] = { - 'href' : href, - 'url' : baseUrl + href, //-- Absolute URL for loading with a web worker - 'type' : type, - 'properties' : properties - }; - - }); - - return manifest; - -}; - -EPUBJS.Parser.prototype.spine = function(spineXml, manifest){ - var selected = spineXml.getElementsByTagName("itemref"), - items = Array.prototype.slice.call(selected); - - // var spineNodeIndex = Array.prototype.indexOf.call(spineXml.parentNode.childNodes, spineXml); - var spineNodeIndex = EPUBJS.core.indexOfElementNode(spineXml); - - var epubcfi = new EPUBJS.EpubCFI(); - - //-- Add to array to mantain ordering and cross reference with manifest - return items.map(function(item, index) { - var Id = item.getAttribute('idref'); - var cfiBase = epubcfi.generateChapterComponent(spineNodeIndex, index, Id); - var props = item.getAttribute('properties') || ''; - var propArray = props.length ? props.split(' ') : []; - var manifestProps = manifest[Id].properties; - var manifestPropArray = manifestProps.length ? manifestProps.split(' ') : []; - return { - 'id' : Id, - 'linear' : item.getAttribute('linear') || '', - 'properties' : propArray, - 'manifestProperties' : manifestPropArray, - 'href' : manifest[Id].href, - 'url' : manifest[Id].url, - 'index' : index, - 'cfiBase' : cfiBase, - 'cfi' : "epubcfi(" + cfiBase + ")" - }; - }); -}; - -EPUBJS.Parser.prototype.querySelectorByType = function(html, element, type){ - var query = html.querySelector(element+'[*|type="'+type+'"]'); - // Handle IE not supporting namespaced epub:type in querySelector - if(query === null || query.length === 0) { - query = html.querySelectorAll(element); - for (var i = 0; i < query.length; i++) { - if(query[i].getAttributeNS("http://www.idpf.org/2007/ops", "type") === type) { - return query[i]; - } - } - } else { - return query; - } -}; - -EPUBJS.Parser.prototype.nav = function (navHtml, spineIndexByURL, bookSpine) { - var toc = this.querySelectorByType(navHtml, 'nav', 'toc'); - return this.navItems(toc, spineIndexByURL, bookSpine); -}; - -EPUBJS.Parser.prototype.navItems = function (navNode, spineIndexByURL, bookSpine) { - if (!navNode) return []; - - var list = navNode.querySelector('ol'); - if (!list) return []; - - var items = list.childNodes, - result = []; - - Array.prototype.forEach.call(items, function (item) { - if (item.tagName !== 'li') return; - - var content = item.querySelector('a, span'), - href = content.getAttribute('href') || '', - label = content.textContent || '', - split = href.split('#'), - baseUrl = split[0], - spinePos = spineIndexByURL[baseUrl], - spineItem = bookSpine[spinePos], - cfi = spineItem ? spineItem.cfi : '', - subitems = this.navItems(item, spineIndexByURL, bookSpine); - - result.push({ - href: href, - label: label, - spinePos: spinePos, - subitems: subitems, - cfi: cfi - }); - }.bind(this)); - - return result; -}; - -EPUBJS.Parser.prototype.toc = function(tocXml, spineIndexByURL, bookSpine){ - var navPoints = tocXml.querySelectorAll("navMap navPoint"); - var length = navPoints.length; - var i; - var toc = {}; - var list = []; - var item, parent; - - if(!navPoints || length === 0) return list; - - for (i = 0; i < length; ++i) { - item = this.tocItem(navPoints[i], spineIndexByURL, bookSpine); - toc[item.id] = item; - if(!item.parent) { - list.push(item); - } else { - parent = toc[item.parent]; - parent.subitems.push(item); - } - } - - return list; -}; - -EPUBJS.Parser.prototype.tocItem = function(item, spineIndexByURL, bookSpine){ - var id = item.getAttribute('id') || false, - content = item.querySelector("content"), - src = content.getAttribute('src'), - navLabel = item.querySelector("navLabel"), - text = navLabel.textContent ? navLabel.textContent : "", - split = src.split("#"), - baseUrl = split[0], - spinePos = spineIndexByURL[baseUrl], - spineItem = bookSpine[spinePos], - subitems = [], - parentNode = item.parentNode, - parent, - cfi = spineItem ? spineItem.cfi : ''; - - if(parentNode && parentNode.nodeName === "navPoint") { - parent = parentNode.getAttribute('id'); - } - - if(!id) { - if(spinePos) { - spineItem = bookSpine[spinePos]; - id = spineItem.id; - cfi = spineItem.cfi; - } else { - id = 'epubjs-autogen-toc-id-' + EPUBJS.core.uuid(); - item.setAttribute('id', id); - } - } - - return { - "id": id, - "href": src, - "label": text, - "spinePos": spinePos, - "subitems" : subitems, - "parent" : parent, - "cfi" : cfi - }; -}; - - -EPUBJS.Parser.prototype.pageList = function(navHtml, spineIndexByURL, bookSpine){ - var navElement = this.querySelectorByType(navHtml, "nav", "page-list"); - var navItems = navElement ? navElement.querySelectorAll("ol li") : []; - var length = navItems.length; - var i; - var toc = {}; - var list = []; - var item; - - if(!navItems || length === 0) return list; - - for (i = 0; i < length; ++i) { - item = this.pageListItem(navItems[i], spineIndexByURL, bookSpine); - list.push(item); - } - - return list; -}; - -EPUBJS.Parser.prototype.pageListItem = function(item, spineIndexByURL, bookSpine){ - var id = item.getAttribute('id') || false, - content = item.querySelector("a"), - href = content.getAttribute('href') || '', - text = content.textContent || "", - page = parseInt(text), - isCfi = href.indexOf("epubcfi"), - split, - packageUrl, - cfi; - - if(isCfi != -1) { - split = href.split("#"); - packageUrl = split[0]; - cfi = split.length > 1 ? split[1] : false; - return { - "cfi" : cfi, - "href" : href, - "packageUrl" : packageUrl, - "page" : page - }; - } else { - return { - "href" : href, - "page" : page - }; - } -}; - -EPUBJS.Render.Iframe = function() { - this.iframe = null; - this.document = null; - this.window = null; - this.docEl = null; - this.bodyEl = null; - - this.leftPos = 0; - this.pageWidth = 0; - this.id = EPUBJS.core.uuid(); -}; - -//-- Build up any html needed -EPUBJS.Render.Iframe.prototype.create = function(){ - this.element = document.createElement('div'); - this.element.id = "epubjs-view:" + this.id; - - this.isMobile = navigator.userAgent.match(/(iPad|iPhone|iPod|Mobile|Android)/g); - this.transform = EPUBJS.core.prefixed('transform'); - - return this.element; -}; - -EPUBJS.Render.Iframe.prototype.addIframe = function(){ - this.iframe = document.createElement('iframe'); - this.iframe.id = "epubjs-iframe:" + this.id; - this.iframe.scrolling = this.scrolling || "no"; - this.iframe.seamless = "seamless"; - // Back up if seamless isn't supported - this.iframe.style.border = "none"; - - this.iframe.addEventListener("load", this.loaded.bind(this), false); - - if (this._width || this._height) { - this.iframe.height = this._height; - this.iframe.width = this._width; - } - return this.iframe; -}; - -/** -* Sets the source of the iframe with the given URL string -* Takes: Document Contents String -* Returns: promise with document element -*/ -EPUBJS.Render.Iframe.prototype.load = function(contents, url){ - var render = this, - deferred = new RSVP.defer(); - - if(this.window) { - this.unload(); - } - - if (this.iframe) { - this.element.removeChild(this.iframe); - } - - this.iframe = this.addIframe(); - this.element.appendChild(this.iframe); - - - this.iframe.onload = function(e) { - var title; - - render.document = render.iframe.contentDocument; - render.docEl = render.document.documentElement; - render.headEl = render.document.head; - render.bodyEl = render.document.body || render.document.querySelector("body"); - render.window = render.iframe.contentWindow; - - render.window.addEventListener("resize", render.resized.bind(render), false); - - // Reset the scroll position - render.leftPos = 0; - render.setLeft(0); - - //-- Clear Margins - if(render.bodyEl) { - render.bodyEl.style.margin = "0"; - } - - deferred.resolve(render.docEl); - }; - - this.iframe.onerror = function(e) { - //console.error("Error Loading Contents", e); - deferred.reject({ - message : "Error Loading Contents: " + e, - stack : new Error().stack - }); - }; - - // this.iframe.contentWindow.location.replace(url); - this.document = this.iframe.contentDocument; - - if(!this.document) { - deferred.reject(new Error("No Document Available")); - return deferred.promise; - } - - this.iframe.contentDocument.open(); - this.iframe.contentDocument.write(contents); - this.iframe.contentDocument.close(); - - return deferred.promise; -}; - - -EPUBJS.Render.Iframe.prototype.loaded = function(v){ - var url = this.iframe.contentWindow.location.href; - var baseEl, base; - - this.document = this.iframe.contentDocument; - this.docEl = this.document.documentElement; - this.headEl = this.document.head; - this.bodyEl = this.document.body || this.document.querySelector("body"); - this.window = this.iframe.contentWindow; - this.window.focus(); - - if(url != "about:blank"){ - baseEl = this.iframe.contentDocument.querySelector("base"); - base = baseEl.getAttribute('href'); - this.trigger("render:loaded", base); - } - -}; - -// Resize the iframe to the given width and height -EPUBJS.Render.Iframe.prototype.resize = function(width, height){ - var iframeBox; - - if(!this.element) return; - - this.element.style.height = height; - - - if(!isNaN(width) && width % 2 !== 0){ - width += 1; //-- Prevent cutting off edges of text in columns - } - - this.element.style.width = width; - - if (this.iframe) { - this.iframe.height = height; - this.iframe.width = width; - } - - // Set the width for the iframe - this._height = height; - this._width = width; - - // Get the fractional height and width of the iframe - // Default to orginal if bounding rect is 0 - this.width = this.element.getBoundingClientRect().width || width; - this.height = this.element.getBoundingClientRect().height || height; - -}; - - -EPUBJS.Render.Iframe.prototype.resized = function(e){ - // Get the fractional height and width of the iframe - this.width = this.iframe.getBoundingClientRect().width; - this.height = this.iframe.getBoundingClientRect().height; -}; - -EPUBJS.Render.Iframe.prototype.totalWidth = function(){ - return this.docEl.scrollWidth; -}; - -EPUBJS.Render.Iframe.prototype.totalHeight = function(){ - return this.docEl.scrollHeight; -}; - -EPUBJS.Render.Iframe.prototype.setPageDimensions = function(pageWidth, pageHeight){ - this.pageWidth = pageWidth; - this.pageHeight = pageHeight; - //-- Add a page to the width of the document to account an for odd number of pages - // this.docEl.style.width = this.docEl.scrollWidth + pageWidth + "px"; -}; - -EPUBJS.Render.Iframe.prototype.setDirection = function(direction){ - - this.direction = direction; - - // Undo previous changes if needed - if(this.docEl && this.docEl.dir == "rtl"){ - this.docEl.dir = "rtl"; - if (this.layout !== "pre-paginated") { - this.docEl.style.position = "static"; - this.docEl.style.right = "auto"; - } - } - -}; - -EPUBJS.Render.Iframe.prototype.setLeft = function(leftPos){ - // this.bodyEl.style.marginLeft = -leftPos + "px"; - // this.docEl.style.marginLeft = -leftPos + "px"; - // this.docEl.style[EPUBJS.Render.Iframe.transform] = 'translate('+ (-leftPos) + 'px, 0)'; - - if (this.isMobile) { - this.docEl.style[this.transform] = 'translate('+ (-leftPos) + 'px, 0)'; - } else { - this.document.defaultView.scrollTo(leftPos, 0); - } - -}; - -EPUBJS.Render.Iframe.prototype.setLayout = function (layout) { - this.layout = layout; -}; - -EPUBJS.Render.Iframe.prototype.setStyle = function(style, val, prefixed){ - if(prefixed) { - style = EPUBJS.core.prefixed(style); - } - - if(this.bodyEl) this.bodyEl.style[style] = val; -}; - -EPUBJS.Render.Iframe.prototype.removeStyle = function(style){ - - if(this.bodyEl) this.bodyEl.style[style] = ''; - -}; - -EPUBJS.Render.Iframe.prototype.setClasses = function(classes){ - if(this.bodyEl) this.bodyEl.className = classes.join(" "); -}; - -EPUBJS.Render.Iframe.prototype.addHeadTag = function(tag, attrs, _doc) { - var doc = _doc || this.document; - var tagEl = doc.createElement(tag); - var headEl = doc.head; - - for(var attr in attrs) { - tagEl.setAttribute(attr, attrs[attr]); - } - - if(headEl) headEl.insertBefore(tagEl, headEl.firstChild); -}; - -EPUBJS.Render.Iframe.prototype.page = function(pg){ - this.leftPos = this.pageWidth * (pg-1); //-- pages start at 1 - - // Reverse for rtl langs - if(this.direction === "rtl"){ - this.leftPos = this.leftPos * -1; - } - - this.setLeft(this.leftPos); -}; - -//-- Show the page containing an Element -EPUBJS.Render.Iframe.prototype.getPageNumberByElement = function(el){ - var left, pg; - if(!el) return; - - left = this.leftPos + el.getBoundingClientRect().left; //-- Calculate left offset compaired to scrolled position - - pg = Math.floor(left / this.pageWidth) + 1; //-- pages start at 1 - - return pg; -}; - -//-- Show the page containing an Element -EPUBJS.Render.Iframe.prototype.getPageNumberByRect = function(boundingClientRect){ - var left, pg; - - left = this.leftPos + boundingClientRect.left; //-- Calculate left offset compaired to scrolled position - pg = Math.floor(left / this.pageWidth) + 1; //-- pages start at 1 - - return pg; -}; - -// Return the root element of the content -EPUBJS.Render.Iframe.prototype.getBaseElement = function(){ - return this.bodyEl; -}; - -// Return the document element -EPUBJS.Render.Iframe.prototype.getDocumentElement = function(){ - return this.docEl; -}; - -// Checks if an element is on the screen -EPUBJS.Render.Iframe.prototype.isElementVisible = function(el){ - var rect; - var left; - - if(el && typeof el.getBoundingClientRect === 'function'){ - rect = el.getBoundingClientRect(); - left = rect.left; //+ rect.width; - if( rect.width !== 0 && - rect.height !== 0 && // Element not visible - left >= 0 && - left < this.pageWidth ) { - return true; - } - } - - return false; -}; - - -EPUBJS.Render.Iframe.prototype.scroll = function(bool){ - if(bool) { - // this.iframe.scrolling = "yes"; - this.scrolling = "yes"; - } else { - this.scrolling = "no"; - // this.iframe.scrolling = "no"; - } -}; - -// Cleanup event listeners -EPUBJS.Render.Iframe.prototype.unload = function(){ - this.window.removeEventListener("resize", this.resized); - this.iframe.removeEventListener("load", this.loaded); -}; - -//-- Enable binding events to Render -RSVP.EventTarget.mixin(EPUBJS.Render.Iframe.prototype); - -EPUBJS.Renderer = function(renderMethod, hidden) { - // Dom events to listen for - this.listenedEvents = ["keydown", "keyup", "keypressed", "mouseup", "mousedown", "click"]; - this.upEvent = "mouseup"; - this.downEvent = "mousedown"; - if('ontouchstart' in document.documentElement) { - this.listenedEvents.push("touchstart", "touchend"); - this.upEvent = "touchend"; - this.downEvent = "touchstart"; - } - /** - * Setup a render method. - * Options are: Iframe - */ - if(renderMethod && typeof(EPUBJS.Render[renderMethod]) != "undefined"){ - this.render = new EPUBJS.Render[renderMethod](); - } else { - console.error("Not a Valid Rendering Method"); - } - - // Listen for load events - this.render.on("render:loaded", this.loaded.bind(this)); - - // Cached for replacement urls from storage - this.caches = {}; - - // Blank Cfi for Parsing - this.epubcfi = new EPUBJS.EpubCFI(); - - this.spreads = true; - this.isForcedSingle = false; - this.resized = this.onResized.bind(this); - - this.layoutSettings = {}; - - this.hidden = hidden || false; - //-- Adds Hook methods to the Book prototype - // Hooks will all return before triggering the callback. - EPUBJS.Hooks.mixin(this); - //-- Get pre-registered hooks for events - this.getHooks("beforeChapterDisplay"); - - //-- Queue up page changes if page map isn't ready - this._q = EPUBJS.core.queue(this); - - this._moving = false; - -}; - -//-- Renderer events for listening -EPUBJS.Renderer.prototype.Events = [ - "renderer:keydown", - "renderer:keyup", - "renderer:keypressed", - "renderer:mouseup", - "renderer:mousedown", - "renderer:click", - "renderer:touchstart", - "renderer:touchend", - "renderer:selected", - "renderer:chapterUnload", - "renderer:chapterUnloaded", - "renderer:chapterDisplayed", - "renderer:locationChanged", - "renderer:visibleLocationChanged", - "renderer:visibleRangeChanged", - "renderer:resized", - "renderer:spreads", - "renderer:beforeResize" -]; - -/** -* Creates an element to render to. -* Resizes to passed width and height or to the elements size -*/ -EPUBJS.Renderer.prototype.initialize = function(element, width, height){ - this.container = element; - this.element = this.render.create(); - - this.initWidth = width; - this.initHeight = height; - - this.width = width || this.container.clientWidth; - this.height = height || this.container.clientHeight; - - this.container.appendChild(this.element); - - if(width && height){ - this.render.resize(this.width, this.height); - } else { - this.render.resize('100%', '100%'); - } - - document.addEventListener("orientationchange", this.onResized.bind(this)); -}; - -/** -* Display a chapter -* Takes: chapter object, global layout settings -* Returns: Promise with passed Renderer after pages has loaded -*/ -EPUBJS.Renderer.prototype.displayChapter = function(chapter, globalLayout){ - var store = false; - if(this._moving) { - console.warning("Rendering In Progress"); - var deferred = new RSVP.defer(); - deferred.reject({ - message : "Rendering In Progress", - stack : new Error().stack - }); - return deferred.promise; - } - this._moving = true; - // Get the url string from the chapter (may be from storage) - return chapter.render(). - then(function(contents) { - - // Unload the previous chapter listener - if(this.currentChapter) { - this.trigger("renderer:chapterUnload"); - this.currentChapter.unload(); // Remove stored blobs - - if(this.render.window){ - this.render.window.removeEventListener("resize", this.resized); - } - - this.removeEventListeners(); - this.removeSelectionListeners(); - this.trigger("renderer:chapterUnloaded"); - this.contents = null; - this.doc = null; - this.pageMap = null; - } - - this.currentChapter = chapter; - - this.chapterPos = 1; - - this.currentChapterCfiBase = chapter.cfiBase; - - this.layoutSettings = this.reconcileLayoutSettings(globalLayout, chapter.properties); - - return this.load(contents, chapter.href); - - }.bind(this), function() { - this._moving = false; - }.bind(this)); - -}; - -/** -* Loads a url (string) and renders it, -* attaching event listeners and triggering hooks. -* Returns: Promise with the rendered contents. -*/ - -EPUBJS.Renderer.prototype.load = function(contents, url){ - var deferred = new RSVP.defer(); - var loaded; - - // Switch to the required layout method for the settings - this.layoutMethod = this.determineLayout(this.layoutSettings); - this.layout = new EPUBJS.Layout[this.layoutMethod](); - - this.visible(false); - - this.render.load(contents, url).then(function(contents) { - - // Duck-type fixed layout books. - if (EPUBJS.Layout.isFixedLayout(contents)) { - this.layoutSettings.layout = "pre-paginated"; - this.layoutMethod = this.determineLayout(this.layoutSettings); - this.layout = new EPUBJS.Layout[this.layoutMethod](); - } - this.render.setLayout(this.layoutSettings.layout); - - // HTML element must have direction set if RTL or columnns will - // not be in the correct direction in Firefox - // Firefox also need the html element to be position right - if(this.render.direction == "rtl" && this.render.docEl.dir != "rtl"){ - this.render.docEl.dir = "rtl"; - if (this.render.layout !== "pre-paginated") { - this.render.docEl.style.position = "absolute"; - this.render.docEl.style.right = "0"; - } - } - - this.afterLoad(contents); - - //-- Trigger registered hooks before displaying - this.beforeDisplay(function(){ - - this.afterDisplay(); - - this.visible(true); - - - deferred.resolve(this); //-- why does this return the renderer? - - }.bind(this)); - - }.bind(this)); - - return deferred.promise; -}; - -EPUBJS.Renderer.prototype.afterLoad = function(contents) { - var formated; - // this.currentChapter.setDocument(this.render.document); - this.contents = contents; - this.doc = this.render.document; - - // Format the contents using the current layout method - this.formated = this.layout.format(contents, this.render.width, this.render.height, this.gap); - this.render.setPageDimensions(this.formated.pageWidth, this.formated.pageHeight); - - // window.addEventListener("orientationchange", this.onResized.bind(this), false); - if(!this.initWidth && !this.initHeight){ - this.render.window.addEventListener("resize", this.resized, false); - } - - this.addEventListeners(); - this.addSelectionListeners(); - -}; - -EPUBJS.Renderer.prototype.afterDisplay = function(contents) { - - var pages = this.layout.calculatePages(); - var msg = this.currentChapter; - var queued = this._q.length(); - this._moving = false; - - this.updatePages(pages); - - this.visibleRangeCfi = this.getVisibleRangeCfi(); - this.currentLocationCfi = this.visibleRangeCfi.start; - - if(queued === 0) { - this.trigger("renderer:locationChanged", this.currentLocationCfi); - this.trigger("renderer:visibleRangeChanged", this.visibleRangeCfi); - } - - msg.cfi = this.currentLocationCfi; //TODO: why is this cfi passed to chapterDisplayed - this.trigger("renderer:chapterDisplayed", msg); - -}; - -EPUBJS.Renderer.prototype.loaded = function(url){ - this.trigger("render:loaded", url); - // var uri = EPUBJS.core.uri(url); - // var relative = uri.path.replace(book.bookUrl, ''); - // console.log(url, uri, relative); -}; - -/** -* Reconciles the current chapters layout properies with -* the global layout properities. -* Takes: global layout settings object, chapter properties string -* Returns: Object with layout properties -*/ -EPUBJS.Renderer.prototype.reconcileLayoutSettings = function(global, chapter){ - var settings = {}; - - //-- Get the global defaults - for (var attr in global) { - if (global.hasOwnProperty(attr)){ - settings[attr] = global[attr]; - } - } - //-- Get the chapter's display type - chapter.forEach(function(prop){ - var rendition = prop.replace("rendition:", ''); - var split = rendition.indexOf("-"); - var property, value; - - if(split != -1){ - property = rendition.slice(0, split); - value = rendition.slice(split+1); - - settings[property] = value; - } - }); - return settings; -}; - -/** -* Uses the settings to determine which Layout Method is needed -* Triggers events based on the method choosen -* Takes: Layout settings object -* Returns: String of appropriate for EPUBJS.Layout function -*/ -EPUBJS.Renderer.prototype.determineLayout = function(settings){ - // Default is layout: reflowable & spread: auto - var spreads = this.determineSpreads(this.minSpreadWidth); - var layoutMethod = spreads ? "ReflowableSpreads" : "Reflowable"; - var scroll = false; - - if(settings.layout === "pre-paginated") { - layoutMethod = "Fixed"; - scroll = true; - spreads = false; - } - - if(settings.layout === "reflowable" && settings.spread === "none") { - layoutMethod = "Reflowable"; - scroll = false; - spreads = false; - } - - if(settings.layout === "reflowable" && settings.spread === "both") { - layoutMethod = "ReflowableSpreads"; - scroll = false; - spreads = true; - } - - this.spreads = spreads; - this.render.scroll(scroll); - this.trigger("renderer:spreads", spreads); - return layoutMethod; -}; - -// Shortcut to trigger the hook before displaying the chapter -EPUBJS.Renderer.prototype.beforeDisplay = function(callback, renderer){ - this.triggerHooks("beforeChapterDisplay", callback, this); -}; - -// Update the renderer with the information passed by the layout -EPUBJS.Renderer.prototype.updatePages = function(layout){ - this.pageMap = this.mapPage(); - // this.displayedPages = layout.displayedPages; - - if (this.spreads) { - this.displayedPages = Math.ceil(this.pageMap.length / 2); - } else { - this.displayedPages = this.pageMap.length; - } - - this.currentChapter.pages = this.pageMap.length; - - this._q.flush(); -}; - -// Apply the layout again and jump back to the previous cfi position -EPUBJS.Renderer.prototype.reformat = function(){ - var renderer = this; - var formated, pages; - var spreads; - - if(!this.contents) return; - - spreads = this.determineSpreads(this.minSpreadWidth); - - // Only re-layout if the spreads have switched - if(spreads != this.spreads){ - this.spreads = spreads; - this.layoutMethod = this.determineLayout(this.layoutSettings); - this.layout = new EPUBJS.Layout[this.layoutMethod](); - } - - // Reset pages - this.chapterPos = 1; - - this.render.page(this.chapterPos); - // Give the css styles time to update - // clearTimeout(this.timeoutTillCfi); - // this.timeoutTillCfi = setTimeout(function(){ - renderer.formated = renderer.layout.format(renderer.render.docEl, renderer.render.width, renderer.render.height, renderer.gap); - renderer.render.setPageDimensions(renderer.formated.pageWidth, renderer.formated.pageHeight); - - pages = renderer.layout.calculatePages(); - renderer.updatePages(pages); - - //-- Go to current page after formating - if(renderer.currentLocationCfi){ - renderer.gotoCfi(renderer.currentLocationCfi); - } - // renderer.timeoutTillCfi = null; - -}; - -// Hide and show the render's container . -EPUBJS.Renderer.prototype.visible = function(bool){ - if(typeof(bool) === "undefined") { - return this.element.style.visibility; - } - - if(bool === true && !this.hidden){ - this.element.style.visibility = "visible"; - }else if(bool === false){ - this.element.style.visibility = "hidden"; - } -}; - -// Remove the render element and clean up listeners -EPUBJS.Renderer.prototype.remove = function() { - if(this.render.window) { - this.render.unload(); - this.render.window.removeEventListener("resize", this.resized); - this.removeEventListeners(); - this.removeSelectionListeners(); - } - - // clean container content - //this.container.innerHtml = ""; // not safe - this.container.removeChild(this.element); -}; - -//-- STYLES - -EPUBJS.Renderer.prototype.applyStyles = function(styles) { - for (var style in styles) { - this.render.setStyle(style, styles[style]); - } -}; - -EPUBJS.Renderer.prototype.setStyle = function(style, val, prefixed){ - this.render.setStyle(style, val, prefixed); -}; - -EPUBJS.Renderer.prototype.removeStyle = function(style){ - this.render.removeStyle(style); -}; - -EPUBJS.Renderer.prototype.setClasses = function(classes){ - this.render.setClasses(classes); -}; - -//-- HEAD TAGS -EPUBJS.Renderer.prototype.applyHeadTags = function(headTags) { - for ( var headTag in headTags ) { - this.render.addHeadTag(headTag, headTags[headTag]); - } -}; - -//-- NAVIGATION - -EPUBJS.Renderer.prototype.page = function(pg){ - if(!this.pageMap) { - console.warn("pageMap not set, queuing"); - this._q.enqueue("page", arguments); - return true; - } - - if(pg >= 1 && pg <= this.displayedPages){ - this.chapterPos = pg; - - this.render.page(pg); - this.visibleRangeCfi = this.getVisibleRangeCfi(); - this.currentLocationCfi = this.visibleRangeCfi.start; - this.trigger("renderer:locationChanged", this.currentLocationCfi); - this.trigger("renderer:visibleRangeChanged", this.visibleRangeCfi); - - return true; - } - //-- Return false if page is greater than the total - return false; -}; - -// Short cut to find next page's cfi starting at the last visible element -/* -EPUBJS.Renderer.prototype.nextPage = function(){ - var pg = this.chapterPos + 1; - if(pg <= this.displayedPages){ - this.chapterPos = pg; - - this.render.page(pg); - - this.currentLocationCfi = this.getPageCfi(this.visibileEl); - this.trigger("renderer:locationChanged", this.currentLocationCfi); - - return true; - } - //-- Return false if page is greater than the total - return false; -}; -*/ -EPUBJS.Renderer.prototype.nextPage = function(){ - return this.page(this.chapterPos + 1); -}; - -EPUBJS.Renderer.prototype.prevPage = function(){ - return this.page(this.chapterPos - 1); -}; - -//-- Show the page containing an Element -EPUBJS.Renderer.prototype.pageByElement = function(el){ - var pg; - if(!el) return; - - pg = this.render.getPageNumberByElement(el); - this.page(pg); -}; - -// Jump to the last page of the chapter -EPUBJS.Renderer.prototype.lastPage = function(){ - if(this._moving) { - return this._q.enqueue("lastPage", arguments); - } - - this.page(this.displayedPages); -}; - -// Jump to the first page of the chapter -EPUBJS.Renderer.prototype.firstPage = function(){ - if(this._moving) { - return this._q.enqueue("firstPage", arguments); - } - - this.page(1); -}; - -//-- Find a section by fragement id -EPUBJS.Renderer.prototype.section = function(fragment){ - var el = this.doc.getElementById(fragment); - - if(el){ - this.pageByElement(el); - } - -}; - -EPUBJS.Renderer.prototype.firstElementisTextNode = function(node) { - var children = node.childNodes; - var leng = children.length; - - if(leng && - children[0] && // First Child - children[0].nodeType === 3 && // This is a textNodes - children[0].textContent.trim().length) { // With non whitespace or return characters - return true; - } - return false; -}; - -EPUBJS.Renderer.prototype.isGoodNode = function(node) { - var embeddedElements = ["audio", "canvas", "embed", "iframe", "img", "math", "object", "svg", "video"]; - if (embeddedElements.indexOf(node.tagName.toLowerCase()) !== -1) { - // Embedded elements usually do not have a text node as first element, but are also good nodes - return true; - } - return this.firstElementisTextNode(node); -}; - -// Walk the node tree from a start element to next visible element -EPUBJS.Renderer.prototype.walk = function(node, x, y) { - var r, children, leng, - startNode = node, - prevNode, - stack = [startNode]; - - var STOP = 10000, ITER=0; - - while(!r && stack.length) { - node = stack.shift(); - if( this.containsPoint(node, x, y) && this.isGoodNode(node)) { - r = node; - } - - if(!r && node && node.childElementCount > 0){ - children = node.children; - if (children && children.length) { - leng = children.length ? children.length : 0; - } else { - return r; - } - for (var i = leng-1; i >= 0; i--) { - if(children[i] != prevNode) stack.unshift(children[i]); - } - } - - if(!r && stack.length === 0 && startNode && startNode.parentNode !== null){ - stack.push(startNode.parentNode); - prevNode = startNode; - startNode = startNode.parentNode; - } - - - ITER++; - if(ITER > STOP) { - console.error("ENDLESS LOOP"); - break; - } - - } - - return r; -}; - -// Checks if an element is on the screen -EPUBJS.Renderer.prototype.containsPoint = function(el, x, y){ - var rect; - var left; - if(el && typeof el.getBoundingClientRect === 'function'){ - rect = el.getBoundingClientRect(); - // console.log(el, rect, x, y); - - if( rect.width !== 0 && - rect.height !== 0 && // Element not visible - rect.left >= x && - x <= rect.left + rect.width) { - return true; - } - } - - return false; -}; - -EPUBJS.Renderer.prototype.textSprint = function(root, func) { - var filterEmpty = function(node){ - if ( ! /^\s*$/.test(node.data) ) { - return NodeFilter.FILTER_ACCEPT; - } else { - return NodeFilter.FILTER_REJECT; - } - }; - var treeWalker; - var node; - - try { - treeWalker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT, { - acceptNode: filterEmpty - }, false); - while ((node = treeWalker.nextNode())) { - func(node); - } - } catch (e) { - // IE doesn't accept the object, just wants a function - // https://msdn.microsoft.com/en-us/library/ff974820(v=vs.85).aspx - treeWalker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT, filterEmpty, false); - while ((node = treeWalker.nextNode())) { - func(node); - } - } - - - -}; - -EPUBJS.Renderer.prototype.sprint = function(root, func) { - var treeWalker = document.createTreeWalker(root, NodeFilter.SHOW_ELEMENT, null, false); - var node; - while ((node = treeWalker.nextNode())) { - func(node); - } - -}; - -EPUBJS.Renderer.prototype.mapPage = function(){ - var renderer = this; - var map = []; - var root = this.render.getBaseElement(); - var page = 1; - var width = this.layout.colWidth + this.layout.gap; - var offset = this.formated.pageWidth * (this.chapterPos-1); - var limit = (width * page) - offset;// (width * page) - offset; - var elLimit = 0; - var prevRange; - var prevRanges; - var cfi; - var lastChildren = null; - var prevElement; - var startRange, endRange; - var startCfi, endCfi; - var check = function(node) { - var elPos; - var elRange; - var found; - if (node.nodeType == Node.TEXT_NODE) { - - elRange = document.createRange(); - elRange.selectNodeContents(node); - elPos = elRange.getBoundingClientRect(); - - if(!elPos || (elPos.width === 0 && elPos.height === 0)) { - return; - } - - //-- Element starts new Col - if(elPos.left > elLimit) { - found = checkText(node); - } - - //-- Element Spans new Col - if(elPos.right > elLimit) { - found = checkText(node); - } - - prevElement = node; - - if (found) { - prevRange = null; - } - } - - }; - var checkText = function(node){ - var result; - var ranges = renderer.splitTextNodeIntoWordsRanges(node); - - ranges.forEach(function(range){ - var pos = range.getBoundingClientRect(); - - if(!pos || (pos.width === 0 && pos.height === 0)) { - return; - } - if(pos.left + pos.width < limit) { - if(!map[page-1]){ - range.collapse(true); - cfi = renderer.currentChapter.cfiFromRange(range); - // map[page-1].start = cfi; - result = map.push({ start: cfi, end: null }); - } - } else { - // Previous Range is null since we already found our last map pair - // Use that last walked textNode - if(!prevRange && prevElement) { - prevRanges = renderer.splitTextNodeIntoWordsRanges(prevElement); - prevRange = prevRanges[prevRanges.length-1]; - } - - if(prevRange && map.length){ - prevRange.collapse(false); - cfi = renderer.currentChapter.cfiFromRange(prevRange); - if (map[map.length-1]) { - map[map.length-1].end = cfi; - } - } - - range.collapse(true); - cfi = renderer.currentChapter.cfiFromRange(range); - result = map.push({ - start: cfi, - end: null - }); - - page += 1; - limit = (width * page) - offset; - elLimit = limit; - } - - prevRange = range; - }); - - return result; - }; - var docEl = this.render.getDocumentElement(); - var dir = docEl.dir; - - // Set back to ltr before sprinting to get correct order - if(dir == "rtl") { - docEl.dir = "ltr"; - if (this.layoutSettings.layout !== "pre-paginated") { - docEl.style.position = "static"; - } - } - - this.textSprint(root, check); - - // Reset back to previous RTL settings - if(dir == "rtl") { - docEl.dir = dir; - if (this.layoutSettings.layout !== "pre-paginated") { - docEl.style.left = "auto"; - docEl.style.right = "0"; - } - } - - // Check the remaining children that fit on this page - // to ensure the end is correctly calculated - if(!prevRange && prevElement) { - prevRanges = renderer.splitTextNodeIntoWordsRanges(prevElement); - prevRange = prevRanges[prevRanges.length-1]; - } - - if(prevRange){ - prevRange.collapse(false); - cfi = renderer.currentChapter.cfiFromRange(prevRange); - map[map.length-1].end = cfi; - } - - // Handle empty map - if(!map.length) { - startRange = this.doc.createRange(); - startRange.selectNodeContents(root); - startRange.collapse(true); - startCfi = renderer.currentChapter.cfiFromRange(startRange); - - endRange = this.doc.createRange(); - endRange.selectNodeContents(root); - endRange.collapse(false); - endCfi = renderer.currentChapter.cfiFromRange(endRange); - - - map.push({ start: startCfi, end: endCfi }); - - } - - // clean up - prevRange = null; - prevRanges = undefined; - startRange = null; - endRange = null; - root = null; - - return map; -}; - - -EPUBJS.Renderer.prototype.indexOfBreakableChar = function (text, startPosition) { - var whiteCharacters = "\x2D\x20\t\r\n\b\f"; - // '-' \x2D - // ' ' \x20 - - if (! startPosition) { - startPosition = 0; - } - - for (var i = startPosition; i < text.length; i++) { - if (whiteCharacters.indexOf(text.charAt(i)) != -1) { - return i; - } - } - - return -1; -}; - - -EPUBJS.Renderer.prototype.splitTextNodeIntoWordsRanges = function(node){ - var ranges = []; - var text = node.textContent.trim(); - var range; - var rect; - var list; - - // Usage of indexOf() function for space character as word delimiter - // is not sufficient in case of other breakable characters like \r\n- etc - var pos = this.indexOfBreakableChar(text); - - if(pos === -1) { - range = this.doc.createRange(); - range.selectNodeContents(node); - return [range]; - } - - range = this.doc.createRange(); - range.setStart(node, 0); - range.setEnd(node, pos); - ranges.push(range); - - // there was a word miss in case of one letter words - range = this.doc.createRange(); - range.setStart(node, pos+1); - - while ( pos != -1 ) { - - pos = this.indexOfBreakableChar(text, pos + 1); - if(pos > 0) { - - if(range) { - range.setEnd(node, pos); - ranges.push(range); - } - - range = this.doc.createRange(); - range.setStart(node, pos+1); - } - } - - if(range) { - range.setEnd(node, text.length); - ranges.push(range); - } - - return ranges; -}; - -EPUBJS.Renderer.prototype.rangePosition = function(range){ - var rect; - var list; - - list = range.getClientRects(); - - if(list.length) { - rect = list[0]; - return rect; - } - - return null; -}; - -/* -// Get the cfi of the current page -EPUBJS.Renderer.prototype.getPageCfi = function(prevEl){ - var range = this.doc.createRange(); - var position; - // TODO : this might need to take margin / padding into account? - var x = 1;//this.formated.pageWidth/2; - var y = 1;//;this.formated.pageHeight/2; - - range = this.getRange(x, y); - - // var test = this.doc.defaultView.getSelection(); - // var r = this.doc.createRange(); - // test.removeAllRanges(); - // r.setStart(range.startContainer, range.startOffset); - // r.setEnd(range.startContainer, range.startOffset + 1); - // test.addRange(r); - - return this.currentChapter.cfiFromRange(range); -}; -*/ - -// Get the cfi of the current page -EPUBJS.Renderer.prototype.getPageCfi = function(){ - var pg = (this.chapterPos * 2)-1; - return this.pageMap[pg].start; -}; - -EPUBJS.Renderer.prototype.getRange = function(x, y, forceElement){ - var range = this.doc.createRange(); - var position; - forceElement = true; // temp override - if(typeof document.caretPositionFromPoint !== "undefined" && !forceElement){ - position = this.doc.caretPositionFromPoint(x, y); - range.setStart(position.offsetNode, position.offset); - } else if(typeof document.caretRangeFromPoint !== "undefined" && !forceElement){ - range = this.doc.caretRangeFromPoint(x, y); - } else { - this.visibileEl = this.findElementAfter(x, y); - range.setStart(this.visibileEl, 1); - } - - // var test = this.doc.defaultView.getSelection(); - // var r = this.doc.createRange(); - // test.removeAllRanges(); - // r.setStart(range.startContainer, range.startOffset); - // r.setEnd(range.startContainer, range.startOffset + 1); - // test.addRange(r); - return range; -}; - -/* -EPUBJS.Renderer.prototype.getVisibleRangeCfi = function(prevEl){ - var startX = 0; - var startY = 0; - var endX = this.width-1; - var endY = this.height-1; - var startRange = this.getRange(startX, startY); - var endRange = this.getRange(endX, endY); //fix if carret not avail - var startCfi = this.currentChapter.cfiFromRange(startRange); - var endCfi; - if(endRange) { - endCfi = this.currentChapter.cfiFromRange(endRange); - } - - return { - start: startCfi, - end: endCfi || false - }; -}; -*/ - -EPUBJS.Renderer.prototype.pagesInCurrentChapter = function() { - var pgs; - var length; - - if(!this.pageMap) { - console.warn("page map not loaded"); - return false; - } - - length = this.pageMap.length; - - // if(this.spreads){ - // pgs = Math.ceil(length / 2); - // } else { - // pgs = length; - // } - - return length; -}; - -EPUBJS.Renderer.prototype.currentRenderedPage = function(){ - var pg; - - if(!this.pageMap) { - console.warn("page map not loaded"); - return false; - } - - if (this.spreads && this.pageMap.length > 1) { - pg = (this.chapterPos*2) - 1; - } else { - pg = this.chapterPos; - } - - return pg; -}; - -EPUBJS.Renderer.prototype.getRenderedPagesLeft = function(){ - var pg; - var lastPage; - var pagesLeft; - - if(!this.pageMap) { - console.warn("page map not loaded"); - return false; - } - - lastPage = this.pageMap.length; - - if (this.spreads) { - pg = (this.chapterPos*2) - 1; - } else { - pg = this.chapterPos; - } - - pagesLeft = lastPage - pg; - return pagesLeft; - -}; - -EPUBJS.Renderer.prototype.getVisibleRangeCfi = function(){ - var pg; - var startRange, endRange; - - if(!this.pageMap) { - console.warn("page map not loaded"); - return false; - } - - if (this.spreads) { - pg = this.chapterPos*2; - startRange = this.pageMap[pg-2]; - endRange = startRange; - - if(this.pageMap.length > 1 && this.pageMap.length > pg-1) { - endRange = this.pageMap[pg-1]; - } - } else { - pg = this.chapterPos; - startRange = this.pageMap[pg-1]; - endRange = startRange; - } - - if(!startRange) { - console.warn("page range miss:", pg, this.pageMap); - startRange = this.pageMap[this.pageMap.length-1]; - endRange = startRange; - } - - return { - start: startRange.start, - end: endRange.end - }; -}; - -// Goto a cfi position in the current chapter -EPUBJS.Renderer.prototype.gotoCfi = function(cfi){ - var pg; - var marker; - var range; - - if(this._moving){ - return this._q.enqueue("gotoCfi", arguments); - } - - if(EPUBJS.core.isString(cfi)){ - cfi = this.epubcfi.parse(cfi); - } - - if(typeof document.evaluate === 'undefined') { - marker = this.epubcfi.addMarker(cfi, this.doc); - if(marker) { - pg = this.render.getPageNumberByElement(marker); - // Must Clean up Marker before going to page - this.epubcfi.removeMarker(marker, this.doc); - this.page(pg); - } - } else { - range = this.epubcfi.generateRangeFromCfi(cfi, this.doc); - if(range) { - // [email protected] - // It seems that sometimes getBoundingClientRect() returns null for first page CFI in chapter. - // It is always reproductible if few consecutive chapters have only one page. - // NOTE: This is only workaround and the issue needs an deeper investigation. - // NOTE: Observed on Android 4.2.1 using WebView widget as HTML renderer (Asus TF300T). - var rect = range.getBoundingClientRect(); - if (rect) { - pg = this.render.getPageNumberByRect(rect); - - } else { - // Goto first page in chapter - pg = 1; - } - - this.page(pg); - - // Reset the current location cfi to requested cfi - this.currentLocationCfi = cfi.str; - } else { - // Failed to find a range, go to first page - this.page(1); - } - } -}; - -// Walk nodes until a visible element is found -EPUBJS.Renderer.prototype.findFirstVisible = function(startEl){ - var el = startEl || this.render.getBaseElement(); - var found; - // [email protected] - // Looks like an old API usage - // Set x and y as 0 to fullfill walk method API. - found = this.walk(el, 0, 0); - - if(found) { - return found; - }else{ - return startEl; - } - -}; -// TODO: remove me - unsused -EPUBJS.Renderer.prototype.findElementAfter = function(x, y, startEl){ - var el = startEl || this.render.getBaseElement(); - var found; - found = this.walk(el, x, y); - if(found) { - return found; - }else{ - return el; - } - -}; - -/* -EPUBJS.Renderer.prototype.route = function(hash, callback){ - var location = window.location.hash.replace('#/', ''); - if(this.useHash && location.length && location != this.prevLocation){ - this.show(location, callback); - this.prevLocation = location; - return true; - } - return false; -} - -EPUBJS.Renderer.prototype.hideHashChanges = function(){ - this.useHash = false; -} - -*/ - -EPUBJS.Renderer.prototype.resize = function(width, height, setSize){ - var spreads; - - this.width = width; - this.height = height; - - if(setSize !== false) { - this.render.resize(this.width, this.height); - } - - - - if(this.contents){ - this.reformat(); - } - - this.trigger("renderer:resized", { - width: this.width, - height: this.height - }); -}; - -//-- Listeners for events in the frame - -EPUBJS.Renderer.prototype.onResized = function(e) { - this.trigger('renderer:beforeResize'); - - var width = this.container.clientWidth; - var height = this.container.clientHeight; - - this.resize(width, height, false); -}; - -EPUBJS.Renderer.prototype.addEventListeners = function(){ - if(!this.render.document) { - return; - } - this.listenedEvents.forEach(function(eventName){ - this.render.document.addEventListener(eventName, this.triggerEvent.bind(this), false); - }, this); - -}; - -EPUBJS.Renderer.prototype.removeEventListeners = function(){ - if(!this.render.document) { - return; - } - this.listenedEvents.forEach(function(eventName){ - this.render.document.removeEventListener(eventName, this.triggerEvent, false); - }, this); - -}; - -// Pass browser events -EPUBJS.Renderer.prototype.triggerEvent = function(e){ - this.trigger("renderer:"+e.type, e); -}; - -EPUBJS.Renderer.prototype.addSelectionListeners = function(){ - this.render.document.addEventListener("selectionchange", this.onSelectionChange.bind(this), false); -}; - -EPUBJS.Renderer.prototype.removeSelectionListeners = function(){ - if(!this.render.document) { - return; - } - this.doc.removeEventListener("selectionchange", this.onSelectionChange, false); -}; - -EPUBJS.Renderer.prototype.onSelectionChange = function(e){ - if (this.selectionEndTimeout) { - clearTimeout(this.selectionEndTimeout); - } - this.selectionEndTimeout = setTimeout(function() { - this.selectedRange = this.render.window.getSelection(); - this.trigger("renderer:selected", this.selectedRange); - }.bind(this), 500); -}; - - -//-- Spreads - -EPUBJS.Renderer.prototype.setMinSpreadWidth = function(width){ - this.minSpreadWidth = width; - this.spreads = this.determineSpreads(width); -}; - -EPUBJS.Renderer.prototype.determineSpreads = function(cutoff){ - if(this.isForcedSingle || !cutoff || this.width < cutoff) { - return false; //-- Single Page - }else{ - return true; //-- Double Page - } -}; - -EPUBJS.Renderer.prototype.forceSingle = function(bool){ - if(bool) { - this.isForcedSingle = true; - // this.spreads = false; - } else { - this.isForcedSingle = false; - // this.spreads = this.determineSpreads(this.minSpreadWidth); - } -}; - -EPUBJS.Renderer.prototype.setGap = function(gap){ - this.gap = gap; //-- False == auto gap -}; - -EPUBJS.Renderer.prototype.setDirection = function(direction){ - this.direction = direction; - this.render.setDirection(this.direction); -}; - -//-- Content Replacements - -EPUBJS.Renderer.prototype.replace = function(query, func, finished, progress){ - var items = this.contents.querySelectorAll(query), - resources = Array.prototype.slice.call(items), - count = resources.length; - - - if(count === 0) { - finished(false); - return; - } - resources.forEach(function(item){ - var called = false; - var after = function(result, full){ - if(called === false) { - count--; - if(progress) progress(result, full, count); - if(count <= 0 && finished) finished(true); - called = true; - } - }; - - func(item, after); - - }.bind(this)); - -}; - -//-- Enable binding events to Renderer -RSVP.EventTarget.mixin(EPUBJS.Renderer.prototype); - -var EPUBJS = EPUBJS || {}; -EPUBJS.replace = {}; - -//-- Replaces the relative links within the book to use our internal page changer -EPUBJS.replace.hrefs = function(callback, renderer){ - var book = this; - var replacments = function(link, done){ - var href = link.getAttribute("href"), - isRelative = href.search("://"), - directory, - relative, - location, - base, - uri, - url; - - if(href.indexOf("mailto:") === 0){ - done(); - return; - } - - if(isRelative != -1){ - - link.setAttribute("target", "_blank"); - - }else{ - // Links may need to be resolved, such as ../chp1.xhtml - base = renderer.render.docEl.querySelector('base'); - url = base.getAttribute("href"); - uri = EPUBJS.core.uri(url); - directory = uri.directory; - - if (href.indexOf("#") === 0) { - href = uri.filename + href; - } - - if(directory) { - // We must ensure that the file:// protocol is preserved for - // local file links, as in certain contexts (such as under - // Titanium), file links without the file:// protocol will not - // work - if (uri.protocol === "file") { - relative = EPUBJS.core.resolveUrl(uri.base, href); - } else { - relative = EPUBJS.core.resolveUrl(directory, href); - } - } else { - relative = href; - } - - link.onclick = function(){ - book.trigger("book:linkClicked", href); - book.goto(relative); - return false; - }; - - } - done(); - - }; - - renderer.replace("a[href]", replacments, callback); - -}; - -EPUBJS.replace.head = function(callback, renderer) { - - renderer.replaceWithStored("link[href]", "href", EPUBJS.replace.links, callback); - -}; - - -//-- Replaces assets src's to point to stored version if browser is offline -EPUBJS.replace.resources = function(callback, renderer){ - //srcs = this.doc.querySelectorAll('[src]'); - renderer.replaceWithStored("[src]", "src", EPUBJS.replace.srcs, callback); - -}; - -EPUBJS.replace.posters = function(callback, renderer){ - - renderer.replaceWithStored("[poster]", "poster", EPUBJS.replace.srcs, callback); - -}; - -EPUBJS.replace.svg = function(callback, renderer) { - - renderer.replaceWithStored("svg image", "xlink:href", function(_store, full, done){ - _store.getUrl(full).then(done); - }, callback); - -}; - -EPUBJS.replace.srcs = function(_store, full, done){ - - var isRelative = (full.search("://") === -1); - - if (isRelative) { - _store.getUrl(full).then(done); - } else { - done(); - } - -}; - -//-- Replaces links in head, such as stylesheets - link[href] -EPUBJS.replace.links = function(_store, full, done, link){ - //-- Handle replacing urls in CSS - if(link.getAttribute("rel") === "stylesheet") { - EPUBJS.replace.stylesheets(_store, full).then(function(url, full){ - // done - done(url, full); - }, function(reason) { - // we were unable to replace the style sheets - done(null); - }); - }else{ - _store.getUrl(full).then(done, function(reason) { - // we were unable to get the url, signal to upper layer - done(null); - }); - } -}; - -EPUBJS.replace.stylesheets = function(_store, full) { - var deferred = new RSVP.defer(); - - if(!_store) return; - - _store.getText(full).then(function(text){ - var url; - - EPUBJS.replace.cssImports(_store, full, text).then(function (importText) { - - text = importText + text; - - EPUBJS.replace.cssUrls(_store, full, text).then(function(newText){ - var _URL = window.URL || window.webkitURL || window.mozURL; - - var blob = new Blob([newText], { "type" : "text\/css" }), - url = _URL.createObjectURL(blob); - - deferred.resolve(url); - - }, function(reason) { - deferred.reject(reason); - }); - - },function(reason) { - deferred.reject(reason); - }); - - }, function(reason) { - deferred.reject(reason); - }); - - return deferred.promise; -}; - -EPUBJS.replace.cssImports = function (_store, base, text) { - var deferred = new RSVP.defer(); - if(!_store) return; - - // check for css @import - var importRegex = /@import\s+(?:url\()?\'?\"?((?!data:)[^\'|^\"^\)]*)\'?\"?\)?/gi; - var importMatches, importFiles = [], allImportText = ''; - - while (importMatches = importRegex.exec(text)) { - importFiles.push(importMatches[1]); - } - - if (importFiles.length === 0) { - deferred.resolve(allImportText); - } - - importFiles.forEach(function (fileUrl) { - var full = EPUBJS.core.resolveUrl(base, fileUrl); - full = EPUBJS.core.uri(full).path; - _store.getText(full).then(function(importText){ - allImportText += importText; - if (importFiles.indexOf(fileUrl) === importFiles.length - 1) { - deferred.resolve(allImportText); - } - }, function(reason) { - deferred.reject(reason); - }); - }); - - return deferred.promise; - -}; - - -EPUBJS.replace.cssUrls = function(_store, base, text){ - var deferred = new RSVP.defer(), - matches = text.match(/url\(\'?\"?((?!data:)[^\'|^\"^\)]*)\'?\"?\)/g); - - if(!_store) return; - - if(!matches){ - deferred.resolve(text); - return deferred.promise; - } - - var promises = matches.map(function(str) { - var full = EPUBJS.core.resolveUrl(base, str.replace(/url\(|[|\)|\'|\"]|\?.*$/g, '')); - return _store.getUrl(full).then(function(url) { - text = text.replace(str, 'url("'+url+'")'); - }, function(reason) { - deferred.reject(reason); - }); - }); - - RSVP.all(promises).then(function(){ - deferred.resolve(text); - }); - - return deferred.promise; -}; - - -EPUBJS.Storage = function(withCredentials){ - - this.checkRequirements(); - this.urlCache = {}; - this.withCredentials = withCredentials; - this.URL = window.URL || window.webkitURL || window.mozURL; - this.offline = false; -}; - -//-- Load the zip lib and set the workerScriptsPath -EPUBJS.Storage.prototype.checkRequirements = function(callback){ - if(typeof(localforage) == "undefined") console.error("localForage library not loaded"); -}; - -EPUBJS.Storage.prototype.put = function(assets, store) { - var deferred = new RSVP.defer(); - var count = assets.length; - var current = 0; - var next = function(deferred){ - var done = deferred || new RSVP.defer(); - var url; - var encodedUrl; - - if(current >= count) { - done.resolve(); - } else { - url = assets[current].url; - encodedUrl = window.encodeURIComponent(url); - - EPUBJS.core.request(url, "binary") - .then(function (data) { - return localforage.setItem(encodedUrl, data); - }) - .then(function(data){ - current++; - // Load up the next - setTimeout(function(){ - next(done); - }, 1); - - }); - } - return done.promise; - }.bind(this); - - if(!Array.isArray(assets)) { - assets = [assets]; - } - - next().then(function(){ - deferred.resolve(); - }.bind(this)); - - return deferred.promise; -}; - -EPUBJS.Storage.prototype.token = function(url, value){ - var encodedUrl = window.encodeURIComponent(url); - return localforage.setItem(encodedUrl, value) - .then(function (result) { - if (result === null) { - return false; - } else { - return true; - } - }); -}; - -EPUBJS.Storage.prototype.isStored = function(url){ - var encodedUrl = window.encodeURIComponent(url); - return localforage.getItem(encodedUrl) - .then(function (result) { - if (result === null) { - return false; - } else { - return true; - } - }); -}; - -EPUBJS.Storage.prototype.getText = function(url){ - var encodedUrl = window.encodeURIComponent(url); - - return EPUBJS.core.request(url, 'arraybuffer', this.withCredentials) - .then(function(buffer){ - - if(this.offline){ - this.offline = false; - this.trigger("offline", false); - } - localforage.setItem(encodedUrl, buffer); - return buffer; - }.bind(this)) - .then(function(data) { - var deferred = new RSVP.defer(); - var mimeType = EPUBJS.core.getMimeType(url); - var blob = new Blob([data], {type : mimeType}); - var reader = new FileReader(); - reader.addEventListener("loadend", function() { - deferred.resolve(reader.result); - }); - reader.readAsText(blob, mimeType); - return deferred.promise; - }) - .catch(function() { - - var deferred = new RSVP.defer(); - var entry = localforage.getItem(encodedUrl); - - if(!this.offline){ - this.offline = true; - this.trigger("offline", true); - } - - if(!entry) { - deferred.reject({ - message : "File not found in the storage: " + url, - stack : new Error().stack - }); - return deferred.promise; - } - - entry.then(function(data) { - var mimeType = EPUBJS.core.getMimeType(url); - var blob = new Blob([data], {type : mimeType}); - var reader = new FileReader(); - reader.addEventListener("loadend", function() { - deferred.resolve(reader.result); - }); - reader.readAsText(blob, mimeType); - }); - - return deferred.promise; - }.bind(this)); -}; - -EPUBJS.Storage.prototype.getUrl = function(url){ - var encodedUrl = window.encodeURIComponent(url); - - return EPUBJS.core.request(url, 'arraybuffer', this.withCredentials) - .then(function(buffer){ - if(this.offline){ - this.offline = false; - this.trigger("offline", false); - } - localforage.setItem(encodedUrl, buffer); - return url; - }.bind(this)) - .catch(function() { - var deferred = new RSVP.defer(); - var entry; - var _URL = window.URL || window.webkitURL || window.mozURL; - var tempUrl; - - if(!this.offline){ - this.offline = true; - this.trigger("offline", true); - } - - if(encodedUrl in this.urlCache) { - deferred.resolve(this.urlCache[encodedUrl]); - return deferred.promise; - } - - entry = localforage.getItem(encodedUrl); - - if(!entry) { - deferred.reject({ - message : "File not found in the storage: " + url, - stack : new Error().stack - }); - return deferred.promise; - } - - entry.then(function(data) { - var blob = new Blob([data], {type : EPUBJS.core.getMimeType(url)}); - tempUrl = _URL.createObjectURL(blob); - deferred.resolve(tempUrl); - this.urlCache[encodedUrl] = tempUrl; - }.bind(this)); - - - return deferred.promise; - }.bind(this)); -}; - -EPUBJS.Storage.prototype.getXml = function(url){ - var encodedUrl = window.encodeURIComponent(url); - - return EPUBJS.core.request(url, 'arraybuffer', this.withCredentials) - .then(function(buffer){ - if(this.offline){ - this.offline = false; - this.trigger("offline", false); - } - localforage.setItem(encodedUrl, buffer); - return buffer; - }.bind(this)) - .then(function(data) { - var deferred = new RSVP.defer(); - var mimeType = EPUBJS.core.getMimeType(url); - var blob = new Blob([data], {type : mimeType}); - var reader = new FileReader(); - reader.addEventListener("loadend", function() { - var parser = new DOMParser(); - var doc = parser.parseFromString(reader.result, "text/xml"); - deferred.resolve(doc); - }); - reader.readAsText(blob, mimeType); - return deferred.promise; - }) - .catch(function() { - var deferred = new RSVP.defer(); - var entry = localforage.getItem(encodedUrl); - - if(!this.offline){ - this.offline = true; - this.trigger("offline", true); - } - - if(!entry) { - deferred.reject({ - message : "File not found in the storage: " + url, - stack : new Error().stack - }); - return deferred.promise; - } - - entry.then(function(data) { - var mimeType = EPUBJS.core.getMimeType(url); - var blob = new Blob([data], {type : mimeType}); - var reader = new FileReader(); - reader.addEventListener("loadend", function() { - var parser = new DOMParser(); - var doc = parser.parseFromString(reader.result, "text/xml"); - deferred.resolve(doc); - }); - reader.readAsText(blob, mimeType); - }); - - return deferred.promise; - }.bind(this)); -}; - -EPUBJS.Storage.prototype.revokeUrl = function(url){ - var _URL = window.URL || window.webkitURL || window.mozURL; - var fromCache = this.urlCache[url]; - if(fromCache) _URL.revokeObjectURL(fromCache); -}; - -EPUBJS.Storage.prototype.failed = function(error){ - console.error(error); -}; - -RSVP.EventTarget.mixin(EPUBJS.Storage.prototype); - -EPUBJS.Unarchiver = function(url){ - - this.checkRequirements(); - this.urlCache = {}; - -}; - -//-- Load the zip lib and set the workerScriptsPath -EPUBJS.Unarchiver.prototype.checkRequirements = function(callback){ - if(typeof(JSZip) == "undefined") console.error("JSZip lib not loaded"); -}; - -EPUBJS.Unarchiver.prototype.open = function(zipUrl, callback){ - if (zipUrl instanceof ArrayBuffer) { - this.zip = new JSZip(zipUrl); - var deferred = new RSVP.defer(); - deferred.resolve(); - return deferred.promise; - } else { - return EPUBJS.core.request(zipUrl, "binary").then(function(data){ - this.zip = new JSZip(data); - }.bind(this)); - } -}; - -EPUBJS.Unarchiver.prototype.getXml = function(url, encoding){ - var decodededUrl = window.decodeURIComponent(url); - return this.getText(decodededUrl, encoding). - then(function(text){ - var parser = new DOMParser(); - var mimeType = EPUBJS.core.getMimeType(url); - - // Remove byte order mark before parsing - // https://www.w3.org/International/questions/qa-byte-order-mark - if(text.charCodeAt(0) === 0xFEFF) { - text = text.slice(1); - } - - return parser.parseFromString(text, mimeType); - }); - -}; - -EPUBJS.Unarchiver.prototype.getUrl = function(url, mime){ - var unarchiver = this; - var deferred = new RSVP.defer(); - var decodededUrl = window.decodeURIComponent(url); - var entry = this.zip.file(decodededUrl); - var _URL = window.URL || window.webkitURL || window.mozURL; - var tempUrl; - var blob; - - if(!entry) { - deferred.reject({ - message : "File not found in the epub: " + url, - stack : new Error().stack - }); - return deferred.promise; - } - - if(url in this.urlCache) { - deferred.resolve(this.urlCache[url]); - return deferred.promise; - } - - blob = new Blob([entry.asUint8Array()], {type : EPUBJS.core.getMimeType(entry.name)}); - - tempUrl = _URL.createObjectURL(blob); - deferred.resolve(tempUrl); - unarchiver.urlCache[url] = tempUrl; - - return deferred.promise; -}; - -EPUBJS.Unarchiver.prototype.getText = function(url, encoding){ - var unarchiver = this; - var deferred = new RSVP.defer(); - var decodededUrl = window.decodeURIComponent(url); - var entry = this.zip.file(decodededUrl); - var text; - - if(!entry) { - deferred.reject({ - message : "File not found in the epub: " + url, - stack : new Error().stack - }); - return deferred.promise; - } - - text = entry.asText(); - deferred.resolve(text); - - return deferred.promise; -}; - -EPUBJS.Unarchiver.prototype.revokeUrl = function(url){ - var _URL = window.URL || window.webkitURL || window.mozURL; - var fromCache = this.urlCache[url]; - if(fromCache) _URL.revokeObjectURL(fromCache); -}; - -EPUBJS.Unarchiver.prototype.failed = function(error){ - console.error(error); -}; - -EPUBJS.Unarchiver.prototype.afterSaved = function(error){ - this.callback(); -}; - -EPUBJS.Unarchiver.prototype.toStorage = function(entries){ - var timeout = 0, - delay = 20, - that = this, - count = entries.length; - - function callback(){ - count--; - if(count === 0) that.afterSaved(); - } - - entries.forEach(function(entry){ - - setTimeout(function(entry){ - that.saveEntryFileToStorage(entry, callback); - }, timeout, entry); - - timeout += delay; - }); - - console.log("time", timeout); - - //entries.forEach(this.saveEntryFileToStorage.bind(this)); -}; - -// EPUBJS.Unarchiver.prototype.saveEntryFileToStorage = function(entry, callback){ -// var that = this; -// entry.getData(new zip.BlobWriter(), function(blob) { -// EPUBJS.storage.save(entry.filename, blob, callback); -// }); -// }; - -/* - From Zip.js, by Gildas Lormeau - */ - -(function() { - "use strict"; - var table = { - "application" : { - "ecmascript" : [ "es", "ecma" ], - "javascript" : "js", - "ogg" : "ogx", - "pdf" : "pdf", - "postscript" : [ "ps", "ai", "eps", "epsi", "epsf", "eps2", "eps3" ], - "rdf+xml" : "rdf", - "smil" : [ "smi", "smil" ], - "xhtml+xml" : [ "xhtml", "xht" ], - "xml" : [ "xml", "xsl", "xsd", "opf", "ncx" ], - "zip" : "zip", - "x-httpd-eruby" : "rhtml", - "x-latex" : "latex", - "x-maker" : [ "frm", "maker", "frame", "fm", "fb", "book", "fbdoc" ], - "x-object" : "o", - "x-shockwave-flash" : [ "swf", "swfl" ], - "x-silverlight" : "scr", - "epub+zip" : "epub", - "font-tdpfr" : "pfr", - "inkml+xml" : [ "ink", "inkml" ], - "json" : "json", - "jsonml+json" : "jsonml", - "mathml+xml" : "mathml", - "metalink+xml" : "metalink", - "mp4" : "mp4s", - // "oebps-package+xml" : "opf", - "omdoc+xml" : "omdoc", - "oxps" : "oxps", - "vnd.amazon.ebook" : "azw", - "widget" : "wgt", - // "x-dtbncx+xml" : "ncx", - "x-dtbook+xml" : "dtb", - "x-dtbresource+xml" : "res", - "x-font-bdf" : "bdf", - "x-font-ghostscript" : "gsf", - "x-font-linux-psf" : "psf", - "x-font-otf" : "otf", - "x-font-pcf" : "pcf", - "x-font-snf" : "snf", - "x-font-ttf" : [ "ttf", "ttc" ], - "x-font-type1" : [ "pfa", "pfb", "pfm", "afm" ], - "x-font-woff" : "woff", - "x-mobipocket-ebook" : [ "prc", "mobi" ], - "x-mspublisher" : "pub", - "x-nzb" : "nzb", - "x-tgif" : "obj", - "xaml+xml" : "xaml", - "xml-dtd" : "dtd", - "xproc+xml" : "xpl", - "xslt+xml" : "xslt", - "internet-property-stream" : "acx", - "x-compress" : "z", - "x-compressed" : "tgz", - "x-gzip" : "gz", - }, - "audio" : { - "flac" : "flac", - "midi" : [ "mid", "midi", "kar", "rmi" ], - "mpeg" : [ "mpga", "mpega", "mp2", "mp3", "m4a", "mp2a", "m2a", "m3a" ], - "mpegurl" : "m3u", - "ogg" : [ "oga", "ogg", "spx" ], - "x-aiff" : [ "aif", "aiff", "aifc" ], - "x-ms-wma" : "wma", - "x-wav" : "wav", - "adpcm" : "adp", - "mp4" : "mp4a", - "webm" : "weba", - "x-aac" : "aac", - "x-caf" : "caf", - "x-matroska" : "mka", - "x-pn-realaudio-plugin" : "rmp", - "xm" : "xm", - "mid" : [ "mid", "rmi" ] - }, - "image" : { - "gif" : "gif", - "ief" : "ief", - "jpeg" : [ "jpeg", "jpg", "jpe" ], - "pcx" : "pcx", - "png" : "png", - "svg+xml" : [ "svg", "svgz" ], - "tiff" : [ "tiff", "tif" ], - "x-icon" : "ico", - "bmp" : "bmp", - "webp" : "webp", - "x-pict" : [ "pic", "pct" ], - "x-tga" : "tga", - "cis-cod" : "cod", - }, - "message" : { - "rfc822" : [ "eml", "mime", "mht", "mhtml", "nws" ] - }, - "text" : { - "cache-manifest" : [ "manifest", "appcache" ], - "calendar" : [ "ics", "icz", "ifb" ], - "css" : "css", - "csv" : "csv", - "h323" : "323", - "html" : [ "html", "htm", "shtml", "stm" ], - "iuls" : "uls", - "mathml" : "mml", - "plain" : [ "txt", "text", "brf", "conf", "def", "list", "log", "in", "bas" ], - "richtext" : "rtx", - "tab-separated-values" : "tsv", - "x-bibtex" : "bib", - "x-dsrc" : "d", - "x-diff" : [ "diff", "patch" ], - "x-haskell" : "hs", - "x-java" : "java", - "x-literate-haskell" : "lhs", - "x-moc" : "moc", - "x-pascal" : [ "p", "pas" ], - "x-pcs-gcd" : "gcd", - "x-perl" : [ "pl", "pm" ], - "x-python" : "py", - "x-scala" : "scala", - "x-setext" : "etx", - "x-tcl" : [ "tcl", "tk" ], - "x-tex" : [ "tex", "ltx", "sty", "cls" ], - "x-vcard" : "vcf", - "sgml" : [ "sgml", "sgm" ], - "x-c" : [ "c", "cc", "cxx", "cpp", "h", "hh", "dic" ], - "x-fortran" : [ "f", "for", "f77", "f90" ], - "x-opml" : "opml", - "x-nfo" : "nfo", - "x-sfv" : "sfv", - "x-uuencode" : "uu", - "webviewhtml" : "htt" - }, - "video" : { - "mpeg" : [ "mpeg", "mpg", "mpe", "m1v", "m2v", "mp2", "mpa", "mpv2" ], - "mp4" : [ "mp4", "mp4v", "mpg4" ], - "quicktime" : [ "qt", "mov" ], - "ogg" : "ogv", - "vnd.mpegurl" : [ "mxu", "m4u" ], - "x-flv" : "flv", - "x-la-asf" : [ "lsf", "lsx" ], - "x-mng" : "mng", - "x-ms-asf" : [ "asf", "asx", "asr" ], - "x-ms-wm" : "wm", - "x-ms-wmv" : "wmv", - "x-ms-wmx" : "wmx", - "x-ms-wvx" : "wvx", - "x-msvideo" : "avi", - "x-sgi-movie" : "movie", - "x-matroska" : [ "mpv", "mkv", "mk3d", "mks" ], - "3gpp2" : "3g2", - "h261" : "h261", - "h263" : "h263", - "h264" : "h264", - "jpeg" : "jpgv", - "jpm" : [ "jpm", "jpgm" ], - "mj2" : [ "mj2", "mjp2" ], - "vnd.ms-playready.media.pyv" : "pyv", - "vnd.uvvu.mp4" : [ "uvu", "uvvu" ], - "vnd.vivo" : "viv", - "webm" : "webm", - "x-f4v" : "f4v", - "x-m4v" : "m4v", - "x-ms-vob" : "vob", - "x-smv" : "smv" - } - }; - - var mimeTypes = (function() { - var type, subtype, val, index, mimeTypes = {}; - for (type in table) { - if (table.hasOwnProperty(type)) { - for (subtype in table[type]) { - if (table[type].hasOwnProperty(subtype)) { - val = table[type][subtype]; - if (typeof val == "string") { - mimeTypes[val] = type + "/" + subtype; - } else { - for (index = 0; index < val.length; index++) { - mimeTypes[val[index]] = type + "/" + subtype; - } - } - } - } - } - } - return mimeTypes; - })(); - - EPUBJS.core.getMimeType = function(filename) { - var defaultValue = "text/plain";//"application/octet-stream"; - return filename && mimeTypes[filename.split(".").pop().toLowerCase()] || defaultValue; - }; - -})(); - -//# sourceMappingURL=epub.js.map
\ No newline at end of file +(function(e,t){'object'==typeof exports&&'object'==typeof module?module.exports=t(require('xmldom'),function(){try{return require('jszip')}catch(t){}}()):'function'==typeof define&&define.amd?define(['xmldom','jszip'],t):'object'==typeof exports?exports.ePub=t(require('xmldom'),function(){try{return require('jszip')}catch(t){}}()):e.ePub=t(e.xmldom,e.jszip)})(this,function(e,t){var n=String.prototype,a=Math.ceil,i=Math.round,o=Math.max,s=Math.floor;return function(e){function t(a){if(n[a])return n[a].exports;var i=n[a]={i:a,l:!1,exports:{}};return e[a].call(i.exports,i,i.exports,t),i.l=!0,i.exports}var n={};return t.m=e,t.c=n,t.d=function(e,n,a){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:a})},t.n=function(e){var n=e&&e.__esModule?function(){return e['default']}:function(){return e};return t.d(n,'a',n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p='/dist/',t(t.s=25)}([function(e,t,n){'use strict';function a(e,t){if(!(e instanceof t))throw new TypeError('Cannot call a class as a function')}function i(){var e=new Date().getTime(),t='xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g,function(t){var n=0|(e+16*Math.random())%16;return e=s(e/16),('x'==t?n:8|7&n).toString(16)});return t}function r(e){return!isNaN(parseFloat(e))&&isFinite(e)}function l(e,t,n,a,i){var o=a||0,s=i||t.length,r=parseInt(o+(s-o)/2),d;return(n||(n=function(e,t){return e>t?1:e<t?-1:e==t?0:void 0}),0>=s-o)?r:(d=n(t[r],e),1==s-o?0<=d?r:r+1:0===d?r:-1===d?l(e,t,n,r,s):l(e,t,n,o,r))}function d(e,t,n,a,i){var o=a||0,s=i||t.length,r=parseInt(o+(s-o)/2),l;return(n||(n=function(e,t){return e>t?1:e<t?-1:e==t?0:void 0}),0>=s-o)?-1:(l=n(t[r],e),1==s-o?0===l?r:-1:0===l?r:-1===l?d(e,t,n,r,s):d(e,t,n,o,r))}function u(e,t){for(var n=e.parentNode,a=n.childNodes,o=-1,s=0,i;s<a.length&&(i=a[s],i.nodeType===t&&o++,i!=e);s++);return o}function c(e,t){return new Blob([e],{type:t})}function p(e,t){return'undefined'==typeof e.querySelector?e.getElementsByTagName(t):e.querySelectorAll(t)}function h(e,t,n){for(var a=document.createTreeWalker(e,n,null,!1),i;i=a.nextNode();)t(i)}function g(e,t){if(t(e))return!0;if(e=e.firstChild,e)do{var n=g(e,t);if(n)return!0;e=e.nextSibling}while(e)}function f(e){for(var t=[e];e;e=e.parentNode)t.unshift(e);return t}Object.defineProperty(t,'__esModule',{value:!0});var m=function(){function e(e,t){for(var n=0,a;n<t.length;n++)a=t[n],a.enumerable=a.enumerable||!1,a.configurable=!0,'value'in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}return function(t,n,a){return n&&e(t.prototype,n),a&&e(t,a),t}}();t.uuid=i,t.documentHeight=function(){return o(document.documentElement.clientHeight,document.body.scrollHeight,document.documentElement.scrollHeight,document.body.offsetHeight,document.documentElement.offsetHeight)},t.isElement=function(e){return!!(e&&1==e.nodeType)},t.isNumber=r,t.isFloat=function(e){var t=parseFloat(e);return!1!==r(e)&&('string'==typeof e&&-1<e.indexOf('.')||s(t)!==t)},t.prefixed=function(e){var t=['Webkit','webkit','Moz','O','ms'],n=['-webkit-','-webkit-','-moz-','-o-','-ms-'],a=e[0].toUpperCase()+e.slice(1),o=t.length;if('undefined'==typeof document||'undefined'!=typeof document.body.style[e])return e;for(var s=0;s<o;s++)if('undefined'!=typeof document.body.style[t[s]+a])return n[s]+e;return e},t.defaults=function(e){for(var t=1,n=arguments.length,a;t<n;t++)for(var i in a=arguments[t],a)void 0===e[i]&&(e[i]=a[i]);return e},t.extend=function(e){var t=[].slice.call(arguments,1);return t.forEach(function(t){t&&Object.getOwnPropertyNames(t).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))})}),e},t.insert=function(e,t,n){var a=l(e,t,n);return t.splice(a,0,e),a},t.locationOf=l,t.indexOfSorted=d,t.bounds=function(e){var t=window.getComputedStyle(e),n=0,a=0;return['width','paddingRight','paddingLeft','marginRight','marginLeft','borderRightWidth','borderLeftWidth'].forEach(function(e){n+=parseFloat(t[e])||0}),['height','paddingTop','paddingBottom','marginTop','marginBottom','borderTopWidth','borderBottomWidth'].forEach(function(e){a+=parseFloat(t[e])||0}),{height:a,width:n}},t.borders=function(e){var t=window.getComputedStyle(e),n=0,a=0;return['paddingRight','paddingLeft','marginRight','marginLeft','borderRightWidth','borderLeftWidth'].forEach(function(e){n+=parseFloat(t[e])||0}),['paddingTop','paddingBottom','marginTop','marginBottom','borderTopWidth','borderBottomWidth'].forEach(function(e){a+=parseFloat(t[e])||0}),{height:a,width:n}},t.windowBounds=function(){var e=window.innerWidth,t=window.innerHeight;return{top:0,left:0,right:e,bottom:t,width:e,height:t}},t.indexOfNode=u,t.indexOfTextNode=function(e){return u(e,b)},t.indexOfElementNode=function(e){return u(e,v)},t.isXml=function(e){return-1<['xml','opf','ncx'].indexOf(e)},t.createBlob=c,t.createBlobUrl=function(e,t){var n=c(e,t),a;return a=k.createObjectURL(n),a},t.revokeBlobUrl=function(e){return k.revokeObjectURL(e)},t.createBase64Url=function(e,t){var n,a;if('string'==typeof e)return n=btoa(encodeURIComponent(e)),a='data:'+t+';base64,'+n,a},t.type=function(e){return Object.prototype.toString.call(e).slice(8,-1)},t.parse=function(e,t,a){var i,o;return o='undefined'==typeof DOMParser||a?n(16).DOMParser:DOMParser,65279===e.charCodeAt(0)&&(e=e.slice(1)),i=new o().parseFromString(e,t),i},t.qs=function(e,t){var n;if(!e)throw new Error('No Element Provided');return'undefined'==typeof e.querySelector?(n=e.getElementsByTagName(t),n.length)?n[0]:void 0:e.querySelector(t)},t.qsa=p,t.qsp=function(e,t,n){var a,i;if('undefined'!=typeof e.querySelector){for(var o in t+='[',n)t+=o+'~=\''+n[o]+'\'';return t+=']',e.querySelector(t)}return(a=e.getElementsByTagName(t),i=Array.prototype.slice.call(a,0).filter(function(e){for(var t in n)if(e.getAttribute(t)===n[t])return!0;return!1}),i)?i[0]:void 0},t.sprint=function(e,t){var n=e.ownerDocument||e;'undefined'==typeof n.createTreeWalker?g(e,function(e){e&&3===e.nodeType&&t(e)},!0):h(e,t,NodeFilter.SHOW_TEXT)},t.treeWalker=h,t.walk=g,t.blob2base64=function(e){return new Promise(function(t){var n=new FileReader;n.readAsDataURL(e),n.onloadend=function(){t(n.result)}})},t.defer=function(){var e=this;this.resolve=null,this.reject=null,this.id=i(),this.promise=new Promise(function(t,n){e.resolve=t,e.reject=n}),Object.freeze(this)},t.querySelectorByType=function(e,t,n){var a;if('undefined'!=typeof e.querySelector&&(a=e.querySelector(t+'[*|type="'+n+'"]')),!a||0===a.length){a=p(e,t);for(var o=0;o<a.length;o++)if(a[o].getAttributeNS('http://www.idpf.org/2007/ops','type')===n||a[o].getAttribute('epub:type')===n)return a[o]}else return a},t.findChildren=function(e){for(var t=[],n=e.childNodes,a=0,i;a<n.length;a++)i=n[a],1===i.nodeType&&t.push(i);return t},t.parents=f,t.filterChildren=function(e,t,n){for(var a=[],o=e.childNodes,s=0,i;s<o.length;s++)if(i=o[s],1===i.nodeType&&i.nodeName.toLowerCase()===t){if(n)return i;a.push(i)}if(!n)return a},t.getParentByTagName=function(e,t){var n;if(null!==e&&''!==t)for(n=e.parentNode;1===n.nodeType;){if(n.tagName.toLowerCase()===t)return n;n=n.parentNode}};var y=t.requestAnimationFrame='undefined'!=typeof window&&(window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame),v=1,b=3,k='undefined'==typeof URL?'undefined'==typeof window?void 0:window.URL||window.webkitURL||window.mozURL:URL,x=t.RangeObject=function(){function e(){a(this,e),this.collapsed=!1,this.commonAncestorContainer=void 0,this.endContainer=void 0,this.endOffset=void 0,this.startContainer=void 0,this.startOffset=void 0}return m(e,[{key:'setStart',value:function(e,t){this.startContainer=e,this.startOffset=t,this.endContainer?this.commonAncestorContainer=this._commonAncestorContainer():this.collapse(!0),this._checkCollapsed()}},{key:'setEnd',value:function(e,t){this.endContainer=e,this.endOffset=t,this.startContainer?(this.collapsed=!1,this.commonAncestorContainer=this._commonAncestorContainer()):this.collapse(!1),this._checkCollapsed()}},{key:'collapse',value:function(e){this.collapsed=!0,e?(this.endContainer=this.startContainer,this.endOffset=this.startOffset,this.commonAncestorContainer=this.startContainer.parentNode):(this.startContainer=this.endContainer,this.startOffset=this.endOffset,this.commonAncestorContainer=this.endOffset.parentNode)}},{key:'selectNode',value:function(e){var t=e.parentNode,n=Array.prototype.indexOf.call(t.childNodes,e);this.setStart(t,n),this.setEnd(t,n+1)}},{key:'selectNodeContents',value:function(e){var t=e.childNodes[e.childNodes-1],n=3===e.nodeType?e.textContent.length:parent.childNodes.length;this.setStart(e,0),this.setEnd(e,n)}},{key:'_commonAncestorContainer',value:function(e,t){var n=f(e||this.startContainer),a=f(t||this.endContainer);if(n[0]==a[0])for(var o=0;o<n.length;o++)if(n[o]!=a[o])return n[o-1]}},{key:'_checkCollapsed',value:function(){this.collapsed=this.startContainer===this.endContainer&&this.startOffset===this.endOffset}},{key:'toString',value:function(){}}]),e}()},function(e,t,n){'use strict';function a(e,t){if(!(e instanceof t))throw new TypeError('Cannot call a class as a function')}Object.defineProperty(t,'__esModule',{value:!0});var o='function'==typeof Symbol&&'symbol'==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&'function'==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?'symbol':typeof e},i=function(){function e(e,t){for(var n=0,a;n<t.length;n++)a=t[n],a.enumerable=a.enumerable||!1,a.configurable=!0,'value'in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}return function(t,n,a){return n&&e(t.prototype,n),a&&e(t,a),t}}(),s=n(0),r=1,l=3,d=function(){function e(t,n,i){a(this,e);var r;if(this.str='',this.base={},this.spinePos=0,this.range=!1,this.path={},this.start=null,this.end=null,!(this instanceof e))return new e(t,n,i);if('string'==typeof n?this.base=this.parseComponent(n):'object'===('undefined'==typeof n?'undefined':o(n))&&n.steps&&(this.base=n),r=this.checkType(t),'string'===r)return this.str=t,(0,s.extend)(this,this.parse(t));if('range'===r)return(0,s.extend)(this,this.fromRange(t,this.base,i));if('node'===r)return(0,s.extend)(this,this.fromNode(t,this.base,i));if('EpubCFI'===r&&t.path)return t;if(!t)return this;throw new TypeError('not a valid argument for EpubCFI')}return i(e,[{key:'checkType',value:function(t){return this.isCfiString(t)?'string':'object'===('undefined'==typeof t?'undefined':o(t))&&('Range'===(0,s.type)(t)||'undefined'!=typeof t.startContainer)?'range':'object'===('undefined'==typeof t?'undefined':o(t))&&'undefined'!=typeof t.nodeType?'node':'object'===('undefined'==typeof t?'undefined':o(t))&&t instanceof e&&'EpubCFI'}},{key:'parse',value:function(e){var t={spinePos:-1,range:!1,base:{},path:{},start:null,end:null},n,a,i;return'string'==typeof e?(0===e.indexOf('epubcfi(')&&')'===e[e.length-1]&&(e=e.slice(8,e.length-1)),n=this.getChapterComponent(e),!n)?{spinePos:-1}:(t.base=this.parseComponent(n),a=this.getPathComponent(e),t.path=this.parseComponent(a),i=this.getRange(e),i&&(t.range=!0,t.start=this.parseComponent(i[0]),t.end=this.parseComponent(i[1])),t.spinePos=t.base.steps[1].index,t):{spinePos:-1}}},{key:'parseComponent',value:function(e){var t={steps:[],terminal:{offset:null,assertion:null}},n=e.split(':'),a=n[0].split('/'),i;return 1<n.length&&(i=n[1],t.terminal=this.parseTerminal(i)),''===a[0]&&a.shift(),t.steps=a.map(function(e){return this.parseStep(e)}.bind(this)),t}},{key:'parseStep',value:function(e){var t,n,a,i,o;if(i=e.match(/\[(.*)\]/),i&&i[1]&&(o=i[1]),n=parseInt(e),!isNaN(n))return 0==n%2?(t='element',a=n/2-1):(t='text',a=(n-1)/2),{type:t,index:a,id:o||null}}},{key:'parseTerminal',value:function(e){var t=e.match(/\[(.*)\]/),n,a;return t&&t[1]?(n=parseInt(e.split('[')[0]),a=t[1]):n=parseInt(e),(0,s.isNumber)(n)||(n=null),{offset:n,assertion:a}}},{key:'getChapterComponent',value:function(e){var t=e.split('!');return t[0]}},{key:'getPathComponent',value:function(e){var t=e.split('!');if(t[1]){var n=t[1].split(',');return n[0]}}},{key:'getRange',value:function(e){var t=e.split(',');return 3===t.length&&[t[1],t[2]]}},{key:'getCharecterOffsetComponent',value:function(e){var t=e.split(':');return t[1]||''}},{key:'joinSteps',value:function(e){return e?e.map(function(e){var t='';return'element'===e.type&&(t+=2*(e.index+1)),'text'===e.type&&(t+=1+2*e.index),e.id&&(t+='['+e.id+']'),t}).join('/'):''}},{key:'segmentString',value:function(e){var t='/';return t+=this.joinSteps(e.steps),e.terminal&&null!=e.terminal.offset&&(t+=':'+e.terminal.offset),e.terminal&&null!=e.terminal.assertion&&(t+='['+e.terminal.assertion+']'),t}},{key:'toString',value:function(){var e='epubcfi(';return e+=this.segmentString(this.base),e+='!',e+=this.segmentString(this.path),this.range&&this.start&&(e+=',',e+=this.segmentString(this.start)),this.range&&this.end&&(e+=',',e+=this.segmentString(this.end)),e+=')',e}},{key:'compare',value:function(t,n){var a,o,s,r,l,l;if('string'==typeof t&&(t=new e(t)),'string'==typeof n&&(n=new e(n)),t.spinePos>n.spinePos)return 1;if(t.spinePos<n.spinePos)return-1;t.range?(a=t.path.steps.concat(t.start.steps),s=t.start.terminal):(a=t.path.steps,s=t.path.terminal),n.range?(o=n.path.steps.concat(n.start.steps),r=n.start.terminal):(o=n.path.steps,r=n.path.terminal);for(var d=0;d<a.length;d++){if(!a[d])return-1;if(!o[d])return 1;if(a[d].index>o[d].index)return 1;if(a[d].index<o[d].index)return-1}return a.length<o.length?1:s.offset>r.offset?1:s.offset<r.offset?-1:0}},{key:'step',value:function(e){var t=e.nodeType===l?'text':'element';return{id:e.id,tagName:e.tagName,type:t,index:this.position(e)}}},{key:'filteredStep',value:function(e,t){var n=this.filter(e,t),a;if(n)return a=n.nodeType===l?'text':'element',{id:n.id,tagName:n.tagName,type:a,index:this.filteredPosition(n,t)}}},{key:'pathTo',value:function(e,t,n){for(var a={steps:[],terminal:{offset:null,assertion:null}},i=e,o;i&&i.parentNode&&i.parentNode.nodeType!=9;)o=n?this.filteredStep(i,n):this.step(i),o&&a.steps.unshift(o),i=i.parentNode;return null!=t&&0<=t&&(a.terminal.offset=t,'text'!=a.steps[a.steps.length-1].type&&a.steps.push({type:'text',index:0})),a}},{key:'equalStep',value:function(e,t){return e&&t&&e.index===t.index&&e.id===t.id&&e.type===t.type}},{key:'fromRange',value:function(e,t,n){var a={range:!1,base:{},path:{},start:null,end:null},s=e.startContainer,r=e.endContainer,l=e.startOffset,d=e.endOffset,u=!1;if(n&&(u=null!=s.ownerDocument.querySelector('.'+n)),'string'==typeof t?(a.base=this.parseComponent(t),a.spinePos=a.base.steps[1].index):'object'===('undefined'==typeof t?'undefined':o(t))&&(a.base=t),e.collapsed)u&&(l=this.patchOffset(s,l,n)),a.path=this.pathTo(s,l,n);else{a.range=!0,u&&(l=this.patchOffset(s,l,n)),a.start=this.pathTo(s,l,n),u&&(d=this.patchOffset(r,d,n)),a.end=this.pathTo(r,d,n),a.path={steps:[],terminal:null};var c=a.start.steps.length,p;for(p=0;p<c&&this.equalStep(a.start.steps[p],a.end.steps[p]);p++)p===c-1?a.start.terminal===a.end.terminal&&(a.path.steps.push(a.start.steps[p]),a.range=!1):a.path.steps.push(a.start.steps[p]);a.start.steps=a.start.steps.slice(a.path.steps.length),a.end.steps=a.end.steps.slice(a.path.steps.length)}return a}},{key:'fromNode',value:function(e,t,n){var a={range:!1,base:{},path:{},start:null,end:null};return'string'==typeof t?(a.base=this.parseComponent(t),a.spinePos=a.base.steps[1].index):'object'===('undefined'==typeof t?'undefined':o(t))&&(a.base=t),a.path=this.pathTo(e,null,n),a}},{key:'filter',value:function(e,t){var n=!1,a,i,o,s,r;return e.nodeType===l?(n=!0,o=e.parentNode,a=e.parentNode.classList.contains(t)):(n=!1,a=e.classList.contains(t)),a&&n?(s=o.previousSibling,r=o.nextSibling,s&&s.nodeType===l?i=s:r&&r.nodeType===l&&(i=r),i?i:e):a&&!n?!1:e}},{key:'patchOffset',value:function(e,t,n){if(e.nodeType!=l)throw new Error('Anchor must be a text node');var a=e,i=t;for(e.parentNode.classList.contains(n)&&(a=e.parentNode);a.previousSibling;){if(a.previousSibling.nodeType!==r)i+=a.previousSibling.textContent.length;else if(a.previousSibling.classList.contains(n))i+=a.previousSibling.textContent.length;else break;a=a.previousSibling}return i}},{key:'normalizedMap',value:function(e,t,n){var a={},o=-1,s=e.length,d,i,u;for(d=0;d<s;d++)i=e[d].nodeType,i===r&&e[d].classList.contains(n)&&(i=l),0<d&&i===l&&u===l?a[d]=o:t===i&&(++o,a[d]=o),u=i;return a}},{key:'position',value:function(e){var t,n;return e.nodeType===r?(t=e.parentNode.children,!t&&(t=(0,s.findChildren)(e.parentNode)),n=Array.prototype.indexOf.call(t,e)):(t=this.textNodes(e.parentNode),n=t.indexOf(e)),n}},{key:'filteredPosition',value:function(e,t){var n,a,i;return e.nodeType===r?(n=e.parentNode.children,i=this.normalizedMap(n,r,t)):(n=e.parentNode.childNodes,e.parentNode.classList.contains(t)&&(e=e.parentNode,n=e.parentNode.childNodes),i=this.normalizedMap(n,l,t)),a=Array.prototype.indexOf.call(n,e),i[a]}},{key:'stepsToXpath',value:function(e){var t=['.','*'];return e.forEach(function(e){var n=e.index+1;e.id?t.push('*[position()='+n+' and @id=\''+e.id+'\']'):'text'===e.type?t.push('text()['+n+']'):t.push('*['+n+']')}),t.join('/')}},{key:'stepsToQuerySelector',value:function(e){var t=['html'];return e.forEach(function(e){var n=e.index+1;e.id?t.push('#'+e.id):'text'===e.type||t.push('*:nth-child('+n+')')}),t.join('>')}},{key:'textNodes',value:function(e,t){return Array.prototype.slice.call(e.childNodes).filter(function(e){return e.nodeType===l||t&&e.classList.contains(t)})}},{key:'walkToNode',value:function(e,t,n){var a=t||document,o=a.documentElement,r=e.length,l,d,u;for(u=0;u<r&&(d=e[u],'element'===d.type?d.id?o=a.getElementById(d.id):(l=o.children||(0,s.findChildren)(o),o=l[d.index]):'text'===d.type&&(o=this.textNodes(o,n)[d.index]),!!o);u++);return o}},{key:'findNode',value:function(e,t,n){var a=t||document,i,o;return n||'undefined'==typeof a.evaluate?n?i=this.walkToNode(e,a,n):i=this.walkToNode(e,a):(o=this.stepsToXpath(e),i=a.evaluate(o,a,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue),i}},{key:'fixMiss',value:function(e,t,n,a){var i=this.findNode(e.slice(0,-1),n,a),o=i.childNodes,s=this.normalizedMap(o,l,a),d=e[e.length-1].index,u,c;for(var p in s){if(!s.hasOwnProperty(p))return;if(s[p]===d)if(u=o[p],c=u.textContent.length,t>c)t-=c;else{i=u.nodeType===r?u.childNodes[0]:u;break}}return{container:i,offset:t}}},{key:'toRange',value:function(e,t){var n=e||document,a=this,i=!!t&&null!=n.querySelector('.'+t),o,r,l,d,u,c,p,h;if(o='undefined'==typeof n.createRange?new s.RangeObject:n.createRange(),a.range?(r=a.start,c=a.path.steps.concat(r.steps),d=this.findNode(c,n,i?t:null),l=a.end,p=a.path.steps.concat(l.steps),u=this.findNode(p,n,i?t:null)):(r=a.path,c=a.path.steps,d=this.findNode(a.path.steps,n,i?t:null)),d)try{null==r.terminal.offset?o.setStart(d,0):o.setStart(d,r.terminal.offset)}catch(a){h=this.fixMiss(c,r.terminal.offset,n,i?t:null),o.setStart(h.container,h.offset)}else return console.log('No startContainer found for',this.toString()),null;if(u)try{null==l.terminal.offset?o.setEnd(u,0):o.setEnd(u,l.terminal.offset)}catch(s){h=this.fixMiss(p,a.end.terminal.offset,n,i?t:null),o.setEnd(h.container,h.offset)}return o}},{key:'isCfiString',value:function(e){return'string'==typeof e&&0===e.indexOf('epubcfi(')&&')'===e[e.length-1]}},{key:'generateChapterComponent',value:function(e,t,n){var a=parseInt(t),i='/'+2*(e+1)+'/';return i+=2*(a+1),n&&(i+='['+n+']'),i}},{key:'collapse',value:function(e){this.range&&(this.range=!1,e?(this.path.steps=this.path.steps.concat(this.start.steps),this.path.terminal=this.start.terminal):(this.path.steps=this.path.steps.concat(this.end.steps),this.path.terminal=this.end.terminal))}}]),e}();t.default=d,e.exports=t['default']},function(e,t,n){'use strict';var a=n(27),o=n(41),s=Function.prototype.apply,r=Function.prototype.call,i=Object.create,l=Object.defineProperty,d=Object.defineProperties,u=Object.prototype.hasOwnProperty,c={configurable:!0,enumerable:!1,writable:!0},p,h,g,f,m,y,v;p=function(e,t){var n;return o(t),u.call(this,'__ee__')?n=this.__ee__:(n=c.value=i(null),l(this,'__ee__',c),c.value=null),n[e]?'object'==typeof n[e]?n[e].push(t):n[e]=[n[e],t]:n[e]=t,this},h=function(e,t){var n,a;return o(t),a=this,p.call(this,e,n=function(){g.call(a,e,n),s.call(t,this,arguments)}),n.__eeOnceListener__=t,this},g=function(e,t){var n,a,s,r;if(o(t),!u.call(this,'__ee__'))return this;if(n=this.__ee__,!n[e])return this;if(a=n[e],'object'==typeof a)for(r=0;s=a[r];++r)(s===t||s.__eeOnceListener__===t)&&(2===a.length?n[e]=a[r?0:1]:a.splice(r,1));else(a===t||a.__eeOnceListener__===t)&&delete n[e];return this},f=function(e){var t,n,a,i,o;if(u.call(this,'__ee__')&&(i=this.__ee__[e],!!i))if('object'==typeof i){for(n=arguments.length,o=Array(n-1),t=1;t<n;++t)o[t-1]=arguments[t];for(i=i.slice(),t=0;a=i[t];++t)s.call(a,this,o)}else switch(arguments.length){case 1:r.call(i,this);break;case 2:r.call(i,this,arguments[1]);break;case 3:r.call(i,this,arguments[1],arguments[2]);break;default:for(n=arguments.length,o=Array(n-1),t=1;t<n;++t)o[t-1]=arguments[t];s.call(i,this,o);}},m={on:p,once:h,off:g,emit:f},y={on:a(p),once:a(h),off:a(g),emit:a(f)},v=d({},y),e.exports=t=function(e){return null==e?i(v):d(Object(e),y)},t.methods=m},function(e,t){'use strict';Object.defineProperty(t,'__esModule',{value:!0});var n=t.DOM_EVENTS=['keydown','keyup','keypressed','mouseup','mousedown','click','touchend','touchstart'],a=t.EVENTS={BOOK:{OPEN_FAILED:'openFailed'},CONTENTS:{EXPAND:'expand',RESIZE:'resize',SELECTED:'selected',SELECTED_RANGE:'selectedRange',LINK_CLICKED:'linkClicked'},LOCATIONS:{CHANGED:'changed'},MANAGERS:{RESIZE:'resize',RESIZED:'resized',ORIENTATION_CHANGE:'orientationchange',ADDED:'added',SCROLL:'scroll',SCROLLED:'scrolled'},VIEWS:{AXIS:'axis',LOAD_ERROR:'loaderror',RENDERED:'rendered',RESIZED:'resized',DISPLAYED:'displayed',SHOWN:'shown',HIDDEN:'hidden',MARK_CLICKED:'markClicked'},RENDITION:{STARTED:'started',ATTACHED:'attached',DISPLAYED:'displayed',DISPLAY_ERROR:'displayerror',RENDERED:'rendered',REMOVED:'removed',RESIZED:'resized',ORIENTATION_CHANGE:'orientationchange',LOCATION_CHANGED:'locationChanged',RELOCATED:'relocated',MARK_CLICKED:'markClicked',SELECTED:'selected',LAYOUT:'layout'},LAYOUT:{UPDATED:'updated'}}},function(e,t,n){'use strict';function a(e,t){if(!(e instanceof t))throw new TypeError('Cannot call a class as a function')}Object.defineProperty(t,'__esModule',{value:!0});var i=function(){function e(e,t){for(var n=0,a;n<t.length;n++)a=t[n],a.enumerable=a.enumerable||!1,a.configurable=!0,'value'in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}return function(t,n,a){return n&&e(t.prototype,n),a&&e(t,a),t}}(),o=n(6),s=function(e){return e&&e.__esModule?e:{default:e}}(o),r=function(){function e(t){a(this,e);var n,i;n=t.indexOf('://'),-1<n&&(t=new URL(t).pathname),i=this.parse(t),this.path=t,this.directory=this.isDirectory(t)?t:i.dir+'/',this.filename=i.base,this.extension=i.ext.slice(1)}return i(e,[{key:'parse',value:function(e){return s.default.parse(e)}},{key:'isAbsolute',value:function(e){return s.default.isAbsolute(e||this.path)}},{key:'isDirectory',value:function(e){return'/'===e.charAt(e.length-1)}},{key:'resolve',value:function(e){return s.default.resolve(this.directory,e)}},{key:'relative',value:function(e){return s.default.relative(this.directory,e)}},{key:'splitPath',value:function(e){return this.splitPathRe.exec(e).slice(1)}},{key:'toString',value:function(){return this.path}}]),e}();t.default=r,e.exports=t['default']},function(e,t,n){'use strict';function a(e){return e&&e.__esModule?e:{default:e}}function i(e,t){if(!(e instanceof t))throw new TypeError('Cannot call a class as a function')}Object.defineProperty(t,'__esModule',{value:!0});var o=function(){function e(e,t){for(var n=0,a;n<t.length;n++)a=t[n],a.enumerable=a.enumerable||!1,a.configurable=!0,'value'in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}return function(t,n,a){return n&&e(t.prototype,n),a&&e(t,a),t}}(),s=n(4),r=a(s),l=n(6),d=a(l),u=function(){function e(t,n){i(this,e);var a=-1<t.indexOf('://'),o=t,s;if(this.Url=void 0,this.href=t,this.protocol='',this.origin='',this.hash='',this.hash='',this.search='',this.base=n,!a&&!1!==n&&'string'!=typeof n&&window&&window.location&&(this.base=window.location.href),a||this.base)try{this.Url=this.base?new URL(t,this.base):new URL(t),this.href=this.Url.href,this.protocol=this.Url.protocol,this.origin=this.Url.origin,this.hash=this.Url.hash,this.search=this.Url.search,o=this.Url.pathname}catch(t){this.Url=void 0,this.base&&(s=new r.default(this.base),o=s.resolve(o))}this.Path=new r.default(o),this.directory=this.Path.directory,this.filename=this.Path.filename,this.extension=this.Path.extension}return o(e,[{key:'path',value:function(){return this.Path}},{key:'resolve',value:function(e){var t=-1<e.indexOf('://'),n;return t?e:(n=d.default.resolve(this.directory,e),this.origin+n)}},{key:'relative',value:function(e){return d.default.relative(e,this.directory)}},{key:'toString',value:function(){return this.href}}]),e}();t.default=u,e.exports=t['default']},function(e){'use strict';function t(e){if('string'!=typeof e)throw new TypeError('Path must be a string. Received '+e)}function n(e,t){for(var n='',a=-1,o=0,s=0,i;s<=e.length;++s){if(s<e.length)i=e.charCodeAt(s);else if(47===i)break;else i=47;if(47===i){if(a==s-1||1==o);else if(a!=s-1&&2==o){if(2>n.length||46!==n.charCodeAt(n.length-1)||46!==n.charCodeAt(n.length-2))if(2<n.length){for(var r=n.length-1,l=r;0<=l&&47!==n.charCodeAt(l);--l);if(l!=r){n=-1==l?'':n.slice(0,l),a=s,o=0;continue}}else if(2===n.length||1===n.length){n='',a=s,o=0;continue}t&&(0<n.length?n+='/..':n='..')}else 0<n.length?n+='/'+e.slice(a+1,s):n=e.slice(a+1,s);a=s,o=0}else 46===i&&-1!=o?++o:o=-1}return n}function a(e,t){var n=t.dir||t.root,a=t.base||(t.name||'')+(t.ext||'');return n?n===t.root?n+a:n+e+a:a}if(!o)var o={cwd:function(){return'/'}};var s={resolve:function(){for(var e='',a=!1,s=arguments.length-1,i;-1<=s&&!a;s--){var r;(0<=s?r=arguments[s]:(void 0==i&&(i=o.cwd()),r=i),t(r),0!==r.length)&&(e=r+'/'+e,a=47===r.charCodeAt(0))}return e=n(e,!a),a?0<e.length?'/'+e:'/':0<e.length?e:'.'},normalize:function(e){if(t(e),0===e.length)return'.';var a=47===e.charCodeAt(0),i=47===e.charCodeAt(e.length-1);return e=n(e,!a),0!==e.length||a||(e='.'),0<e.length&&i&&(e+='/'),a?'/'+e:e},isAbsolute:function(e){return t(e),0<e.length&&47===e.charCodeAt(0)},join:function(){if(0===arguments.length)return'.';for(var e=0,n,a;e<arguments.length;++e)a=arguments[e],t(a),0<a.length&&(void 0==n?n=a:n+='/'+a);return void 0===n?'.':s.normalize(n)},relative:function(e,n){if(t(e),t(n),e===n)return'';if(e=s.resolve(e),n=s.resolve(n),e===n)return'';for(var a=1;a<e.length&&47===e.charCodeAt(a);++a);for(var o=e.length,r=o-a,l=1;l<n.length&&47===n.charCodeAt(l);++l);for(var d=n.length,u=d-l,c=r<u?r:u,p=-1,h=0;h<=c;++h){if(h==c){if(u>c){if(47===n.charCodeAt(l+h))return n.slice(l+h+1);if(0==h)return n.slice(l+h)}else r>c&&(47===e.charCodeAt(a+h)?p=h:0==h&&(p=0));break}var i=e.charCodeAt(a+h),g=n.charCodeAt(l+h);if(i!==g)break;else 47===i&&(p=h)}var f='';for(h=a+p+1;h<=o;++h)(h===o||47===e.charCodeAt(h))&&(f+=0===f.length?'..':'/..');return 0<f.length?f+n.slice(l+p):(l+=p,47===n.charCodeAt(l)&&++l,n.slice(l))},_makeLong:function(e){return e},dirname:function(e){if(t(e),0===e.length)return'.';for(var n=e.charCodeAt(0),a=47===n,o=-1,s=!0,r=e.length-1;1<=r;--r)if(n=e.charCodeAt(r),47!==n)s=!1;else if(!s){o=r;break}return-1===o?a?'/':'.':a&&1===o?'//':e.slice(0,o)},basename:function(e,n){if(n!==void 0&&'string'!=typeof n)throw new TypeError('"ext" argument must be a string');t(e);var a=0,o=-1,s=!0,r;if(void 0!==n&&0<n.length&&n.length<=e.length){if(n.length===e.length&&n===e)return'';var i=n.length-1,l=-1;for(r=e.length-1;0<=r;--r){var d=e.charCodeAt(r);if(47!==d)-1==l&&(s=!1,l=r+1),0<=i&&(d===n.charCodeAt(i)?-1==--i&&(o=r):(i=-1,o=l));else if(!s){a=r+1;break}}return a===o?o=l:-1===o&&(o=e.length),e.slice(a,o)}for(r=e.length-1;0<=r;--r)if(47!==e.charCodeAt(r))-1==o&&(s=!1,o=r+1);else if(!s){a=r+1;break}return-1===o?'':e.slice(a,o)},extname:function(e){t(e);for(var n=-1,a=0,o=-1,s=!0,r=0,l=e.length-1,i;0<=l;--l){if(i=e.charCodeAt(l),47===i){if(!s){a=l+1;break}continue}-1==o&&(s=!1,o=l+1),46===i?-1==n?n=l:1!=r&&(r=1):-1!==n&&(r=-1)}return-1===n||-1===o||0==r||1==r&&n===o-1&&n===a+1?'':e.slice(n,o)},format:function(e){if(null===e||'object'!=typeof e)throw new TypeError('Parameter "pathObject" must be an object, not '+typeof e);return a('/',e)},parse:function(e){t(e);var n={root:'',dir:'',base:'',ext:'',name:''};if(0===e.length)return n;var a=e.charCodeAt(0),o=47===a,s;o?(n.root='/',s=1):s=0;for(var r=-1,l=0,d=-1,u=!0,c=e.length-1,i=0;c>=s;--c){if(a=e.charCodeAt(c),47===a){if(!u){l=c+1;break}continue}-1==d&&(u=!1,d=c+1),46===a?-1==r?r=c:1!=i&&(i=1):-1!=r&&(i=-1)}return-1==r||-1==d||0==i||1==i&&r==d-1&&r==l+1?-1!=d&&(0==l&&o?n.base=n.name=e.slice(1,d):n.base=n.name=e.slice(l,d)):(0==l&&o?(n.name=e.slice(1,r),n.base=e.slice(1,d)):(n.name=e.slice(l,r),n.base=e.slice(l,d)),n.ext=e.slice(r,d)),0<l?n.dir=e.slice(0,l-1):o&&(n.dir='/'),n},sep:'/',delimiter:':',posix:null};e.exports=s},function(e,t,n){'use strict';function a(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(t,'__esModule',{value:!0}),t.replaceBase=function(e,t){var n=t.url,a=-1<n.indexOf('://'),i,s;e&&(s=(0,o.qs)(e,'head'),i=(0,o.qs)(s,'base'),!i&&(i=e.createElement('base'),s.insertBefore(i,s.firstChild)),!a&&window&&window.location&&(n=window.location.origin+n),i.setAttribute('href',n))},t.replaceCanonical=function(e,t){var n=t.canonical,a,i;e&&(a=(0,o.qs)(e,'head'),i=(0,o.qs)(a,'link[rel=\'canonical\']'),i?i.setAttribute('href',n):(i=e.createElement('link'),i.setAttribute('rel','canonical'),i.setAttribute('href',n),a.appendChild(i)))},t.replaceMeta=function(e,t){var n=t.idref,a,i;e&&(a=(0,o.qs)(e,'head'),i=(0,o.qs)(a,'link[property=\'dc.identifier\']'),i?i.setAttribute('content',n):(i=e.createElement('meta'),i.setAttribute('name','dc.identifier'),i.setAttribute('content',n),a.appendChild(i)))},t.replaceLinks=function(e,t){var n=e.querySelectorAll('a[href]');if(n.length)for(var a=(0,o.qs)(e.ownerDocument,'base'),r=a?a.getAttribute('href'):void 0,l=function(e){var n=e.getAttribute('href');if(0!==n.indexOf('mailto:')){var a=-1<n.indexOf('://'),i=new s.default(n,r);a?e.setAttribute('target','_blank'):e.onclick=function(){return i&&i.hash?t(i.Path.path+i.hash):i?t(i.Path.path):t(n),!1}}}.bind(this),d=0;d<n.length;d++)l(n[d])},t.substitute=function(e,t,n){return t.forEach(function(t,a){t&&n[a]&&(e=e.replace(new RegExp(t,'g'),n[a]))}),e};var o=n(0),i=n(5),s=a(i),r=n(4),l=a(r)},function(e){var t=function(){return this}();try{t=t||Function('return this')()||(1,eval)('this')}catch(n){'object'==typeof window&&(t=window)}e.exports=t},function(e,t,n){'use strict';var a=n(34)();e.exports=function(e){return e!==a&&null!==e}},function(e,t){'use strict';function n(e,t){if(!(e instanceof t))throw new TypeError('Cannot call a class as a function')}Object.defineProperty(t,'__esModule',{value:!0});var a=function(){function e(e,t){for(var n=0,a;n<t.length;n++)a=t[n],a.enumerable=a.enumerable||!1,a.configurable=!0,'value'in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}return function(t,n,a){return n&&e(t.prototype,n),a&&e(t,a),t}}(),i=function(){function e(t){n(this,e),this.context=t||this,this.hooks=[]}return a(e,[{key:'register',value:function(){for(var e=0;e<arguments.length;++e)if('function'==typeof arguments[e])this.hooks.push(arguments[e]);else for(var t=0;t<arguments[e].length;++t)this.hooks.push(arguments[e][t])}},{key:'trigger',value:function(){var e=arguments,t=this.context,n=[];return this.hooks.forEach(function(a){var i=a.apply(t,e);i&&'function'==typeof i.then&&n.push(i)}),Promise.all(n)}},{key:'list',value:function(){return this.hooks}},{key:'clear',value:function(){return this.hooks=[]}}]),e}();t.default=i,e.exports=t['default']},function(e,t,n){'use strict';Object.defineProperty(t,'__esModule',{value:!0});var a=n(0),i=n(4),o=function(e){return e&&e.__esModule?e:{default:e}}(i);t.default=function(e,t,n,i){function s(t){u.reject(t)}function r(){if(this.readyState===XMLHttpRequest.DONE){var e=!1;if((''===this.responseType||'document'===this.responseType)&&(e=this.responseXML),200===this.status||0===this.status||e){var n;if(!this.response&&!e)return u.reject({status:this.status,message:'Empty Response',stack:new Error().stack}),u.promise;if(403===this.status)return u.reject({status:this.status,response:this.response,message:'Forbidden',stack:new Error().stack}),u.promise;n=e?this.responseXML:(0,a.isXml)(t)?(0,a.parse)(this.response,'text/xml'):'xhtml'==t?(0,a.parse)(this.response,'application/xhtml+xml'):'html'==t||'htm'==t?(0,a.parse)(this.response,'text/html'):'json'==t?JSON.parse(this.response):'blob'==t?l?this.response:new Blob([this.response]):this.response,u.resolve(n)}else u.reject({status:this.status,message:this.response,stack:new Error().stack})}}var l='undefined'!=typeof window&&window.URL,d=l?'blob':'arraybuffer',u=new a.defer,c=new XMLHttpRequest,p=XMLHttpRequest.prototype,h;for(h in'overrideMimeType'in p||Object.defineProperty(p,'overrideMimeType',{value:function(){}}),n&&(c.withCredentials=!0),c.onreadystatechange=r,c.onerror=s,c.open('GET',e,!0),i)c.setRequestHeader(h,i[h]);return'json'==t&&c.setRequestHeader('Accept','application/json'),t||(t=new o.default(e).extension),'blob'==t&&(c.responseType=d),(0,a.isXml)(t)&&c.overrideMimeType('text/xml'),'xhtml'==t,'html'!=t&&'htm'!=t,'binary'==t&&(c.responseType='arraybuffer'),c.send(),u.promise},e.exports=t['default']},function(e,t,n){'use strict';function a(e,t){if(!(e instanceof t))throw new TypeError('Cannot call a class as a function')}Object.defineProperty(t,'__esModule',{value:!0}),t.Task=void 0;var i=function(){function e(e,t){for(var n=0,a;n<t.length;n++)a=t[n],a.enumerable=a.enumerable||!1,a.configurable=!0,'value'in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}return function(t,n,a){return n&&e(t.prototype,n),a&&e(t,a),t}}(),o=n(0),s=function(){function e(t){a(this,e),this._q=[],this.context=t,this.tick=o.requestAnimationFrame,this.running=!1,this.paused=!1}return i(e,[{key:'enqueue',value:function(){var e=[].shift.call(arguments),t=arguments,n,a,i;if(!e)throw new Error('No Task Provided');return'function'==typeof e?(n=new o.defer,a=n.promise,i={task:e,args:t,deferred:n,promise:a}):i={promise:e},this._q.push(i),!1!=this.paused||this.running||this.run(),i.promise}},{key:'dequeue',value:function(){var e,t,n;if(this._q.length&&!this.paused){if(e=this._q.shift(),t=e.task,t)return n=t.apply(this.context,e.args),n&&'function'==typeof n.then?n.then(function(){e.deferred.resolve.apply(this.context,arguments)}.bind(this),function(){e.deferred.reject.apply(this.context,arguments)}.bind(this)):(e.deferred.resolve.apply(this.context,n),e.promise);if(e.promise)return e.promise}else return e=new o.defer,e.deferred.resolve(),e.promise}},{key:'dump',value:function(){for(;this._q.length;)this.dequeue()}},{key:'run',value:function(){var e=this;return this.running||(this.running=!0,this.defered=new o.defer),this.tick.call(window,function(){e._q.length?e.dequeue().then(function(){this.run()}.bind(e)):(e.defered.resolve(),e.running=void 0)}),!0==this.paused&&(this.paused=!1),this.defered.promise}},{key:'flush',value:function(){return this.running?this.running:this._q.length?(this.running=this.dequeue().then(function(){return this.running=void 0,this.flush()}.bind(this)),this.running):void 0}},{key:'clear',value:function(){this._q=[]}},{key:'length',value:function(){return this._q.length}},{key:'pause',value:function(){this.paused=!0}},{key:'stop',value:function(){this._q=[],this.running=!1,this.paused=!0}}]),e}();t.default=s,t.Task=function e(t,n,i){return a(this,e),function(){var e=this,n=arguments||[];return new Promise(function(a,o){n.push(function(e,t){!e&&t?o(t):a(e)}),t.apply(i||e,n)})}}},function(e,t,n){'use strict';function a(e){return e&&e.__esModule?e:{default:e}}function o(e,t){if(!(e instanceof t))throw new TypeError('Cannot call a class as a function')}Object.defineProperty(t,'__esModule',{value:!0});var s=function(){function e(e,t){for(var n=0,a;n<t.length;n++)a=t[n],a.enumerable=a.enumerable||!1,a.configurable=!0,'value'in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}return function(t,n,a){return n&&e(t.prototype,n),a&&e(t,a),t}}(),r=n(2),l=a(r),d=n(0),u=n(1),c=a(u),p=n(19),h=a(p),g=n(7),f=n(3),m='undefined'!=typeof navigator,y=m&&/Chrome/.test(navigator.userAgent),v=m&&!y&&/AppleWebKit/.test(navigator.userAgent),b=function(){function e(t,n,a,i){o(this,e),this.epubcfi=new c.default,this.document=t,this.documentElement=this.document.documentElement,this.content=n||this.document.body,this.window=this.document.defaultView,this._size={width:0,height:0},this.sectionIndex=i||0,this.cfiBase=a||'',this.epubReadingSystem('epub.js',ePub.VERSION),this.listeners()}return s(e,[{key:'width',value:function(e){var t=this.content;return e&&(0,d.isNumber)(e)&&(e+='px'),e&&(t.style.width=e),this.window.getComputedStyle(t).width}},{key:'height',value:function(e){var t=this.content;return e&&(0,d.isNumber)(e)&&(e+='px'),e&&(t.style.height=e),this.window.getComputedStyle(t).height}},{key:'contentWidth',value:function(e){var t=this.content||this.document.body;return e&&(0,d.isNumber)(e)&&(e+='px'),e&&(t.style.width=e),this.window.getComputedStyle(t).width}},{key:'contentHeight',value:function(e){var t=this.content||this.document.body;return e&&(0,d.isNumber)(e)&&(e+='px'),e&&(t.style.height=e),this.window.getComputedStyle(t).height}},{key:'textWidth',value:function(){var e=this.document.createRange(),t=this.content||this.document.body,n=(0,d.borders)(t),a;return e.selectNodeContents(t),a=e.getBoundingClientRect().width,n&&n.width&&(a+=n.width),i(a)}},{key:'textHeight',value:function(){var e=this.document.createRange(),t=this.content||this.document.body,n=(0,d.borders)(t),a;return e.selectNodeContents(t),a=e.getBoundingClientRect().height,a&&n.height&&(a+=n.height),i(a)}},{key:'scrollWidth',value:function(){var e=this.documentElement.scrollWidth;return e}},{key:'scrollHeight',value:function(){var e=this.documentElement.scrollHeight;return e}},{key:'overflow',value:function(e){return e&&(this.documentElement.style.overflow=e),this.window.getComputedStyle(this.documentElement).overflow}},{key:'overflowX',value:function(e){return e&&(this.documentElement.style.overflowX=e),this.window.getComputedStyle(this.documentElement).overflowX}},{key:'overflowY',value:function(e){return e&&(this.documentElement.style.overflowY=e),this.window.getComputedStyle(this.documentElement).overflowY}},{key:'css',value:function(e,t,n){var a=this.content||this.document.body;return t&&a.style.setProperty(e,t,n?'important':''),this.window.getComputedStyle(a)[e]}},{key:'viewport',value:function(e){var t=this.document.querySelector('meta[name=\'viewport\']'),n={width:void 0,height:void 0,scale:void 0,minimum:void 0,maximum:void 0,scalable:void 0},a=[],i={};if(t&&t.hasAttribute('content')){var o=t.getAttribute('content'),s=o.match(/width\s*=\s*([^,]*)/),r=o.match(/height\s*=\s*([^,]*)/),l=o.match(/initial-scale\s*=\s*([^,]*)/),u=o.match(/minimum-scale\s*=\s*([^,]*)/),c=o.match(/maximum-scale\s*=\s*([^,]*)/),p=o.match(/user-scalable\s*=\s*([^,]*)/);s&&s.length&&'undefined'!=typeof s[1]&&(n.width=s[1]),r&&r.length&&'undefined'!=typeof r[1]&&(n.height=r[1]),l&&l.length&&'undefined'!=typeof l[1]&&(n.scale=l[1]),u&&u.length&&'undefined'!=typeof u[1]&&(n.minimum=u[1]),c&&c.length&&'undefined'!=typeof c[1]&&(n.maximum=c[1]),p&&p.length&&'undefined'!=typeof p[1]&&(n.scalable=p[1])}return i=(0,d.defaults)(e||{},n),e&&(i.width&&a.push('width='+i.width),i.height&&a.push('height='+i.height),i.scale&&a.push('initial-scale='+i.scale),'no'===i.scalable?(a.push('minimum-scale='+i.scale),a.push('maximum-scale='+i.scale),a.push('user-scalable='+i.scalable)):(i.scalable&&a.push('user-scalable='+i.scalable),i.minimum&&a.push('minimum-scale='+i.minimum),i.maximum&&a.push('minimum-scale='+i.maximum)),!t&&(t=this.document.createElement('meta'),t.setAttribute('name','viewport'),this.document.querySelector('head').appendChild(t)),t.setAttribute('content',a.join(', ')),this.window.scrollTo(0,0)),i}},{key:'expand',value:function(){this.emit(f.EVENTS.CONTENTS.EXPAND)}},{key:'listeners',value:function(){this.imageLoadListeners(),this.mediaQueryListeners(),this.addEventListeners(),this.addSelectionListeners(),this.resizeListeners(),this.linksHandler()}},{key:'removeListeners',value:function(){this.removeEventListeners(),this.removeSelectionListeners(),clearTimeout(this.expanding)}},{key:'resizeCheck',value:function(){var e=this.textWidth(),t=this.textHeight();(e!=this._size.width||t!=this._size.height)&&(this._size={width:e,height:t},this.onResize&&this.onResize(this._size),this.emit(f.EVENTS.CONTENTS.RESIZE,this._size))}},{key:'resizeListeners',value:function(){clearTimeout(this.expanding),requestAnimationFrame(this.resizeCheck.bind(this)),this.expanding=setTimeout(this.resizeListeners.bind(this),350)}},{key:'transitionListeners',value:function(){var e=this.content;e.style.transitionProperty='font, font-size, font-size-adjust, font-stretch, font-variation-settings, font-weight, width, height',e.style.transitionDuration='0.001ms',e.style.transitionTimingFunction='linear',e.style.transitionDelay='0',this.document.addEventListener('transitionend',this.resizeCheck.bind(this))}},{key:'mediaQueryListeners',value:function(){for(var e=this.document.styleSheets,t=function(e){e.matches&&!this._expanding&&setTimeout(this.expand.bind(this),1)}.bind(this),n=0;n<e.length;n+=1){var a;try{a=e[n].cssRules}catch(t){return}if(!a)return;for(var i=0;i<a.length;i+=1)if(a[i].media){var o=this.window.matchMedia(a[i].media.mediaText);o.addListener(t)}}}},{key:'resizeObservers',value:function(){var e=this;this.observer=new MutationObserver(function(){e.resizeCheck()});this.observer.observe(this.document,{attributes:!0,childList:!0,characterData:!0,subtree:!0})}},{key:'imageLoadListeners',value:function(){for(var e=this.document.querySelectorAll('img'),t=0,n;t<e.length;t++)n=e[t],'undefined'!=typeof n.naturalWidth&&0===n.naturalWidth&&(n.onload=this.expand.bind(this))}},{key:'fontLoadListeners',value:function(){this.document&&this.document.fonts&&this.document.fonts.ready.then(function(){this.resizeCheck()}.bind(this))}},{key:'root',value:function(){return this.document?this.document.documentElement:null}},{key:'locationOf',value:function(e,t){var n={left:0,top:0},a;if(!this.document)return n;if(this.epubcfi.isCfiString(e)){var i=new c.default(e).toRange(this.document,t);if(i)if(i.startContainer.nodeType===Node.ELEMENT_NODE)a=i.startContainer.getBoundingClientRect(),n.left=a.left,n.top=a.top;else if(v){var o=i.startContainer,s=new Range;try{o.nodeType===1?a=o.getBoundingClientRect():i.startOffset+2<o.length?(s.setStart(o,i.startOffset),s.setEnd(o,i.startOffset+2),a=s.getBoundingClientRect()):0<i.startOffset-2?(s.setStart(o,i.startOffset-2),s.setEnd(o,i.startOffset),a=s.getBoundingClientRect()):a=o.parentNode.getBoundingClientRect()}catch(t){console.error(t,t.stack)}}else a=i.getBoundingClientRect()}else if('string'==typeof e&&-1<e.indexOf('#')){var r=e.substring(e.indexOf('#')+1),l=this.document.getElementById(r);l&&(a=l.getBoundingClientRect())}return a&&(n.left=a.left,n.top=a.top),n}},{key:'addStylesheet',value:function(e){return new Promise(function(t){var n=!1,a;return this.document?(a=this.document.querySelector('link[href=\''+e+'\']'),a?void t(!0):void(a=this.document.createElement('link'),a.type='text/css',a.rel='stylesheet',a.href=e,a.onload=a.onreadystatechange=function(){n||this.readyState&&'complete'!=this.readyState||(n=!0,setTimeout(function(){t(!0)},1))},this.document.head.appendChild(a))):void t(!1)}.bind(this))}},{key:'addStylesheetRules',value:function(e){var t='epubjs-inserted-css',n,a;if(this.document&&e&&0!==e.length)if(n=this.document.getElementById('#'+t),n||(n=this.document.createElement('style'),n.id=t),this.document.head.appendChild(n),a=n.sheet,'[object Array]'===Object.prototype.toString.call(e))for(var o=0,i=e.length;o<i;o++){var s=1,r=e[o],l=e[o][0],d='';'[object Array]'===Object.prototype.toString.call(r[1][0])&&(r=r[1],s=0);for(var u=r.length,c;s<u;s++)c=r[s],d+=c[0]+':'+c[1]+(c[2]?' !important':'')+';\n';a.insertRule(l+'{'+d+'}',a.cssRules.length)}else{var p=Object.keys(e);p.forEach(function(t){var n=e[t];if(Array.isArray(n))n.forEach(function(e){var n=Object.keys(e),i=n.map(function(t){return t+':'+e[t]}).join(';');a.insertRule(t+'{'+i+'}',a.cssRules.length)});else{var i=Object.keys(n),o=i.map(function(e){return e+':'+n[e]}).join(';');a.insertRule(t+'{'+o+'}',a.cssRules.length)}})}}},{key:'addScript',value:function(e){return new Promise(function(t){var n=!1,a;return this.document?void(a=this.document.createElement('script'),a.type='text/javascript',a.async=!0,a.src=e,a.onload=a.onreadystatechange=function(){n||this.readyState&&'complete'!=this.readyState||(n=!0,setTimeout(function(){t(!0)},1))},this.document.head.appendChild(a)):void t(!1)}.bind(this))}},{key:'addClass',value:function(e){var t;this.document&&(t=this.content||this.document.body,t&&t.classList.add(e))}},{key:'removeClass',value:function(e){var t;this.document&&(t=this.content||this.document.body,t&&t.classList.remove(e))}},{key:'addEventListeners',value:function(){this.document&&f.DOM_EVENTS.forEach(function(e){this.document.addEventListener(e,this.triggerEvent.bind(this),!1)},this)}},{key:'removeEventListeners',value:function(){this.document&&f.DOM_EVENTS.forEach(function(e){this.document.removeEventListener(e,this.triggerEvent,!1)},this)}},{key:'triggerEvent',value:function(t){this.emit(t.type,t)}},{key:'addSelectionListeners',value:function(){this.document&&this.document.addEventListener('selectionchange',this.onSelectionChange.bind(this),!1)}},{key:'removeSelectionListeners',value:function(){this.document&&this.document.removeEventListener('selectionchange',this.onSelectionChange,!1)}},{key:'onSelectionChange',value:function(){this.selectionEndTimeout&&clearTimeout(this.selectionEndTimeout),this.selectionEndTimeout=setTimeout(function(){var e=this.window.getSelection();this.triggerSelectedEvent(e)}.bind(this),250)}},{key:'triggerSelectedEvent',value:function(e){var t,n;e&&0<e.rangeCount&&(t=e.getRangeAt(0),!t.collapsed&&(n=new c.default(t,this.cfiBase).toString(),this.emit(f.EVENTS.CONTENTS.SELECTED,n),this.emit(f.EVENTS.CONTENTS.SELECTED_RANGE,t)))}},{key:'range',value:function(e,t){var n=new c.default(e);return n.toRange(this.document,t)}},{key:'cfiFromRange',value:function(e,t){return new c.default(e,this.cfiBase,t).toString()}},{key:'cfiFromNode',value:function(e,t){return new c.default(e,this.cfiBase,t).toString()}},{key:'map',value:function(e){var t=new h.default(e);return t.section()}},{key:'size',value:function(e,t){var n={scale:1,scalable:'no'};this.layoutStyle('scrolling'),0<=e&&(this.width(e),n.width=e,this.css('padding','0 '+e/12+'px',!0)),0<=t&&(this.height(t),n.height=t),this.css('margin','0'),this.css('box-sizing','border-box'),this.viewport(n)}},{key:'columns',value:function(e,t,n,a){var i=(0,d.prefixed)('column-axis'),o=(0,d.prefixed)('column-gap'),s=(0,d.prefixed)('column-width'),r=(0,d.prefixed)('column-fill'),l=this.writingMode(),u=0===l.indexOf('vertical')?'vertical':'horizontal';this.layoutStyle('paginated'),'rtl'===this.content.dir&&this.direction('rtl'),this.width(e),this.height(t),this.viewport({width:e,height:t,scale:1,scalable:'no'}),this.css('overflow-y','hidden'),this.css('margin','0',!0),'vertical'==u?this.css('padding',a/2+'px 20px',!0):this.css('padding','20px '+a/2+'px',!0),this.css('box-sizing','border-box'),this.css('max-width','inherit'),this.css(i,'horizontal'),this.css(r,'auto'),this.css(o,a+'px'),this.css(s,n+'px')}},{key:'scaler',value:function(e,t,n){var a='';this.css('transform-origin','top left'),(0<=t||0<=n)&&(a=' translate('+(t||0)+'px, '+(n||0)+'px )'),this.css('transform','scale('+e+')'+a)}},{key:'fit',value:function(e,t){var n=this.viewport(),a=e/parseInt(n.width),i=t/parseInt(n.height),o=a<i?a:i,s=(t-n.height*o)/2;this.layoutStyle('paginated'),this.width(e),this.height(t),this.overflow('hidden'),this.scaler(o,0,s),this.css('background-color','transparent')}},{key:'direction',value:function(e){this.documentElement&&(this.documentElement.style.direction=e)}},{key:'mapPage',value:function(e,t,n,a,i){var o=new h.default(t,i);return o.page(this,e,n,a)}},{key:'linksHandler',value:function(){var e=this;(0,g.replaceLinks)(this.content,function(t){e.emit(f.EVENTS.CONTENTS.LINK_CLICKED,t)})}},{key:'writingMode',value:function(e){var t=(0,d.prefixed)('writing-mode');return e&&this.documentElement&&(this.documentElement.style[t]=e),this.window.getComputedStyle(this.documentElement)[t]||''}},{key:'layoutStyle',value:function(e){return e&&(this._layoutStyle=e,navigator.epubReadingSystem.layoutStyle=this._layoutStyle),this._layoutStyle||'paginated'}},{key:'epubReadingSystem',value:function(e,t){return navigator.epubReadingSystem={name:e,version:t,layoutStyle:this.layoutStyle(),hasFeature:function(e){return'dom-manipulation'===e||'layout-changes'===e||'touch-events'===e||'mouse-events'===e||'keyboard-events'===e||'spine-scripting'!==e&&!1}},navigator.epubReadingSystem}},{key:'destroy',value:function(){this.observer&&this.observer.disconnect(),this.document.removeEventListener('transitionend',this.resizeCheck),this.removeListeners()}}],[{key:'listenedEvents',get:function(){return f.DOM_EVENTS}}]),e}();(0,l.default)(b.prototype),t.default=b,e.exports=t['default']},function(e,t,n){'use strict';function i(e){return e&&e.__esModule?e:{default:e}}function o(e,t){if(!(e instanceof t))throw new TypeError('Cannot call a class as a function')}Object.defineProperty(t,'__esModule',{value:!0});var r=function(){function e(e,t){for(var n=0,a;n<t.length;n++)a=t[n],a.enumerable=a.enumerable||!1,a.configurable=!0,'value'in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}return function(t,n,a){return n&&e(t.prototype,n),a&&e(t,a),t}}(),l=n(2),d=i(l),u=n(0),c=n(19),p=i(c),h=n(12),g=i(h),f=n(56),m=i(f),y=n(66),v=i(y),b=n(3),k=function(){function e(t){o(this,e),this.name='default',this.View=t.view,this.request=t.request,this.renditionQueue=t.queue,this.q=new g.default(this),this.settings=(0,u.extend)(this.settings||{},{infinite:!0,hidden:!1,width:void 0,height:void 0,axis:void 0,flow:'scrolled',ignoreClass:''}),(0,u.extend)(this.settings,t.settings||{}),this.viewSettings={ignoreClass:this.settings.ignoreClass,axis:this.settings.axis,flow:this.settings.flow,layout:this.layout,method:this.settings.method,width:0,height:0,forceEvenPages:!0},this.rendered=!1}return r(e,[{key:'render',value:function(e,t){var n=e.tagName;n&&('body'==n.toLowerCase()||'html'==n.toLowerCase())&&(this.fullsize=!0),this.fullsize&&(this.settings.overflow='visible',this.overflow=this.settings.overflow),this.settings.size=t,this.stage=new m.default({width:t.width,height:t.height,overflow:this.overflow,hidden:this.settings.hidden,axis:this.settings.axis,fullsize:this.fullsize,direction:this.settings.direction}),this.stage.attachTo(e),this.container=this.stage.getContainer(),this.views=new v.default(this.container),this._bounds=this.bounds(),this._stageSize=this.stage.size(),this.viewSettings.width=this._stageSize.width,this.viewSettings.height=this._stageSize.height,this.stage.onResize(this.onResized.bind(this)),this.stage.onOrientationChange(this.onOrientationChange.bind(this)),this.addEventListeners(),this.layout&&this.updateLayout(),this.rendered=!0}},{key:'addEventListeners',value:function(){var e;window.addEventListener('unload',function(){this.destroy()}.bind(this)),e=this.fullsize?window:this.container,e.addEventListener('scroll',this.onScroll.bind(this))}},{key:'removeEventListeners',value:function(){var e;e=this.fullsize?window:this.container,e.removeEventListener('scroll',this.onScroll.bind(this))}},{key:'destroy',value:function(){clearTimeout(this.orientationTimeout),clearTimeout(this.resizeTimeout),clearTimeout(this.afterScrolled),this.clear(),this.removeEventListeners(),this.stage.destroy(),this.rendered=!1}},{key:'onOrientationChange',value:function(){var e=window,t=e.orientation;this.resize(),clearTimeout(this.orientationTimeout),this.orientationTimeout=setTimeout(function(){this.orientationTimeout=void 0,this.resize(),this.emit(b.EVENTS.MANAGERS.ORIENTATION_CHANGE,t)}.bind(this),500)}},{key:'onResized',value:function(){this.resize()}},{key:'resize',value:function(e,t){var n=this.stage.size(e,t);return this.winBounds=(0,u.windowBounds)(),this.orientationTimeout&&this.winBounds.width===this.winBounds.height?void(this._stageSize=void 0):void(this._stageSize&&this._stageSize.width===n.width&&this._stageSize.height===n.height||(this._stageSize=n,this._bounds=this.bounds(),this.clear(),this.viewSettings.width=this._stageSize.width,this.viewSettings.height=this._stageSize.height,this.updateLayout(),this.emit(b.EVENTS.MANAGERS.RESIZED,{width:this._stageSize.width,height:this._stageSize.height})))}},{key:'createView',value:function(e){return new this.View(e,this.viewSettings)}},{key:'display',value:function(e,t){var n=new u.defer,a=n.promise;(t===e.href||(0,u.isNumber)(t))&&(t=void 0);var i=this.views.find(e);if(i&&e){var o=i.offset();if('ltr'===this.settings.direction)this.scrollTo(o.left,o.top,!0);else{var s=i.width();this.scrollTo(o.left+s,o.top,!0)}if(t){var r=i.locationOf(t);this.moveTo(r)}return n.resolve(),a}return this.clear(),this.add(e).then(function(e){if(t){var n=e.locationOf(t);this.moveTo(n)}}.bind(this),function(e){n.reject(e)}).then(function(){var t;if('pre-paginated'===this.layout.name&&1<this.layout.divisor&&(t=e.next(),t))return this.add(t)}.bind(this)).then(function(){this.views.show(),n.resolve()}.bind(this)),a}},{key:'afterDisplayed',value:function(e){this.emit(b.EVENTS.MANAGERS.ADDED,e)}},{key:'afterResized',value:function(e){this.emit(b.EVENTS.MANAGERS.RESIZE,e.section)}},{key:'moveTo',value:function(e){var t=0,n=0;this.isPaginated?(t=s(e.left/this.layout.delta)*this.layout.delta,t+this.layout.delta>this.container.scrollWidth&&(t=this.container.scrollWidth-this.layout.delta)):n=e.top,this.scrollTo(t,n,!0)}},{key:'add',value:function(e){var t=this,n=this.createView(e);return this.views.append(n),n.onDisplayed=this.afterDisplayed.bind(this),n.onResize=this.afterResized.bind(this),n.on(b.EVENTS.VIEWS.AXIS,function(e){t.updateAxis(e)}),n.display(this.request)}},{key:'append',value:function(e){var t=this,n=this.createView(e);return this.views.append(n),n.onDisplayed=this.afterDisplayed.bind(this),n.onResize=this.afterResized.bind(this),n.on(b.EVENTS.VIEWS.AXIS,function(e){t.updateAxis(e)}),n.display(this.request)}},{key:'prepend',value:function(e){var t=this,n=this.createView(e);return n.on(b.EVENTS.VIEWS.RESIZED,function(e){t.counter(e)}),this.views.prepend(n),n.onDisplayed=this.afterDisplayed.bind(this),n.onResize=this.afterResized.bind(this),n.on(b.EVENTS.VIEWS.AXIS,function(e){t.updateAxis(e)}),n.display(this.request)}},{key:'counter',value:function(e){'vertical'===this.settings.axis?this.scrollBy(0,e.heightDelta,!0):this.scrollBy(e.widthDelta,0,!0)}},{key:'next',value:function(){var e=this.settings.direction,t,n;if(this.views.length){if(this.isPaginated&&'horizontal'===this.settings.axis&&(!e||'ltr'===e))this.scrollLeft=this.container.scrollLeft,n=this.container.scrollLeft+this.container.offsetWidth+this.layout.delta,n<=this.container.scrollWidth?this.scrollBy(this.layout.delta,0,!0):t=this.views.last().section.next();else if(this.isPaginated&&'horizontal'===this.settings.axis&&'rtl'===e)this.scrollLeft=this.container.scrollLeft,n=this.container.scrollLeft,0<n?this.scrollBy(this.layout.delta,0,!0):t=this.views.last().section.next();else if(this.isPaginated&&'vertical'===this.settings.axis){this.scrollTop=this.container.scrollTop;var a=this.container.scrollTop+this.container.offsetHeight;a<this.container.scrollHeight?this.scrollBy(0,this.layout.height,!0):t=this.views.last().section.next()}else t=this.views.last().section.next();return t?(this.clear(),this.append(t).then(function(){var e;if('pre-paginated'===this.layout.name&&1<this.layout.divisor&&(e=t.next(),e))return this.append(e)}.bind(this),function(e){displaying.reject(e)}).then(function(){this.views.show()}.bind(this))):void 0}}},{key:'prev',value:function(){var e=this.settings.direction,t,n;if(this.views.length){if(this.isPaginated&&'horizontal'===this.settings.axis&&(!e||'ltr'===e))this.scrollLeft=this.container.scrollLeft,n=this.container.scrollLeft,0<n?this.scrollBy(-this.layout.delta,0,!0):t=this.views.first().section.prev();else if(this.isPaginated&&'horizontal'===this.settings.axis&&'rtl'===e)this.scrollLeft=this.container.scrollLeft,n=this.container.scrollLeft+this.container.offsetWidth+this.layout.delta,n<=this.container.scrollWidth?this.scrollBy(-this.layout.delta,0,!0):t=this.views.first().section.prev();else if(this.isPaginated&&'vertical'===this.settings.axis){this.scrollTop=this.container.scrollTop;var a=this.container.scrollTop;0<a?this.scrollBy(0,-this.layout.height,!0):t=this.views.first().section.prev()}else t=this.views.first().section.prev();return t?(this.clear(),this.prepend(t).then(function(){var e;if('pre-paginated'===this.layout.name&&1<this.layout.divisor&&(e=t.prev(),e))return this.prepend(e)}.bind(this),function(e){displaying.reject(e)}).then(function(){this.isPaginated&&'horizontal'===this.settings.axis&&('rtl'===this.settings.direction?this.scrollTo(0,0,!0):this.scrollTo(this.container.scrollWidth-this.layout.delta,0,!0)),this.views.show()}.bind(this))):void 0}}},{key:'current',value:function(){var e=this.visible();return e.length?e[e.length-1]:null}},{key:'clear',value:function(){this.views&&(this.views.hide(),this.scrollTo(0,0,!0),this.views.clear())}},{key:'currentLocation',value:function(){return this.location='vertical'===this.settings.axis?this.scrolledLocation():this.paginatedLocation(),this.location}},{key:'scrolledLocation',value:function(){var e=this,t=this.visible(),n=this.container.getBoundingClientRect(),o=n.height<window.innerHeight?n.height:window.innerHeight,s=0,r=0;this.fullsize&&(s=window.scrollY);var i=t.map(function(t){var l=t.section,d=l.index,u=l.href,c=t.position(),p=t.height(),h=s+n.top-c.top+r,g=h+o-r;g>p&&(g=p,r=g-h);var f=e.layout.count(p,o).pages,m=a(h/o),y=[],v=a(g/o);y=[];for(var b=m,i;b<=v;b++)i=b+1,y.push(i);var k=e.mapping.page(t.contents,t.section.cfiBase,h,g);return{index:d,href:u,pages:y,totalPages:f,mapping:k}});return i}},{key:'paginatedLocation',value:function(){var e=this,t=this.visible(),n=this.container.getBoundingClientRect(),a=0,o=0;this.fullsize&&(a=window.scrollX);var i=t.map(function(t){var r=t.section,l=r.index,d=r.href,u=t.offset().left,c=t.position().left,p=t.width(),h=a+n.left-c+o,g=h+e.layout.width-o,f=e.mapping.page(t.contents,t.section.cfiBase,h,g),m=e.layout.count(p).pages,y=s(h/e.layout.pageWidth),v=[],b=s(g/e.layout.pageWidth);if(0>y&&(y=0,++b),'rtl'===e.settings.direction){var k=y;y=m-b,b=m-k}for(var x=y+1,i;x<=b;x++)i=x,v.push(i);return{index:l,href:d,pages:v,totalPages:m,mapping:f}});return i}},{key:'isVisible',value:function(e,t,n,a){var i=e.position(),o=a||this.bounds();return'horizontal'===this.settings.axis&&i.right>o.left-t&&i.left<o.right+n||'vertical'===this.settings.axis&&i.bottom>o.top-t&&i.top<o.bottom+n}},{key:'visible',value:function(){for(var e=this.bounds(),t=this.views.displayed(),n=t.length,a=[],o=0,i,s;o<n;o++)s=t[o],i=this.isVisible(s,0,0,e),!0===i&&a.push(s);return a}},{key:'scrollBy',value:function(e,t,n){var a='rtl'===this.settings.direction?-1:1;n&&(this.ignore=!0),this.fullsize?window.scrollBy(e*a,t*a):(e&&(this.container.scrollLeft+=e*a),t&&(this.container.scrollTop+=t)),this.scrolled=!0}},{key:'scrollTo',value:function(e,t,n){n&&(this.ignore=!0),this.fullsize?window.scrollTo(e,t):(this.container.scrollLeft=e,this.container.scrollTop=t),this.scrolled=!0}},{key:'onScroll',value:function(){var e,t;this.fullsize?(e=window.scrollY,t=window.scrollX):(e=this.container.scrollTop,t=this.container.scrollLeft),this.scrollTop=e,this.scrollLeft=t,this.ignore?this.ignore=!1:(this.emit(b.EVENTS.MANAGERS.SCROLL,{top:e,left:t}),clearTimeout(this.afterScrolled),this.afterScrolled=setTimeout(function(){this.emit(b.EVENTS.MANAGERS.SCROLLED,{top:this.scrollTop,left:this.scrollLeft})}.bind(this),20))}},{key:'bounds',value:function(){var e;return e=this.stage.bounds(),e}},{key:'applyLayout',value:function(e){this.layout=e,this.updateLayout()}},{key:'updateLayout',value:function(){this.stage&&(this._stageSize=this.stage.size(),this.isPaginated?(this.layout.calculate(this._stageSize.width,this._stageSize.height,this.settings.gap),this.settings.offset=this.layout.delta):this.layout.calculate(this._stageSize.width,this._stageSize.height),this.viewSettings.width=this.layout.width,this.viewSettings.height=this.layout.height,this.setLayout(this.layout))}},{key:'setLayout',value:function(e){this.viewSettings.layout=e,this.mapping=new p.default(e.props,this.settings.direction,this.settings.axis),this.views&&this.views.forEach(function(t){t&&t.setLayout(e)})}},{key:'updateAxis',value:function(e,t){this.isPaginated||(e='vertical'),(t||e!==this.settings.axis)&&(this.settings.axis=e,this.stage&&this.stage.axis(e),this.viewSettings.axis=e,this.mapping&&(this.mapping=new p.default(this.layout.props,this.settings.direction,this.settings.axis)),this.layout&&('vertical'===e?this.layout.spread('none'):this.layout.spread(this.layout.settings.spread)))}},{key:'updateFlow',value:function(e){var t='paginated'===e||'auto'===e;this.isPaginated=t,('scrolled-doc'===e||'scrolled-continuous'===e||'scrolled'===e)&&this.updateAxis('vertical'),this.viewSettings.flow=e,this.overflow=this.settings.overflow?this.settings.overflow:t?'hidden':'auto',this.updateLayout()}},{key:'getContents',value:function(){var e=[];return this.views?(this.views.forEach(function(t){var n=t&&t.contents;n&&e.push(n)}),e):e}},{key:'direction',value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:'ltr';this.settings.direction=e,this.stage&&this.stage.direction(e),this.viewSettings.direction=e,this.updateLayout()}},{key:'isRendered',value:function(){return this.rendered}}]),e}();(0,d.default)(k.prototype),t.default=k,e.exports=t['default']},function(e){e.exports=function(e){var t=typeof e;return null!=e&&('object'==t||'function'==t)}},function(t){t.exports=e},function(e){'use strict';var t={application:{ecmascript:['es','ecma'],javascript:'js',ogg:'ogx',pdf:'pdf',postscript:['ps','ai','eps','epsi','epsf','eps2','eps3'],"rdf+xml":'rdf',smil:['smi','smil'],"xhtml+xml":['xhtml','xht'],xml:['xml','xsl','xsd','opf','ncx'],zip:'zip',"x-httpd-eruby":'rhtml',"x-latex":'latex',"x-maker":['frm','maker','frame','fm','fb','book','fbdoc'],"x-object":'o',"x-shockwave-flash":['swf','swfl'],"x-silverlight":'scr',"epub+zip":'epub',"font-tdpfr":'pfr',"inkml+xml":['ink','inkml'],json:'json',"jsonml+json":'jsonml',"mathml+xml":'mathml',"metalink+xml":'metalink',mp4:'mp4s',"omdoc+xml":'omdoc',oxps:'oxps',"vnd.amazon.ebook":'azw',widget:'wgt',"x-dtbook+xml":'dtb',"x-dtbresource+xml":'res',"x-font-bdf":'bdf',"x-font-ghostscript":'gsf',"x-font-linux-psf":'psf',"x-font-otf":'otf',"x-font-pcf":'pcf',"x-font-snf":'snf',"x-font-ttf":['ttf','ttc'],"x-font-type1":['pfa','pfb','pfm','afm'],"x-font-woff":'woff',"x-mobipocket-ebook":['prc','mobi'],"x-mspublisher":'pub',"x-nzb":'nzb',"x-tgif":'obj',"xaml+xml":'xaml',"xml-dtd":'dtd',"xproc+xml":'xpl',"xslt+xml":'xslt',"internet-property-stream":'acx',"x-compress":'z',"x-compressed":'tgz',"x-gzip":'gz'},audio:{flac:'flac',midi:['mid','midi','kar','rmi'],mpeg:['mpga','mpega','mp2','mp3','m4a','mp2a','m2a','m3a'],mpegurl:'m3u',ogg:['oga','ogg','spx'],"x-aiff":['aif','aiff','aifc'],"x-ms-wma":'wma',"x-wav":'wav',adpcm:'adp',mp4:'mp4a',webm:'weba',"x-aac":'aac',"x-caf":'caf',"x-matroska":'mka',"x-pn-realaudio-plugin":'rmp',xm:'xm',mid:['mid','rmi']},image:{gif:'gif',ief:'ief',jpeg:['jpeg','jpg','jpe'],pcx:'pcx',png:'png',"svg+xml":['svg','svgz'],tiff:['tiff','tif'],"x-icon":'ico',bmp:'bmp',webp:'webp',"x-pict":['pic','pct'],"x-tga":'tga',"cis-cod":'cod'},text:{"cache-manifest":['manifest','appcache'],css:'css',csv:'csv',html:['html','htm','shtml','stm'],mathml:'mml',plain:['txt','text','brf','conf','def','list','log','in','bas'],richtext:'rtx',"tab-separated-values":'tsv',"x-bibtex":'bib'},video:{mpeg:['mpeg','mpg','mpe','m1v','m2v','mp2','mpa','mpv2'],mp4:['mp4','mp4v','mpg4'],quicktime:['qt','mov'],ogg:'ogv',"vnd.mpegurl":['mxu','m4u'],"x-flv":'flv',"x-la-asf":['lsf','lsx'],"x-mng":'mng',"x-ms-asf":['asf','asx','asr'],"x-ms-wm":'wm',"x-ms-wmv":'wmv',"x-ms-wmx":'wmx',"x-ms-wvx":'wvx',"x-msvideo":'avi',"x-sgi-movie":'movie',"x-matroska":['mpv','mkv','mk3d','mks'],"3gpp2":'3g2',h261:'h261',h263:'h263',h264:'h264',jpeg:'jpgv',jpm:['jpm','jpgm'],mj2:['mj2','mjp2'],"vnd.ms-playready.media.pyv":'pyv',"vnd.uvvu.mp4":['uvu','uvvu'],"vnd.vivo":'viv',webm:'webm',"x-f4v":'f4v',"x-m4v":'m4v',"x-ms-vob":'vob',"x-smv":'smv'}},n=function(){var e={},n,a,i,o;for(n in t)if(t.hasOwnProperty(n))for(a in t[n])if(t[n].hasOwnProperty(a))if(i=t[n][a],'string'==typeof i)e[i]=n+'/'+a;else for(o=0;o<i.length;o++)e[i[o]]=n+'/'+a;return e}();e.exports={lookup:function(e){return e&&n[e.split('.').pop().toLowerCase()]||'text/plain'}}},function(e,t,n){'use strict';function a(e){return e&&e.__esModule?e:{default:e}}function i(e,t){if(!(e instanceof t))throw new TypeError('Cannot call a class as a function')}Object.defineProperty(t,'__esModule',{value:!0});var o='function'==typeof Symbol&&'symbol'==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&'function'==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?'symbol':typeof e},s=function(){function e(e,t){for(var n=0,a;n<t.length;n++)a=t[n],a.enumerable=a.enumerable||!1,a.configurable=!0,'value'in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}return function(t,n,a){return n&&e(t.prototype,n),a&&e(t,a),t}}(),r=n(2),l=a(r),d=n(0),u=n(10),c=a(u),p=n(1),h=a(p),g=n(12),f=a(g),m=n(50),y=a(m),v=n(51),b=a(v),k=n(13),x=a(k),E=n(52),_=a(E),w=n(3),S=n(20),C=a(S),T=n(14),N=a(T),R=n(24),L=a(R),P=function(){function e(t,n){i(this,e),this.settings=(0,d.extend)(this.settings||{},{width:null,height:null,ignoreClass:'',manager:'default',view:'iframe',flow:null,layout:null,spread:null,minSpreadWidth:800,stylesheet:null,script:null}),(0,d.extend)(this.settings,n),'object'===o(this.settings.manager)&&(this.manager=this.settings.manager),this.book=t,this.hooks={},this.hooks.display=new c.default(this),this.hooks.serialize=new c.default(this),this.hooks.content=new c.default(this),this.hooks.unloaded=new c.default(this),this.hooks.layout=new c.default(this),this.hooks.render=new c.default(this),this.hooks.show=new c.default(this),this.hooks.content.register(this.handleLinks.bind(this)),this.hooks.content.register(this.passEvents.bind(this)),this.hooks.content.register(this.adjustImages.bind(this)),this.book.spine.hooks.content.register(this.injectIdentifier.bind(this)),this.settings.stylesheet&&this.book.spine.hooks.content.register(this.injectStylesheet.bind(this)),this.settings.script&&this.book.spine.hooks.content.register(this.injectScript.bind(this)),this.themes=new b.default(this),this.annotations=new _.default(this),this.epubcfi=new h.default,this.q=new f.default(this),this.location=void 0,this.q.enqueue(this.book.opened),this.starting=new d.defer,this.started=this.starting.promise,this.q.enqueue(this.start)}return s(e,[{key:'setManager',value:function(e){this.manager=e}},{key:'requireManager',value:function(e){var t;return t='string'==typeof e&&'default'===e?N.default:'string'==typeof e&&'continuous'===e?L.default:e,t}},{key:'requireView',value:function(e){var t;return t='string'==typeof e&&'iframe'===e?C.default:e,t}},{key:'start',value:function(){this.manager||(this.ViewManager=this.requireManager(this.settings.manager),this.View=this.requireView(this.settings.view),this.manager=new this.ViewManager({view:this.View,queue:this.q,request:this.book.load.bind(this.book),settings:this.settings})),this.direction(this.book.package.metadata.direction),this.settings.globalLayoutProperties=this.determineLayoutProperties(this.book.package.metadata),this.flow(this.settings.globalLayoutProperties.flow),this.layout(this.settings.globalLayoutProperties),this.manager.on(w.EVENTS.MANAGERS.ADDED,this.afterDisplayed.bind(this)),this.manager.on(w.EVENTS.MANAGERS.REMOVED,this.afterRemoved.bind(this)),this.manager.on(w.EVENTS.MANAGERS.RESIZED,this.onResized.bind(this)),this.manager.on(w.EVENTS.MANAGERS.ORIENTATION_CHANGE,this.onOrientationChange.bind(this)),this.manager.on(w.EVENTS.MANAGERS.SCROLLED,this.reportLocation.bind(this)),this.emit(w.EVENTS.RENDITION.STARTED),this.starting.resolve()}},{key:'attachTo',value:function(e){return this.q.enqueue(function(){this.manager.render(e,{width:this.settings.width,height:this.settings.height}),this.emit(w.EVENTS.RENDITION.ATTACHED)}.bind(this))}},{key:'display',value:function(e){return this.displaying&&this.displaying.resolve(),this.q.enqueue(this._display,e)}},{key:'_display',value:function(e){var t=this;if(this.book){var n=this.epubcfi.isCfiString(e),a=new d.defer,i=a.promise,o;return(this.displaying=a,this.book.locations.length()&&(0,d.isFloat)(e)&&(e=this.book.locations.cfiFromPercentage(parseFloat(e))),o=this.book.spine.get(e),!o)?(a.reject(new Error('No Section Found')),i):(this.manager.display(o,e).then(function(){a.resolve(o),t.displaying=void 0,t.emit(w.EVENTS.RENDITION.DISPLAYED,o),t.reportLocation()},function(e){t.emit(w.EVENTS.RENDITION.DISPLAY_ERROR,e)}),i)}}},{key:'afterDisplayed',value:function(e){var t=this;e.on(w.EVENTS.VIEWS.MARK_CLICKED,function(n,a){return t.triggerMarkEvent(n,a,e)}),this.hooks.render.trigger(e,this).then(function(){e.contents?t.hooks.content.trigger(e.contents,t).then(function(){t.emit(w.EVENTS.RENDITION.RENDERED,e.section,e)}):t.emit(w.EVENTS.RENDITION.RENDERED,e.section,e)})}},{key:'afterRemoved',value:function(e){var t=this;this.hooks.unloaded.trigger(e,this).then(function(){t.emit(w.EVENTS.RENDITION.REMOVED,e.section,e)})}},{key:'onResized',value:function(e){this.emit(w.EVENTS.RENDITION.RESIZED,{width:e.width,height:e.height}),this.location&&this.location.start&&this.display(this.location.start.cfi)}},{key:'onOrientationChange',value:function(e){this.emit(w.EVENTS.RENDITION.ORIENTATION_CHANGE,e)}},{key:'moveTo',value:function(e){this.manager.moveTo(e)}},{key:'resize',value:function(e,t){e&&(this.settings.width=e),t&&(this.settings.height=t),this.manager.resize(e,t)}},{key:'clear',value:function(){this.manager.clear()}},{key:'next',value:function(){return this.q.enqueue(this.manager.next.bind(this.manager)).then(this.reportLocation.bind(this))}},{key:'prev',value:function(){return this.q.enqueue(this.manager.prev.bind(this.manager)).then(this.reportLocation.bind(this))}},{key:'determineLayoutProperties',value:function(e){var t=this.settings.layout||e.layout||'reflowable',n=this.settings.spread||e.spread||'auto',a=this.settings.orientation||e.orientation||'auto',i=this.settings.flow||e.flow||'auto',o=e.viewport||'',s=this.settings.minSpreadWidth||e.minSpreadWidth||800,r=this.settings.direction||e.direction||'ltr',l;return(0===this.settings.width||0<this.settings.width)&&(0===this.settings.height||0<this.settings.height),l={layout:t,spread:n,orientation:a,flow:i,viewport:o,minSpreadWidth:s,direction:r},l}},{key:'flow',value:function(e){var t=e;('scrolled'===e||'scrolled-doc'===e||'scrolled-continuous'===e)&&(t='scrolled'),('auto'===e||'paginated'===e)&&(t='paginated'),this.settings.flow=e,this._layout&&this._layout.flow(t),this.manager&&this._layout&&this.manager.applyLayout(this._layout),this.manager&&this.manager.updateFlow(t),this.manager&&this.manager.isRendered()&&this.location&&(this.manager.clear(),this.display(this.location.start.cfi))}},{key:'layout',value:function(e){var t=this;return e&&(this._layout=new y.default(e),this._layout.spread(e.spread,this.settings.minSpreadWidth),this._layout.on(w.EVENTS.LAYOUT.UPDATED,function(e,n){t.emit(w.EVENTS.RENDITION.LAYOUT,e,n)})),this.manager&&this._layout&&this.manager.applyLayout(this._layout),this._layout}},{key:'spread',value:function(e,t){this._layout.spread(e,t),this.manager.isRendered()&&this.manager.updateLayout()}},{key:'direction',value:function(e){this.settings.direction=e||'ltr',this.manager&&this.manager.direction(this.settings.direction),this.manager&&this.manager.isRendered()&&this.location&&(this.manager.clear(),this.display(this.location.start.cfi))}},{key:'reportLocation',value:function(){return this.q.enqueue(function(){requestAnimationFrame(function(){var e=this.manager.currentLocation();if(e&&e.then&&'function'==typeof e.then)e.then(function(e){var t=this.located(e);t&&t.start&&t.end&&(this.location=t,this.emit(w.EVENTS.RENDITION.LOCATION_CHANGED,{index:this.location.start.index,href:this.location.start.href,start:this.location.start.cfi,end:this.location.end.cfi,percentage:this.location.start.percentage}),this.emit(w.EVENTS.RENDITION.RELOCATED,this.location))}.bind(this));else if(e){var t=this.located(e);if(!t||!t.start||!t.end)return;this.location=t,this.emit(w.EVENTS.RENDITION.LOCATION_CHANGED,{index:this.location.start.index,href:this.location.start.href,start:this.location.start.cfi,end:this.location.end.cfi,percentage:this.location.start.percentage}),this.emit(w.EVENTS.RENDITION.RELOCATED,this.location)}}.bind(this))}.bind(this))}},{key:'currentLocation',value:function(){var e=this.manager.currentLocation();if(e&&e.then&&'function'==typeof e.then)e.then(function(e){var t=this.located(e);return t}.bind(this));else if(e){var t=this.located(e);return t}}},{key:'located',value:function(e){if(!e.length)return{};var t=e[0],n=e[e.length-1],a={start:{index:t.index,href:t.href,cfi:t.mapping.start,displayed:{page:t.pages[0]||1,total:t.totalPages}},end:{index:n.index,href:n.href,cfi:n.mapping.end,displayed:{page:n.pages[n.pages.length-1]||1,total:n.totalPages}}},i=this.book.locations.locationFromCfi(t.mapping.start),o=this.book.locations.locationFromCfi(n.mapping.end);null!=i&&(a.start.location=i,a.start.percentage=this.book.locations.percentageFromLocation(i)),null!=o&&(a.end.location=o,a.end.percentage=this.book.locations.percentageFromLocation(o));var s=this.book.pageList.pageFromCfi(t.mapping.start),r=this.book.pageList.pageFromCfi(n.mapping.end);return-1!=s&&(a.start.page=s),-1!=r&&(a.end.page=r),n.index===this.book.spine.last().index&&a.end.displayed.page>=a.end.displayed.total&&(a.atEnd=!0),t.index===this.book.spine.first().index&&1===a.start.displayed.page&&(a.atStart=!0),a}},{key:'destroy',value:function(){this.manager&&this.manager.destroy(),this.book=void 0}},{key:'passEvents',value:function(t){var n=this,e=x.default.listenedEvents;e.forEach(function(a){t.on(a,function(e){return n.triggerViewEvent(e,t)})}),t.on(w.EVENTS.CONTENTS.SELECTED,function(a){return n.triggerSelectedEvent(a,t)})}},{key:'triggerViewEvent',value:function(t,e){this.emit(t.type,t,e)}},{key:'triggerSelectedEvent',value:function(e,t){this.emit(w.EVENTS.RENDITION.SELECTED,e,t)}},{key:'triggerMarkEvent',value:function(e,t,n){this.emit(w.EVENTS.RENDITION.MARK_CLICKED,e,t,n)}},{key:'getRange',value:function(e,t){var n=new h.default(e),a=this.manager.visible().filter(function(e){if(n.spinePos===e.index)return!0});if(a.length)return a[0].contents.range(n,t)}},{key:'adjustImages',value:function(e){return'pre-paginated'===this._layout.name?new Promise(function(e){e()}):(e.addStylesheetRules({img:{"max-width":(this._layout.columnWidth?this._layout.columnWidth+'px':'100%')+'!important',"max-height":(this._layout.height?0.6*this._layout.height+'px':'60%')+'!important',"object-fit":'contain',"page-break-inside":'avoid'},svg:{"max-width":(this._layout.columnWidth?this._layout.columnWidth+'px':'100%')+'!important',"max-height":(this._layout.height?0.6*this._layout.height+'px':'60%')+'!important',"page-break-inside":'avoid'}}),new Promise(function(e){setTimeout(function(){e()},1)}))}},{key:'getContents',value:function(){return this.manager?this.manager.getContents():[]}},{key:'views',value:function(){var e=this.manager?this.manager.views:void 0;return e||[]}},{key:'handleLinks',value:function(e){var t=this;e&&e.on(w.EVENTS.CONTENTS.LINK_CLICKED,function(e){var n=t.book.path.relative(e);t.display(n)})}},{key:'injectStylesheet',value:function(e){var t=e.createElement('link');t.setAttribute('type','text/css'),t.setAttribute('rel','stylesheet'),t.setAttribute('href',this.settings.stylesheet),e.getElementsByTagName('head')[0].appendChild(t)}},{key:'injectScript',value:function(e){var t=e.createElement('script');t.setAttribute('type','text/javascript'),t.setAttribute('src',this.settings.script),t.textContent=' ',e.getElementsByTagName('head')[0].appendChild(t)}},{key:'injectIdentifier',value:function(e){var t=this.book.package.metadata.identifier,n=e.createElement('meta');n.setAttribute('name','dc.relation.ispartof'),t&&n.setAttribute('content',t),e.getElementsByTagName('head')[0].appendChild(n)}}]),e}();(0,l.default)(P.prototype),t.default=P,e.exports=t['default']},function(e,t,n){'use strict';function o(e,t){if(!(e instanceof t))throw new TypeError('Cannot call a class as a function')}Object.defineProperty(t,'__esModule',{value:!0});var s=function(){function e(e,t){for(var n=0,a;n<t.length;n++)a=t[n],a.enumerable=a.enumerable||!1,a.configurable=!0,'value'in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}return function(t,n,a){return n&&e(t.prototype,n),a&&e(t,a),t}}(),r=n(1),l=function(e){return e&&e.__esModule?e:{default:e}}(r),d=function(){function e(t,n,a,i){o(this,e),this.layout=t,this.horizontal='horizontal'===a,this.direction=n||'ltr',this._dev=i}return s(e,[{key:'section',value:function(e){var t=this.findRanges(e),n=this.rangeListToCfiList(e.section.cfiBase,t);return n}},{key:'page',value:function(e,t,n,a){var i=e&&e.document&&e.document.body,o;if(i){if(o=this.rangePairToCfiPair(t,{start:this.findStart(i,n,a),end:this.findEnd(i,n,a)}),!0===this._dev){var s=e.document,d=new l.default(o.start).toRange(s),u=new l.default(o.end).toRange(s),c=s.defaultView.getSelection(),p=s.createRange();c.removeAllRanges(),p.setStart(d.startContainer,d.startOffset),p.setEnd(u.endContainer,u.endOffset),c.addRange(p)}return o}}},{key:'walk',value:function(e,t){if(!(e&&e.nodeType===Node.TEXT_NODE)){var n={acceptNode:function(e){return 0<e.data.trim().length?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_REJECT}},a=n.acceptNode;a.acceptNode=n.acceptNode;for(var i=document.createTreeWalker(e,NodeFilter.SHOW_TEXT,a,!1),o,s;(o=i.nextNode())&&(s=t(o),!s););return s}}},{key:'findRanges',value:function(e){for(var t=[],n=e.contents.scrollWidth(),o=a(n/this.layout.spreadWidth),s=o*this.layout.divisor,r=this.layout.columnWidth,l=this.layout.gap,d=0,i,u;d<s.pages;d++)i=(r+l)*d,u=r*(d+1)+l*d,t.push({start:this.findStart(e.document.body,i,u),end:this.findEnd(e.document.body,i,u)});return t}},{key:'findStart',value:function(e,t,n){for(var a=this,i=[e],o=e,s,r;i.length;)if(s=i.shift(),r=this.walk(s,function(e){var s,r,l,d,u;if(u=a.getBounds(e),a.horizontal&&'ltr'===a.direction){if(s=a.horizontal?u.left:u.top,r=a.horizontal?u.right:u.bottom,s>=t&&s<=n)return e;if(r>t)return e;o=e,i.push(e)}else if(a.horizontal&&'rtl'===a.direction){if(s=u.left,r=u.right,r<=n&&r>=t)return e;if(s<n)return e;o=e,i.push(e)}else{if(l=u.top,d=u.bottom,l>=t&&l<=n)return e;if(d>t)return e;o=e,i.push(e)}}),r)return this.findTextStartRange(r,t,n);return this.findTextStartRange(o,t,n)}},{key:'findEnd',value:function(e,t,n){for(var a=this,o=[e],s=e,r,l;o.length;)if(r=o.shift(),l=this.walk(r,function(e){var r,l,d,u,c;if(c=a.getBounds(e),a.horizontal&&'ltr'===a.direction){if(r=i(c.left),l=i(c.right),r>n&&s)return s;if(l>n)return e;s=e,o.push(e)}else if(a.horizontal&&'rtl'===a.direction){if(r=i(a.horizontal?c.left:c.top),l=i(a.horizontal?c.right:c.bottom),l<t&&s)return s;if(r<t)return e;s=e,o.push(e)}else{if(d=i(c.top),u=i(c.bottom),d>n&&s)return s;if(u>n)return e;s=e,o.push(e)}}),l)return this.findTextEndRange(l,t,n);return this.findTextEndRange(s,t,n)}},{key:'findTextStartRange',value:function(e,t,n){for(var a=this.splitTextNodeIntoRanges(e),o=0,i,s,r,l,d;o<a.length;o++)if(i=a[o],s=i.getBoundingClientRect(),this.horizontal&&'ltr'===this.direction){if(r=s.left,r>=t)return i;}else if(this.horizontal&&'rtl'===this.direction){if(d=s.right,d<=n)return i;}else if(l=s.top,l>=t)return i;return a[0]}},{key:'findTextEndRange',value:function(e,t,n){for(var a=this.splitTextNodeIntoRanges(e),o=0,i,s,r,l,d,u,c;o<a.length;o++){if(s=a[o],r=s.getBoundingClientRect(),this.horizontal&&'ltr'===this.direction){if(l=r.left,d=r.right,l>n&&i)return i;if(d>n)return s}else if(this.horizontal&&'rtl'===this.direction){if(l=r.left,d=r.right,d<t&&i)return i;if(l<t)return s}else{if(u=r.top,c=r.bottom,u>n&&i)return i;if(c>n)return s}i=s}return a[a.length-1]}},{key:'splitTextNodeIntoRanges',value:function(e,t){var n=[],a=e.textContent||'',i=a.trim(),o=e.ownerDocument,s=t||' ',r=i.indexOf(s),l;if(-1===r||e.nodeType!=Node.TEXT_NODE)return l=o.createRange(),l.selectNodeContents(e),[l];for(l=o.createRange(),l.setStart(e,0),l.setEnd(e,r),n.push(l),l=!1;-1!=r;)r=i.indexOf(s,r+1),0<r&&(l&&(l.setEnd(e,r),n.push(l)),l=o.createRange(),l.setStart(e,r+1));return l&&(l.setEnd(e,i.length),n.push(l)),n}},{key:'rangePairToCfiPair',value:function(e,t){var n=t.start,a=t.end;n.collapse(!0),a.collapse(!1);var i=new l.default(n,e).toString(),o=new l.default(a,e).toString();return{start:i,end:o}}},{key:'rangeListToCfiList',value:function(e,t){for(var n=[],a=0,i;a<t.length;a++)i=this.rangePairToCfiPair(e,t[a]),n.push(i);return n}},{key:'getBounds',value:function(e){var t;if(e.nodeType==Node.TEXT_NODE){var n=document.createRange();n.selectNodeContents(e),t=n.getBoundingClientRect()}else t=e.getBoundingClientRect();return t}},{key:'axis',value:function(e){return e&&(this.horizontal='horizontal'===e),this.horizontal}}]),e}();t.default=d,e.exports=t['default']},function(e,t,n){'use strict';function i(e){return e&&e.__esModule?e:{default:e}}function o(e,t){if(!(e instanceof t))throw new TypeError('Cannot call a class as a function')}Object.defineProperty(t,'__esModule',{value:!0});var s=function(){function e(e,t){for(var n=0,a;n<t.length;n++)a=t[n],a.enumerable=a.enumerable||!1,a.configurable=!0,'value'in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}return function(t,n,a){return n&&e(t.prototype,n),a&&e(t,a),t}}(),r=n(2),l=i(r),d=n(0),u=n(1),c=i(u),p=n(13),h=i(p),g=n(3),f=n(53),m=function(){function e(t,n){o(this,e),this.settings=(0,d.extend)({ignoreClass:'',axis:n.layout&&'scrolled'===n.layout.props.flow?'vertical':'horizontal',direction:void 0,width:0,height:0,layout:void 0,globalLayoutProperties:{},method:void 0},n||{}),this.id='epubjs-view-'+(0,d.uuid)(),this.section=t,this.index=t.index,this.element=this.container(this.settings.axis),this.added=!1,this.displayed=!1,this.rendered=!1,this.fixedWidth=0,this.fixedHeight=0,this.epubcfi=new c.default,this.layout=this.settings.layout,this.pane=void 0,this.highlights={},this.underlines={},this.marks={}}return s(e,[{key:'container',value:function(e){var t=document.createElement('div');return t.classList.add('epub-view'),t.style.height='0px',t.style.width='0px',t.style.overflow='hidden',t.style.position='relative',t.style.display='block',t.style.flex=e&&'horizontal'==e?'none':'initial',t}},{key:'create',value:function(){return this.iframe?this.iframe:(this.element||(this.element=this.createContainer()),this.iframe=document.createElement('iframe'),this.iframe.id=this.id,this.iframe.scrolling='no',this.iframe.style.overflow='hidden',this.iframe.seamless='seamless',this.iframe.style.border='none',this.iframe.setAttribute('enable-annotation','true'),this.resizing=!0,this.element.style.visibility='hidden',this.iframe.style.visibility='hidden',this.iframe.style.width='0',this.iframe.style.height='0',this._width=0,this._height=0,this.element.setAttribute('ref',this.index),this.element.appendChild(this.iframe),this.added=!0,this.elementBounds=(0,d.bounds)(this.element),this.supportsSrcdoc=!!('srcdoc'in this.iframe),this.settings.method||(this.settings.method=this.supportsSrcdoc?'srcdoc':'write'),this.iframe)}},{key:'render',value:function(e){return this.create(),this.size(),this.sectionRender||(this.sectionRender=this.section.render(e)),this.sectionRender.then(function(e){return this.load(e)}.bind(this)).then(function(){var e=this;this.layout.format(this.contents);var t=this.contents.writingMode(),n=0===t.indexOf('vertical')?'vertical':'horizontal';return this.setAxis(n),this.emit(g.EVENTS.VIEWS.AXIS,n),this.addListeners(),new Promise(function(t){e.expand(),t()})}.bind(this),function(t){return this.emit(g.EVENTS.VIEWS.LOAD_ERROR,t),new Promise(function(e,n){n(t)})}.bind(this)).then(function(){this.emit(g.EVENTS.VIEWS.RENDERED,this.section)}.bind(this))}},{key:'reset',value:function(){this.iframe&&(this.iframe.style.width='0',this.iframe.style.height='0',this._width=0,this._height=0,this._textWidth=void 0,this._contentWidth=void 0,this._textHeight=void 0,this._contentHeight=void 0),this._needsReframe=!0}},{key:'size',value:function(e,t){var n=e||this.settings.width,a=t||this.settings.height;'pre-paginated'===this.layout.name?this.lock('both',n,a):'horizontal'===this.settings.axis?this.lock('height',n,a):this.lock('width',n,a),this.settings.width=n,this.settings.height=a}},{key:'lock',value:function(e,t,n){var a=(0,d.borders)(this.element),i;i=this.iframe?(0,d.borders)(this.iframe):{width:0,height:0},'width'==e&&(0,d.isNumber)(t)&&(this.lockedWidth=t-a.width-i.width),'height'==e&&(0,d.isNumber)(n)&&(this.lockedHeight=n-a.height-i.height),'both'===e&&(0,d.isNumber)(t)&&(0,d.isNumber)(n)&&(this.lockedWidth=t-a.width-i.width,this.lockedHeight=n-a.height-i.height),this.displayed&&this.iframe&&this.expand()}},{key:'expand',value:function(){var e=this.lockedWidth,t=this.lockedHeight,n;!this.iframe||this._expanding||(this._expanding=!0,'pre-paginated'===this.layout.name?(e=this.layout.columnWidth,t=this.layout.height):'horizontal'===this.settings.axis?(e=this.contents.textWidth(),0<e%this.layout.pageWidth&&(e=a(e/this.layout.pageWidth)*this.layout.pageWidth),this.settings.forceEvenPages&&(n=e/this.layout.delta,1<this.layout.divisor&&'reflowable'===this.layout.name&&0<n%2&&(e+=this.layout.gap+this.layout.columnWidth))):'vertical'===this.settings.axis&&(t=this.contents.textHeight()),(this._needsReframe||e!=this._width||t!=this._height)&&this.reframe(e,t),this._expanding=!1)}},{key:'reframe',value:function(e,t){var n;(0,d.isNumber)(e)&&(this.element.style.width=e+'px',this.iframe.style.width=e+'px',this._width=e),(0,d.isNumber)(t)&&(this.element.style.height=t+'px',this.iframe.style.height=t+'px',this._height=t);var a=this.prevBounds?e-this.prevBounds.width:e,i=this.prevBounds?t-this.prevBounds.height:t;n={width:e,height:t,widthDelta:a,heightDelta:i},this.pane&&this.pane.render(),this.onResize(this,n),this.emit(g.EVENTS.VIEWS.RESIZED,n),this.prevBounds=n,this.elementBounds=(0,d.bounds)(this.element)}},{key:'load',value:function(e){var t=new d.defer,n=t.promise;if(!this.iframe)return t.reject(new Error('No Iframe Available')),n;if(this.iframe.onload=function(e){this.onLoad(e,t)}.bind(this),'blobUrl'===this.settings.method)this.blobUrl=(0,d.createBlobUrl)(e,'application/xhtml+xml'),this.iframe.src=this.blobUrl;else if('srcdoc'===this.settings.method)this.iframe.srcdoc=e;else{if(this.document=this.iframe.contentDocument,!this.document)return t.reject(new Error('No Document Available')),n;this.iframe.contentDocument.open(),this.iframe.contentDocument.write(e),this.iframe.contentDocument.close()}return n}},{key:'onLoad',value:function(e,t){var n=this;this.window=this.iframe.contentWindow,this.document=this.iframe.contentDocument,this.contents=new h.default(this.document,this.document.body,this.section.cfiBase,this.section.index),this.rendering=!1;var a=this.document.querySelector('link[rel=\'canonical\']');a?a.setAttribute('href',this.section.canonical):(a=this.document.createElement('link'),a.setAttribute('rel','canonical'),a.setAttribute('href',this.section.canonical),this.document.querySelector('head').appendChild(a)),this.contents.on(g.EVENTS.CONTENTS.EXPAND,function(){n.displayed&&n.iframe&&(n.expand(),n.contents&&n.layout.format(n.contents))}),this.contents.on(g.EVENTS.CONTENTS.RESIZE,function(){n.displayed&&n.iframe&&(n.expand(),n.contents&&n.layout.format(n.contents))}),t.resolve(this.contents)}},{key:'setLayout',value:function(e){this.layout=e,this.contents&&(this.layout.format(this.contents),this.expand())}},{key:'setAxis',value:function(e){'scrolled'===this.layout.props.flow&&(e='vertical'),this.settings.axis=e,this.element.style.flex='horizontal'==e?'none':'initial',this.size()}},{key:'addListeners',value:function(){}},{key:'removeListeners',value:function(){}},{key:'display',value:function(e){var t=new d.defer;return this.displayed?t.resolve(this):this.render(e).then(function(){this.emit(g.EVENTS.VIEWS.DISPLAYED,this),this.onDisplayed(this),this.displayed=!0,t.resolve(this)}.bind(this),function(e){t.reject(e,this)}),t.promise}},{key:'show',value:function(){this.element.style.visibility='visible',this.iframe&&(this.iframe.style.visibility='visible'),this.emit(g.EVENTS.VIEWS.SHOWN,this)}},{key:'hide',value:function(){this.element.style.visibility='hidden',this.iframe.style.visibility='hidden',this.stopExpanding=!0,this.emit(g.EVENTS.VIEWS.HIDDEN,this)}},{key:'offset',value:function(){return{top:this.element.offsetTop,left:this.element.offsetLeft}}},{key:'width',value:function(){return this._width}},{key:'height',value:function(){return this._height}},{key:'position',value:function(){return this.element.getBoundingClientRect()}},{key:'locationOf',value:function(e){var t=this.iframe.getBoundingClientRect(),n=this.contents.locationOf(e,this.settings.ignoreClass);return{left:n.left,top:n.top}}},{key:'onDisplayed',value:function(){}},{key:'onResize',value:function(){}},{key:'bounds',value:function(e){return(e||!this.elementBounds)&&(this.elementBounds=(0,d.bounds)(this.element)),this.elementBounds}},{key:'highlight',value:function(e){var t=this,n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},a=arguments[2];if(this.contents){var i=this.contents.range(e),o=function(){t.emit(g.EVENTS.VIEWS.MARK_CLICKED,e,n)};n.epubcfi=e,this.pane||(this.pane=new f.Pane(this.iframe,this.element));var s=new f.Highlight(i,'epubjs-hl',n,{fill:'yellow',"fill-opacity":'0.3',"mix-blend-mode":'multiply'}),r=this.pane.addMark(s);return this.highlights[e]={mark:r,element:r.element,listeners:[o,a]},r.element.setAttribute('ref','epubjs-hl'),r.element.addEventListener('click',o),r.element.addEventListener('touchstart',o),a&&(r.element.addEventListener('click',a),r.element.addEventListener('touchstart',a)),r}}},{key:'underline',value:function(e){var t=this,n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},a=arguments[2];if(this.contents){var i=this.contents.range(e),o=function(){t.emit(g.EVENTS.VIEWS.MARK_CLICKED,e,n)};n.epubcfi=e,this.pane||(this.pane=new f.Pane(this.iframe,this.element));var s=new f.Underline(i,'epubjs-ul',n,{stroke:'black',"stroke-opacity":'0.3',"mix-blend-mode":'multiply'}),r=this.pane.addMark(s);return this.underlines[e]={mark:r,element:r.element,listeners:[o,a]},r.element.setAttribute('ref','epubjs-ul'),r.element.addEventListener('click',o),r.element.addEventListener('touchstart',o),a&&(r.element.addEventListener('click',a),r.element.addEventListener('touchstart',a)),r}}},{key:'mark',value:function(e){var t=this,n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},a=arguments[2];if(this.contents){if(e in this.marks){var o=this.marks[e];return o}var s=this.contents.range(e);if(s){var r=s.commonAncestorContainer,l=1===r.nodeType?r:r.parentNode,d=function(){t.emit(g.EVENTS.VIEWS.MARK_CLICKED,e,n)};s.collapsed&&1===r.nodeType?(s=new Range,s.selectNodeContents(r)):s.collapsed&&(s=new Range,s.selectNodeContents(l));var u,c,p;if('pre-paginated'===this.layout.name||'horizontal'!==this.settings.axis){var h=s.getBoundingClientRect();u=h.top,c=h.right}else for(var f=s.getClientRects(),m=void 0,y=0;y!=f.length;y++)m=f[y],(!p||m.left<p)&&(p=m.left,c=p+this.layout.columnWidth-this.layout.gap,u=m.top);var i=this.document.createElement('a');return i.setAttribute('ref','epubjs-mk'),i.style.position='absolute',i.style.top=u+'px',i.style.left=c+'px',i.dataset.epubcfi=e,n&&Object.keys(n).forEach(function(e){i.dataset[e]=n[e]}),a&&(i.addEventListener('click',a),i.addEventListener('touchstart',a)),i.addEventListener('click',d),i.addEventListener('touchstart',d),this.element.appendChild(i),this.marks[e]={element:i,listeners:[d,a]},l}}}},{key:'unhighlight',value:function(e){var t;e in this.highlights&&(t=this.highlights[e],this.pane.removeMark(t.mark),t.listeners.forEach(function(e){e&&t.element.removeEventListener('click',e)}),delete this.highlights[e])}},{key:'ununderline',value:function(e){var t;e in this.underlines&&(t=this.underlines[e],this.pane.removeMark(t.mark),t.listeners.forEach(function(e){e&&t.element.removeEventListener('click',e)}),delete this.underlines[e])}},{key:'unmark',value:function(e){var t;e in this.marks&&(t=this.marks[e],this.element.removeChild(t.element),t.listeners.forEach(function(e){e&&t.element.removeEventListener('click',e)}),delete this.marks[e])}},{key:'destroy',value:function(){for(var e in this.highlights)this.unhighlight(e);for(var t in this.underlines)this.ununderline(t);for(var n in this.marks)this.unmark(n);this.blobUrl&&(0,d.revokeBlobUrl)(this.blobUrl),this.displayed&&(this.displayed=!1,this.removeListeners(),this.stopExpanding=!0,this.element.removeChild(this.iframe),this.iframe=void 0,this.contents=void 0,this._textWidth=null,this._textHeight=null,this._width=null,this._height=null)}}]),e}();(0,l.default)(m.prototype),t.default=m,e.exports=t['default']},function(e,t,n){var a=n(15),i=n(58),s=n(60),r=Math.min;e.exports=function(e,t,n){function l(t){var n=b,a=k;return b=k=void 0,f=t,E=e.apply(a,n),E}function d(e){return f=e,_=setTimeout(p,t),m?l(e):E}function u(e){var n=e-w,a=e-f,i=t-n;return y?r(i,x-a):i}function c(e){var n=e-w,a=e-f;return void 0==w||n>=t||0>n||y&&a>=x}function p(){var e=i();return c(e)?h(e):void(_=setTimeout(p,u(e)))}function h(e){return(_=void 0,v&&b)?l(e):(b=k=void 0,E)}function g(){var e=i(),n=c(e);if(b=arguments,k=this,w=e,n){if(void 0===_)return d(w);if(y)return _=setTimeout(p,t),l(w)}return void 0===_&&(_=setTimeout(p,t)),E}var f=0,m=!1,y=!1,v=!0,b,k,x,E,_,w;if('function'!=typeof e)throw new TypeError('Expected a function');return t=s(t)||0,a(n)&&(m=!!n.leading,y='maxWait'in n,x=y?o(s(n.maxWait)||0,t):x,v='trailing'in n?!!n.trailing:v),g.cancel=function(){void 0!==_&&clearTimeout(_),f=0,b=w=k=_=void 0},g.flush=function(){return void 0===_?E:h(i())},g}},function(e,t,n){var a=n(59),i='object'==typeof self&&self&&self.Object===Object&&self,o=a||i||Function('return this')();e.exports=o},function(e,t,n){var a=n(22),i=a.Symbol;e.exports=i},function(e,t,n){'use strict';function a(e){return e&&e.__esModule?e:{default:e}}function i(e,t){if(!(e instanceof t))throw new TypeError('Cannot call a class as a function')}function o(e,t){if(!e)throw new ReferenceError('this hasn\'t been initialised - super() hasn\'t been called');return t&&('object'==typeof t||'function'==typeof t)?t:e}function r(e,t){if('function'!=typeof t&&null!==t)throw new TypeError('Super expression must either be null or a function, not '+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(t,'__esModule',{value:!0});var l=function(){function e(e,t){for(var n=0,a;n<t.length;n++)a=t[n],a.enumerable=a.enumerable||!1,a.configurable=!0,'value'in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}return function(t,n,a){return n&&e(t.prototype,n),a&&e(t,a),t}}(),d=n(0),u=n(14),c=a(u),p=n(3),h=n(21),g=a(h),f=function(e){function t(e){i(this,t);var n=o(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));return n.name='continuous',n.settings=(0,d.extend)(n.settings||{},{infinite:!0,overflow:void 0,axis:void 0,flow:'scrolled',offset:500,offsetDelta:250,width:void 0,height:void 0}),(0,d.extend)(n.settings,e.settings||{}),'undefined'!=e.settings.gap&&0===e.settings.gap&&(n.settings.gap=e.settings.gap),n.viewSettings={ignoreClass:n.settings.ignoreClass,axis:n.settings.axis,flow:n.settings.flow,layout:n.layout,width:0,height:0,forceEvenPages:!1},n.scrollTop=0,n.scrollLeft=0,n}return r(t,e),l(t,[{key:'display',value:function(e,t){return c.default.prototype.display.call(this,e,t).then(function(){return this.fill()}.bind(this))}},{key:'fill',value:function(e){var t=this,n=e||new d.defer;return this.q.enqueue(function(){return t.check()}).then(function(e){e?t.fill(n):n.resolve()}),n.promise}},{key:'moveTo',value:function(e){var t=0,n=0,a=0,i=0;this.isPaginated?(t=s(e.left/this.layout.delta)*this.layout.delta,a=t+this.settings.offset):(n=e.top,i=e.top+this.settings.offset),(0<t||0<n)&&this.scrollBy(t,n,!0)}},{key:'afterResized',value:function(e){this.emit(p.EVENTS.MANAGERS.RESIZE,e.section)}},{key:'removeShownListeners',value:function(e){e.onDisplayed=function(){}}},{key:'add',value:function(e){var t=this,n=this.createView(e);return this.views.append(n),n.on(p.EVENTS.VIEWS.RESIZED,function(){n.expanded=!0}),n.on(p.EVENTS.VIEWS.AXIS,function(e){t.updateAxis(e)}),n.onDisplayed=this.afterDisplayed.bind(this),n.onResize=this.afterResized.bind(this),n.display(this.request)}},{key:'append',value:function(e){var t=this.createView(e);return t.on(p.EVENTS.VIEWS.RESIZED,function(){t.expanded=!0}),this.views.append(t),t.onDisplayed=this.afterDisplayed.bind(this),t}},{key:'prepend',value:function(e){var t=this,n=this.createView(e);return n.on(p.EVENTS.VIEWS.RESIZED,function(e){t.counter(e),n.expanded=!0}),this.views.prepend(n),n.onDisplayed=this.afterDisplayed.bind(this),n}},{key:'counter',value:function(e){'vertical'===this.settings.axis?this.scrollBy(0,e.heightDelta,!0):this.scrollBy(e.widthDelta,0,!0)}},{key:'update',value:function(e){for(var t=this.bounds(),n=this.views.all(),a=n.length,o=[],s='undefined'==typeof e?this.settings.offset||0:e,r=new d.defer,l=[],u=0,i,c;u<a;u++)if(c=n[u],i=this.isVisible(c,s,s,t),!0===i){if(!c.displayed){var p=c.display(this.request).then(function(e){e.show()},function(){c.hide()});l.push(p)}else c.show();o.push(c)}else this.q.enqueue(c.destroy.bind(c)),clearTimeout(this.trimTimeout),this.trimTimeout=setTimeout(function(){this.q.enqueue(this.trim.bind(this))}.bind(this),250);return l.length?Promise.all(l).catch(function(e){r.reject(e)}):(r.resolve(),r.promise)}},{key:'check',value:function(e,t){var n=this,a=new d.defer,i=[],o='horizontal'===this.settings.axis,r=this.settings.offset||0;e&&o&&(r=e),t&&!o&&(r=t);var l=this._bounds,u='rtl'===this.settings.direction,c=o&&u?-1:1,p=o?this.scrollLeft:this.scrollTop*c,h=o?s(l.width):l.height,g=o?this.container.scrollWidth:this.container.scrollHeight,f=function(){var e=n.views.first(),t=e&&e.section.prev();t&&i.push(n.prepend(t))},m=function(){var e=n.views.last(),t=e&&e.section.next();t&&i.push(n.append(t))};p+h+r>=g&&(o&&u?f():m()),0>p-r&&(o&&u?m():f());var y=i.map(function(e){return e.displayed});return i.length?Promise.all(y).then(function(){if('pre-paginated'===n.layout.name&&n.layout.props.spread)return n.check()}).then(function(){return n.update(r)},function(e){return e}):(this.q.enqueue(function(){this.update()}.bind(this)),a.resolve(!1),a.promise)}},{key:'trim',value:function(){for(var e=new d.defer,t=this.views.displayed(),n=t[0],a=t[t.length-1],o=this.views.indexOf(n),s=this.views.indexOf(a),r=this.views.slice(0,o),l=this.views.slice(s+1),u=0;u<r.length-1;u++)this.erase(r[u],r);for(var i=1;i<l.length;i++)this.erase(l[i]);return e.resolve(),e.promise}},{key:'erase',value:function(e,t){var n,a;this.settings.height?(n=this.container.scrollTop,a=this.container.scrollLeft):(n=window.scrollY,a=window.scrollX);var i=e.bounds();this.views.remove(e),t&&('vertical'===this.settings.axis?this.scrollTo(0,n-i.height,!0):this.scrollTo(a-s(i.width),0,!0))}},{key:'addEventListeners',value:function(){window.addEventListener('unload',function(){this.ignore=!0,this.destroy()}.bind(this)),this.addScrollListeners()}},{key:'addScrollListeners',value:function(){var e;this.tick=d.requestAnimationFrame,this.settings.height?(this.prevScrollTop=this.container.scrollTop,this.prevScrollLeft=this.container.scrollLeft):(this.prevScrollTop=window.scrollY,this.prevScrollLeft=window.scrollX),this.scrollDeltaVert=0,this.scrollDeltaHorz=0,this.settings.height?(e=this.container,this.scrollTop=this.container.scrollTop,this.scrollLeft=this.container.scrollLeft):(e=window,this.scrollTop=window.scrollY,this.scrollLeft=window.scrollX),e.addEventListener('scroll',this.onScroll.bind(this)),this._scrolled=(0,g.default)(this.scrolled.bind(this),30),this.didScroll=!1}},{key:'removeEventListeners',value:function(){var e;e=this.settings.height?this.container:window,e.removeEventListener('scroll',this.onScroll.bind(this))}},{key:'onScroll',value:function(){var e=Math.abs,t=void 0,n=void 0,a='rtl'===this.settings.direction?-1:1;this.settings.height?(t=this.container.scrollTop,n=this.container.scrollLeft):(t=window.scrollY*a,n=window.scrollX*a),this.scrollTop=t,this.scrollLeft=n,this.ignore?this.ignore=!1:this._scrolled(),this.scrollDeltaVert+=e(t-this.prevScrollTop),this.scrollDeltaHorz+=e(n-this.prevScrollLeft),this.prevScrollTop=t,this.prevScrollLeft=n,clearTimeout(this.scrollTimeout),this.scrollTimeout=setTimeout(function(){this.scrollDeltaVert=0,this.scrollDeltaHorz=0}.bind(this),150),this.didScroll=!1}},{key:'scrolled',value:function(){this.q.enqueue(function(){this.check()}.bind(this)),this.emit(p.EVENTS.MANAGERS.SCROLL,{top:this.scrollTop,left:this.scrollLeft}),clearTimeout(this.afterScrolled),this.afterScrolled=setTimeout(function(){this.emit(p.EVENTS.MANAGERS.SCROLLED,{top:this.scrollTop,left:this.scrollLeft})}.bind(this))}},{key:'next',value:function(){var e=this.settings.direction,t='pre-paginated'===this.layout.props.name&&this.layout.props.spread?2*this.layout.props.delta:this.layout.props.delta;this.views.length&&(this.isPaginated&&'horizontal'===this.settings.axis?this.scrollBy(t,0,!0):this.scrollBy(0,this.layout.height,!0),this.q.enqueue(function(){this.check()}.bind(this)))}},{key:'prev',value:function(){var e=this.settings.direction,t='pre-paginated'===this.layout.props.name&&this.layout.props.spread?2*this.layout.props.delta:this.layout.props.delta;this.views.length&&(this.isPaginated&&'horizontal'===this.settings.axis?this.scrollBy(-t,0,!0):this.scrollBy(0,-this.layout.height,!0),this.q.enqueue(function(){this.check()}.bind(this)))}},{key:'updateAxis',value:function(e,t){this.isPaginated||(e='vertical'),(t||e!==this.settings.axis)&&(this.settings.axis=e,this.stage&&this.stage.axis(e),this.viewSettings.axis=e,this.mapping&&this.mapping.axis(e),this.layout&&('vertical'===e?this.layout.spread('none'):this.layout.spread(this.layout.settings.spread)),this.settings.infinite='vertical'===e)}}]),t}(c.default);t.default=f,e.exports=t['default']},function(e,t,n){'use strict';(function(a){function i(e){return e&&e.__esModule?e:{default:e}}function o(e,t){return new r.default(e,t)}Object.defineProperty(t,'__esModule',{value:!0});var s=n(26),r=i(s),l=n(18),d=i(l),u=n(1),c=i(u),p=n(13),h=i(p),g=n(0),f=function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t.default=e,t}(g);n(69);var m=n(20),y=i(m),v=n(14),b=i(v),k=n(24),x=i(k);o.VERSION='0.3','undefined'!=typeof a&&(a.EPUBJS_VERSION=o.VERSION),o.Book=r.default,o.Rendition=d.default,o.Contents=h.default,o.CFI=c.default,o.utils=f,t.default=o,e.exports=t['default']}).call(t,n(8))},function(e,t,n){'use strict';function a(e){return e&&e.__esModule?e:{default:e}}function i(e,t){if(!(e instanceof t))throw new TypeError('Cannot call a class as a function')}Object.defineProperty(t,'__esModule',{value:!0});var o=function(){function e(e,t){for(var n=0,a;n<t.length;n++)a=t[n],a.enumerable=a.enumerable||!1,a.configurable=!0,'value'in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}return function(t,n,a){return n&&e(t.prototype,n),a&&e(t,a),t}}(),s=n(2),r=a(s),l=n(0),d=n(5),u=a(d),c=n(4),p=a(c),h=n(42),g=a(h),f=n(44),m=a(f),y=n(45),v=a(y),b=n(46),k=a(b),x=n(47),E=a(x),_=n(48),w=a(_),S=n(49),C=a(S),T=n(18),N=a(T),R=n(67),L=a(R),P=n(11),A=a(P),I=n(1),O=a(I),z=n(3),D='META-INF/container.xml',B={BINARY:'binary',BASE64:'base64',EPUB:'epub',OPF:'opf',MANIFEST:'json',DIRECTORY:'directory'},q=function(){function e(t,n){var a=this;i(this,e),'undefined'==typeof n&&'string'!=typeof t&&!1==t instanceof Blob&&(n=t,t=void 0),this.settings=(0,l.extend)(this.settings||{},{requestMethod:void 0,requestCredentials:void 0,requestHeaders:void 0,encoding:void 0,replacements:void 0,canonical:void 0,openAs:void 0}),(0,l.extend)(this.settings,n),this.opening=new l.defer,this.opened=this.opening.promise,this.isOpen=!1,this.loading={manifest:new l.defer,spine:new l.defer,metadata:new l.defer,cover:new l.defer,navigation:new l.defer,pageList:new l.defer,resources:new l.defer},this.loaded={manifest:this.loading.manifest.promise,spine:this.loading.spine.promise,metadata:this.loading.metadata.promise,cover:this.loading.cover.promise,navigation:this.loading.navigation.promise,pageList:this.loading.pageList.promise,resources:this.loading.resources.promise},this.ready=Promise.all([this.loaded.manifest,this.loaded.spine,this.loaded.metadata,this.loaded.cover,this.loaded.navigation,this.loaded.resources]),this.isRendered=!1,this.request=this.settings.requestMethod||A.default,this.spine=new g.default,this.locations=new m.default(this.spine,this.load.bind(this)),this.navigation=void 0,this.pageList=void 0,this.url=void 0,this.path=void 0,this.archived=!1,this.archive=void 0,this.resources=void 0,this.rendition=void 0,this.container=void 0,this.packaging=void 0,t&&this.open(t,this.settings.openAs).catch(function(){var e=new Error('Cannot load book at '+t);a.emit(z.EVENTS.BOOK.OPEN_FAILED,e)})}return o(e,[{key:'open',value:function(e,t){var n=t||this.determineType(e),a;return n===B.BINARY?(this.archived=!0,this.url=new u.default('/',''),a=this.openEpub(e)):n===B.BASE64?(this.archived=!0,this.url=new u.default('/',''),a=this.openEpub(e,n)):n===B.EPUB?(this.archived=!0,this.url=new u.default('/',''),a=this.request(e,'binary').then(this.openEpub.bind(this))):n==B.OPF?(this.url=new u.default(e),a=this.openPackaging(this.url.Path.toString())):n==B.MANIFEST?(this.url=new u.default(e),a=this.openManifest(this.url.Path.toString())):(this.url=new u.default(e),a=this.openContainer(D).then(this.openPackaging.bind(this))),a}},{key:'openEpub',value:function(e,t){var n=this;return this.unarchive(e,t||this.settings.encoding).then(function(){return n.openContainer(D)}).then(function(e){return n.openPackaging(e)})}},{key:'openContainer',value:function(e){var t=this;return this.load(e).then(function(e){return t.container=new v.default(e),t.resolve(t.container.packagePath)})}},{key:'openPackaging',value:function(e){var t=this;return this.path=new p.default(e),this.load(e).then(function(e){return t.packaging=new k.default(e),t.unpack(t.packaging)})}},{key:'openManifest',value:function(e){var t=this;return this.path=new p.default(e),this.load(e).then(function(e){return t.packaging=new k.default,t.packaging.load(e),t.unpack(t.packaging)})}},{key:'load',value:function(e){var t;return this.archived?(t=this.resolve(e),this.archive.request(t)):(t=this.resolve(e),this.request(t,null,this.settings.requestCredentials,this.settings.requestHeaders))}},{key:'resolve',value:function(e,t){if(e){var n=e,a=-1<e.indexOf('://');return a?e:(this.path&&(n=this.path.resolve(e)),!1!=t&&this.url&&(n=this.url.resolve(n)),n)}}},{key:'canonical',value:function(e){var t=e;return e?(t=this.settings.canonical?this.settings.canonical(e):this.resolve(e,!0),t):''}},{key:'determineType',value:function(e){var t,n,a;return'base64'===this.settings.encoding?B.BASE64:'string'==typeof e?(t=new u.default(e),n=t.path(),a=n.extension,a?'epub'===a?B.EPUB:'opf'===a?B.OPF:'json'===a?B.MANIFEST:void 0:B.DIRECTORY):B.BINARY}},{key:'unpack',value:function(e){var t=this;this.package=e,this.spine.unpack(this.package,this.resolve.bind(this),this.canonical.bind(this)),this.resources=new w.default(this.package.manifest,{archive:this.archive,resolver:this.resolve.bind(this),request:this.request.bind(this),replacements:this.settings.replacements||(this.archived?'blobUrl':'base64')}),this.loadNavigation(this.package).then(function(){t.loading.navigation.resolve(t.navigation)}),this.package.coverPath&&(this.cover=this.resolve(this.package.coverPath)),this.loading.manifest.resolve(this.package.manifest),this.loading.metadata.resolve(this.package.metadata),this.loading.spine.resolve(this.spine),this.loading.cover.resolve(this.cover),this.loading.resources.resolve(this.resources),this.loading.pageList.resolve(this.pageList),this.isOpen=!0,this.archived||this.settings.replacements&&'none'!=this.settings.replacements?this.replacements().then(function(){t.opening.resolve(t)}).catch(function(e){console.error(e)}):this.opening.resolve(this)}},{key:'loadNavigation',value:function(e){var t=this,n=e.navPath||e.ncxPath,a=e.toc;return a?new Promise(function(n){t.navigation=new E.default(a),e.pageList&&(t.pageList=new C.default(e.pageList)),n(t.navigation)}):n?this.load(n,'xml').then(function(e){return t.navigation=new E.default(e),t.pageList=new C.default(e),t.navigation}):new Promise(function(e){t.navigation=new E.default,t.pageList=new C.default,e(t.navigation)})}},{key:'section',value:function(e){return this.spine.get(e)}},{key:'renderTo',value:function(e,t){return this.rendition=new N.default(this,t),this.rendition.attachTo(e),this.rendition}},{key:'setRequestCredentials',value:function(e){this.settings.requestCredentials=e}},{key:'setRequestHeaders',value:function(e){this.settings.requestHeaders=e}},{key:'unarchive',value:function(e,t){return this.archive=new L.default,this.archive.open(e,t)}},{key:'coverUrl',value:function(){var e=this,t=this.loaded.cover.then(function(){return e.archived?e.resources.get(e.cover):e.cover});return t}},{key:'replacements',value:function(){var e=this;return this.spine.hooks.serialize.register(function(t,n){n.output=e.resources.substitute(t,n.url)}),this.resources.replacements().then(function(){return e.resources.replaceCss()})}},{key:'getRange',value:function(e){var t=new O.default(e),n=this.spine.get(t.spinePos),a=this.load.bind(this);return n?n.load(a).then(function(){var e=t.toRange(n.document);return e}):new Promise(function(e,t){t('CFI could not be found')})}},{key:'key',value:function(e){var t=e||this.package.metadata.identifier||this.url.filename;return'epubjs:'+'0.3'+':'+t}},{key:'destroy',value:function(){this.opened=void 0,this.loading=void 0,this.loaded=void 0,this.ready=void 0,this.isOpen=!1,this.isRendered=!1,this.spine&&this.spine.destroy(),this.locations&&this.locations.destroy(),this.pageList&&this.pageList.destroy(),this.archive&&this.archive.destroy(),this.resources&&this.resources.destroy(),this.container&&this.container.destroy(),this.packaging&&this.packaging.destroy(),this.rendition&&this.rendition.destroy(),this.spine=void 0,this.locations=void 0,this.pageList=void 0,this.archive=void 0,this.resources=void 0,this.container=void 0,this.packaging=void 0,this.rendition=void 0,this.navigation=void 0,this.url=void 0,this.path=void 0,this.archived=!1}}]),e}();(0,r.default)(q.prototype),t.default=q,e.exports=t['default']},function(e,t,n){'use strict';var a=n(28),i=n(36),o=n(37),s=n(38),r;r=e.exports=function(t,n){var o,r,l,d,u;return 2>arguments.length||'string'!=typeof t?(d=n,n=t,t=null):d=arguments[2],null==t?(o=l=!0,r=!1):(o=s.call(t,'c'),r=s.call(t,'e'),l=s.call(t,'w')),u={value:n,configurable:o,enumerable:r,writable:l},d?a(i(d),u):u},r.gs=function(t,n,r){var l,d,u,p;return'string'==typeof t?u=arguments[3]:(u=r,r=n,n=t,t=null),null==n?n=void 0:o(n)?null==r?r=void 0:!o(r)&&(u=r,r=void 0):(u=n,n=r=void 0),null==t?(l=!0,d=!1):(l=s.call(t,'c'),d=s.call(t,'e')),p={get:n,set:r,configurable:l,enumerable:d},u?a(i(u),p):p}},function(e,t,n){'use strict';e.exports=n(29)()?Object.assign:n(30)},function(e){'use strict';e.exports=function(){var e=Object.assign,t;return!('function'!=typeof e)&&(t={foo:'raz'},e(t,{bar:'dwa'},{trzy:'trzy'}),'razdwatrzy'===t.foo+t.bar+t.trzy)}},function(e,t,n){'use strict';var a=n(31),s=n(35);e.exports=function(e,t){var n=o(arguments.length,2),r,l,i;for(e=Object(s(e)),i=function(n){try{e[n]=t[n]}catch(t){r||(r=t)}},l=1;l<n;++l)t=arguments[l],a(t).forEach(i);if(r!==void 0)throw r;return e}},function(e,t,n){'use strict';e.exports=n(32)()?Object.keys:n(33)},function(e){'use strict';e.exports=function(){try{return Object.keys('primitive'),!0}catch(t){return!1}}},function(e,t,n){'use strict';var a=n(9),i=Object.keys;e.exports=function(e){return i(a(e)?Object(e):e)}},function(e){'use strict';e.exports=function(){}},function(e,t,n){'use strict';var a=n(9);e.exports=function(e){if(!a(e))throw new TypeError('Cannot use null or undefined');return e}},function(e,t,n){'use strict';var a=n(9),i=Array.prototype.forEach,o=Object.create,s=function(e,t){for(var n in e)t[n]=e[n]};e.exports=function(){var e=o(null);return i.call(arguments,function(t){a(t)&&s(Object(t),e)}),e}},function(e){'use strict';e.exports=function(e){return'function'==typeof e}},function(e,t,a){'use strict';e.exports=a(39)()?n.contains:a(40)},function(e){'use strict';var t='razdwatrzy';e.exports=function(){return!('function'!=typeof t.contains)&&!0===t.contains('dwa')&&!1===t.contains('foo')}},function(e){'use strict';var t=n.indexOf;e.exports=function(e){return-1<t.call(this,e,arguments[1])}},function(e){'use strict';e.exports=function(e){if('function'!=typeof e)throw new TypeError(e+' is not a function');return e}},function(e,t,n){'use strict';function a(e){return e&&e.__esModule?e:{default:e}}function i(e,t){if(!(e instanceof t))throw new TypeError('Cannot call a class as a function')}Object.defineProperty(t,'__esModule',{value:!0});var o=function(){function e(e,t){for(var n=0,a;n<t.length;n++)a=t[n],a.enumerable=a.enumerable||!1,a.configurable=!0,'value'in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}return function(t,n,a){return n&&e(t.prototype,n),a&&e(t,a),t}}(),s=n(1),r=a(s),l=n(10),d=a(l),u=n(43),c=a(u),p=n(7),h=function(){function e(){i(this,e),this.spineItems=[],this.spineByHref={},this.spineById={},this.hooks={},this.hooks.serialize=new d.default,this.hooks.content=new d.default,this.hooks.content.register(p.replaceBase),this.hooks.content.register(p.replaceCanonical),this.hooks.content.register(p.replaceMeta),this.epubcfi=new r.default,this.loaded=!1,this.items=void 0,this.manifest=void 0,this.spineNodeIndex=void 0,this.baseUrl=void 0,this.length=void 0}return o(e,[{key:'unpack',value:function(e,t,n){var a=this;this.items=e.spine,this.manifest=e.manifest,this.spineNodeIndex=e.spineNodeIndex,this.baseUrl=e.baseUrl||e.basePath||'',this.length=this.items.length,this.items.forEach(function(e,i){var o=a.manifest[e.idref],s;e.index=i,e.cfiBase=a.epubcfi.generateChapterComponent(a.spineNodeIndex,e.index,e.idref),e.href&&(e.url=t(e.href,!0),e.canonical=n(e.href)),o&&(e.href=o.href,e.url=t(e.href,!0),e.canonical=n(e.href),o.properties.length&&e.properties.push.apply(e.properties,o.properties)),'yes'===e.linear?(e.prev=function(){for(var t=e.index,n;0<t;){if(n=this.get(t-1),n&&n.linear)return n;t-=1}}.bind(a),e.next=function(){for(var t=e.index,n;t<this.spineItems.length-1;){if(n=this.get(t+1),n&&n.linear)return n;t+=1}}.bind(a)):(e.prev=function(){},e.next=function(){}),s=new c.default(e,a.hooks),a.append(s)}),this.loaded=!0}},{key:'get',value:function(e){var t=0;if('undefined'==typeof e)for(;t<this.spineItems.length;){var n=this.spineItems[t];if(n&&n.linear)break;t+=1}else if(this.epubcfi.isCfiString(e)){var a=new r.default(e);t=a.spinePos}else'number'==typeof e||!1===isNaN(e)?t=e:'string'==typeof e&&0===e.indexOf('#')?t=this.spineById[e.substring(1)]:'string'==typeof e&&(e=e.split('#')[0],t=this.spineByHref[e]||this.spineByHref[encodeURI(e)]);return this.spineItems[t]||null}},{key:'append',value:function(e){var t=this.spineItems.length;return e.index=t,this.spineItems.push(e),this.spineByHref[decodeURI(e.href)]=t,this.spineByHref[encodeURI(e.href)]=t,this.spineByHref[e.href]=t,this.spineById[e.idref]=t,t}},{key:'prepend',value:function(e){return this.spineByHref[e.href]=0,this.spineById[e.idref]=0,this.spineItems.forEach(function(e,t){e.index=t}),0}},{key:'remove',value:function(e){var t=this.spineItems.indexOf(e);if(-1<t)return delete this.spineByHref[e.href],delete this.spineById[e.idref],this.spineItems.splice(t,1)}},{key:'each',value:function(){return this.spineItems.forEach.apply(this.spineItems,arguments)}},{key:'first',value:function(){var e=0;do{var t=this.get(e);if(t&&t.linear)return t;e+=1}while(e<this.spineItems.length)}},{key:'last',value:function(){var e=this.spineItems.length-1;do{var t=this.get(e);if(t&&t.linear)return t;e-=1}while(0<=e)}},{key:'destroy',value:function(){this.each(function(e){return e.destroy()}),this.spineItems=void 0,this.spineByHref=void 0,this.spineById=void 0,this.hooks.serialize.clear(),this.hooks.content.clear(),this.hooks=void 0,this.epubcfi=void 0,this.loaded=!1,this.items=void 0,this.manifest=void 0,this.spineNodeIndex=void 0,this.baseUrl=void 0,this.length=void 0}}]),e}();t.default=h,e.exports=t['default']},function(e,t,n){'use strict';function a(e){return e&&e.__esModule?e:{default:e}}function i(e,t){if(!(e instanceof t))throw new TypeError('Cannot call a class as a function')}Object.defineProperty(t,'__esModule',{value:!0});var o=function(){function e(e,t){for(var n=0,a;n<t.length;n++)a=t[n],a.enumerable=a.enumerable||!1,a.configurable=!0,'value'in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}return function(t,n,a){return n&&e(t.prototype,n),a&&e(t,a),t}}(),s=n(0),r=n(1),l=a(r),d=n(10),u=a(d),c=n(7),p=function(){function e(t,n){i(this,e),this.idref=t.idref,this.linear='yes'===t.linear,this.properties=t.properties,this.index=t.index,this.href=t.href,this.url=t.url,this.canonical=t.canonical,this.next=t.next,this.prev=t.prev,this.cfiBase=t.cfiBase,n?this.hooks=n:(this.hooks={},this.hooks.serialize=new u.default(this),this.hooks.content=new u.default(this)),this.document=void 0,this.contents=void 0,this.output=void 0}return o(e,[{key:'load',value:function(e){var t=e||this.request||n(11),a=new s.defer,i=a.promise;return this.contents?a.resolve(this.contents):t(this.url).then(function(e){return this.document=e,this.contents=e.documentElement,this.hooks.content.trigger(this.document,this)}.bind(this)).then(function(){a.resolve(this.contents)}.bind(this)).catch(function(e){a.reject(e)}),i}},{key:'base',value:function(){return(0,c.replaceBase)(this.document,this)}},{key:'render',value:function(e){var t=new s.defer,a=t.promise;return this.output,this.load(e).then(function(e){var t='undefined'!=typeof navigator&&navigator.userAgent||'',a=0<=t.indexOf('Trident'),i;i='undefined'==typeof XMLSerializer||a?n(16).XMLSerializer:XMLSerializer;var o=new i;return this.output=o.serializeToString(e),this.output}.bind(this)).then(function(){return this.hooks.serialize.trigger(this.output,this)}.bind(this)).then(function(){t.resolve(this.output)}.bind(this)).catch(function(e){t.reject(e)}),a}},{key:'find',value:function(e){var t=this,n=[],a=e.toLowerCase(),i=function(e){for(var i=e.textContent.toLowerCase(),o=t.document.createRange(),s=-1,r=150,l,d,u;-1!=d;)d=i.indexOf(a,s+1),-1!=d&&(o=t.document.createRange(),o.setStart(e,d),o.setEnd(e,d+a.length),l=t.cfiFromRange(o),e.textContent.length<r?u=e.textContent:(u=e.textContent.substring(d-r/2,d+r/2),u='...'+u+'...'),n.push({cfi:l,excerpt:u})),s=d};return(0,s.sprint)(t.document,function(e){i(e)}),n}},{key:'reconcileLayoutSettings',value:function(e){var t={layout:e.layout,spread:e.spread,orientation:e.orientation};return this.properties.forEach(function(e){var n=e.replace('rendition:',''),a=n.indexOf('-'),i,o;-1!=a&&(i=n.slice(0,a),o=n.slice(a+1),t[i]=o)}),t}},{key:'cfiFromRange',value:function(e){return new l.default(e,this.cfiBase).toString()}},{key:'cfiFromElement',value:function(e){return new l.default(e,this.cfiBase).toString()}},{key:'unload',value:function(){this.document=void 0,this.contents=void 0,this.output=void 0}},{key:'destroy',value:function(){this.unload(),this.hooks.serialize.clear(),this.hooks.content.clear(),this.hooks=void 0,this.idref=void 0,this.linear=void 0,this.properties=void 0,this.index=void 0,this.href=void 0,this.url=void 0,this.next=void 0,this.prev=void 0,this.cfiBase=void 0}}]),e}();t.default=p,e.exports=t['default']},function(e,t,n){'use strict';function i(e){return e&&e.__esModule?e:{default:e}}function o(e,t){if(!(e instanceof t))throw new TypeError('Cannot call a class as a function')}Object.defineProperty(t,'__esModule',{value:!0});var s=function(){function e(e,t){for(var n=0,a;n<t.length;n++)a=t[n],a.enumerable=a.enumerable||!1,a.configurable=!0,'value'in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}return function(t,n,a){return n&&e(t.prototype,n),a&&e(t,a),t}}(),r=n(0),l=n(12),d=i(l),u=n(1),c=i(u),p=n(3),h=n(2),g=i(h),f=function(){function e(t,n,a){o(this,e),this.spine=t,this.request=n,this.pause=a||100,this.q=new d.default(this),this.epubcfi=new c.default,this._locations=[],this.total=0,this.break=150,this._current=0,this.currentLocation='',this._currentCfi='',this.processingTimeout=void 0}return s(e,[{key:'generate',value:function(e){return e&&(this.break=e),this.q.pause(),this.spine.each(function(e){e.linear&&this.q.enqueue(this.process.bind(this),e)}.bind(this)),this.q.run().then(function(){return this.total=this._locations.length-1,this._currentCfi&&(this.currentLocation=this._currentCfi),this._locations}.bind(this))}},{key:'createRange',value:function(){return{startContainer:void 0,startOffset:void 0,endContainer:void 0,endOffset:void 0}}},{key:'process',value:function(e){return e.load(this.request).then(function(t){var n=new r.defer,a=this.parse(t,e.cfiBase);return this._locations=this._locations.concat(a),e.unload(),this.processingTimeout=setTimeout(function(){return n.resolve(a)},this.pause),n.promise}.bind(this))}},{key:'parse',value:function(e,t,n){var a=[],i=e.ownerDocument,o=(0,r.qs)(i,'body'),s=0,l=n||this.break,d,u;if((0,r.sprint)(o,function(e){var n=e.length,i=0,o;if(0===e.textContent.trim().length)return!1;for(0==s&&(d=this.createRange(),d.startContainer=e,d.startOffset=0),o=l-s,o>n&&(s+=n,i=n);i<n;)if(o=l-s,0===s&&(i+=1,d=this.createRange(),d.startContainer=e,d.startOffset=i),i+o>=n)s+=n-i,i=n;else{i+=o,d.endContainer=e,d.endOffset=i;var r=new c.default(d,t).toString();a.push(r),s=0}u=e}.bind(this)),d&&d.startContainer&&u){d.endContainer=u,d.endOffset=u.length;var p=new c.default(d,t).toString();a.push(p),s=0}return a}},{key:'locationFromCfi',value:function(e){var t;return(c.default.prototype.isCfiString(e)&&(e=new c.default(e)),0===this._locations.length)?-1:(t=(0,r.locationOf)(e,this._locations,this.epubcfi.compare),t>this.total?this.total:t)}},{key:'percentageFromCfi',value:function(e){if(0===this._locations.length)return null;var t=this.locationFromCfi(e);return this.percentageFromLocation(t)}},{key:'percentageFromLocation',value:function(e){return e&&this.total?e/this.total:0}},{key:'cfiFromLocation',value:function(e){var t=-1;return'number'!=typeof e&&(e=parseInt(e)),0<=e&&e<this._locations.length&&(t=this._locations[e]),t}},{key:'cfiFromPercentage',value:function(e){var t;if(1<e&&console.warn('Normalize cfiFromPercentage value to between 0 - 1'),1<=e){var n=new c.default(this._locations[this.total]);return n.collapse(),n.toString()}return t=a(this.total*e),this.cfiFromLocation(t)}},{key:'load',value:function(e){return this._locations='string'==typeof e?JSON.parse(e):e,this.total=this._locations.length-1,this._locations}},{key:'save',value:function(){return JSON.stringify(this._locations)}},{key:'getCurrent',value:function(){return this._current}},{key:'setCurrent',value:function(e){var t;if('string'==typeof e)this._currentCfi=e;else if('number'==typeof e)this._current=e;else return;0===this._locations.length||('string'==typeof e?(t=this.locationFromCfi(e),this._current=t):t=e,this.emit(p.EVENTS.LOCATIONS.CHANGED,{percentage:this.percentageFromLocation(t)}))}},{key:'length',value:function(){return this._locations.length}},{key:'destroy',value:function(){this.spine=void 0,this.request=void 0,this.pause=void 0,this.q.stop(),this.q=void 0,this.epubcfi=void 0,this._locations=void 0,this.total=void 0,this.break=void 0,this._current=void 0,this.currentLocation=void 0,this._currentCfi=void 0,clearTimeout(this.processingTimeout)}},{key:'currentLocation',get:function(){return this._current},set:function(e){this.setCurrent(e)}}]),e}();(0,g.default)(f.prototype),t.default=f,e.exports=t['default']},function(e,t,n){'use strict';function a(e,t){if(!(e instanceof t))throw new TypeError('Cannot call a class as a function')}Object.defineProperty(t,'__esModule',{value:!0});var i=function(){function e(e,t){for(var n=0,a;n<t.length;n++)a=t[n],a.enumerable=a.enumerable||!1,a.configurable=!0,'value'in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}return function(t,n,a){return n&&e(t.prototype,n),a&&e(t,a),t}}(),o=n(6),s=function(e){return e&&e.__esModule?e:{default:e}}(o),r=n(0),l=function(){function e(t){a(this,e),this.packagePath='',this.directory='',this.encoding='',t&&this.parse(t)}return i(e,[{key:'parse',value:function(e){var t;if(!e)throw new Error('Container File Not Found');if(t=(0,r.qs)(e,'rootfile'),!t)throw new Error('No RootFile Found');this.packagePath=t.getAttribute('full-path'),this.directory=s.default.dirname(this.packagePath),this.encoding=e.xmlEncoding}},{key:'destroy',value:function(){this.packagePath=void 0,this.directory=void 0,this.encoding=void 0}}]),e}();t.default=l,e.exports=t['default']},function(e,t,n){'use strict';function a(e,t){if(!(e instanceof t))throw new TypeError('Cannot call a class as a function')}Object.defineProperty(t,'__esModule',{value:!0});var i=function(){function e(e,t){for(var n=0,a;n<t.length;n++)a=t[n],a.enumerable=a.enumerable||!1,a.configurable=!0,'value'in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}return function(t,n,a){return n&&e(t.prototype,n),a&&e(t,a),t}}(),o=n(0),s=function(){function e(t){a(this,e),this.manifest={},this.navPath='',this.ncxPath='',this.coverPath='',this.spineNodeIndex=0,this.spine=[],this.metadata={},t&&this.parse(t)}return i(e,[{key:'parse',value:function(e){var t,n,a;if(!e)throw new Error('Package File Not Found');if(t=(0,o.qs)(e,'metadata'),!t)throw new Error('No Metadata Found');if(n=(0,o.qs)(e,'manifest'),!n)throw new Error('No Manifest Found');if(a=(0,o.qs)(e,'spine'),!a)throw new Error('No Spine Found');return this.manifest=this.parseManifest(n),this.navPath=this.findNavPath(n),this.ncxPath=this.findNcxPath(n,a),this.coverPath=this.findCoverPath(e),this.spineNodeIndex=(0,o.indexOfElementNode)(a),this.spine=this.parseSpine(a,this.manifest),this.metadata=this.parseMetadata(t),this.metadata.direction=a.getAttribute('page-progression-direction'),{metadata:this.metadata,spine:this.spine,manifest:this.manifest,navPath:this.navPath,ncxPath:this.ncxPath,coverPath:this.coverPath,spineNodeIndex:this.spineNodeIndex}}},{key:'parseMetadata',value:function(e){var t={title:this.getElementText(e,'title'),creator:this.getElementText(e,'creator'),description:this.getElementText(e,'description'),pubdate:this.getElementText(e,'date'),publisher:this.getElementText(e,'publisher'),identifier:this.getElementText(e,'identifier'),language:this.getElementText(e,'language'),rights:this.getElementText(e,'rights'),modified_date:this.getPropertyText(e,'dcterms:modified'),layout:this.getPropertyText(e,'rendition:layout'),orientation:this.getPropertyText(e,'rendition:orientation'),flow:this.getPropertyText(e,'rendition:flow'),viewport:this.getPropertyText(e,'rendition:viewport')};return t}},{key:'parseManifest',value:function(e){var t={},n=(0,o.qsa)(e,'item'),a=Array.prototype.slice.call(n);return a.forEach(function(e){var n=e.getAttribute('id'),a=e.getAttribute('href')||'',i=e.getAttribute('media-type')||'',o=e.getAttribute('properties')||'';t[n]={href:a,type:i,properties:o.length?o.split(' '):[]}}),t}},{key:'parseSpine',value:function(e){var t=[],n=(0,o.qsa)(e,'itemref'),a=Array.prototype.slice.call(n);return a.forEach(function(e,n){var a=e.getAttribute('idref'),i=e.getAttribute('properties')||'',o=i.length?i.split(' '):[],s={idref:a,linear:e.getAttribute('linear')||'yes',properties:o,index:n};t.push(s)}),t}},{key:'findNavPath',value:function(e){var t=(0,o.qsp)(e,'item',{properties:'nav'});return!!t&&t.getAttribute('href')}},{key:'findNcxPath',value:function(e,t){var n=(0,o.qsp)(e,'item',{"media-type":'application/x-dtbncx+xml'}),a;return n||(a=t.getAttribute('toc'),a&&(n=e.getElementById(a))),!!n&&n.getAttribute('href')}},{key:'findCoverPath',value:function(e){var t=(0,o.qs)(e,'package'),n=t.getAttribute('version');if('2.0'===n){var a=(0,o.qsp)(e,'meta',{name:'cover'});if(a){var i=a.getAttribute('content'),s=e.getElementById(i);return s?s.getAttribute('href'):''}return!1}var r=(0,o.qsp)(e,'item',{properties:'cover-image'});return r?r.getAttribute('href'):''}},{key:'getElementText',value:function(e,t){var n=e.getElementsByTagNameNS('http://purl.org/dc/elements/1.1/',t),a;return n&&0!==n.length?(a=n[0],a.childNodes.length?a.childNodes[0].nodeValue:''):''}},{key:'getPropertyText',value:function(e,t){var n=(0,o.qsp)(e,'meta',{property:t});return n&&n.childNodes.length?n.childNodes[0].nodeValue:''}},{key:'load',value:function(e){var t=this;return this.metadata=e.metadata,this.spine=e.spine.map(function(e,t){return e.index=t,e}),e.resources.forEach(function(e,n){t.manifest[n]=e,e.rel&&'cover'===e.rel[0]&&(t.coverPath=e.href)}),this.spineNodeIndex=0,this.toc=e.toc.map(function(e){return e.label=e.title,e}),{metadata:this.metadata,spine:this.spine,manifest:this.manifest,navPath:this.navPath,ncxPath:this.ncxPath,coverPath:this.coverPath,spineNodeIndex:this.spineNodeIndex,toc:this.toc}}},{key:'destroy',value:function(){this.manifest=void 0,this.navPath=void 0,this.ncxPath=void 0,this.coverPath=void 0,this.spineNodeIndex=void 0,this.spine=void 0,this.metadata=void 0}}]),e}();t.default=s,e.exports=t['default']},function(e,t,n){'use strict';function a(e,t){if(!(e instanceof t))throw new TypeError('Cannot call a class as a function')}Object.defineProperty(t,'__esModule',{value:!0});var i=function(){function e(e,t){for(var n=0,a;n<t.length;n++)a=t[n],a.enumerable=a.enumerable||!1,a.configurable=!0,'value'in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}return function(t,n,a){return n&&e(t.prototype,n),a&&e(t,a),t}}(),o=n(0),s=function(){function e(t){a(this,e),this.toc=[],this.tocByHref={},this.tocById={},this.landmarks=[],this.landmarksByType={},this.length=0,t&&this.parse(t)}return i(e,[{key:'parse',value:function(e){var t=e.nodeType,n,a;t&&(n=(0,o.qs)(e,'html'),a=(0,o.qs)(e,'ncx')),t?n?(this.toc=this.parseNav(e),this.landmarks=this.parseLandmarks(e)):a&&(this.toc=this.parseNcx(e)):this.toc=this.load(e),this.length=0,this.unpack(this.toc)}},{key:'unpack',value:function(e){for(var t=0,n;t<e.length;t++)n=e[t],n.href&&(this.tocByHref[n.href]=t),n.id&&(this.tocById[n.id]=t),this.length++,n.subitems.length&&this.unpack(n.subitems)}},{key:'get',value:function(e){var t;return e?(0===e.indexOf('#')?t=this.tocById[e.substring(1)]:e in this.tocByHref&&(t=this.tocByHref[e]),this.toc[t]):this.toc}},{key:'landmark',value:function(e){var t;return e?(t=this.landmarksByType[e],this.landmarks[t]):this.landmarks}},{key:'parseNav',value:function(e){var t=(0,o.querySelectorByType)(e,'nav','toc'),n=t?(0,o.qsa)(t,'li'):[],a=n.length,s={},r=[],l,i,d;if(!n||0===a)return r;for(l=0;l<a;++l)i=this.navItem(n[l]),i&&(s[i.id]=i,i.parent?(d=s[i.parent],d.subitems.push(i)):r.push(i));return r}},{key:'navItem',value:function(e){var t=e.getAttribute('id')||void 0,n=(0,o.filterChildren)(e,'a',!0);if(n){var a=n.getAttribute('href')||'',i=n.textContent||'',s=(0,o.getParentByTagName)(e,'li'),r;for(s&&(r=s.getAttribute('id'));!r&&s;)s=(0,o.getParentByTagName)(s,'li'),s&&(r=s.getAttribute('id'));return{id:t,href:a,label:i,subitems:[],parent:r}}}},{key:'parseLandmarks',value:function(e){var t=(0,o.querySelectorByType)(e,'nav','landmarks'),n=t?(0,o.qsa)(t,'li'):[],a=n.length,s=[],r,i;if(!n||0===a)return s;for(r=0;r<a;++r)i=this.landmarkItem(n[r]),i&&(s.push(i),this.landmarksByType[i.type]=r);return s}},{key:'landmarkItem',value:function(e){var t=(0,o.filterChildren)(e,'a',!0);if(t){var n=t.getAttributeNS('http://www.idpf.org/2007/ops','type')||void 0,a=t.getAttribute('href')||'',i=t.textContent||'';return{href:a,label:i,type:n}}}},{key:'parseNcx',value:function(e){var t=(0,o.qsa)(e,'navPoint'),n=t.length,a={},s=[],r,i,l;if(!t||0===n)return s;for(r=0;r<n;++r)i=this.ncxItem(t[r]),a[i.id]=i,i.parent?(l=a[i.parent],l.subitems.push(i)):s.push(i);return s}},{key:'ncxItem',value:function(e){var t=e.getAttribute('id')||!1,n=(0,o.qs)(e,'content'),a=n.getAttribute('src'),i=(0,o.qs)(e,'navLabel'),s=i.textContent?i.textContent:'',r=e.parentNode,l;return r&&'navPoint'===r.nodeName&&(l=r.getAttribute('id')),{id:t,href:a,label:s,subitems:[],parent:l}}},{key:'load',value:function(e){var t=this;return e.map(function(e){return e.label=e.title,e.children&&(e.subitems=t.load(e.children)),e})}},{key:'forEach',value:function(e){return this.toc.forEach(e)}}]),e}();t.default=s,e.exports=t['default']},function(e,t,n){'use strict';function a(e){return e&&e.__esModule?e:{default:e}}function i(e,t){if(!(e instanceof t))throw new TypeError('Cannot call a class as a function')}Object.defineProperty(t,'__esModule',{value:!0});var o=function(){function e(e,t){for(var n=0,a;n<t.length;n++)a=t[n],a.enumerable=a.enumerable||!1,a.configurable=!0,'value'in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}return function(t,n,a){return n&&e(t.prototype,n),a&&e(t,a),t}}(),s=n(7),r=n(0),l=n(5),d=a(l),u=n(17),c=a(u),p=n(4),h=a(p),g=n(6),f=a(g),m=function(){function e(t,n){i(this,e),this.settings={replacements:n&&n.replacements||'base64',archive:n&&n.archive,resolver:n&&n.resolver,request:n&&n.request},this.manifest=t,this.resources=Object.keys(t).map(function(e){return t[e]}),this.replacementUrls=[],this.html=[],this.assets=[],this.css=[],this.urls=[],this.cssUrls=[],this.split(),this.splitUrls()}return o(e,[{key:'split',value:function(){this.html=this.resources.filter(function(e){if('application/xhtml+xml'===e.type||'text/html'===e.type)return!0}),this.assets=this.resources.filter(function(e){if('application/xhtml+xml'!==e.type&&'text/html'!==e.type)return!0}),this.css=this.resources.filter(function(e){if('text/css'===e.type)return!0})}},{key:'splitUrls',value:function(){this.urls=this.assets.map(function(e){return e.href}.bind(this)),this.cssUrls=this.css.map(function(e){return e.href})}},{key:'createUrl',value:function(e){var t=new d.default(e),n=c.default.lookup(t.filename);return this.settings.archive?this.settings.archive.createUrl(e,{base64:'base64'===this.settings.replacements}):'base64'===this.settings.replacements?this.settings.request(e,'blob').then(function(e){return(0,r.blob2base64)(e)}).then(function(e){return(0,r.createBase64Url)(e,n)}):this.settings.request(e,'blob').then(function(e){return(0,r.createBlobUrl)(e,n)})}},{key:'replacements',value:function(){var e=this;if('none'===this.settings.replacements)return new Promise(function(e){e(this.urls)}.bind(this));var t=this.urls.map(function(t){var n=e.settings.resolver(t);return e.createUrl(n).catch(function(e){return console.error(e),null})});return Promise.all(t).then(function(t){return e.replacementUrls=t.filter(function(e){return'string'==typeof e}),t})}},{key:'replaceCss',value:function(e,t){var n=[];return e=e||this.settings.archive,t=t||this.settings.resolver,this.cssUrls.forEach(function(a){var i=this.createCssFile(a,e,t).then(function(e){var t=this.urls.indexOf(a);-1<t&&(this.replacementUrls[t]=e)}.bind(this));n.push(i)}.bind(this)),Promise.all(n)}},{key:'createCssFile',value:function(e){var t=this,n;if(f.default.isAbsolute(e))return new Promise(function(e){e()});var a=this.settings.resolver(e),i;i=this.settings.archive?this.settings.archive.getText(a):this.settings.request(a,'text');var o=this.urls.map(function(e){var n=t.settings.resolver(e),i=new h.default(a).relative(n);return i});return i?i.then(function(e){return e=(0,s.substitute)(e,o,t.replacementUrls),n='base64'===t.settings.replacements?(0,r.createBase64Url)(e,'text/css'):(0,r.createBlobUrl)(e,'text/css'),n},function(){return new Promise(function(e){e()})}):new Promise(function(e){e()})}},{key:'relativeTo',value:function(e,t){return t=t||this.settings.resolver,this.urls.map(function(n){var a=t(n),i=new h.default(e).relative(a);return i}.bind(this))}},{key:'get',value:function(e){var t=this.urls.indexOf(e);return-1===t?void 0:this.replacementUrls.length?new Promise(function(e){e(this.replacementUrls[t])}.bind(this)):this.createUrl(e)}},{key:'substitute',value:function(e,t){var n;return n=t?this.relativeTo(t):this.urls,(0,s.substitute)(e,n,this.replacementUrls)}},{key:'destroy',value:function(){this.settings=void 0,this.manifest=void 0,this.resources=void 0,this.replacementUrls=void 0,this.html=void 0,this.assets=void 0,this.css=void 0,this.urls=void 0,this.cssUrls=void 0}}]),e}();t.default=m,e.exports=t['default']},function(e,t,n){'use strict';function a(e,t){if(!(e instanceof t))throw new TypeError('Cannot call a class as a function')}Object.defineProperty(t,'__esModule',{value:!0});var o=function(){function e(e,t){for(var n=0,a;n<t.length;n++)a=t[n],a.enumerable=a.enumerable||!1,a.configurable=!0,'value'in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}return function(t,n,a){return n&&e(t.prototype,n),a&&e(t,a),t}}(),s=n(1),r=function(e){return e&&e.__esModule?e:{default:e}}(s),l=n(0),d=function(){function e(t){a(this,e),this.pages=[],this.locations=[],this.epubcfi=new r.default,this.firstPage=0,this.lastPage=0,this.totalPages=0,this.toc=void 0,this.ncx=void 0,t&&(this.pageList=this.parse(t)),this.pageList&&this.pageList.length&&this.process(this.pageList)}return o(e,[{key:'parse',value:function(e){var t=(0,l.qs)(e,'html'),n=(0,l.qs)(e,'ncx');return t?this.parseNav(e):void n}},{key:'parseNav',value:function(e){var t=(0,l.querySelectorByType)(e,'nav','page-list'),n=t?(0,l.qsa)(t,'li'):[],a=n.length,o=[],s,i;if(!n||0===a)return o;for(s=0;s<a;++s)i=this.item(n[s]),o.push(i);return o}},{key:'item',value:function(e){var t=(0,l.qs)(e,'a'),n=t.getAttribute('href')||'',a=t.textContent||'',i=parseInt(a),o=n.indexOf('epubcfi'),s,r,d;return-1==o?{href:n,page:i}:(s=n.split('#'),r=s[0],d=!!(1<s.length)&&s[1],{cfi:d,href:n,packageUrl:r,page:i})}},{key:'process',value:function(e){e.forEach(function(e){this.pages.push(e.page),e.cfi&&this.locations.push(e.cfi)},this),this.firstPage=parseInt(this.pages[0]),this.lastPage=parseInt(this.pages[this.pages.length-1]),this.totalPages=this.lastPage-this.firstPage}},{key:'pageFromCfi',value:function(e){var t=-1;if(0===this.locations.length)return-1;var n=(0,l.indexOfSorted)(e,this.locations,this.epubcfi.compare);return-1==n?(n=(0,l.locationOf)(e,this.locations,this.epubcfi.compare),t=0<=n-1?this.pages[n-1]:this.pages[0],void 0!==t||(t=-1)):t=this.pages[n],t}},{key:'cfiFromPage',value:function(e){var t=-1;'number'!=typeof e&&(e=parseInt(e));var n=this.pages.indexOf(e);return-1!=n&&(t=this.locations[n]),t}},{key:'pageFromPercentage',value:function(e){var t=i(this.totalPages*e);return t}},{key:'percentageFromPage',value:function(e){var t=(e-this.firstPage)/this.totalPages;return i(1e3*t)/1e3}},{key:'percentageFromCfi',value:function(e){var t=this.pageFromCfi(e),n=this.percentageFromPage(t);return n}},{key:'destroy',value:function(){this.pages=void 0,this.locations=void 0,this.epubcfi=void 0,this.pageList=void 0,this.toc=void 0,this.ncx=void 0}}]),e}();t.default=d,e.exports=t['default']},function(e,t,n){'use strict';function i(e,t){if(!(e instanceof t))throw new TypeError('Cannot call a class as a function')}Object.defineProperty(t,'__esModule',{value:!0});var o=function(){function e(e,t){for(var n=0,a;n<t.length;n++)a=t[n],a.enumerable=a.enumerable||!1,a.configurable=!0,'value'in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}return function(t,n,a){return n&&e(t.prototype,n),a&&e(t,a),t}}(),r=n(0),l=n(3),d=n(2),u=function(e){return e&&e.__esModule?e:{default:e}}(d),c=function(){function e(t){i(this,e),this.settings=t,this.name=t.layout||'reflowable',this._spread='none'!==t.spread,this._minSpreadWidth=t.minSpreadWidth||800,this._evenSpreads=t.evenSpreads||!1,this._flow='scrolled'===t.flow||'scrolled-continuous'===t.flow||'scrolled-doc'===t.flow?'scrolled':'paginated',this.width=0,this.height=0,this.spreadWidth=0,this.delta=0,this.columnWidth=0,this.gap=0,this.divisor=1,this.props={name:this.name,spread:this._spread,flow:this._flow,width:0,height:0,spreadWidth:0,delta:0,columnWidth:0,gap:0,divisor:1}}return o(e,[{key:'flow',value:function(e){return'undefined'!=typeof e&&(this._flow='scrolled'===e||'scrolled-continuous'===e||'scrolled-doc'===e?'scrolled':'paginated',this.update({flow:this._flow})),this._flow}},{key:'spread',value:function(e,t){return e&&(this._spread='none'!==e,this.update({spread:this._spread})),0<=t&&(this._minSpreadWidth=t),this._spread}},{key:'calculate',value:function(e,t,n){var a=1,i=n||0,o=e,r=t,l=s(o/12),d,u,c,p;a=this._spread&&o>=this._minSpreadWidth?2:1,'reflowable'!==this.name||'paginated'!==this._flow||0<=n||(i=0==l%2?l:l-1),'pre-paginated'===this.name&&(i=0),1<a?(d=o/a-i,c=d+i):(d=o,c=o),'pre-paginated'===this.name&&1<a&&(o=d),u=d*a+i,p=o,this.width=o,this.height=r,this.spreadWidth=u,this.pageWidth=c,this.delta=p,this.columnWidth=d,this.gap=i,this.divisor=a,this.update({width:o,height:r,spreadWidth:u,pageWidth:c,delta:p,columnWidth:d,gap:i,divisor:a})}},{key:'format',value:function(e){var t;return t='pre-paginated'===this.name?e.fit(this.columnWidth,this.height):'paginated'===this._flow?e.columns(this.width,this.height,this.columnWidth,this.gap):e.size(this.width,null),t}},{key:'count',value:function(e,t){var n,i;return'pre-paginated'===this.name?(n=1,i=1):'paginated'===this._flow?(t=t||this.delta,n=a(e/t),i=n*this.divisor):(t=t||this.height,n=a(e/t),i=n),{spreads:n,pages:i}}},{key:'update',value:function(e){var t=this;if(Object.keys(e).forEach(function(n){t.props[n]===e[n]&&delete e[n]}),0<Object.keys(e).length){var n=(0,r.extend)(this.props,e);this.emit(l.EVENTS.LAYOUT.UPDATED,n,e)}}}]),e}();(0,u.default)(c.prototype),t.default=c,e.exports=t['default']},function(e,t,n){'use strict';function a(e,t){if(!(e instanceof t))throw new TypeError('Cannot call a class as a function')}Object.defineProperty(t,'__esModule',{value:!0});var i='function'==typeof Symbol&&'symbol'==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&'function'==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?'symbol':typeof e},o=function(){function e(e,t){for(var n=0,a;n<t.length;n++)a=t[n],a.enumerable=a.enumerable||!1,a.configurable=!0,'value'in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}return function(t,n,a){return n&&e(t.prototype,n),a&&e(t,a),t}}(),s=n(5),r=function(e){return e&&e.__esModule?e:{default:e}}(s),l=function(){function e(t){a(this,e),this.rendition=t,this._themes={default:{rules:{},url:'',serialized:''}},this._overrides={},this._current='default',this._injected=[],this.rendition.hooks.content.register(this.inject.bind(this)),this.rendition.hooks.content.register(this.overrides.bind(this))}return o(e,[{key:'register',value:function(){return 0===arguments.length?void 0:1===arguments.length&&'object'===i(arguments[0])?this.registerThemes(arguments[0]):1===arguments.length&&'string'==typeof arguments[0]?this.default(arguments[0]):2===arguments.length&&'string'==typeof arguments[1]?this.registerUrl(arguments[0],arguments[1]):2===arguments.length&&'object'===i(arguments[1])?this.registerRules(arguments[0],arguments[1]):void 0}},{key:'default',value:function(e){return e?'string'==typeof e?this.registerUrl('default',e):'object'===('undefined'==typeof e?'undefined':i(e))?this.registerRules('default',e):void 0:void 0}},{key:'registerThemes',value:function(e){for(var t in e)e.hasOwnProperty(t)&&('string'==typeof e[t]?this.registerUrl(t,e[t]):this.registerRules(t,e[t]))}},{key:'registerUrl',value:function(e,t){var n=new r.default(t);this._themes[e]={url:n.toString()},this._injected[e]&&this.update(e)}},{key:'registerRules',value:function(e,t){this._themes[e]={rules:t},this._injected[e]&&this.update(e)}},{key:'select',value:function(e){var t=this._current,n;this._current=e,this.update(e),n=this.rendition.getContents(),n.forEach(function(n){n.removeClass(t),n.addClass(e)})}},{key:'update',value:function(e){var t=this,n=this.rendition.getContents();n.forEach(function(n){t.add(e,n)})}},{key:'inject',value:function(e){var t=[],n=this._themes,a;for(var i in n)n.hasOwnProperty(i)&&(i===this._current||'default'==i)&&(a=n[i],(a.rules&&0<Object.keys(a.rules).length||a.url&&-1===t.indexOf(a.url))&&this.add(i,e),this._injected.push(i));'default'!=this._current&&e.addClass(this._current)}},{key:'add',value:function(e,t){var n=this._themes[e];n&&t&&(n.url?t.addStylesheet(n.url):n.serialized||n.rules&&(t.addStylesheetRules(n.rules),n.injected=!0))}},{key:'override',value:function(e,t,n){var a=this,i=this.rendition.getContents();this._overrides[e]={value:t,priority:!0===n},i.forEach(function(t){t.css(e,a._overrides[e].value,a._overrides[e].priority)})}},{key:'overrides',value:function(e){var t=this._overrides;for(var n in t)t.hasOwnProperty(n)&&e.css(n,t[n].value,t[n].priority)}},{key:'fontSize',value:function(e){this.override('font-size',e)}},{key:'font',value:function(e){this.override('font-family',e,!0)}},{key:'destroy',value:function(){this.rendition=void 0,this._themes=void 0,this._overrides=void 0,this._current=void 0,this._injected=void 0}}]),e}();t.default=l,e.exports=t['default']},function(e,t,n){'use strict';function a(e){return e&&e.__esModule?e:{default:e}}function i(e,t){if(!(e instanceof t))throw new TypeError('Cannot call a class as a function')}Object.defineProperty(t,'__esModule',{value:!0});var o=function(){function e(e,t){for(var n=0,a;n<t.length;n++)a=t[n],a.enumerable=a.enumerable||!1,a.configurable=!0,'value'in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}return function(t,n,a){return n&&e(t.prototype,n),a&&e(t,a),t}}(),s=n(2),r=a(s),l=n(1),d=a(l),u=function(){function e(t){i(this,e),this.rendition=t,this.highlights=[],this.underlines=[],this.marks=[],this._annotations={},this._annotationsBySectionIndex={},this.rendition.hooks.render.register(this.inject.bind(this)),this.rendition.hooks.unloaded.register(this.clear.bind(this))}return o(e,[{key:'add',value:function(e,t,n,a){var i=encodeURI(t),o=new d.default(t),s=o.spinePos,r=new c({type:e,cfiRange:t,data:n,sectionIndex:s,cb:a});this._annotations[i]=r,s in this._annotationsBySectionIndex?this._annotationsBySectionIndex[s].push(i):this._annotationsBySectionIndex[s]=[i];var l=this.rendition.views();return l.forEach(function(e){r.sectionIndex===e.index&&r.attach(e)}),r}},{key:'remove',value:function(e,t){var n=this,a=encodeURI(e);if(a in this._annotations){var i=this._annotations[a];if(t&&i.type!==t)return;var o=this.rendition.views();o.forEach(function(e){n._removeFromAnnotationBySectionIndex(i.sectionIndex,a),i.sectionIndex===e.index&&i.detach(e)}),delete this._annotations[a]}}},{key:'_removeFromAnnotationBySectionIndex',value:function(e,t){this._annotationsBySectionIndex[e]=this._annotationsAt(e).filter(function(e){return e!==t})}},{key:'_annotationsAt',value:function(e){return this._annotationsBySectionIndex[e]}},{key:'highlight',value:function(e,t,n){this.add('highlight',e,t,n)}},{key:'underline',value:function(e,t,n){this.add('underline',e,t,n)}},{key:'mark',value:function(e,t,n){this.add('mark',e,t,n)}},{key:'each',value:function(){return this._annotations.forEach.apply(this._annotations,arguments)}},{key:'inject',value:function(e){var t=this,n=e.index;if(n in this._annotationsBySectionIndex){var a=this._annotationsBySectionIndex[n];a.forEach(function(n){var a=t._annotations[n];a.attach(e)})}}},{key:'clear',value:function(e){var t=this,n=e.index;if(n in this._annotationsBySectionIndex){var a=this._annotationsBySectionIndex[n];a.forEach(function(n){var a=t._annotations[n];a.detach(e)})}}},{key:'show',value:function(){}},{key:'hide',value:function(){}}]),e}(),c=function(){function e(t){var n=t.type,a=t.cfiRange,o=t.data,s=t.sectionIndex,r=t.cb;i(this,e),this.type=n,this.cfiRange=a,this.data=o,this.sectionIndex=s,this.mark=void 0,this.cb=r}return o(e,[{key:'update',value:function(e){this.data=e}},{key:'attach',value:function(e){var t=this.cfiRange,n=this.data,a=this.type,i=this.mark,o=this.cb,s;return'highlight'===a?s=e.highlight(t,n,o):'underline'===a?s=e.underline(t,n,o):'mark'===a&&(s=e.mark(t,n,o)),this.mark=s,s}},{key:'detach',value:function(e){var t=this.cfiRange,n=this.type,a;return e&&('highlight'===n?a=e.unhighlight(t):'underline'===n?a=e.ununderline(t):'mark'===n&&(a=e.unmark(t))),this.mark=void 0,a}},{key:'text',value:function(){}}]),e}();(0,r.default)(c.prototype),t.default=u,e.exports=t['default']},function(e,t,n){'use strict';function a(e){return e&&e.__esModule?e:{default:e}}function i(e,t){if(!e)throw new ReferenceError('this hasn\'t been initialised - super() hasn\'t been called');return t&&('object'===('undefined'==typeof t?'undefined':u(t))||'function'==typeof t)?t:e}function o(e,t){if('function'!=typeof t&&null!==t)throw new TypeError('Super expression must either be null or a function, not '+('undefined'==typeof t?'undefined':u(t)));e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function s(e,t){if(!(e instanceof t))throw new TypeError('Cannot call a class as a function')}function r(e,t){var n=t.getBoundingClientRect(),a=e.getBoundingClientRect();return{top:a.top-n.top,left:a.left-n.left,height:e.scrollHeight,width:e.scrollWidth}}function l(e,t){e.style.top=t.top+'px',e.style.left=t.left+'px',e.style.height=t.height+'px',e.style.width=t.width+'px'}function d(e,t){return t.right<=e.right&&t.left>=e.left&&t.top>=e.top&&t.bottom<=e.bottom}var u='function'==typeof Symbol&&'symbol'==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&'function'==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?'symbol':typeof e};Object.defineProperty(t,'__esModule',{value:!0}),t.Underline=t.Highlight=t.Mark=t.Pane=void 0;var c=function e(t,n,a){null===t&&(t=Function.prototype);var i=Object.getOwnPropertyDescriptor(t,n);if(i===void 0){var o=Object.getPrototypeOf(t);return null===o?void 0:e(o,n,a)}if('value'in i)return i.value;var s=i.get;return void 0===s?void 0:s.call(a)},p=function(){function e(e,t){for(var n=0,a;n<t.length;n++)a=t[n],a.enumerable=a.enumerable||!1,a.configurable=!0,'value'in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}return function(t,n,a){return n&&e(t.prototype,n),a&&e(t,a),t}}(),h=n(54),f=a(h),g=n(55),m=a(g),y=t.Pane=function(){function e(t){var n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:document.body;s(this,e),this.target=t,this.element=f.default.createElement('svg'),this.marks=[],this.element.style.position='absolute',this.element.setAttribute('pointer-events','none'),m.default.proxyMouse(this.target,this.marks),this.container=n,this.container.appendChild(this.element),this.render()}return p(e,[{key:'addMark',value:function(e){var t=f.default.createElement('g');return this.element.appendChild(t),e.bind(t,this.container),this.marks.push(e),e.render(),e}},{key:'removeMark',value:function(e){var t=this.marks.indexOf(e);if(-1!==t){var n=e.unbind();this.element.removeChild(n),this.marks.splice(t,1)}}},{key:'render',value:function(){l(this.element,r(this.target,this.container));var e=!0,t=!1,n;try{for(var a=this.marks[Symbol.iterator](),i,o;!(e=(i=a.next()).done);e=!0)o=i.value,o.render()}catch(e){t=!0,n=e}finally{try{!e&&a.return&&a.return()}finally{if(t)throw n}}}}]),e}(),v=t.Mark=function(){function e(){s(this,e),this.element=null}return p(e,[{key:'bind',value:function(e,t){this.element=e,this.container=t}},{key:'unbind',value:function(){var e=this.element;return this.element=null,e}},{key:'render',value:function(){}},{key:'dispatchEvent',value:function(t){this.element&&this.element.dispatchEvent(t)}},{key:'getBoundingClientRect',value:function(){return this.element.getBoundingClientRect()}},{key:'getClientRects',value:function(){for(var e=[],t=this.element.firstChild;t;)e.push(t.getBoundingClientRect()),t=t.nextSibling;return e}},{key:'filteredRanges',value:function(){var e=Array.from(this.range.getClientRects());return e.filter(function(t){for(var n=0;n<e.length;n++){if(e[n]===t)return!0;var a=d(e[n],t);if(a)return!1}return!0})}}]),e}(),b=t.Highlight=function(e){function t(e,n,a,o){s(this,t);var r=i(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return r.range=e,r.className=n,r.data=a||{},r.attributes=o||{},r}return o(t,e),p(t,[{key:'bind',value:function(e,n){for(var a in c(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),'bind',this).call(this,e,n),this.data)this.data.hasOwnProperty(a)&&(this.element.dataset[a]=this.data[a]);for(var a in this.attributes)this.attributes.hasOwnProperty(a)&&this.element.setAttribute(a,this.attributes[a]);this.className&&this.element.classList.add(this.className)}},{key:'render',value:function(){for(;this.element.firstChild;)this.element.removeChild(this.element.firstChild);for(var e=this.element.ownerDocument.createDocumentFragment(),t=this.filteredRanges(),n=this.element.getBoundingClientRect(),a=this.container.getBoundingClientRect(),o=0,i=t.length;o<i;o++){var s=t[o],r=f.default.createElement('rect');r.setAttribute('x',s.left-n.left+a.left),r.setAttribute('y',s.top-n.top+a.top),r.setAttribute('height',s.height),r.setAttribute('width',s.width),e.appendChild(r)}this.element.appendChild(e)}}]),t}(v),k=t.Underline=function(e){function t(e,n,a,o){return s(this,t),i(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e,n,a,o))}return o(t,e),p(t,[{key:'render',value:function(){for(;this.element.firstChild;)this.element.removeChild(this.element.firstChild);for(var e=this.element.ownerDocument.createDocumentFragment(),t=this.filteredRanges(),n=this.element.getBoundingClientRect(),a=this.container.getBoundingClientRect(),o=0,i=t.length;o<i;o++){var s=t[o],r=f.default.createElement('rect');r.setAttribute('x',s.left-n.left+a.left),r.setAttribute('y',s.top-n.top+a.top),r.setAttribute('height',s.height),r.setAttribute('width',s.width),r.setAttribute('fill','none');var l=f.default.createElement('line');l.setAttribute('x1',s.left-n.left+a.left),l.setAttribute('x2',s.left-n.left+a.left+s.width),l.setAttribute('y1',s.top-n.top+a.top+s.height-1),l.setAttribute('y2',s.top-n.top+a.top+s.height-1),l.setAttribute('stroke-width',1),l.setAttribute('stroke','black'),l.setAttribute('stroke-linecap','square'),e.appendChild(r),e.appendChild(l)}this.element.appendChild(e)}}]),t}(b)},function(e,t){'use strict';function n(e){return document.createElementNS('http://www.w3.org/2000/svg',e)}Object.defineProperty(t,'__esModule',{value:!0}),t.createElement=n,t.default={createElement:n}},function(e,t){'use strict';function n(n,s){function t(r){for(var e=s.length-1;0<=e;e--){var i=s[e],t=r.clientX,l=r.clientY;if(r.touches&&r.touches.length&&(t=r.touches[0].clientX,l=r.touches[0].clientY),!!o(i,n,t,l)){i.dispatchEvent(a(r));break}}}if('iframe'===n.nodeName||'IFRAME'===n.nodeName)try{this.target=n.contentDocument}catch(e){this.target=n}else this.target=n;for(var e=['mouseup','mousedown','click','touchstart'],i=0,r;i<e.length;i++)r=e[i],this.target.addEventListener(r,function(n){return t(n)},!1)}function a(t){var e=Object.assign({},t,{bubbles:!1});try{return new MouseEvent(t.type,e)}catch(a){var n=document.createEvent('MouseEvents');return n.initMouseEvent(t.type,!1,e.cancelable,e.view,e.detail,e.screenX,e.screenY,e.clientX,e.clientY,e.ctrlKey,e.altKey,e.shiftKey,e.metaKey,e.button,e.relatedTarget),n}}function o(e,t,n,a){function o(e,t,n){var a=e.top-s.top,i=e.left-s.left,o=a+e.height,r=i+e.width;return a<=n&&i<=t&&o>n&&r>t}var s=t.getBoundingClientRect(),r=e.getBoundingClientRect();if(!o(r,n,a))return!1;for(var l=e.getClientRects(),d=0,i=l.length;d<i;d++)if(o(l[d],n,a))return!0;return!1}Object.defineProperty(t,'__esModule',{value:!0}),t.proxyMouse=n,t.clone=a,t.default={proxyMouse:n}},function(e,t,n){'use strict';function a(e,t){if(!(e instanceof t))throw new TypeError('Cannot call a class as a function')}Object.defineProperty(t,'__esModule',{value:!0});var i=function(){function e(e,t){for(var n=0,a;n<t.length;n++)a=t[n],a.enumerable=a.enumerable||!1,a.configurable=!0,'value'in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}return function(t,n,a){return n&&e(t.prototype,n),a&&e(t,a),t}}(),o=n(0),r=n(57),l=function(e){return e&&e.__esModule?e:{default:e}}(r),d=function(){function e(t){a(this,e),this.settings=t||{},this.id='epubjs-container-'+(0,o.uuid)(),this.container=this.create(this.settings),this.settings.hidden&&(this.wrapper=this.wrap(this.container))}return i(e,[{key:'create',value:function(e){var t=e.height,n=e.width,a=e.overflow||!1,i=e.axis||'vertical',s=e.direction;e.height&&(0,o.isNumber)(e.height)&&(t=e.height+'px'),e.width&&(0,o.isNumber)(e.width)&&(n=e.width+'px');var r=document.createElement('div');return r.id=this.id,r.classList.add('epub-container'),r.style.wordSpacing='0',r.style.lineHeight='0',r.style.verticalAlign='top',r.style.position='relative','horizontal'===i&&(r.style.display='flex',r.style.flexDirection='row',r.style.flexWrap='nowrap'),n&&(r.style.width=n),t&&(r.style.height=t),a&&(r.style.overflow=a),s&&(r.dir=s,r.style.direction=s),s&&this.settings.fullsize&&(document.body.style.direction=s),r}},{key:'wrap',value:function(e){var t=document.createElement('div');return t.style.visibility='hidden',t.style.overflow='hidden',t.style.width='0',t.style.height='0',t.appendChild(e),t}},{key:'getElement',value:function(e){var t;if((0,o.isElement)(e)?t=e:'string'==typeof e&&(t=document.getElementById(e)),!t)throw new Error('Not an Element');return t}},{key:'attachTo',value:function(e){var t=this.getElement(e),n;if(t)return n=this.settings.hidden?this.wrapper:this.container,t.appendChild(n),this.element=t,t}},{key:'getContainer',value:function(){return this.container}},{key:'onResize',value:function(e){(0,o.isNumber)(this.settings.width)&&(0,o.isNumber)(this.settings.height)||(this.resizeFunc=(0,l.default)(e,50),window.addEventListener('resize',this.resizeFunc,!1))}},{key:'onOrientationChange',value:function(e){this.orientationChangeFunc=e,window.addEventListener('orientationchange',this.orientationChangeFunc,!1)}},{key:'size',value:function(e,t){var n;null===e&&(n=this.element.getBoundingClientRect(),n.width&&(e=s(n.width),this.container.style.width=e+'px')),null===t&&(n=n||this.element.getBoundingClientRect(),n.height&&(t=n.height,this.container.style.height=n.height+'px')),(0,o.isNumber)(e)||(n=this.container.getBoundingClientRect(),e=s(n.width)),(0,o.isNumber)(t)||(n=n||this.container.getBoundingClientRect(),t=n.height),this.containerStyles=window.getComputedStyle(this.container),this.containerPadding={left:parseFloat(this.containerStyles['padding-left'])||0,right:parseFloat(this.containerStyles['padding-right'])||0,top:parseFloat(this.containerStyles['padding-top'])||0,bottom:parseFloat(this.containerStyles['padding-bottom'])||0};var a=(0,o.windowBounds)();return e||(e=a.width),(this.settings.fullsize||!t)&&(t=a.height),{width:e-this.containerPadding.left-this.containerPadding.right,height:t-this.containerPadding.top-this.containerPadding.bottom}}},{key:'bounds',value:function(){var e;return'visible'!==this.container.style.overflow&&(e=this.container&&this.container.getBoundingClientRect()),e&&e.width&&e.height?e:(0,o.windowBounds)()}},{key:'getSheet',value:function(){var e=document.createElement('style');return e.appendChild(document.createTextNode('')),document.head.appendChild(e),e.sheet}},{key:'addStyleRules',value:function(e,t){var n='#'+this.id+' ',a='';this.sheet||(this.sheet=this.getSheet()),t.forEach(function(e){for(var t in e)e.hasOwnProperty(t)&&(a+=t+':'+e[t]+';')}),this.sheet.insertRule(n+e+' {'+a+'}',0)}},{key:'axis',value:function(e){'horizontal'===e?(this.container.style.display='flex',this.container.style.flexDirection='row',this.container.style.flexWrap='nowrap'):this.container.style.display='block'}},{key:'direction',value:function(e){this.container&&(this.container.dir=e,this.container.style.direction=e),this.settings.fullsize&&(document.body.style.direction=e)}},{key:'destroy',value:function(){var e;this.element&&(e=this.settings.hidden?this.wrapper:this.container,this.element.contains(this.container)&&this.element.removeChild(this.container),window.removeEventListener('resize',this.resizeFunc),window.removeEventListener('orientationChange',this.orientationChangeFunc))}}]),e}();t.default=d,e.exports=t['default']},function(e,t,n){var a=n(21),i=n(15);e.exports=function(e,t,n){var o=!0,s=!0;if('function'!=typeof e)throw new TypeError('Expected a function');return i(n)&&(o='leading'in n?!!n.leading:o,s='trailing'in n?!!n.trailing:s),a(e,t,{leading:o,maxWait:t,trailing:s})}},function(e,t,n){var a=n(22);e.exports=function(){return a.Date.now()}},function(e,t,n){(function(t){var n='object'==typeof t&&t&&t.Object===Object&&t;e.exports=n}).call(t,n(8))},function(e,t,n){var a=n(15),i=n(61),o=0/0,s=/^\s+|\s+$/g,r=/^[-+]0x[0-9a-f]+$/i,l=/^0b[01]+$/i,d=/^0o[0-7]+$/i,u=parseInt;e.exports=function(e){if('number'==typeof e)return e;if(i(e))return o;if(a(e)){var t='function'==typeof e.valueOf?e.valueOf():e;e=a(t)?t+'':t}if('string'!=typeof e)return 0===e?e:+e;e=e.replace(s,'');var n=l.test(e);return n||d.test(e)?u(e.slice(2),n?2:8):r.test(e)?o:+e}},function(e,t,n){var a=n(62),i=n(65);e.exports=function(e){return'symbol'==typeof e||i(e)&&a(e)=='[object Symbol]'}},function(e,t,n){var a=n(23),i=n(63),o=n(64),s=a?a.toStringTag:void 0;e.exports=function(e){return null==e?void 0===e?'[object Undefined]':'[object Null]':s&&s in Object(e)?i(e):o(e)}},function(e,t,n){var a=n(23),i=Object.prototype,o=i.hasOwnProperty,s=i.toString,r=a?a.toStringTag:void 0;e.exports=function(e){var t=o.call(e,r),n=e[r];try{e[r]=void 0}catch(t){}var a=s.call(e);return t?e[r]=n:delete e[r],a}},function(e){var t=Object.prototype,n=t.toString;e.exports=function(e){return n.call(e)}},function(e){e.exports=function(e){return null!=e&&'object'==typeof e}},function(e,t){'use strict';function n(e,t){if(!(e instanceof t))throw new TypeError('Cannot call a class as a function')}Object.defineProperty(t,'__esModule',{value:!0});var a=function(){function e(e,t){for(var n=0,a;n<t.length;n++)a=t[n],a.enumerable=a.enumerable||!1,a.configurable=!0,'value'in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}return function(t,n,a){return n&&e(t.prototype,n),a&&e(t,a),t}}(),i=function(){function e(t){n(this,e),this.container=t,this._views=[],this.length=0,this.hidden=!1}return a(e,[{key:'all',value:function(){return this._views}},{key:'first',value:function(){return this._views[0]}},{key:'last',value:function(){return this._views[this._views.length-1]}},{key:'indexOf',value:function(e){return this._views.indexOf(e)}},{key:'slice',value:function(){return this._views.slice.apply(this._views,arguments)}},{key:'get',value:function(e){return this._views[e]}},{key:'append',value:function(e){return this._views.push(e),this.container&&this.container.appendChild(e.element),this.length++,e}},{key:'prepend',value:function(e){return this._views.unshift(e),this.container&&this.container.insertBefore(e.element,this.container.firstChild),this.length++,e}},{key:'insert',value:function(e,t){return this._views.splice(t,0,e),this.container&&(t<this.container.children.length?this.container.insertBefore(e.element,this.container.children[t]):this.container.appendChild(e.element)),this.length++,e}},{key:'remove',value:function(e){var t=this._views.indexOf(e);-1<t&&this._views.splice(t,1),this.destroy(e),this.length--}},{key:'destroy',value:function(e){e.displayed&&e.destroy(),this.container&&this.container.removeChild(e.element),e=null}},{key:'forEach',value:function(){return this._views.forEach.apply(this._views,arguments)}},{key:'clear',value:function(){var e=this.length,t;if(this.length){for(var n=0;n<e;n++)t=this._views[n],this.destroy(t);this._views=[],this.length=0}}},{key:'find',value:function(e){for(var t=this.length,n=0,a;n<t;n++)if(a=this._views[n],a.displayed&&a.section.index==e.index)return a}},{key:'displayed',value:function(){for(var e=[],t=this.length,n=0,a;n<t;n++)a=this._views[n],a.displayed&&e.push(a);return e}},{key:'show',value:function(){for(var e=this.length,t=0,n;t<e;t++)n=this._views[t],n.displayed&&n.show();this.hidden=!1}},{key:'hide',value:function(){for(var e=this.length,t=0,n;t<e;t++)n=this._views[t],n.displayed&&n.hide();this.hidden=!0}}]),e}();t.default=i,e.exports=t['default']},function(e,t,n){'use strict';function a(e){return e&&e.__esModule?e:{default:e}}function i(e,t){if(!(e instanceof t))throw new TypeError('Cannot call a class as a function')}Object.defineProperty(t,'__esModule',{value:!0});var o=function(){function e(e,t){for(var n=0,a;n<t.length;n++)a=t[n],a.enumerable=a.enumerable||!1,a.configurable=!0,'value'in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}return function(t,n,a){return n&&e(t.prototype,n),a&&e(t,a),t}}(),s=n(0),r=n(11),l=a(r),d=n(17),u=a(d),c=n(4),p=a(c),h=function(){function e(){i(this,e),this.zip=void 0,this.urlCache={},this.checkRequirements()}return o(e,[{key:'checkRequirements',value:function(){try{if('undefined'==typeof JSZip){var e=n(68);this.zip=new e}else this.zip=new JSZip}catch(t){throw new Error('JSZip lib not loaded')}}},{key:'open',value:function(e,t){return this.zip.loadAsync(e,{base64:t})}},{key:'openUrl',value:function(e,t){return(0,l.default)(e,'binary').then(function(e){return this.zip.loadAsync(e,{base64:t})}.bind(this))}},{key:'request',value:function(e,t){var n=new s.defer,a=new p.default(e),i;return t||(t=a.extension),i='blob'==t?this.getBlob(e):this.getText(e),i?i.then(function(e){var a=this.handleResponse(e,t);n.resolve(a)}.bind(this)):n.reject({message:'File not found in the epub: '+e,stack:new Error().stack}),n.promise}},{key:'handleResponse',value:function(e,t){var n;return n='json'==t?JSON.parse(e):(0,s.isXml)(t)?(0,s.parse)(e,'text/xml'):'xhtml'==t?(0,s.parse)(e,'application/xhtml+xml'):'html'==t||'htm'==t?(0,s.parse)(e,'text/html'):e,n}},{key:'getBlob',value:function(e,t){var n=window.decodeURIComponent(e.substr(1)),a=this.zip.file(n);if(a)return t=t||u.default.lookup(a.name),a.async('uint8array').then(function(e){return new Blob([e],{type:t})})}},{key:'getText',value:function(e){var t=window.decodeURIComponent(e.substr(1)),n=this.zip.file(t);if(n)return n.async('string').then(function(e){return e})}},{key:'getBase64',value:function(e,t){var n=window.decodeURIComponent(e.substr(1)),a=this.zip.file(n);if(a)return t=t||u.default.lookup(a.name),a.async('base64').then(function(e){return'data:'+t+';base64,'+e})}},{key:'createUrl',value:function(e,t){var n=new s.defer,a=window.URL||window.webkitURL||window.mozURL,i=t&&t.base64,o,r;return e in this.urlCache?(n.resolve(this.urlCache[e]),n.promise):(i?(r=this.getBase64(e),r&&r.then(function(t){this.urlCache[e]=t,n.resolve(t)}.bind(this))):(r=this.getBlob(e),r&&r.then(function(t){o=a.createObjectURL(t),this.urlCache[e]=o,n.resolve(o)}.bind(this))),r||n.reject({message:'File not found in the epub: '+e,stack:new Error().stack}),n.promise)}},{key:'revokeUrl',value:function(e){var t=window.URL||window.webkitURL||window.mozURL,n=this.urlCache[e];n&&t.revokeObjectURL(n)}},{key:'destroy',value:function(){var e=window.URL||window.webkitURL||window.mozURL;for(var t in this.urlCache)e.revokeObjectURL(t);this.zip=void 0,this.urlCache={}}}]),e}();t.default=h,e.exports=t['default']},function(n){if('undefined'==typeof t){var a=new Error('Cannot find module "jszip"');throw a.code='MODULE_NOT_FOUND',a}n.exports=t},function(e,t,n){'use strict';(function(e,n){var a='function'==typeof Symbol&&'symbol'==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&'function'==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?'symbol':typeof e},i,o,s;(function(r,l){r||(r=window||e),'object'===a(n)&&n.exports?n.exports=l(r):(o=[],i=l,s='function'==typeof i?i.apply(t,o):i,!(s!==void 0&&(n.exports=s)))})(void 0,function(e){function t(e){return void 0!==u[e]}function n(){r.call(this),this._isInvalid=!0}function a(e){return''==e&&n.call(this),e.toLowerCase()}function o(e){var t=e.charCodeAt(0);return 32<t&&127>t&&-1==[34,35,60,62,63,96].indexOf(t)?e:encodeURIComponent(e)}function s(e){var t=e.charCodeAt(0);return 32<t&&127>t&&-1==[34,35,60,62,96].indexOf(t)?e:encodeURIComponent(e)}function i(e,r,l){function d(e){x.push(e)}var m=r||'scheme start',y=0,v='',b=!1,k=!1,x=[];loop:for(;(e[y-1]!=f||0==y)&&!this._isInvalid;){var E=e[y];switch(m){case'scheme start':if(E&&h.test(E))v+=E.toLowerCase(),m='scheme';else if(!r){v='',m='no scheme';continue}else{d('Invalid scheme.');break loop}break;case'scheme':if(E&&g.test(E))v+=E.toLowerCase();else if(':'==E){if(this._scheme=v,v='',r)break loop;t(this._scheme)&&(this._isRelative=!0),m='file'==this._scheme?'relative':this._isRelative&&l&&l._scheme==this._scheme?'relative or authority':this._isRelative?'authority first slash':'scheme data'}else if(!r){v='',y=0,m='no scheme';continue}else if(f==E)break loop;else{d('Code point not allowed in scheme: '+E);break loop}break;case'scheme data':'?'==E?(this._query='?',m='query'):'#'==E?(this._fragment='#',m='fragment'):f!=E&&'\t'!=E&&'\n'!=E&&'\r'!=E&&(this._schemeData+=o(E));break;case'no scheme':if(!l||!t(l._scheme))d('Missing scheme.'),n.call(this);else{m='relative';continue}break;case'relative or authority':if('/'==E&&'/'==e[y+1])m='authority ignore slashes';else{d('Expected /, got: '+E),m='relative';continue}break;case'relative':if(this._isRelative=!0,'file'!=this._scheme&&(this._scheme=l._scheme),f==E){this._host=l._host,this._port=l._port,this._path=l._path.slice(),this._query=l._query,this._username=l._username,this._password=l._password;break loop}else if('/'==E||'\\'==E)'\\'==E&&d('\\ is an invalid code point.'),m='relative slash';else if('?'==E)this._host=l._host,this._port=l._port,this._path=l._path.slice(),this._query='?',this._username=l._username,this._password=l._password,m='query';else if('#'==E)this._host=l._host,this._port=l._port,this._path=l._path.slice(),this._query=l._query,this._fragment='#',this._username=l._username,this._password=l._password,m='fragment';else{var c=e[y+1],_=e[y+2];'file'==this._scheme&&h.test(E)&&(':'==c||'|'==c)&&(f==_||'/'==_||'\\'==_||'?'==_||'#'==_)||(this._host=l._host,this._port=l._port,this._username=l._username,this._password=l._password,this._path=l._path.slice(),this._path.pop()),m='relative path';continue}break;case'relative slash':if('/'==E||'\\'==E)'\\'==E&&d('\\ is an invalid code point.'),m='file'==this._scheme?'file host':'authority ignore slashes';else{'file'!=this._scheme&&(this._host=l._host,this._port=l._port,this._username=l._username,this._password=l._password),m='relative path';continue}break;case'authority first slash':if('/'==E)m='authority second slash';else{d('Expected \'/\', got: '+E),m='authority ignore slashes';continue}break;case'authority second slash':if(m='authority ignore slashes','/'!=E){d('Expected \'/\', got: '+E);continue}break;case'authority ignore slashes':if('/'!=E&&'\\'!=E){m='authority';continue}else d('Expected authority, got: '+E);break;case'authority':if('@'==E){b&&(d('@ already seen.'),v+='%40'),b=!0;for(var w=0,i;w<v.length;w++){if(i=v[w],'\t'==i||'\n'==i||'\r'==i){d('Invalid whitespace in authority.');continue}if(':'==i&&null===this._password){this._password='';continue}var S=o(i);null===this._password?this._username+=S:this._password+=S}v=''}else if(f==E||'/'==E||'\\'==E||'?'==E||'#'==E){y-=v.length,v='',m='host';continue}else v+=E;break;case'file host':if(f==E||'/'==E||'\\'==E||'?'==E||'#'==E){2==v.length&&h.test(v[0])&&(':'==v[1]||'|'==v[1])?m='relative path':0==v.length?m='relative path start':(this._host=a.call(this,v),v='',m='relative path start');continue}else'\t'==E||'\n'==E||'\r'==E?d('Invalid whitespace in file host.'):v+=E;break;case'host':case'hostname':if(':'==E&&!k){if(this._host=a.call(this,v),v='',m='port','hostname'==r)break loop;}else if(f==E||'/'==E||'\\'==E||'?'==E||'#'==E){if(this._host=a.call(this,v),v='',m='relative path start',r)break loop;continue}else'\t'!=E&&'\n'!=E&&'\r'!=E?('['==E?k=!0:']'==E&&(k=!1),v+=E):d('Invalid code point in host/hostname: '+E);break;case'port':if(/[0-9]/.test(E))v+=E;else if(f==E||'/'==E||'\\'==E||'?'==E||'#'==E||r){if(''!=v){var C=parseInt(v,10);C!=u[this._scheme]&&(this._port=C+''),v=''}if(r)break loop;m='relative path start';continue}else'\t'==E||'\n'==E||'\r'==E?d('Invalid code point in port: '+E):n.call(this);break;case'relative path start':if('\\'==E&&d('\'\\\' not allowed in path.'),m='relative path','/'!=E&&'\\'!=E)continue;break;case'relative path':if(f==E||'/'==E||'\\'==E||!r&&('?'==E||'#'==E)){'\\'==E&&d('\\ not allowed in relative path.');var T;(T=p[v.toLowerCase()])&&(v=T),'..'==v?(this._path.pop(),'/'!=E&&'\\'!=E&&this._path.push('')):'.'==v&&'/'!=E&&'\\'!=E?this._path.push(''):'.'!=v&&('file'==this._scheme&&0==this._path.length&&2==v.length&&h.test(v[0])&&'|'==v[1]&&(v=v[0]+':'),this._path.push(v)),v='','?'==E?(this._query='?',m='query'):'#'==E&&(this._fragment='#',m='fragment')}else'\t'!=E&&'\n'!=E&&'\r'!=E&&(v+=o(E));break;case'query':r||'#'!=E?f!=E&&'\t'!=E&&'\n'!=E&&'\r'!=E&&(this._query+=s(E)):(this._fragment='#',m='fragment');break;case'fragment':f!=E&&'\t'!=E&&'\n'!=E&&'\r'!=E&&(this._fragment+=E);}y++}}function r(){this._scheme='',this._schemeData='',this._username='',this._password=null,this._host='',this._port='',this._path=[],this._query='',this._fragment='',this._isInvalid=!1,this._isRelative=!1}function l(e,t){void 0===t||t instanceof l||(t=new l(t+'')),this._url=e,r.call(this);var n=e.replace(/^[ \t\r\n\f]+|[ \t\r\n\f]+$/g,'');i.call(this,n,null,t)}var d=!1;if(!e.forceJURL)try{var c=new URL('b','http://a');c.pathname='c%20d',d='http://a/c%20d'===c.href}catch(t){}if(d)return e.URL;var u=Object.create(null);u.ftp=21,u.file=0,u.gopher=70,u.http=80,u.https=443,u.ws=80,u.wss=443;var p=Object.create(null);p['%2e']='.',p['.%2e']='..',p['%2e.']='..',p['%2e%2e']='..';var h=/[a-zA-Z]/,g=/[a-zA-Z0-9\+\-\.]/,f;l.prototype={toString:function(){return this.href},get href(){if(this._isInvalid)return this._url;var e='';return(''!=this._username||null!=this._password)&&(e=this._username+(null==this._password?'':':'+this._password)+'@'),this.protocol+(this._isRelative?'//'+e+this.host:'')+this.pathname+this._query+this._fragment},set href(e){r.call(this),i.call(this,e)},get protocol(){return this._scheme+':'},set protocol(e){this._isInvalid||i.call(this,e+':','scheme start')},get host(){return this._isInvalid?'':this._port?this._host+':'+this._port:this._host},set host(e){this._isInvalid||!this._isRelative||i.call(this,e,'host')},get hostname(){return this._host},set hostname(e){this._isInvalid||!this._isRelative||i.call(this,e,'hostname')},get port(){return this._port},set port(e){this._isInvalid||!this._isRelative||i.call(this,e,'port')},get pathname(){return this._isInvalid?'':this._isRelative?'/'+this._path.join('/'):this._schemeData},set pathname(e){this._isInvalid||!this._isRelative||(this._path=[],i.call(this,e,'relative path start'))},get search(){return this._isInvalid||!this._query||'?'==this._query?'':this._query},set search(e){this._isInvalid||!this._isRelative||(this._query='?','?'==e[0]&&(e=e.slice(1)),i.call(this,e,'query'))},get hash(){return this._isInvalid||!this._fragment||'#'==this._fragment?'':this._fragment},set hash(e){this._isInvalid||(this._fragment='#','#'==e[0]&&(e=e.slice(1)),i.call(this,e,'fragment'))},get origin(){var e;if(this._isInvalid||!this._scheme)return'';switch(this._scheme){case'file':return'file://';case'data':case'javascript':case'mailto':return'null';}return e=this.host,e?this._scheme+'://'+e:''}};var m=e.URL;return m&&(l.createObjectURL=function(){return m.createObjectURL.apply(m,arguments)},l.revokeObjectURL=function(e){m.revokeObjectURL(e)}),l})}).call(t,n(8),n(70)(e))},function(e){e.exports=function(e){return e.webpackPolyfill||(e.deprecate=function(){},e.paths=[],!e.children&&(e.children=[]),Object.defineProperty(e,'loaded',{enumerable:!0,get:function(){return e.l}}),Object.defineProperty(e,'id',{enumerable:!0,get:function(){return e.i}}),e.webpackPolyfill=1),e}}])});
\ No newline at end of file diff --git a/lib/smartimages.js b/lib/smartimages.js deleted file mode 100644 index 8c1ec5f..0000000 --- a/lib/smartimages.js +++ /dev/null @@ -1,73 +0,0 @@ -EPUBJS.Hooks.register("beforeChapterDisplay").smartimages = function(callback, renderer){ - var images = renderer.contents.querySelectorAll('img'), - items = Array.prototype.slice.call(images), - iheight = renderer.height,//chapter.bodyEl.clientHeight,//chapter.doc.body.getBoundingClientRect().height, - oheight; - - if(renderer.layoutSettings.layout != "reflowable") { - callback(); - return; //-- Only adjust images for reflowable text - } - - items.forEach(function(item){ - - var size = function() { - var itemRect = item.getBoundingClientRect(), - rectHeight = itemRect.height, - top = itemRect.top, - oHeight = item.getAttribute('data-height'), - height = oHeight || rectHeight, - newHeight, - fontSize = Number(getComputedStyle(item, "").fontSize.match(/(\d*(\.\d*)?)px/)[1]), - fontAdjust = fontSize ? fontSize / 2 : 0; - - iheight = renderer.contents.clientHeight; - if(top < 0) top = 0; - - if(height + top >= iheight) { - - if(top < iheight/2) { - // Remove top and half font-size from height to keep container from overflowing - newHeight = iheight - top - fontAdjust; - item.style.maxHeight = newHeight + "px"; - item.style.width= "auto"; - }else{ - if(height > iheight) { - item.style.maxHeight = iheight + "px"; - item.style.width= "auto"; - itemRect = item.getBoundingClientRect(); - height = itemRect.height; - } - item.style.display = "block"; - item.style["WebkitColumnBreakBefore"] = "always"; - item.style["breakBefore"] = "column"; - - } - - item.setAttribute('data-height', newHeight); - - }else{ - item.style.removeProperty('max-height'); - item.style.removeProperty('margin-top'); - } - } - - var unloaded = function(){ - // item.removeEventListener('load', size); // crashes in IE - renderer.off("renderer:resized", size); - renderer.off("renderer:chapterUnload", this); - }; - - item.addEventListener('load', size, false); - - renderer.on("renderer:resized", size); - - renderer.on("renderer:chapterUnload", unloaded); - - size(); - - }); - - if(callback) callback(); - -} diff --git a/lib/zip.min.js b/lib/zip.min.js index a09f35b..b918873 100644 --- a/lib/zip.min.js +++ b/lib/zip.min.js @@ -1,14 +1,15 @@ /*! -JSZip - A Javascript class for generating and reading zip files +JSZip v3.1.5 - A JavaScript class for generating and reading zip files <http://stuartk.com/jszip> -(c) 2009-2014 Stuart Knightley <stuart [at] stuartk.com> +(c) 2009-2016 Stuart Knightley <stuart [at] stuartk.com> Dual licenced under the MIT license or GPLv3. See https://raw.github.com/Stuk/jszip/master/LICENSE.markdown. JSZip uses the library pako released under the MIT license : https://github.com/nodeca/pako/blob/master/LICENSE */ -!function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;"undefined"!=typeof window?b=window:"undefined"!=typeof global?b=global:"undefined"!=typeof self&&(b=self),b.JSZip=a()}}(function(){return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);throw new Error("Cannot find module '"+g+"'")}var j=c[g]={exports:{}};b[g][0].call(j.exports,function(a){var c=b[g][1][a];return e(c?c:a)},j,j.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b,c){"use strict";var d="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";c.encode=function(a){for(var b,c,e,f,g,h,i,j="",k=0;k<a.length;)b=a.charCodeAt(k++),c=a.charCodeAt(k++),e=a.charCodeAt(k++),f=b>>2,g=(3&b)<<4|c>>4,h=(15&c)<<2|e>>6,i=63&e,isNaN(c)?h=i=64:isNaN(e)&&(i=64),j=j+d.charAt(f)+d.charAt(g)+d.charAt(h)+d.charAt(i);return j},c.decode=function(a){var b,c,e,f,g,h,i,j="",k=0;for(a=a.replace(/[^A-Za-z0-9\+\/\=]/g,"");k<a.length;)f=d.indexOf(a.charAt(k++)),g=d.indexOf(a.charAt(k++)),h=d.indexOf(a.charAt(k++)),i=d.indexOf(a.charAt(k++)),b=f<<2|g>>4,c=(15&g)<<4|h>>2,e=(3&h)<<6|i,j+=String.fromCharCode(b),64!=h&&(j+=String.fromCharCode(c)),64!=i&&(j+=String.fromCharCode(e));return j}},{}],2:[function(a,b){"use strict";function c(){this.compressedSize=0,this.uncompressedSize=0,this.crc32=0,this.compressionMethod=null,this.compressedContent=null}c.prototype={getContent:function(){return null},getCompressedContent:function(){return null}},b.exports=c},{}],3:[function(a,b,c){"use strict";c.STORE={magic:"\x00\x00",compress:function(a){return a},uncompress:function(a){return a},compressInputType:null,uncompressInputType:null},c.DEFLATE=a("./flate")},{"./flate":8}],4:[function(a,b){"use strict";var c=a("./utils"),d=[0,1996959894,3993919788,2567524794,124634137,1886057615,3915621685,2657392035,249268274,2044508324,3772115230,2547177864,162941995,2125561021,3887607047,2428444049,498536548,1789927666,4089016648,2227061214,450548861,1843258603,4107580753,2211677639,325883990,1684777152,4251122042,2321926636,335633487,1661365465,4195302755,2366115317,997073096,1281953886,3579855332,2724688242,1006888145,1258607687,3524101629,2768942443,901097722,1119000684,3686517206,2898065728,853044451,1172266101,3705015759,2882616665,651767980,1373503546,3369554304,3218104598,565507253,1454621731,3485111705,3099436303,671266974,1594198024,3322730930,2970347812,795835527,1483230225,3244367275,3060149565,1994146192,31158534,2563907772,4023717930,1907459465,112637215,2680153253,3904427059,2013776290,251722036,2517215374,3775830040,2137656763,141376813,2439277719,3865271297,1802195444,476864866,2238001368,4066508878,1812370925,453092731,2181625025,4111451223,1706088902,314042704,2344532202,4240017532,1658658271,366619977,2362670323,4224994405,1303535960,984961486,2747007092,3569037538,1256170817,1037604311,2765210733,3554079995,1131014506,879679996,2909243462,3663771856,1141124467,855842277,2852801631,3708648649,1342533948,654459306,3188396048,3373015174,1466479909,544179635,3110523913,3462522015,1591671054,702138776,2966460450,3352799412,1504918807,783551873,3082640443,3233442989,3988292384,2596254646,62317068,1957810842,3939845945,2647816111,81470997,1943803523,3814918930,2489596804,225274430,2053790376,3826175755,2466906013,167816743,2097651377,4027552580,2265490386,503444072,1762050814,4150417245,2154129355,426522225,1852507879,4275313526,2312317920,282753626,1742555852,4189708143,2394877945,397917763,1622183637,3604390888,2714866558,953729732,1340076626,3518719985,2797360999,1068828381,1219638859,3624741850,2936675148,906185462,1090812512,3747672003,2825379669,829329135,1181335161,3412177804,3160834842,628085408,1382605366,3423369109,3138078467,570562233,1426400815,3317316542,2998733608,733239954,1555261956,3268935591,3050360625,752459403,1541320221,2607071920,3965973030,1969922972,40735498,2617837225,3943577151,1913087877,83908371,2512341634,3803740692,2075208622,213261112,2463272603,3855990285,2094854071,198958881,2262029012,4057260610,1759359992,534414190,2176718541,4139329115,1873836001,414664567,2282248934,4279200368,1711684554,285281116,2405801727,4167216745,1634467795,376229701,2685067896,3608007406,1308918612,956543938,2808555105,3495958263,1231636301,1047427035,2932959818,3654703836,1088359270,936918e3,2847714899,3736837829,1202900863,817233897,3183342108,3401237130,1404277552,615818150,3134207493,3453421203,1423857449,601450431,3009837614,3294710456,1567103746,711928724,3020668471,3272380065,1510334235,755167117];b.exports=function(a,b){if("undefined"==typeof a||!a.length)return 0;var e="string"!==c.getTypeOf(a);"undefined"==typeof b&&(b=0);var f=0,g=0,h=0;b=-1^b;for(var i=0,j=a.length;j>i;i++)h=e?a[i]:a.charCodeAt(i),g=255&(b^h),f=d[g],b=b>>>8^f;return-1^b}},{"./utils":21}],5:[function(a,b){"use strict";function c(){this.data=null,this.length=0,this.index=0}var d=a("./utils");c.prototype={checkOffset:function(a){this.checkIndex(this.index+a)},checkIndex:function(a){if(this.length<a||0>a)throw new Error("End of data reached (data length = "+this.length+", asked index = "+a+"). Corrupted zip ?")},setIndex:function(a){this.checkIndex(a),this.index=a},skip:function(a){this.setIndex(this.index+a)},byteAt:function(){},readInt:function(a){var b,c=0;for(this.checkOffset(a),b=this.index+a-1;b>=this.index;b--)c=(c<<8)+this.byteAt(b);return this.index+=a,c},readString:function(a){return d.transformTo("string",this.readData(a))},readData:function(){},lastIndexOfSignature:function(){},readDate:function(){var a=this.readInt(4);return new Date((a>>25&127)+1980,(a>>21&15)-1,a>>16&31,a>>11&31,a>>5&63,(31&a)<<1)}},b.exports=c},{"./utils":21}],6:[function(a,b,c){"use strict";c.base64=!1,c.binary=!1,c.dir=!1,c.createFolders=!1,c.date=null,c.compression=null,c.compressionOptions=null,c.comment=null,c.unixPermissions=null,c.dosPermissions=null},{}],7:[function(a,b,c){"use strict";var d=a("./utils");c.string2binary=function(a){return d.string2binary(a)},c.string2Uint8Array=function(a){return d.transformTo("uint8array",a)},c.uint8Array2String=function(a){return d.transformTo("string",a)},c.string2Blob=function(a){var b=d.transformTo("arraybuffer",a);return d.arrayBuffer2Blob(b)},c.arrayBuffer2Blob=function(a){return d.arrayBuffer2Blob(a)},c.transformTo=function(a,b){return d.transformTo(a,b)},c.getTypeOf=function(a){return d.getTypeOf(a)},c.checkSupport=function(a){return d.checkSupport(a)},c.MAX_VALUE_16BITS=d.MAX_VALUE_16BITS,c.MAX_VALUE_32BITS=d.MAX_VALUE_32BITS,c.pretty=function(a){return d.pretty(a)},c.findCompression=function(a){return d.findCompression(a)},c.isRegExp=function(a){return d.isRegExp(a)}},{"./utils":21}],8:[function(a,b,c){"use strict";var d="undefined"!=typeof Uint8Array&&"undefined"!=typeof Uint16Array&&"undefined"!=typeof Uint32Array,e=a("pako");c.uncompressInputType=d?"uint8array":"array",c.compressInputType=d?"uint8array":"array",c.magic="\b\x00",c.compress=function(a,b){return e.deflateRaw(a,{level:b.level||-1})},c.uncompress=function(a){return e.inflateRaw(a)}},{pako:24}],9:[function(a,b){"use strict";function c(a,b){return this instanceof c?(this.files={},this.comment=null,this.root="",a&&this.load(a,b),void(this.clone=function(){var a=new c;for(var b in this)"function"!=typeof this[b]&&(a[b]=this[b]);return a})):new c(a,b)}var d=a("./base64");c.prototype=a("./object"),c.prototype.load=a("./load"),c.support=a("./support"),c.defaults=a("./defaults"),c.utils=a("./deprecatedPublicUtils"),c.base64={encode:function(a){return d.encode(a)},decode:function(a){return d.decode(a)}},c.compressions=a("./compressions"),b.exports=c},{"./base64":1,"./compressions":3,"./defaults":6,"./deprecatedPublicUtils":7,"./load":10,"./object":13,"./support":17}],10:[function(a,b){"use strict";var c=a("./base64"),d=a("./zipEntries");b.exports=function(a,b){var e,f,g,h;for(b=b||{},b.base64&&(a=c.decode(a)),f=new d(a,b),e=f.files,g=0;g<e.length;g++)h=e[g],this.file(h.fileName,h.decompressed,{binary:!0,optimizedBinaryString:!0,date:h.date,dir:h.dir,comment:h.fileComment.length?h.fileComment:null,unixPermissions:h.unixPermissions,dosPermissions:h.dosPermissions,createFolders:b.createFolders});return f.zipComment.length&&(this.comment=f.zipComment),this}},{"./base64":1,"./zipEntries":22}],11:[function(a,b){(function(a){"use strict";b.exports=function(b,c){return new a(b,c)},b.exports.test=function(b){return a.isBuffer(b)}}).call(this,"undefined"!=typeof Buffer?Buffer:void 0)},{}],12:[function(a,b){"use strict";function c(a){this.data=a,this.length=this.data.length,this.index=0}var d=a("./uint8ArrayReader");c.prototype=new d,c.prototype.readData=function(a){this.checkOffset(a);var b=this.data.slice(this.index,this.index+a);return this.index+=a,b},b.exports=c},{"./uint8ArrayReader":18}],13:[function(a,b){"use strict";var c=a("./support"),d=a("./utils"),e=a("./crc32"),f=a("./signature"),g=a("./defaults"),h=a("./base64"),i=a("./compressions"),j=a("./compressedObject"),k=a("./nodeBuffer"),l=a("./utf8"),m=a("./stringWriter"),n=a("./uint8ArrayWriter"),o=function(a){if(a._data instanceof j&&(a._data=a._data.getContent(),a.options.binary=!0,a.options.base64=!1,"uint8array"===d.getTypeOf(a._data))){var b=a._data;a._data=new Uint8Array(b.length),0!==b.length&&a._data.set(b,0)}return a._data},p=function(a){var b=o(a),e=d.getTypeOf(b);return"string"===e?!a.options.binary&&c.nodebuffer?k(b,"utf-8"):a.asBinary():b},q=function(a){var b=o(this);return null===b||"undefined"==typeof b?"":(this.options.base64&&(b=h.decode(b)),b=a&&this.options.binary?D.utf8decode(b):d.transformTo("string",b),a||this.options.binary||(b=d.transformTo("string",D.utf8encode(b))),b)},r=function(a,b,c){this.name=a,this.dir=c.dir,this.date=c.date,this.comment=c.comment,this.unixPermissions=c.unixPermissions,this.dosPermissions=c.dosPermissions,this._data=b,this.options=c,this._initialMetadata={dir:c.dir,date:c.date}};r.prototype={asText:function(){return q.call(this,!0)},asBinary:function(){return q.call(this,!1)},asNodeBuffer:function(){var a=p(this);return d.transformTo("nodebuffer",a)},asUint8Array:function(){var a=p(this);return d.transformTo("uint8array",a)},asArrayBuffer:function(){return this.asUint8Array().buffer}};var s=function(a,b){var c,d="";for(c=0;b>c;c++)d+=String.fromCharCode(255&a),a>>>=8;return d},t=function(){var a,b,c={};for(a=0;a<arguments.length;a++)for(b in arguments[a])arguments[a].hasOwnProperty(b)&&"undefined"==typeof c[b]&&(c[b]=arguments[a][b]);return c},u=function(a){return a=a||{},a.base64!==!0||null!==a.binary&&void 0!==a.binary||(a.binary=!0),a=t(a,g),a.date=a.date||new Date,null!==a.compression&&(a.compression=a.compression.toUpperCase()),a},v=function(a,b,c){var e,f=d.getTypeOf(b);if(c=u(c),"string"==typeof c.unixPermissions&&(c.unixPermissions=parseInt(c.unixPermissions,8)),c.unixPermissions&&16384&c.unixPermissions&&(c.dir=!0),c.dosPermissions&&16&c.dosPermissions&&(c.dir=!0),c.dir&&(a=x(a)),c.createFolders&&(e=w(a))&&y.call(this,e,!0),c.dir||null===b||"undefined"==typeof b)c.base64=!1,c.binary=!1,b=null,f=null;else if("string"===f)c.binary&&!c.base64&&c.optimizedBinaryString!==!0&&(b=d.string2binary(b));else{if(c.base64=!1,c.binary=!0,!(f||b instanceof j))throw new Error("The data of '"+a+"' is in an unsupported format !");"arraybuffer"===f&&(b=d.transformTo("uint8array",b))}var g=new r(a,b,c);return this.files[a]=g,g},w=function(a){"/"==a.slice(-1)&&(a=a.substring(0,a.length-1));var b=a.lastIndexOf("/");return b>0?a.substring(0,b):""},x=function(a){return"/"!=a.slice(-1)&&(a+="/"),a},y=function(a,b){return b="undefined"!=typeof b?b:!1,a=x(a),this.files[a]||v.call(this,a,null,{dir:!0,createFolders:b}),this.files[a]},z=function(a,b,c){var f,g=new j;return a._data instanceof j?(g.uncompressedSize=a._data.uncompressedSize,g.crc32=a._data.crc32,0===g.uncompressedSize||a.dir?(b=i.STORE,g.compressedContent="",g.crc32=0):a._data.compressionMethod===b.magic?g.compressedContent=a._data.getCompressedContent():(f=a._data.getContent(),g.compressedContent=b.compress(d.transformTo(b.compressInputType,f),c))):(f=p(a),(!f||0===f.length||a.dir)&&(b=i.STORE,f=""),g.uncompressedSize=f.length,g.crc32=e(f),g.compressedContent=b.compress(d.transformTo(b.compressInputType,f),c)),g.compressedSize=g.compressedContent.length,g.compressionMethod=b.magic,g},A=function(a,b){var c=a;return a||(c=b?16893:33204),(65535&c)<<16},B=function(a){return 63&(a||0)},C=function(a,b,c,g,h){var i,j,k,m,n=(c.compressedContent,d.transformTo("string",l.utf8encode(b.name))),o=b.comment||"",p=d.transformTo("string",l.utf8encode(o)),q=n.length!==b.name.length,r=p.length!==o.length,t=b.options,u="",v="",w="";k=b._initialMetadata.dir!==b.dir?b.dir:t.dir,m=b._initialMetadata.date!==b.date?b.date:t.date;var x=0,y=0;k&&(x|=16),"UNIX"===h?(y=798,x|=A(b.unixPermissions,k)):(y=20,x|=B(b.dosPermissions,k)),i=m.getHours(),i<<=6,i|=m.getMinutes(),i<<=5,i|=m.getSeconds()/2,j=m.getFullYear()-1980,j<<=4,j|=m.getMonth()+1,j<<=5,j|=m.getDate(),q&&(v=s(1,1)+s(e(n),4)+n,u+="up"+s(v.length,2)+v),r&&(w=s(1,1)+s(this.crc32(p),4)+p,u+="uc"+s(w.length,2)+w);var z="";z+="\n\x00",z+=q||r?"\x00\b":"\x00\x00",z+=c.compressionMethod,z+=s(i,2),z+=s(j,2),z+=s(c.crc32,4),z+=s(c.compressedSize,4),z+=s(c.uncompressedSize,4),z+=s(n.length,2),z+=s(u.length,2);var C=f.LOCAL_FILE_HEADER+z+n+u,D=f.CENTRAL_FILE_HEADER+s(y,2)+z+s(p.length,2)+"\x00\x00\x00\x00"+s(x,4)+s(g,4)+n+u+p;return{fileRecord:C,dirRecord:D,compressedObject:c}},D={load:function(){throw new Error("Load method is not defined. Is the file jszip-load.js included ?")},filter:function(a){var b,c,d,e,f=[];for(b in this.files)this.files.hasOwnProperty(b)&&(d=this.files[b],e=new r(d.name,d._data,t(d.options)),c=b.slice(this.root.length,b.length),b.slice(0,this.root.length)===this.root&&a(c,e)&&f.push(e));return f},file:function(a,b,c){if(1===arguments.length){if(d.isRegExp(a)){var e=a;return this.filter(function(a,b){return!b.dir&&e.test(a)})}return this.filter(function(b,c){return!c.dir&&b===a})[0]||null}return a=this.root+a,v.call(this,a,b,c),this},folder:function(a){if(!a)return this;if(d.isRegExp(a))return this.filter(function(b,c){return c.dir&&a.test(b)});var b=this.root+a,c=y.call(this,b),e=this.clone();return e.root=c.name,e},remove:function(a){a=this.root+a;var b=this.files[a];if(b||("/"!=a.slice(-1)&&(a+="/"),b=this.files[a]),b&&!b.dir)delete this.files[a];else for(var c=this.filter(function(b,c){return c.name.slice(0,a.length)===a}),d=0;d<c.length;d++)delete this.files[c[d].name];return this},generate:function(a){a=t(a||{},{base64:!0,compression:"STORE",compressionOptions:null,type:"base64",platform:"DOS",comment:null,mimeType:"application/zip"}),d.checkSupport(a.type),("darwin"===a.platform||"freebsd"===a.platform||"linux"===a.platform||"sunos"===a.platform)&&(a.platform="UNIX"),"win32"===a.platform&&(a.platform="DOS");var b,c,e=[],g=0,j=0,k=d.transformTo("string",this.utf8encode(a.comment||this.comment||""));for(var l in this.files)if(this.files.hasOwnProperty(l)){var o=this.files[l],p=o.options.compression||a.compression.toUpperCase(),q=i[p];if(!q)throw new Error(p+" is not a valid compression method !");var r=o.options.compressionOptions||a.compressionOptions||{},u=z.call(this,o,q,r),v=C.call(this,l,o,u,g,a.platform);g+=v.fileRecord.length+u.compressedSize,j+=v.dirRecord.length,e.push(v)}var w="";w=f.CENTRAL_DIRECTORY_END+"\x00\x00\x00\x00"+s(e.length,2)+s(e.length,2)+s(j,4)+s(g,4)+s(k.length,2)+k;var x=a.type.toLowerCase();for(b="uint8array"===x||"arraybuffer"===x||"blob"===x||"nodebuffer"===x?new n(g+j+w.length):new m(g+j+w.length),c=0;c<e.length;c++)b.append(e[c].fileRecord),b.append(e[c].compressedObject.compressedContent);for(c=0;c<e.length;c++)b.append(e[c].dirRecord);b.append(w);var y=b.finalize();switch(a.type.toLowerCase()){case"uint8array":case"arraybuffer":case"nodebuffer":return d.transformTo(a.type.toLowerCase(),y);case"blob":return d.arrayBuffer2Blob(d.transformTo("arraybuffer",y),a.mimeType);case"base64":return a.base64?h.encode(y):y;default:return y}},crc32:function(a,b){return e(a,b)},utf8encode:function(a){return d.transformTo("string",l.utf8encode(a))},utf8decode:function(a){return l.utf8decode(a)}};b.exports=D},{"./base64":1,"./compressedObject":2,"./compressions":3,"./crc32":4,"./defaults":6,"./nodeBuffer":11,"./signature":14,"./stringWriter":16,"./support":17,"./uint8ArrayWriter":19,"./utf8":20,"./utils":21}],14:[function(a,b,c){"use strict";c.LOCAL_FILE_HEADER="PK",c.CENTRAL_FILE_HEADER="PK",c.CENTRAL_DIRECTORY_END="PK",c.ZIP64_CENTRAL_DIRECTORY_LOCATOR="PK",c.ZIP64_CENTRAL_DIRECTORY_END="PK",c.DATA_DESCRIPTOR="PK\b"},{}],15:[function(a,b){"use strict";function c(a,b){this.data=a,b||(this.data=e.string2binary(this.data)),this.length=this.data.length,this.index=0}var d=a("./dataReader"),e=a("./utils");c.prototype=new d,c.prototype.byteAt=function(a){return this.data.charCodeAt(a)},c.prototype.lastIndexOfSignature=function(a){return this.data.lastIndexOf(a)},c.prototype.readData=function(a){this.checkOffset(a);var b=this.data.slice(this.index,this.index+a);return this.index+=a,b},b.exports=c},{"./dataReader":5,"./utils":21}],16:[function(a,b){"use strict";var c=a("./utils"),d=function(){this.data=[]};d.prototype={append:function(a){a=c.transformTo("string",a),this.data.push(a)},finalize:function(){return this.data.join("")}},b.exports=d},{"./utils":21}],17:[function(a,b,c){(function(a){"use strict";if(c.base64=!0,c.array=!0,c.string=!0,c.arraybuffer="undefined"!=typeof ArrayBuffer&&"undefined"!=typeof Uint8Array,c.nodebuffer="undefined"!=typeof a,c.uint8array="undefined"!=typeof Uint8Array,"undefined"==typeof ArrayBuffer)c.blob=!1;else{var b=new ArrayBuffer(0);try{c.blob=0===new Blob([b],{type:"application/zip"}).size}catch(d){try{var e=window.BlobBuilder||window.WebKitBlobBuilder||window.MozBlobBuilder||window.MSBlobBuilder,f=new e;f.append(b),c.blob=0===f.getBlob("application/zip").size}catch(d){c.blob=!1}}}}).call(this,"undefined"!=typeof Buffer?Buffer:void 0)},{}],18:[function(a,b){"use strict";function c(a){a&&(this.data=a,this.length=this.data.length,this.index=0)}var d=a("./dataReader");c.prototype=new d,c.prototype.byteAt=function(a){return this.data[a]},c.prototype.lastIndexOfSignature=function(a){for(var b=a.charCodeAt(0),c=a.charCodeAt(1),d=a.charCodeAt(2),e=a.charCodeAt(3),f=this.length-4;f>=0;--f)if(this.data[f]===b&&this.data[f+1]===c&&this.data[f+2]===d&&this.data[f+3]===e)return f;return-1},c.prototype.readData=function(a){if(this.checkOffset(a),0===a)return new Uint8Array(0);var b=this.data.subarray(this.index,this.index+a);return this.index+=a,b},b.exports=c},{"./dataReader":5}],19:[function(a,b){"use strict";var c=a("./utils"),d=function(a){this.data=new Uint8Array(a),this.index=0};d.prototype={append:function(a){0!==a.length&&(a=c.transformTo("uint8array",a),this.data.set(a,this.index),this.index+=a.length)},finalize:function(){return this.data}},b.exports=d},{"./utils":21}],20:[function(a,b,c){"use strict";for(var d=a("./utils"),e=a("./support"),f=a("./nodeBuffer"),g=new Array(256),h=0;256>h;h++)g[h]=h>=252?6:h>=248?5:h>=240?4:h>=224?3:h>=192?2:1;g[254]=g[254]=1;var i=function(a){var b,c,d,f,g,h=a.length,i=0;for(f=0;h>f;f++)c=a.charCodeAt(f),55296===(64512&c)&&h>f+1&&(d=a.charCodeAt(f+1),56320===(64512&d)&&(c=65536+(c-55296<<10)+(d-56320),f++)),i+=128>c?1:2048>c?2:65536>c?3:4;for(b=e.uint8array?new Uint8Array(i):new Array(i),g=0,f=0;i>g;f++)c=a.charCodeAt(f),55296===(64512&c)&&h>f+1&&(d=a.charCodeAt(f+1),56320===(64512&d)&&(c=65536+(c-55296<<10)+(d-56320),f++)),128>c?b[g++]=c:2048>c?(b[g++]=192|c>>>6,b[g++]=128|63&c):65536>c?(b[g++]=224|c>>>12,b[g++]=128|c>>>6&63,b[g++]=128|63&c):(b[g++]=240|c>>>18,b[g++]=128|c>>>12&63,b[g++]=128|c>>>6&63,b[g++]=128|63&c);return b},j=function(a,b){var c;for(b=b||a.length,b>a.length&&(b=a.length),c=b-1;c>=0&&128===(192&a[c]);)c--;return 0>c?b:0===c?b:c+g[a[c]]>b?c:b},k=function(a){var b,c,e,f,h=a.length,i=new Array(2*h);for(c=0,b=0;h>b;)if(e=a[b++],128>e)i[c++]=e;else if(f=g[e],f>4)i[c++]=65533,b+=f-1;else{for(e&=2===f?31:3===f?15:7;f>1&&h>b;)e=e<<6|63&a[b++],f--;f>1?i[c++]=65533:65536>e?i[c++]=e:(e-=65536,i[c++]=55296|e>>10&1023,i[c++]=56320|1023&e)}return i.length!==c&&(i.subarray?i=i.subarray(0,c):i.length=c),d.applyFromCharCode(i)};c.utf8encode=function(a){return e.nodebuffer?f(a,"utf-8"):i(a)},c.utf8decode=function(a){if(e.nodebuffer)return d.transformTo("nodebuffer",a).toString("utf-8");a=d.transformTo(e.uint8array?"uint8array":"array",a);for(var b=[],c=0,f=a.length,g=65536;f>c;){var h=j(a,Math.min(c+g,f));b.push(e.uint8array?k(a.subarray(c,h)):k(a.slice(c,h))),c=h}return b.join("")}},{"./nodeBuffer":11,"./support":17,"./utils":21}],21:[function(a,b,c){"use strict";function d(a){return a}function e(a,b){for(var c=0;c<a.length;++c)b[c]=255&a.charCodeAt(c);return b}function f(a){var b=65536,d=[],e=a.length,f=c.getTypeOf(a),g=0,h=!0;try{switch(f){case"uint8array":String.fromCharCode.apply(null,new Uint8Array(0));break;case"nodebuffer":String.fromCharCode.apply(null,j(0))}}catch(i){h=!1}if(!h){for(var k="",l=0;l<a.length;l++)k+=String.fromCharCode(a[l]);return k}for(;e>g&&b>1;)try{d.push("array"===f||"nodebuffer"===f?String.fromCharCode.apply(null,a.slice(g,Math.min(g+b,e))):String.fromCharCode.apply(null,a.subarray(g,Math.min(g+b,e)))),g+=b}catch(i){b=Math.floor(b/2)}return d.join("")}function g(a,b){for(var c=0;c<a.length;c++)b[c]=a[c];return b}var h=a("./support"),i=a("./compressions"),j=a("./nodeBuffer");c.string2binary=function(a){for(var b="",c=0;c<a.length;c++)b+=String.fromCharCode(255&a.charCodeAt(c));return b},c.arrayBuffer2Blob=function(a,b){c.checkSupport("blob"),b=b||"application/zip";try{return new Blob([a],{type:b})}catch(d){try{var e=window.BlobBuilder||window.WebKitBlobBuilder||window.MozBlobBuilder||window.MSBlobBuilder,f=new e;return f.append(a),f.getBlob(b)}catch(d){throw new Error("Bug : can't construct the Blob.")}}},c.applyFromCharCode=f;var k={};k.string={string:d,array:function(a){return e(a,new Array(a.length))},arraybuffer:function(a){return k.string.uint8array(a).buffer},uint8array:function(a){return e(a,new Uint8Array(a.length))},nodebuffer:function(a){return e(a,j(a.length))}},k.array={string:f,array:d,arraybuffer:function(a){return new Uint8Array(a).buffer},uint8array:function(a){return new Uint8Array(a)},nodebuffer:function(a){return j(a)}},k.arraybuffer={string:function(a){return f(new Uint8Array(a))},array:function(a){return g(new Uint8Array(a),new Array(a.byteLength))},arraybuffer:d,uint8array:function(a){return new Uint8Array(a)},nodebuffer:function(a){return j(new Uint8Array(a))}},k.uint8array={string:f,array:function(a){return g(a,new Array(a.length))},arraybuffer:function(a){return a.buffer},uint8array:d,nodebuffer:function(a){return j(a)}},k.nodebuffer={string:f,array:function(a){return g(a,new Array(a.length))},arraybuffer:function(a){return k.nodebuffer.uint8array(a).buffer},uint8array:function(a){return g(a,new Uint8Array(a.length))},nodebuffer:d},c.transformTo=function(a,b){if(b||(b=""),!a)return b;c.checkSupport(a);var d=c.getTypeOf(b),e=k[d][a](b);return e},c.getTypeOf=function(a){return"string"==typeof a?"string":"[object Array]"===Object.prototype.toString.call(a)?"array":h.nodebuffer&&j.test(a)?"nodebuffer":h.uint8array&&a instanceof Uint8Array?"uint8array":h.arraybuffer&&a instanceof ArrayBuffer?"arraybuffer":void 0},c.checkSupport=function(a){var b=h[a.toLowerCase()];if(!b)throw new Error(a+" is not supported by this browser")},c.MAX_VALUE_16BITS=65535,c.MAX_VALUE_32BITS=-1,c.pretty=function(a){var b,c,d="";for(c=0;c<(a||"").length;c++)b=a.charCodeAt(c),d+="\\x"+(16>b?"0":"")+b.toString(16).toUpperCase();return d},c.findCompression=function(a){for(var b in i)if(i.hasOwnProperty(b)&&i[b].magic===a)return i[b];return null},c.isRegExp=function(a){return"[object RegExp]"===Object.prototype.toString.call(a)}},{"./compressions":3,"./nodeBuffer":11,"./support":17}],22:[function(a,b){"use strict";function c(a,b){this.files=[],this.loadOptions=b,a&&this.load(a)}var d=a("./stringReader"),e=a("./nodeBufferReader"),f=a("./uint8ArrayReader"),g=a("./utils"),h=a("./signature"),i=a("./zipEntry"),j=a("./support"),k=a("./object");c.prototype={checkSignature:function(a){var b=this.reader.readString(4);if(b!==a)throw new Error("Corrupted zip or bug : unexpected signature ("+g.pretty(b)+", expected "+g.pretty(a)+")")},readBlockEndOfCentral:function(){this.diskNumber=this.reader.readInt(2),this.diskWithCentralDirStart=this.reader.readInt(2),this.centralDirRecordsOnThisDisk=this.reader.readInt(2),this.centralDirRecords=this.reader.readInt(2),this.centralDirSize=this.reader.readInt(4),this.centralDirOffset=this.reader.readInt(4),this.zipCommentLength=this.reader.readInt(2),this.zipComment=this.reader.readString(this.zipCommentLength),this.zipComment=k.utf8decode(this.zipComment)},readBlockZip64EndOfCentral:function(){this.zip64EndOfCentralSize=this.reader.readInt(8),this.versionMadeBy=this.reader.readString(2),this.versionNeeded=this.reader.readInt(2),this.diskNumber=this.reader.readInt(4),this.diskWithCentralDirStart=this.reader.readInt(4),this.centralDirRecordsOnThisDisk=this.reader.readInt(8),this.centralDirRecords=this.reader.readInt(8),this.centralDirSize=this.reader.readInt(8),this.centralDirOffset=this.reader.readInt(8),this.zip64ExtensibleData={};for(var a,b,c,d=this.zip64EndOfCentralSize-44,e=0;d>e;)a=this.reader.readInt(2),b=this.reader.readInt(4),c=this.reader.readString(b),this.zip64ExtensibleData[a]={id:a,length:b,value:c}},readBlockZip64EndOfCentralLocator:function(){if(this.diskWithZip64CentralDirStart=this.reader.readInt(4),this.relativeOffsetEndOfZip64CentralDir=this.reader.readInt(8),this.disksCount=this.reader.readInt(4),this.disksCount>1)throw new Error("Multi-volumes zip are not supported")},readLocalFiles:function(){var a,b;for(a=0;a<this.files.length;a++)b=this.files[a],this.reader.setIndex(b.localHeaderOffset),this.checkSignature(h.LOCAL_FILE_HEADER),b.readLocalPart(this.reader),b.handleUTF8(),b.processAttributes()},readCentralDir:function(){var a;for(this.reader.setIndex(this.centralDirOffset);this.reader.readString(4)===h.CENTRAL_FILE_HEADER;)a=new i({zip64:this.zip64},this.loadOptions),a.readCentralPart(this.reader),this.files.push(a)},readEndOfCentral:function(){var a=this.reader.lastIndexOfSignature(h.CENTRAL_DIRECTORY_END);if(-1===a){var b=!0;try{this.reader.setIndex(0),this.checkSignature(h.LOCAL_FILE_HEADER),b=!1}catch(c){}throw new Error(b?"Can't find end of central directory : is this a zip file ? If it is, see http://stuk.github.io/jszip/documentation/howto/read_zip.html":"Corrupted zip : can't find end of central directory")}if(this.reader.setIndex(a),this.checkSignature(h.CENTRAL_DIRECTORY_END),this.readBlockEndOfCentral(),this.diskNumber===g.MAX_VALUE_16BITS||this.diskWithCentralDirStart===g.MAX_VALUE_16BITS||this.centralDirRecordsOnThisDisk===g.MAX_VALUE_16BITS||this.centralDirRecords===g.MAX_VALUE_16BITS||this.centralDirSize===g.MAX_VALUE_32BITS||this.centralDirOffset===g.MAX_VALUE_32BITS){if(this.zip64=!0,a=this.reader.lastIndexOfSignature(h.ZIP64_CENTRAL_DIRECTORY_LOCATOR),-1===a)throw new Error("Corrupted zip : can't find the ZIP64 end of central directory locator");this.reader.setIndex(a),this.checkSignature(h.ZIP64_CENTRAL_DIRECTORY_LOCATOR),this.readBlockZip64EndOfCentralLocator(),this.reader.setIndex(this.relativeOffsetEndOfZip64CentralDir),this.checkSignature(h.ZIP64_CENTRAL_DIRECTORY_END),this.readBlockZip64EndOfCentral()}},prepareReader:function(a){var b=g.getTypeOf(a);this.reader="string"!==b||j.uint8array?"nodebuffer"===b?new e(a):new f(g.transformTo("uint8array",a)):new d(a,this.loadOptions.optimizedBinaryString)},load:function(a){this.prepareReader(a),this.readEndOfCentral(),this.readCentralDir(),this.readLocalFiles()}},b.exports=c},{"./nodeBufferReader":12,"./object":13,"./signature":14,"./stringReader":15,"./support":17,"./uint8ArrayReader":18,"./utils":21,"./zipEntry":23}],23:[function(a,b){"use strict";function c(a,b){this.options=a,this.loadOptions=b}var d=a("./stringReader"),e=a("./utils"),f=a("./compressedObject"),g=a("./object"),h=0,i=3;c.prototype={isEncrypted:function(){return 1===(1&this.bitFlag)},useUTF8:function(){return 2048===(2048&this.bitFlag)},prepareCompressedContent:function(a,b,c){return function(){var d=a.index;a.setIndex(b);var e=a.readData(c);return a.setIndex(d),e}},prepareContent:function(a,b,c,d,f){return function(){var a=e.transformTo(d.uncompressInputType,this.getCompressedContent()),b=d.uncompress(a);if(b.length!==f)throw new Error("Bug : uncompressed data size mismatch");return b}},readLocalPart:function(a){var b,c;if(a.skip(22),this.fileNameLength=a.readInt(2),c=a.readInt(2),this.fileName=a.readString(this.fileNameLength),a.skip(c),-1==this.compressedSize||-1==this.uncompressedSize)throw new Error("Bug or corrupted zip : didn't get enough informations from the central directory (compressedSize == -1 || uncompressedSize == -1)");if(b=e.findCompression(this.compressionMethod),null===b)throw new Error("Corrupted zip : compression "+e.pretty(this.compressionMethod)+" unknown (inner file : "+this.fileName+")");if(this.decompressed=new f,this.decompressed.compressedSize=this.compressedSize,this.decompressed.uncompressedSize=this.uncompressedSize,this.decompressed.crc32=this.crc32,this.decompressed.compressionMethod=this.compressionMethod,this.decompressed.getCompressedContent=this.prepareCompressedContent(a,a.index,this.compressedSize,b),this.decompressed.getContent=this.prepareContent(a,a.index,this.compressedSize,b,this.uncompressedSize),this.loadOptions.checkCRC32&&(this.decompressed=e.transformTo("string",this.decompressed.getContent()),g.crc32(this.decompressed)!==this.crc32))throw new Error("Corrupted zip : CRC32 mismatch")},readCentralPart:function(a){if(this.versionMadeBy=a.readInt(2),this.versionNeeded=a.readInt(2),this.bitFlag=a.readInt(2),this.compressionMethod=a.readString(2),this.date=a.readDate(),this.crc32=a.readInt(4),this.compressedSize=a.readInt(4),this.uncompressedSize=a.readInt(4),this.fileNameLength=a.readInt(2),this.extraFieldsLength=a.readInt(2),this.fileCommentLength=a.readInt(2),this.diskNumberStart=a.readInt(2),this.internalFileAttributes=a.readInt(2),this.externalFileAttributes=a.readInt(4),this.localHeaderOffset=a.readInt(4),this.isEncrypted())throw new Error("Encrypted zip are not supported");this.fileName=a.readString(this.fileNameLength),this.readExtraFields(a),this.parseZIP64ExtraField(a),this.fileComment=a.readString(this.fileCommentLength)},processAttributes:function(){this.unixPermissions=null,this.dosPermissions=null;var a=this.versionMadeBy>>8;this.dir=16&this.externalFileAttributes?!0:!1,a===h&&(this.dosPermissions=63&this.externalFileAttributes),a===i&&(this.unixPermissions=this.externalFileAttributes>>16&65535),this.dir||"/"!==this.fileName.slice(-1)||(this.dir=!0)},parseZIP64ExtraField:function(){if(this.extraFields[1]){var a=new d(this.extraFields[1].value);this.uncompressedSize===e.MAX_VALUE_32BITS&&(this.uncompressedSize=a.readInt(8)),this.compressedSize===e.MAX_VALUE_32BITS&&(this.compressedSize=a.readInt(8)),this.localHeaderOffset===e.MAX_VALUE_32BITS&&(this.localHeaderOffset=a.readInt(8)),this.diskNumberStart===e.MAX_VALUE_32BITS&&(this.diskNumberStart=a.readInt(4))}},readExtraFields:function(a){var b,c,d,e=a.index;for(this.extraFields=this.extraFields||{};a.index<e+this.extraFieldsLength;)b=a.readInt(2),c=a.readInt(2),d=a.readString(c),this.extraFields[b]={id:b,length:c,value:d}},handleUTF8:function(){if(this.useUTF8())this.fileName=g.utf8decode(this.fileName),this.fileComment=g.utf8decode(this.fileComment);else{var a=this.findExtraFieldUnicodePath();null!==a&&(this.fileName=a);var b=this.findExtraFieldUnicodeComment();null!==b&&(this.fileComment=b)}},findExtraFieldUnicodePath:function(){var a=this.extraFields[28789];if(a){var b=new d(a.value);return 1!==b.readInt(1)?null:g.crc32(this.fileName)!==b.readInt(4)?null:g.utf8decode(b.readString(a.length-5)) -}return null},findExtraFieldUnicodeComment:function(){var a=this.extraFields[25461];if(a){var b=new d(a.value);return 1!==b.readInt(1)?null:g.crc32(this.fileComment)!==b.readInt(4)?null:g.utf8decode(b.readString(a.length-5))}return null}},b.exports=c},{"./compressedObject":2,"./object":13,"./stringReader":15,"./utils":21}],24:[function(a,b){"use strict";var c=a("./lib/utils/common").assign,d=a("./lib/deflate"),e=a("./lib/inflate"),f=a("./lib/zlib/constants"),g={};c(g,d,e,f),b.exports=g},{"./lib/deflate":25,"./lib/inflate":26,"./lib/utils/common":27,"./lib/zlib/constants":30}],25:[function(a,b,c){"use strict";function d(a,b){var c=new s(b);if(c.push(a,!0),c.err)throw c.msg;return c.result}function e(a,b){return b=b||{},b.raw=!0,d(a,b)}function f(a,b){return b=b||{},b.gzip=!0,d(a,b)}var g=a("./zlib/deflate.js"),h=a("./utils/common"),i=a("./utils/strings"),j=a("./zlib/messages"),k=a("./zlib/zstream"),l=0,m=4,n=0,o=1,p=-1,q=0,r=8,s=function(a){this.options=h.assign({level:p,method:r,chunkSize:16384,windowBits:15,memLevel:8,strategy:q,to:""},a||{});var b=this.options;b.raw&&b.windowBits>0?b.windowBits=-b.windowBits:b.gzip&&b.windowBits>0&&b.windowBits<16&&(b.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new k,this.strm.avail_out=0;var c=g.deflateInit2(this.strm,b.level,b.method,b.windowBits,b.memLevel,b.strategy);if(c!==n)throw new Error(j[c]);b.header&&g.deflateSetHeader(this.strm,b.header)};s.prototype.push=function(a,b){var c,d,e=this.strm,f=this.options.chunkSize;if(this.ended)return!1;d=b===~~b?b:b===!0?m:l,e.input="string"==typeof a?i.string2buf(a):a,e.next_in=0,e.avail_in=e.input.length;do{if(0===e.avail_out&&(e.output=new h.Buf8(f),e.next_out=0,e.avail_out=f),c=g.deflate(e,d),c!==o&&c!==n)return this.onEnd(c),this.ended=!0,!1;(0===e.avail_out||0===e.avail_in&&d===m)&&this.onData("string"===this.options.to?i.buf2binstring(h.shrinkBuf(e.output,e.next_out)):h.shrinkBuf(e.output,e.next_out))}while((e.avail_in>0||0===e.avail_out)&&c!==o);return d===m?(c=g.deflateEnd(this.strm),this.onEnd(c),this.ended=!0,c===n):!0},s.prototype.onData=function(a){this.chunks.push(a)},s.prototype.onEnd=function(a){a===n&&(this.result="string"===this.options.to?this.chunks.join(""):h.flattenChunks(this.chunks)),this.chunks=[],this.err=a,this.msg=this.strm.msg},c.Deflate=s,c.deflate=d,c.deflateRaw=e,c.gzip=f},{"./utils/common":27,"./utils/strings":28,"./zlib/deflate.js":32,"./zlib/messages":37,"./zlib/zstream":39}],26:[function(a,b,c){"use strict";function d(a,b){var c=new m(b);if(c.push(a,!0),c.err)throw c.msg;return c.result}function e(a,b){return b=b||{},b.raw=!0,d(a,b)}var f=a("./zlib/inflate.js"),g=a("./utils/common"),h=a("./utils/strings"),i=a("./zlib/constants"),j=a("./zlib/messages"),k=a("./zlib/zstream"),l=a("./zlib/gzheader"),m=function(a){this.options=g.assign({chunkSize:16384,windowBits:0,to:""},a||{});var b=this.options;b.raw&&b.windowBits>=0&&b.windowBits<16&&(b.windowBits=-b.windowBits,0===b.windowBits&&(b.windowBits=-15)),!(b.windowBits>=0&&b.windowBits<16)||a&&a.windowBits||(b.windowBits+=32),b.windowBits>15&&b.windowBits<48&&0===(15&b.windowBits)&&(b.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new k,this.strm.avail_out=0;var c=f.inflateInit2(this.strm,b.windowBits);if(c!==i.Z_OK)throw new Error(j[c]);this.header=new l,f.inflateGetHeader(this.strm,this.header)};m.prototype.push=function(a,b){var c,d,e,j,k,l=this.strm,m=this.options.chunkSize;if(this.ended)return!1;d=b===~~b?b:b===!0?i.Z_FINISH:i.Z_NO_FLUSH,l.input="string"==typeof a?h.binstring2buf(a):a,l.next_in=0,l.avail_in=l.input.length;do{if(0===l.avail_out&&(l.output=new g.Buf8(m),l.next_out=0,l.avail_out=m),c=f.inflate(l,i.Z_NO_FLUSH),c!==i.Z_STREAM_END&&c!==i.Z_OK)return this.onEnd(c),this.ended=!0,!1;l.next_out&&(0===l.avail_out||c===i.Z_STREAM_END||0===l.avail_in&&d===i.Z_FINISH)&&("string"===this.options.to?(e=h.utf8border(l.output,l.next_out),j=l.next_out-e,k=h.buf2string(l.output,e),l.next_out=j,l.avail_out=m-j,j&&g.arraySet(l.output,l.output,e,j,0),this.onData(k)):this.onData(g.shrinkBuf(l.output,l.next_out)))}while(l.avail_in>0&&c!==i.Z_STREAM_END);return c===i.Z_STREAM_END&&(d=i.Z_FINISH),d===i.Z_FINISH?(c=f.inflateEnd(this.strm),this.onEnd(c),this.ended=!0,c===i.Z_OK):!0},m.prototype.onData=function(a){this.chunks.push(a)},m.prototype.onEnd=function(a){a===i.Z_OK&&(this.result="string"===this.options.to?this.chunks.join(""):g.flattenChunks(this.chunks)),this.chunks=[],this.err=a,this.msg=this.strm.msg},c.Inflate=m,c.inflate=d,c.inflateRaw=e,c.ungzip=d},{"./utils/common":27,"./utils/strings":28,"./zlib/constants":30,"./zlib/gzheader":33,"./zlib/inflate.js":35,"./zlib/messages":37,"./zlib/zstream":39}],27:[function(a,b,c){"use strict";var d="undefined"!=typeof Uint8Array&&"undefined"!=typeof Uint16Array&&"undefined"!=typeof Int32Array;c.assign=function(a){for(var b=Array.prototype.slice.call(arguments,1);b.length;){var c=b.shift();if(c){if("object"!=typeof c)throw new TypeError(c+"must be non-object");for(var d in c)c.hasOwnProperty(d)&&(a[d]=c[d])}}return a},c.shrinkBuf=function(a,b){return a.length===b?a:a.subarray?a.subarray(0,b):(a.length=b,a)};var e={arraySet:function(a,b,c,d,e){if(b.subarray&&a.subarray)return void a.set(b.subarray(c,c+d),e);for(var f=0;d>f;f++)a[e+f]=b[c+f]},flattenChunks:function(a){var b,c,d,e,f,g;for(d=0,b=0,c=a.length;c>b;b++)d+=a[b].length;for(g=new Uint8Array(d),e=0,b=0,c=a.length;c>b;b++)f=a[b],g.set(f,e),e+=f.length;return g}},f={arraySet:function(a,b,c,d,e){for(var f=0;d>f;f++)a[e+f]=b[c+f]},flattenChunks:function(a){return[].concat.apply([],a)}};c.setTyped=function(a){a?(c.Buf8=Uint8Array,c.Buf16=Uint16Array,c.Buf32=Int32Array,c.assign(c,e)):(c.Buf8=Array,c.Buf16=Array,c.Buf32=Array,c.assign(c,f))},c.setTyped(d)},{}],28:[function(a,b,c){"use strict";function d(a,b){if(65537>b&&(a.subarray&&g||!a.subarray&&f))return String.fromCharCode.apply(null,e.shrinkBuf(a,b));for(var c="",d=0;b>d;d++)c+=String.fromCharCode(a[d]);return c}var e=a("./common"),f=!0,g=!0;try{String.fromCharCode.apply(null,[0])}catch(h){f=!1}try{String.fromCharCode.apply(null,new Uint8Array(1))}catch(h){g=!1}for(var i=new e.Buf8(256),j=0;256>j;j++)i[j]=j>=252?6:j>=248?5:j>=240?4:j>=224?3:j>=192?2:1;i[254]=i[254]=1,c.string2buf=function(a){var b,c,d,f,g,h=a.length,i=0;for(f=0;h>f;f++)c=a.charCodeAt(f),55296===(64512&c)&&h>f+1&&(d=a.charCodeAt(f+1),56320===(64512&d)&&(c=65536+(c-55296<<10)+(d-56320),f++)),i+=128>c?1:2048>c?2:65536>c?3:4;for(b=new e.Buf8(i),g=0,f=0;i>g;f++)c=a.charCodeAt(f),55296===(64512&c)&&h>f+1&&(d=a.charCodeAt(f+1),56320===(64512&d)&&(c=65536+(c-55296<<10)+(d-56320),f++)),128>c?b[g++]=c:2048>c?(b[g++]=192|c>>>6,b[g++]=128|63&c):65536>c?(b[g++]=224|c>>>12,b[g++]=128|c>>>6&63,b[g++]=128|63&c):(b[g++]=240|c>>>18,b[g++]=128|c>>>12&63,b[g++]=128|c>>>6&63,b[g++]=128|63&c);return b},c.buf2binstring=function(a){return d(a,a.length)},c.binstring2buf=function(a){for(var b=new e.Buf8(a.length),c=0,d=b.length;d>c;c++)b[c]=a.charCodeAt(c);return b},c.buf2string=function(a,b){var c,e,f,g,h=b||a.length,j=new Array(2*h);for(e=0,c=0;h>c;)if(f=a[c++],128>f)j[e++]=f;else if(g=i[f],g>4)j[e++]=65533,c+=g-1;else{for(f&=2===g?31:3===g?15:7;g>1&&h>c;)f=f<<6|63&a[c++],g--;g>1?j[e++]=65533:65536>f?j[e++]=f:(f-=65536,j[e++]=55296|f>>10&1023,j[e++]=56320|1023&f)}return d(j,e)},c.utf8border=function(a,b){var c;for(b=b||a.length,b>a.length&&(b=a.length),c=b-1;c>=0&&128===(192&a[c]);)c--;return 0>c?b:0===c?b:c+i[a[c]]>b?c:b}},{"./common":27}],29:[function(a,b){"use strict";function c(a,b,c,d){for(var e=65535&a|0,f=a>>>16&65535|0,g=0;0!==c;){g=c>2e3?2e3:c,c-=g;do e=e+b[d++]|0,f=f+e|0;while(--g);e%=65521,f%=65521}return e|f<<16|0}b.exports=c},{}],30:[function(a,b){b.exports={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8}},{}],31:[function(a,b){"use strict";function c(){for(var a,b=[],c=0;256>c;c++){a=c;for(var d=0;8>d;d++)a=1&a?3988292384^a>>>1:a>>>1;b[c]=a}return b}function d(a,b,c,d){var f=e,g=d+c;a=-1^a;for(var h=d;g>h;h++)a=a>>>8^f[255&(a^b[h])];return-1^a}var e=c();b.exports=d},{}],32:[function(a,b,c){"use strict";function d(a,b){return a.msg=G[b],b}function e(a){return(a<<1)-(a>4?9:0)}function f(a){for(var b=a.length;--b>=0;)a[b]=0}function g(a){var b=a.state,c=b.pending;c>a.avail_out&&(c=a.avail_out),0!==c&&(C.arraySet(a.output,b.pending_buf,b.pending_out,c,a.next_out),a.next_out+=c,b.pending_out+=c,a.total_out+=c,a.avail_out-=c,b.pending-=c,0===b.pending&&(b.pending_out=0))}function h(a,b){D._tr_flush_block(a,a.block_start>=0?a.block_start:-1,a.strstart-a.block_start,b),a.block_start=a.strstart,g(a.strm)}function i(a,b){a.pending_buf[a.pending++]=b}function j(a,b){a.pending_buf[a.pending++]=b>>>8&255,a.pending_buf[a.pending++]=255&b}function k(a,b,c,d){var e=a.avail_in;return e>d&&(e=d),0===e?0:(a.avail_in-=e,C.arraySet(b,a.input,a.next_in,e,c),1===a.state.wrap?a.adler=E(a.adler,b,e,c):2===a.state.wrap&&(a.adler=F(a.adler,b,e,c)),a.next_in+=e,a.total_in+=e,e)}function l(a,b){var c,d,e=a.max_chain_length,f=a.strstart,g=a.prev_length,h=a.nice_match,i=a.strstart>a.w_size-jb?a.strstart-(a.w_size-jb):0,j=a.window,k=a.w_mask,l=a.prev,m=a.strstart+ib,n=j[f+g-1],o=j[f+g];a.prev_length>=a.good_match&&(e>>=2),h>a.lookahead&&(h=a.lookahead);do if(c=b,j[c+g]===o&&j[c+g-1]===n&&j[c]===j[f]&&j[++c]===j[f+1]){f+=2,c++;do;while(j[++f]===j[++c]&&j[++f]===j[++c]&&j[++f]===j[++c]&&j[++f]===j[++c]&&j[++f]===j[++c]&&j[++f]===j[++c]&&j[++f]===j[++c]&&j[++f]===j[++c]&&m>f);if(d=ib-(m-f),f=m-ib,d>g){if(a.match_start=b,g=d,d>=h)break;n=j[f+g-1],o=j[f+g]}}while((b=l[b&k])>i&&0!==--e);return g<=a.lookahead?g:a.lookahead}function m(a){var b,c,d,e,f,g=a.w_size;do{if(e=a.window_size-a.lookahead-a.strstart,a.strstart>=g+(g-jb)){C.arraySet(a.window,a.window,g,g,0),a.match_start-=g,a.strstart-=g,a.block_start-=g,c=a.hash_size,b=c;do d=a.head[--b],a.head[b]=d>=g?d-g:0;while(--c);c=g,b=c;do d=a.prev[--b],a.prev[b]=d>=g?d-g:0;while(--c);e+=g}if(0===a.strm.avail_in)break;if(c=k(a.strm,a.window,a.strstart+a.lookahead,e),a.lookahead+=c,a.lookahead+a.insert>=hb)for(f=a.strstart-a.insert,a.ins_h=a.window[f],a.ins_h=(a.ins_h<<a.hash_shift^a.window[f+1])&a.hash_mask;a.insert&&(a.ins_h=(a.ins_h<<a.hash_shift^a.window[f+hb-1])&a.hash_mask,a.prev[f&a.w_mask]=a.head[a.ins_h],a.head[a.ins_h]=f,f++,a.insert--,!(a.lookahead+a.insert<hb)););}while(a.lookahead<jb&&0!==a.strm.avail_in)}function n(a,b){var c=65535;for(c>a.pending_buf_size-5&&(c=a.pending_buf_size-5);;){if(a.lookahead<=1){if(m(a),0===a.lookahead&&b===H)return sb;if(0===a.lookahead)break}a.strstart+=a.lookahead,a.lookahead=0;var d=a.block_start+c;if((0===a.strstart||a.strstart>=d)&&(a.lookahead=a.strstart-d,a.strstart=d,h(a,!1),0===a.strm.avail_out))return sb;if(a.strstart-a.block_start>=a.w_size-jb&&(h(a,!1),0===a.strm.avail_out))return sb}return a.insert=0,b===K?(h(a,!0),0===a.strm.avail_out?ub:vb):a.strstart>a.block_start&&(h(a,!1),0===a.strm.avail_out)?sb:sb}function o(a,b){for(var c,d;;){if(a.lookahead<jb){if(m(a),a.lookahead<jb&&b===H)return sb;if(0===a.lookahead)break}if(c=0,a.lookahead>=hb&&(a.ins_h=(a.ins_h<<a.hash_shift^a.window[a.strstart+hb-1])&a.hash_mask,c=a.prev[a.strstart&a.w_mask]=a.head[a.ins_h],a.head[a.ins_h]=a.strstart),0!==c&&a.strstart-c<=a.w_size-jb&&(a.match_length=l(a,c)),a.match_length>=hb)if(d=D._tr_tally(a,a.strstart-a.match_start,a.match_length-hb),a.lookahead-=a.match_length,a.match_length<=a.max_lazy_match&&a.lookahead>=hb){a.match_length--;do a.strstart++,a.ins_h=(a.ins_h<<a.hash_shift^a.window[a.strstart+hb-1])&a.hash_mask,c=a.prev[a.strstart&a.w_mask]=a.head[a.ins_h],a.head[a.ins_h]=a.strstart;while(0!==--a.match_length);a.strstart++}else a.strstart+=a.match_length,a.match_length=0,a.ins_h=a.window[a.strstart],a.ins_h=(a.ins_h<<a.hash_shift^a.window[a.strstart+1])&a.hash_mask;else d=D._tr_tally(a,0,a.window[a.strstart]),a.lookahead--,a.strstart++;if(d&&(h(a,!1),0===a.strm.avail_out))return sb}return a.insert=a.strstart<hb-1?a.strstart:hb-1,b===K?(h(a,!0),0===a.strm.avail_out?ub:vb):a.last_lit&&(h(a,!1),0===a.strm.avail_out)?sb:tb}function p(a,b){for(var c,d,e;;){if(a.lookahead<jb){if(m(a),a.lookahead<jb&&b===H)return sb;if(0===a.lookahead)break}if(c=0,a.lookahead>=hb&&(a.ins_h=(a.ins_h<<a.hash_shift^a.window[a.strstart+hb-1])&a.hash_mask,c=a.prev[a.strstart&a.w_mask]=a.head[a.ins_h],a.head[a.ins_h]=a.strstart),a.prev_length=a.match_length,a.prev_match=a.match_start,a.match_length=hb-1,0!==c&&a.prev_length<a.max_lazy_match&&a.strstart-c<=a.w_size-jb&&(a.match_length=l(a,c),a.match_length<=5&&(a.strategy===S||a.match_length===hb&&a.strstart-a.match_start>4096)&&(a.match_length=hb-1)),a.prev_length>=hb&&a.match_length<=a.prev_length){e=a.strstart+a.lookahead-hb,d=D._tr_tally(a,a.strstart-1-a.prev_match,a.prev_length-hb),a.lookahead-=a.prev_length-1,a.prev_length-=2;do++a.strstart<=e&&(a.ins_h=(a.ins_h<<a.hash_shift^a.window[a.strstart+hb-1])&a.hash_mask,c=a.prev[a.strstart&a.w_mask]=a.head[a.ins_h],a.head[a.ins_h]=a.strstart);while(0!==--a.prev_length);if(a.match_available=0,a.match_length=hb-1,a.strstart++,d&&(h(a,!1),0===a.strm.avail_out))return sb}else if(a.match_available){if(d=D._tr_tally(a,0,a.window[a.strstart-1]),d&&h(a,!1),a.strstart++,a.lookahead--,0===a.strm.avail_out)return sb}else a.match_available=1,a.strstart++,a.lookahead--}return a.match_available&&(d=D._tr_tally(a,0,a.window[a.strstart-1]),a.match_available=0),a.insert=a.strstart<hb-1?a.strstart:hb-1,b===K?(h(a,!0),0===a.strm.avail_out?ub:vb):a.last_lit&&(h(a,!1),0===a.strm.avail_out)?sb:tb}function q(a,b){for(var c,d,e,f,g=a.window;;){if(a.lookahead<=ib){if(m(a),a.lookahead<=ib&&b===H)return sb;if(0===a.lookahead)break}if(a.match_length=0,a.lookahead>=hb&&a.strstart>0&&(e=a.strstart-1,d=g[e],d===g[++e]&&d===g[++e]&&d===g[++e])){f=a.strstart+ib;do;while(d===g[++e]&&d===g[++e]&&d===g[++e]&&d===g[++e]&&d===g[++e]&&d===g[++e]&&d===g[++e]&&d===g[++e]&&f>e);a.match_length=ib-(f-e),a.match_length>a.lookahead&&(a.match_length=a.lookahead)}if(a.match_length>=hb?(c=D._tr_tally(a,1,a.match_length-hb),a.lookahead-=a.match_length,a.strstart+=a.match_length,a.match_length=0):(c=D._tr_tally(a,0,a.window[a.strstart]),a.lookahead--,a.strstart++),c&&(h(a,!1),0===a.strm.avail_out))return sb}return a.insert=0,b===K?(h(a,!0),0===a.strm.avail_out?ub:vb):a.last_lit&&(h(a,!1),0===a.strm.avail_out)?sb:tb}function r(a,b){for(var c;;){if(0===a.lookahead&&(m(a),0===a.lookahead)){if(b===H)return sb;break}if(a.match_length=0,c=D._tr_tally(a,0,a.window[a.strstart]),a.lookahead--,a.strstart++,c&&(h(a,!1),0===a.strm.avail_out))return sb}return a.insert=0,b===K?(h(a,!0),0===a.strm.avail_out?ub:vb):a.last_lit&&(h(a,!1),0===a.strm.avail_out)?sb:tb}function s(a){a.window_size=2*a.w_size,f(a.head),a.max_lazy_match=B[a.level].max_lazy,a.good_match=B[a.level].good_length,a.nice_match=B[a.level].nice_length,a.max_chain_length=B[a.level].max_chain,a.strstart=0,a.block_start=0,a.lookahead=0,a.insert=0,a.match_length=a.prev_length=hb-1,a.match_available=0,a.ins_h=0}function t(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=Y,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new C.Buf16(2*fb),this.dyn_dtree=new C.Buf16(2*(2*db+1)),this.bl_tree=new C.Buf16(2*(2*eb+1)),f(this.dyn_ltree),f(this.dyn_dtree),f(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new C.Buf16(gb+1),this.heap=new C.Buf16(2*cb+1),f(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new C.Buf16(2*cb+1),f(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}function u(a){var b;return a&&a.state?(a.total_in=a.total_out=0,a.data_type=X,b=a.state,b.pending=0,b.pending_out=0,b.wrap<0&&(b.wrap=-b.wrap),b.status=b.wrap?lb:qb,a.adler=2===b.wrap?0:1,b.last_flush=H,D._tr_init(b),M):d(a,O)}function v(a){var b=u(a);return b===M&&s(a.state),b}function w(a,b){return a&&a.state?2!==a.state.wrap?O:(a.state.gzhead=b,M):O}function x(a,b,c,e,f,g){if(!a)return O;var h=1;if(b===R&&(b=6),0>e?(h=0,e=-e):e>15&&(h=2,e-=16),1>f||f>Z||c!==Y||8>e||e>15||0>b||b>9||0>g||g>V)return d(a,O);8===e&&(e=9);var i=new t;return a.state=i,i.strm=a,i.wrap=h,i.gzhead=null,i.w_bits=e,i.w_size=1<<i.w_bits,i.w_mask=i.w_size-1,i.hash_bits=f+7,i.hash_size=1<<i.hash_bits,i.hash_mask=i.hash_size-1,i.hash_shift=~~((i.hash_bits+hb-1)/hb),i.window=new C.Buf8(2*i.w_size),i.head=new C.Buf16(i.hash_size),i.prev=new C.Buf16(i.w_size),i.lit_bufsize=1<<f+6,i.pending_buf_size=4*i.lit_bufsize,i.pending_buf=new C.Buf8(i.pending_buf_size),i.d_buf=i.lit_bufsize>>1,i.l_buf=3*i.lit_bufsize,i.level=b,i.strategy=g,i.method=c,v(a)}function y(a,b){return x(a,b,Y,$,_,W)}function z(a,b){var c,h,k,l;if(!a||!a.state||b>L||0>b)return a?d(a,O):O;if(h=a.state,!a.output||!a.input&&0!==a.avail_in||h.status===rb&&b!==K)return d(a,0===a.avail_out?Q:O);if(h.strm=a,c=h.last_flush,h.last_flush=b,h.status===lb)if(2===h.wrap)a.adler=0,i(h,31),i(h,139),i(h,8),h.gzhead?(i(h,(h.gzhead.text?1:0)+(h.gzhead.hcrc?2:0)+(h.gzhead.extra?4:0)+(h.gzhead.name?8:0)+(h.gzhead.comment?16:0)),i(h,255&h.gzhead.time),i(h,h.gzhead.time>>8&255),i(h,h.gzhead.time>>16&255),i(h,h.gzhead.time>>24&255),i(h,9===h.level?2:h.strategy>=T||h.level<2?4:0),i(h,255&h.gzhead.os),h.gzhead.extra&&h.gzhead.extra.length&&(i(h,255&h.gzhead.extra.length),i(h,h.gzhead.extra.length>>8&255)),h.gzhead.hcrc&&(a.adler=F(a.adler,h.pending_buf,h.pending,0)),h.gzindex=0,h.status=mb):(i(h,0),i(h,0),i(h,0),i(h,0),i(h,0),i(h,9===h.level?2:h.strategy>=T||h.level<2?4:0),i(h,wb),h.status=qb);else{var m=Y+(h.w_bits-8<<4)<<8,n=-1;n=h.strategy>=T||h.level<2?0:h.level<6?1:6===h.level?2:3,m|=n<<6,0!==h.strstart&&(m|=kb),m+=31-m%31,h.status=qb,j(h,m),0!==h.strstart&&(j(h,a.adler>>>16),j(h,65535&a.adler)),a.adler=1}if(h.status===mb)if(h.gzhead.extra){for(k=h.pending;h.gzindex<(65535&h.gzhead.extra.length)&&(h.pending!==h.pending_buf_size||(h.gzhead.hcrc&&h.pending>k&&(a.adler=F(a.adler,h.pending_buf,h.pending-k,k)),g(a),k=h.pending,h.pending!==h.pending_buf_size));)i(h,255&h.gzhead.extra[h.gzindex]),h.gzindex++;h.gzhead.hcrc&&h.pending>k&&(a.adler=F(a.adler,h.pending_buf,h.pending-k,k)),h.gzindex===h.gzhead.extra.length&&(h.gzindex=0,h.status=nb)}else h.status=nb;if(h.status===nb)if(h.gzhead.name){k=h.pending;do{if(h.pending===h.pending_buf_size&&(h.gzhead.hcrc&&h.pending>k&&(a.adler=F(a.adler,h.pending_buf,h.pending-k,k)),g(a),k=h.pending,h.pending===h.pending_buf_size)){l=1;break}l=h.gzindex<h.gzhead.name.length?255&h.gzhead.name.charCodeAt(h.gzindex++):0,i(h,l)}while(0!==l);h.gzhead.hcrc&&h.pending>k&&(a.adler=F(a.adler,h.pending_buf,h.pending-k,k)),0===l&&(h.gzindex=0,h.status=ob)}else h.status=ob;if(h.status===ob)if(h.gzhead.comment){k=h.pending;do{if(h.pending===h.pending_buf_size&&(h.gzhead.hcrc&&h.pending>k&&(a.adler=F(a.adler,h.pending_buf,h.pending-k,k)),g(a),k=h.pending,h.pending===h.pending_buf_size)){l=1;break}l=h.gzindex<h.gzhead.comment.length?255&h.gzhead.comment.charCodeAt(h.gzindex++):0,i(h,l)}while(0!==l);h.gzhead.hcrc&&h.pending>k&&(a.adler=F(a.adler,h.pending_buf,h.pending-k,k)),0===l&&(h.status=pb)}else h.status=pb;if(h.status===pb&&(h.gzhead.hcrc?(h.pending+2>h.pending_buf_size&&g(a),h.pending+2<=h.pending_buf_size&&(i(h,255&a.adler),i(h,a.adler>>8&255),a.adler=0,h.status=qb)):h.status=qb),0!==h.pending){if(g(a),0===a.avail_out)return h.last_flush=-1,M}else if(0===a.avail_in&&e(b)<=e(c)&&b!==K)return d(a,Q);if(h.status===rb&&0!==a.avail_in)return d(a,Q);if(0!==a.avail_in||0!==h.lookahead||b!==H&&h.status!==rb){var o=h.strategy===T?r(h,b):h.strategy===U?q(h,b):B[h.level].func(h,b);if((o===ub||o===vb)&&(h.status=rb),o===sb||o===ub)return 0===a.avail_out&&(h.last_flush=-1),M;if(o===tb&&(b===I?D._tr_align(h):b!==L&&(D._tr_stored_block(h,0,0,!1),b===J&&(f(h.head),0===h.lookahead&&(h.strstart=0,h.block_start=0,h.insert=0))),g(a),0===a.avail_out))return h.last_flush=-1,M}return b!==K?M:h.wrap<=0?N:(2===h.wrap?(i(h,255&a.adler),i(h,a.adler>>8&255),i(h,a.adler>>16&255),i(h,a.adler>>24&255),i(h,255&a.total_in),i(h,a.total_in>>8&255),i(h,a.total_in>>16&255),i(h,a.total_in>>24&255)):(j(h,a.adler>>>16),j(h,65535&a.adler)),g(a),h.wrap>0&&(h.wrap=-h.wrap),0!==h.pending?M:N)}function A(a){var b;return a&&a.state?(b=a.state.status,b!==lb&&b!==mb&&b!==nb&&b!==ob&&b!==pb&&b!==qb&&b!==rb?d(a,O):(a.state=null,b===qb?d(a,P):M)):O}var B,C=a("../utils/common"),D=a("./trees"),E=a("./adler32"),F=a("./crc32"),G=a("./messages"),H=0,I=1,J=3,K=4,L=5,M=0,N=1,O=-2,P=-3,Q=-5,R=-1,S=1,T=2,U=3,V=4,W=0,X=2,Y=8,Z=9,$=15,_=8,ab=29,bb=256,cb=bb+1+ab,db=30,eb=19,fb=2*cb+1,gb=15,hb=3,ib=258,jb=ib+hb+1,kb=32,lb=42,mb=69,nb=73,ob=91,pb=103,qb=113,rb=666,sb=1,tb=2,ub=3,vb=4,wb=3,xb=function(a,b,c,d,e){this.good_length=a,this.max_lazy=b,this.nice_length=c,this.max_chain=d,this.func=e};B=[new xb(0,0,0,0,n),new xb(4,4,8,4,o),new xb(4,5,16,8,o),new xb(4,6,32,32,o),new xb(4,4,16,16,p),new xb(8,16,32,32,p),new xb(8,16,128,128,p),new xb(8,32,128,256,p),new xb(32,128,258,1024,p),new xb(32,258,258,4096,p)],c.deflateInit=y,c.deflateInit2=x,c.deflateReset=v,c.deflateResetKeep=u,c.deflateSetHeader=w,c.deflate=z,c.deflateEnd=A,c.deflateInfo="pako deflate (from Nodeca project)"},{"../utils/common":27,"./adler32":29,"./crc32":31,"./messages":37,"./trees":38}],33:[function(a,b){"use strict";function c(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1}b.exports=c},{}],34:[function(a,b){"use strict";var c=30,d=12;b.exports=function(a,b){var e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C;e=a.state,f=a.next_in,B=a.input,g=f+(a.avail_in-5),h=a.next_out,C=a.output,i=h-(b-a.avail_out),j=h+(a.avail_out-257),k=e.dmax,l=e.wsize,m=e.whave,n=e.wnext,o=e.window,p=e.hold,q=e.bits,r=e.lencode,s=e.distcode,t=(1<<e.lenbits)-1,u=(1<<e.distbits)-1;a:do{15>q&&(p+=B[f++]<<q,q+=8,p+=B[f++]<<q,q+=8),v=r[p&t];b:for(;;){if(w=v>>>24,p>>>=w,q-=w,w=v>>>16&255,0===w)C[h++]=65535&v;else{if(!(16&w)){if(0===(64&w)){v=r[(65535&v)+(p&(1<<w)-1)];continue b}if(32&w){e.mode=d;break a}a.msg="invalid literal/length code",e.mode=c;break a}x=65535&v,w&=15,w&&(w>q&&(p+=B[f++]<<q,q+=8),x+=p&(1<<w)-1,p>>>=w,q-=w),15>q&&(p+=B[f++]<<q,q+=8,p+=B[f++]<<q,q+=8),v=s[p&u];c:for(;;){if(w=v>>>24,p>>>=w,q-=w,w=v>>>16&255,!(16&w)){if(0===(64&w)){v=s[(65535&v)+(p&(1<<w)-1)];continue c}a.msg="invalid distance code",e.mode=c;break a}if(y=65535&v,w&=15,w>q&&(p+=B[f++]<<q,q+=8,w>q&&(p+=B[f++]<<q,q+=8)),y+=p&(1<<w)-1,y>k){a.msg="invalid distance too far back",e.mode=c;break a}if(p>>>=w,q-=w,w=h-i,y>w){if(w=y-w,w>m&&e.sane){a.msg="invalid distance too far back",e.mode=c;break a}if(z=0,A=o,0===n){if(z+=l-w,x>w){x-=w;do C[h++]=o[z++];while(--w);z=h-y,A=C}}else if(w>n){if(z+=l+n-w,w-=n,x>w){x-=w;do C[h++]=o[z++];while(--w);if(z=0,x>n){w=n,x-=w;do C[h++]=o[z++];while(--w);z=h-y,A=C}}}else if(z+=n-w,x>w){x-=w;do C[h++]=o[z++];while(--w);z=h-y,A=C}for(;x>2;)C[h++]=A[z++],C[h++]=A[z++],C[h++]=A[z++],x-=3;x&&(C[h++]=A[z++],x>1&&(C[h++]=A[z++]))}else{z=h-y;do C[h++]=C[z++],C[h++]=C[z++],C[h++]=C[z++],x-=3;while(x>2);x&&(C[h++]=C[z++],x>1&&(C[h++]=C[z++]))}break}}break}}while(g>f&&j>h);x=q>>3,f-=x,q-=x<<3,p&=(1<<q)-1,a.next_in=f,a.next_out=h,a.avail_in=g>f?5+(g-f):5-(f-g),a.avail_out=j>h?257+(j-h):257-(h-j),e.hold=p,e.bits=q}},{}],35:[function(a,b,c){"use strict";function d(a){return(a>>>24&255)+(a>>>8&65280)+((65280&a)<<8)+((255&a)<<24)}function e(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new r.Buf16(320),this.work=new r.Buf16(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}function f(a){var b;return a&&a.state?(b=a.state,a.total_in=a.total_out=b.total=0,a.msg="",b.wrap&&(a.adler=1&b.wrap),b.mode=K,b.last=0,b.havedict=0,b.dmax=32768,b.head=null,b.hold=0,b.bits=0,b.lencode=b.lendyn=new r.Buf32(ob),b.distcode=b.distdyn=new r.Buf32(pb),b.sane=1,b.back=-1,C):F}function g(a){var b;return a&&a.state?(b=a.state,b.wsize=0,b.whave=0,b.wnext=0,f(a)):F}function h(a,b){var c,d;return a&&a.state?(d=a.state,0>b?(c=0,b=-b):(c=(b>>4)+1,48>b&&(b&=15)),b&&(8>b||b>15)?F:(null!==d.window&&d.wbits!==b&&(d.window=null),d.wrap=c,d.wbits=b,g(a))):F}function i(a,b){var c,d;return a?(d=new e,a.state=d,d.window=null,c=h(a,b),c!==C&&(a.state=null),c):F}function j(a){return i(a,rb)}function k(a){if(sb){var b;for(p=new r.Buf32(512),q=new r.Buf32(32),b=0;144>b;)a.lens[b++]=8;for(;256>b;)a.lens[b++]=9;for(;280>b;)a.lens[b++]=7;for(;288>b;)a.lens[b++]=8;for(v(x,a.lens,0,288,p,0,a.work,{bits:9}),b=0;32>b;)a.lens[b++]=5;v(y,a.lens,0,32,q,0,a.work,{bits:5}),sb=!1}a.lencode=p,a.lenbits=9,a.distcode=q,a.distbits=5}function l(a,b,c,d){var e,f=a.state;return null===f.window&&(f.wsize=1<<f.wbits,f.wnext=0,f.whave=0,f.window=new r.Buf8(f.wsize)),d>=f.wsize?(r.arraySet(f.window,b,c-f.wsize,f.wsize,0),f.wnext=0,f.whave=f.wsize):(e=f.wsize-f.wnext,e>d&&(e=d),r.arraySet(f.window,b,c-d,e,f.wnext),d-=e,d?(r.arraySet(f.window,b,c-d,d,0),f.wnext=d,f.whave=f.wsize):(f.wnext+=e,f.wnext===f.wsize&&(f.wnext=0),f.whave<f.wsize&&(f.whave+=e))),0}function m(a,b){var c,e,f,g,h,i,j,m,n,o,p,q,ob,pb,qb,rb,sb,tb,ub,vb,wb,xb,yb,zb,Ab=0,Bb=new r.Buf8(4),Cb=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15];if(!a||!a.state||!a.output||!a.input&&0!==a.avail_in)return F;c=a.state,c.mode===V&&(c.mode=W),h=a.next_out,f=a.output,j=a.avail_out,g=a.next_in,e=a.input,i=a.avail_in,m=c.hold,n=c.bits,o=i,p=j,xb=C;a:for(;;)switch(c.mode){case K:if(0===c.wrap){c.mode=W;break}for(;16>n;){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}if(2&c.wrap&&35615===m){c.check=0,Bb[0]=255&m,Bb[1]=m>>>8&255,c.check=t(c.check,Bb,2,0),m=0,n=0,c.mode=L;break}if(c.flags=0,c.head&&(c.head.done=!1),!(1&c.wrap)||(((255&m)<<8)+(m>>8))%31){a.msg="incorrect header check",c.mode=lb;break}if((15&m)!==J){a.msg="unknown compression method",c.mode=lb;break}if(m>>>=4,n-=4,wb=(15&m)+8,0===c.wbits)c.wbits=wb;else if(wb>c.wbits){a.msg="invalid window size",c.mode=lb;break}c.dmax=1<<wb,a.adler=c.check=1,c.mode=512&m?T:V,m=0,n=0;break;case L:for(;16>n;){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}if(c.flags=m,(255&c.flags)!==J){a.msg="unknown compression method",c.mode=lb;break}if(57344&c.flags){a.msg="unknown header flags set",c.mode=lb;break}c.head&&(c.head.text=m>>8&1),512&c.flags&&(Bb[0]=255&m,Bb[1]=m>>>8&255,c.check=t(c.check,Bb,2,0)),m=0,n=0,c.mode=M;case M:for(;32>n;){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}c.head&&(c.head.time=m),512&c.flags&&(Bb[0]=255&m,Bb[1]=m>>>8&255,Bb[2]=m>>>16&255,Bb[3]=m>>>24&255,c.check=t(c.check,Bb,4,0)),m=0,n=0,c.mode=N;case N:for(;16>n;){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}c.head&&(c.head.xflags=255&m,c.head.os=m>>8),512&c.flags&&(Bb[0]=255&m,Bb[1]=m>>>8&255,c.check=t(c.check,Bb,2,0)),m=0,n=0,c.mode=O;case O:if(1024&c.flags){for(;16>n;){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}c.length=m,c.head&&(c.head.extra_len=m),512&c.flags&&(Bb[0]=255&m,Bb[1]=m>>>8&255,c.check=t(c.check,Bb,2,0)),m=0,n=0}else c.head&&(c.head.extra=null);c.mode=P;case P:if(1024&c.flags&&(q=c.length,q>i&&(q=i),q&&(c.head&&(wb=c.head.extra_len-c.length,c.head.extra||(c.head.extra=new Array(c.head.extra_len)),r.arraySet(c.head.extra,e,g,q,wb)),512&c.flags&&(c.check=t(c.check,e,q,g)),i-=q,g+=q,c.length-=q),c.length))break a;c.length=0,c.mode=Q;case Q:if(2048&c.flags){if(0===i)break a;q=0;do wb=e[g+q++],c.head&&wb&&c.length<65536&&(c.head.name+=String.fromCharCode(wb));while(wb&&i>q);if(512&c.flags&&(c.check=t(c.check,e,q,g)),i-=q,g+=q,wb)break a}else c.head&&(c.head.name=null);c.length=0,c.mode=R;case R:if(4096&c.flags){if(0===i)break a;q=0;do wb=e[g+q++],c.head&&wb&&c.length<65536&&(c.head.comment+=String.fromCharCode(wb));while(wb&&i>q);if(512&c.flags&&(c.check=t(c.check,e,q,g)),i-=q,g+=q,wb)break a}else c.head&&(c.head.comment=null);c.mode=S;case S:if(512&c.flags){for(;16>n;){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}if(m!==(65535&c.check)){a.msg="header crc mismatch",c.mode=lb;break}m=0,n=0}c.head&&(c.head.hcrc=c.flags>>9&1,c.head.done=!0),a.adler=c.check=0,c.mode=V;break;case T:for(;32>n;){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}a.adler=c.check=d(m),m=0,n=0,c.mode=U;case U:if(0===c.havedict)return a.next_out=h,a.avail_out=j,a.next_in=g,a.avail_in=i,c.hold=m,c.bits=n,E;a.adler=c.check=1,c.mode=V;case V:if(b===A||b===B)break a;case W:if(c.last){m>>>=7&n,n-=7&n,c.mode=ib;break}for(;3>n;){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}switch(c.last=1&m,m>>>=1,n-=1,3&m){case 0:c.mode=X;break;case 1:if(k(c),c.mode=bb,b===B){m>>>=2,n-=2;break a}break;case 2:c.mode=$;break;case 3:a.msg="invalid block type",c.mode=lb}m>>>=2,n-=2;break;case X:for(m>>>=7&n,n-=7&n;32>n;){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}if((65535&m)!==(m>>>16^65535)){a.msg="invalid stored block lengths",c.mode=lb;break}if(c.length=65535&m,m=0,n=0,c.mode=Y,b===B)break a;case Y:c.mode=Z;case Z:if(q=c.length){if(q>i&&(q=i),q>j&&(q=j),0===q)break a;r.arraySet(f,e,g,q,h),i-=q,g+=q,j-=q,h+=q,c.length-=q;break}c.mode=V;break;case $:for(;14>n;){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}if(c.nlen=(31&m)+257,m>>>=5,n-=5,c.ndist=(31&m)+1,m>>>=5,n-=5,c.ncode=(15&m)+4,m>>>=4,n-=4,c.nlen>286||c.ndist>30){a.msg="too many length or distance symbols",c.mode=lb;break}c.have=0,c.mode=_;case _:for(;c.have<c.ncode;){for(;3>n;){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}c.lens[Cb[c.have++]]=7&m,m>>>=3,n-=3}for(;c.have<19;)c.lens[Cb[c.have++]]=0;if(c.lencode=c.lendyn,c.lenbits=7,yb={bits:c.lenbits},xb=v(w,c.lens,0,19,c.lencode,0,c.work,yb),c.lenbits=yb.bits,xb){a.msg="invalid code lengths set",c.mode=lb;break}c.have=0,c.mode=ab;case ab:for(;c.have<c.nlen+c.ndist;){for(;Ab=c.lencode[m&(1<<c.lenbits)-1],qb=Ab>>>24,rb=Ab>>>16&255,sb=65535&Ab,!(n>=qb);){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}if(16>sb)m>>>=qb,n-=qb,c.lens[c.have++]=sb;else{if(16===sb){for(zb=qb+2;zb>n;){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}if(m>>>=qb,n-=qb,0===c.have){a.msg="invalid bit length repeat",c.mode=lb;break}wb=c.lens[c.have-1],q=3+(3&m),m>>>=2,n-=2}else if(17===sb){for(zb=qb+3;zb>n;){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}m>>>=qb,n-=qb,wb=0,q=3+(7&m),m>>>=3,n-=3}else{for(zb=qb+7;zb>n;){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}m>>>=qb,n-=qb,wb=0,q=11+(127&m),m>>>=7,n-=7}if(c.have+q>c.nlen+c.ndist){a.msg="invalid bit length repeat",c.mode=lb;break}for(;q--;)c.lens[c.have++]=wb}}if(c.mode===lb)break;if(0===c.lens[256]){a.msg="invalid code -- missing end-of-block",c.mode=lb;break}if(c.lenbits=9,yb={bits:c.lenbits},xb=v(x,c.lens,0,c.nlen,c.lencode,0,c.work,yb),c.lenbits=yb.bits,xb){a.msg="invalid literal/lengths set",c.mode=lb;break}if(c.distbits=6,c.distcode=c.distdyn,yb={bits:c.distbits},xb=v(y,c.lens,c.nlen,c.ndist,c.distcode,0,c.work,yb),c.distbits=yb.bits,xb){a.msg="invalid distances set",c.mode=lb;break}if(c.mode=bb,b===B)break a;case bb:c.mode=cb;case cb:if(i>=6&&j>=258){a.next_out=h,a.avail_out=j,a.next_in=g,a.avail_in=i,c.hold=m,c.bits=n,u(a,p),h=a.next_out,f=a.output,j=a.avail_out,g=a.next_in,e=a.input,i=a.avail_in,m=c.hold,n=c.bits,c.mode===V&&(c.back=-1); -break}for(c.back=0;Ab=c.lencode[m&(1<<c.lenbits)-1],qb=Ab>>>24,rb=Ab>>>16&255,sb=65535&Ab,!(n>=qb);){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}if(rb&&0===(240&rb)){for(tb=qb,ub=rb,vb=sb;Ab=c.lencode[vb+((m&(1<<tb+ub)-1)>>tb)],qb=Ab>>>24,rb=Ab>>>16&255,sb=65535&Ab,!(n>=tb+qb);){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}m>>>=tb,n-=tb,c.back+=tb}if(m>>>=qb,n-=qb,c.back+=qb,c.length=sb,0===rb){c.mode=hb;break}if(32&rb){c.back=-1,c.mode=V;break}if(64&rb){a.msg="invalid literal/length code",c.mode=lb;break}c.extra=15&rb,c.mode=db;case db:if(c.extra){for(zb=c.extra;zb>n;){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}c.length+=m&(1<<c.extra)-1,m>>>=c.extra,n-=c.extra,c.back+=c.extra}c.was=c.length,c.mode=eb;case eb:for(;Ab=c.distcode[m&(1<<c.distbits)-1],qb=Ab>>>24,rb=Ab>>>16&255,sb=65535&Ab,!(n>=qb);){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}if(0===(240&rb)){for(tb=qb,ub=rb,vb=sb;Ab=c.distcode[vb+((m&(1<<tb+ub)-1)>>tb)],qb=Ab>>>24,rb=Ab>>>16&255,sb=65535&Ab,!(n>=tb+qb);){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}m>>>=tb,n-=tb,c.back+=tb}if(m>>>=qb,n-=qb,c.back+=qb,64&rb){a.msg="invalid distance code",c.mode=lb;break}c.offset=sb,c.extra=15&rb,c.mode=fb;case fb:if(c.extra){for(zb=c.extra;zb>n;){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}c.offset+=m&(1<<c.extra)-1,m>>>=c.extra,n-=c.extra,c.back+=c.extra}if(c.offset>c.dmax){a.msg="invalid distance too far back",c.mode=lb;break}c.mode=gb;case gb:if(0===j)break a;if(q=p-j,c.offset>q){if(q=c.offset-q,q>c.whave&&c.sane){a.msg="invalid distance too far back",c.mode=lb;break}q>c.wnext?(q-=c.wnext,ob=c.wsize-q):ob=c.wnext-q,q>c.length&&(q=c.length),pb=c.window}else pb=f,ob=h-c.offset,q=c.length;q>j&&(q=j),j-=q,c.length-=q;do f[h++]=pb[ob++];while(--q);0===c.length&&(c.mode=cb);break;case hb:if(0===j)break a;f[h++]=c.length,j--,c.mode=cb;break;case ib:if(c.wrap){for(;32>n;){if(0===i)break a;i--,m|=e[g++]<<n,n+=8}if(p-=j,a.total_out+=p,c.total+=p,p&&(a.adler=c.check=c.flags?t(c.check,f,p,h-p):s(c.check,f,p,h-p)),p=j,(c.flags?m:d(m))!==c.check){a.msg="incorrect data check",c.mode=lb;break}m=0,n=0}c.mode=jb;case jb:if(c.wrap&&c.flags){for(;32>n;){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}if(m!==(4294967295&c.total)){a.msg="incorrect length check",c.mode=lb;break}m=0,n=0}c.mode=kb;case kb:xb=D;break a;case lb:xb=G;break a;case mb:return H;case nb:default:return F}return a.next_out=h,a.avail_out=j,a.next_in=g,a.avail_in=i,c.hold=m,c.bits=n,(c.wsize||p!==a.avail_out&&c.mode<lb&&(c.mode<ib||b!==z))&&l(a,a.output,a.next_out,p-a.avail_out)?(c.mode=mb,H):(o-=a.avail_in,p-=a.avail_out,a.total_in+=o,a.total_out+=p,c.total+=p,c.wrap&&p&&(a.adler=c.check=c.flags?t(c.check,f,p,a.next_out-p):s(c.check,f,p,a.next_out-p)),a.data_type=c.bits+(c.last?64:0)+(c.mode===V?128:0)+(c.mode===bb||c.mode===Y?256:0),(0===o&&0===p||b===z)&&xb===C&&(xb=I),xb)}function n(a){if(!a||!a.state)return F;var b=a.state;return b.window&&(b.window=null),a.state=null,C}function o(a,b){var c;return a&&a.state?(c=a.state,0===(2&c.wrap)?F:(c.head=b,b.done=!1,C)):F}var p,q,r=a("../utils/common"),s=a("./adler32"),t=a("./crc32"),u=a("./inffast"),v=a("./inftrees"),w=0,x=1,y=2,z=4,A=5,B=6,C=0,D=1,E=2,F=-2,G=-3,H=-4,I=-5,J=8,K=1,L=2,M=3,N=4,O=5,P=6,Q=7,R=8,S=9,T=10,U=11,V=12,W=13,X=14,Y=15,Z=16,$=17,_=18,ab=19,bb=20,cb=21,db=22,eb=23,fb=24,gb=25,hb=26,ib=27,jb=28,kb=29,lb=30,mb=31,nb=32,ob=852,pb=592,qb=15,rb=qb,sb=!0;c.inflateReset=g,c.inflateReset2=h,c.inflateResetKeep=f,c.inflateInit=j,c.inflateInit2=i,c.inflate=m,c.inflateEnd=n,c.inflateGetHeader=o,c.inflateInfo="pako inflate (from Nodeca project)"},{"../utils/common":27,"./adler32":29,"./crc32":31,"./inffast":34,"./inftrees":36}],36:[function(a,b){"use strict";var c=a("../utils/common"),d=15,e=852,f=592,g=0,h=1,i=2,j=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0],k=[16,16,16,16,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,16,72,78],l=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0],m=[16,16,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,64,64];b.exports=function(a,b,n,o,p,q,r,s){var t,u,v,w,x,y,z,A,B,C=s.bits,D=0,E=0,F=0,G=0,H=0,I=0,J=0,K=0,L=0,M=0,N=null,O=0,P=new c.Buf16(d+1),Q=new c.Buf16(d+1),R=null,S=0;for(D=0;d>=D;D++)P[D]=0;for(E=0;o>E;E++)P[b[n+E]]++;for(H=C,G=d;G>=1&&0===P[G];G--);if(H>G&&(H=G),0===G)return p[q++]=20971520,p[q++]=20971520,s.bits=1,0;for(F=1;G>F&&0===P[F];F++);for(F>H&&(H=F),K=1,D=1;d>=D;D++)if(K<<=1,K-=P[D],0>K)return-1;if(K>0&&(a===g||1!==G))return-1;for(Q[1]=0,D=1;d>D;D++)Q[D+1]=Q[D]+P[D];for(E=0;o>E;E++)0!==b[n+E]&&(r[Q[b[n+E]]++]=E);if(a===g?(N=R=r,y=19):a===h?(N=j,O-=257,R=k,S-=257,y=256):(N=l,R=m,y=-1),M=0,E=0,D=F,x=q,I=H,J=0,v=-1,L=1<<H,w=L-1,a===h&&L>e||a===i&&L>f)return 1;for(var T=0;;){T++,z=D-J,r[E]<y?(A=0,B=r[E]):r[E]>y?(A=R[S+r[E]],B=N[O+r[E]]):(A=96,B=0),t=1<<D-J,u=1<<I,F=u;do u-=t,p[x+(M>>J)+u]=z<<24|A<<16|B|0;while(0!==u);for(t=1<<D-1;M&t;)t>>=1;if(0!==t?(M&=t-1,M+=t):M=0,E++,0===--P[D]){if(D===G)break;D=b[n+r[E]]}if(D>H&&(M&w)!==v){for(0===J&&(J=H),x+=F,I=D-J,K=1<<I;G>I+J&&(K-=P[I+J],!(0>=K));)I++,K<<=1;if(L+=1<<I,a===h&&L>e||a===i&&L>f)return 1;v=M&w,p[v]=H<<24|I<<16|x-q|0}}return 0!==M&&(p[x+M]=D-J<<24|64<<16|0),s.bits=H,0}},{"../utils/common":27}],37:[function(a,b){"use strict";b.exports={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"}},{}],38:[function(a,b,c){"use strict";function d(a){for(var b=a.length;--b>=0;)a[b]=0}function e(a){return 256>a?gb[a]:gb[256+(a>>>7)]}function f(a,b){a.pending_buf[a.pending++]=255&b,a.pending_buf[a.pending++]=b>>>8&255}function g(a,b,c){a.bi_valid>V-c?(a.bi_buf|=b<<a.bi_valid&65535,f(a,a.bi_buf),a.bi_buf=b>>V-a.bi_valid,a.bi_valid+=c-V):(a.bi_buf|=b<<a.bi_valid&65535,a.bi_valid+=c)}function h(a,b,c){g(a,c[2*b],c[2*b+1])}function i(a,b){var c=0;do c|=1&a,a>>>=1,c<<=1;while(--b>0);return c>>>1}function j(a){16===a.bi_valid?(f(a,a.bi_buf),a.bi_buf=0,a.bi_valid=0):a.bi_valid>=8&&(a.pending_buf[a.pending++]=255&a.bi_buf,a.bi_buf>>=8,a.bi_valid-=8)}function k(a,b){var c,d,e,f,g,h,i=b.dyn_tree,j=b.max_code,k=b.stat_desc.static_tree,l=b.stat_desc.has_stree,m=b.stat_desc.extra_bits,n=b.stat_desc.extra_base,o=b.stat_desc.max_length,p=0;for(f=0;U>=f;f++)a.bl_count[f]=0;for(i[2*a.heap[a.heap_max]+1]=0,c=a.heap_max+1;T>c;c++)d=a.heap[c],f=i[2*i[2*d+1]+1]+1,f>o&&(f=o,p++),i[2*d+1]=f,d>j||(a.bl_count[f]++,g=0,d>=n&&(g=m[d-n]),h=i[2*d],a.opt_len+=h*(f+g),l&&(a.static_len+=h*(k[2*d+1]+g)));if(0!==p){do{for(f=o-1;0===a.bl_count[f];)f--;a.bl_count[f]--,a.bl_count[f+1]+=2,a.bl_count[o]--,p-=2}while(p>0);for(f=o;0!==f;f--)for(d=a.bl_count[f];0!==d;)e=a.heap[--c],e>j||(i[2*e+1]!==f&&(a.opt_len+=(f-i[2*e+1])*i[2*e],i[2*e+1]=f),d--)}}function l(a,b,c){var d,e,f=new Array(U+1),g=0;for(d=1;U>=d;d++)f[d]=g=g+c[d-1]<<1;for(e=0;b>=e;e++){var h=a[2*e+1];0!==h&&(a[2*e]=i(f[h]++,h))}}function m(){var a,b,c,d,e,f=new Array(U+1);for(c=0,d=0;O-1>d;d++)for(ib[d]=c,a=0;a<1<<_[d];a++)hb[c++]=d;for(hb[c-1]=d,e=0,d=0;16>d;d++)for(jb[d]=e,a=0;a<1<<ab[d];a++)gb[e++]=d;for(e>>=7;R>d;d++)for(jb[d]=e<<7,a=0;a<1<<ab[d]-7;a++)gb[256+e++]=d;for(b=0;U>=b;b++)f[b]=0;for(a=0;143>=a;)eb[2*a+1]=8,a++,f[8]++;for(;255>=a;)eb[2*a+1]=9,a++,f[9]++;for(;279>=a;)eb[2*a+1]=7,a++,f[7]++;for(;287>=a;)eb[2*a+1]=8,a++,f[8]++;for(l(eb,Q+1,f),a=0;R>a;a++)fb[2*a+1]=5,fb[2*a]=i(a,5);kb=new nb(eb,_,P+1,Q,U),lb=new nb(fb,ab,0,R,U),mb=new nb(new Array(0),bb,0,S,W)}function n(a){var b;for(b=0;Q>b;b++)a.dyn_ltree[2*b]=0;for(b=0;R>b;b++)a.dyn_dtree[2*b]=0;for(b=0;S>b;b++)a.bl_tree[2*b]=0;a.dyn_ltree[2*X]=1,a.opt_len=a.static_len=0,a.last_lit=a.matches=0}function o(a){a.bi_valid>8?f(a,a.bi_buf):a.bi_valid>0&&(a.pending_buf[a.pending++]=a.bi_buf),a.bi_buf=0,a.bi_valid=0}function p(a,b,c,d){o(a),d&&(f(a,c),f(a,~c)),E.arraySet(a.pending_buf,a.window,b,c,a.pending),a.pending+=c}function q(a,b,c,d){var e=2*b,f=2*c;return a[e]<a[f]||a[e]===a[f]&&d[b]<=d[c]}function r(a,b,c){for(var d=a.heap[c],e=c<<1;e<=a.heap_len&&(e<a.heap_len&&q(b,a.heap[e+1],a.heap[e],a.depth)&&e++,!q(b,d,a.heap[e],a.depth));)a.heap[c]=a.heap[e],c=e,e<<=1;a.heap[c]=d}function s(a,b,c){var d,f,i,j,k=0;if(0!==a.last_lit)do d=a.pending_buf[a.d_buf+2*k]<<8|a.pending_buf[a.d_buf+2*k+1],f=a.pending_buf[a.l_buf+k],k++,0===d?h(a,f,b):(i=hb[f],h(a,i+P+1,b),j=_[i],0!==j&&(f-=ib[i],g(a,f,j)),d--,i=e(d),h(a,i,c),j=ab[i],0!==j&&(d-=jb[i],g(a,d,j)));while(k<a.last_lit);h(a,X,b)}function t(a,b){var c,d,e,f=b.dyn_tree,g=b.stat_desc.static_tree,h=b.stat_desc.has_stree,i=b.stat_desc.elems,j=-1;for(a.heap_len=0,a.heap_max=T,c=0;i>c;c++)0!==f[2*c]?(a.heap[++a.heap_len]=j=c,a.depth[c]=0):f[2*c+1]=0;for(;a.heap_len<2;)e=a.heap[++a.heap_len]=2>j?++j:0,f[2*e]=1,a.depth[e]=0,a.opt_len--,h&&(a.static_len-=g[2*e+1]);for(b.max_code=j,c=a.heap_len>>1;c>=1;c--)r(a,f,c);e=i;do c=a.heap[1],a.heap[1]=a.heap[a.heap_len--],r(a,f,1),d=a.heap[1],a.heap[--a.heap_max]=c,a.heap[--a.heap_max]=d,f[2*e]=f[2*c]+f[2*d],a.depth[e]=(a.depth[c]>=a.depth[d]?a.depth[c]:a.depth[d])+1,f[2*c+1]=f[2*d+1]=e,a.heap[1]=e++,r(a,f,1);while(a.heap_len>=2);a.heap[--a.heap_max]=a.heap[1],k(a,b),l(f,j,a.bl_count)}function u(a,b,c){var d,e,f=-1,g=b[1],h=0,i=7,j=4;for(0===g&&(i=138,j=3),b[2*(c+1)+1]=65535,d=0;c>=d;d++)e=g,g=b[2*(d+1)+1],++h<i&&e===g||(j>h?a.bl_tree[2*e]+=h:0!==e?(e!==f&&a.bl_tree[2*e]++,a.bl_tree[2*Y]++):10>=h?a.bl_tree[2*Z]++:a.bl_tree[2*$]++,h=0,f=e,0===g?(i=138,j=3):e===g?(i=6,j=3):(i=7,j=4))}function v(a,b,c){var d,e,f=-1,i=b[1],j=0,k=7,l=4;for(0===i&&(k=138,l=3),d=0;c>=d;d++)if(e=i,i=b[2*(d+1)+1],!(++j<k&&e===i)){if(l>j){do h(a,e,a.bl_tree);while(0!==--j)}else 0!==e?(e!==f&&(h(a,e,a.bl_tree),j--),h(a,Y,a.bl_tree),g(a,j-3,2)):10>=j?(h(a,Z,a.bl_tree),g(a,j-3,3)):(h(a,$,a.bl_tree),g(a,j-11,7));j=0,f=e,0===i?(k=138,l=3):e===i?(k=6,l=3):(k=7,l=4)}}function w(a){var b;for(u(a,a.dyn_ltree,a.l_desc.max_code),u(a,a.dyn_dtree,a.d_desc.max_code),t(a,a.bl_desc),b=S-1;b>=3&&0===a.bl_tree[2*cb[b]+1];b--);return a.opt_len+=3*(b+1)+5+5+4,b}function x(a,b,c,d){var e;for(g(a,b-257,5),g(a,c-1,5),g(a,d-4,4),e=0;d>e;e++)g(a,a.bl_tree[2*cb[e]+1],3);v(a,a.dyn_ltree,b-1),v(a,a.dyn_dtree,c-1)}function y(a){var b,c=4093624447;for(b=0;31>=b;b++,c>>>=1)if(1&c&&0!==a.dyn_ltree[2*b])return G;if(0!==a.dyn_ltree[18]||0!==a.dyn_ltree[20]||0!==a.dyn_ltree[26])return H;for(b=32;P>b;b++)if(0!==a.dyn_ltree[2*b])return H;return G}function z(a){pb||(m(),pb=!0),a.l_desc=new ob(a.dyn_ltree,kb),a.d_desc=new ob(a.dyn_dtree,lb),a.bl_desc=new ob(a.bl_tree,mb),a.bi_buf=0,a.bi_valid=0,n(a)}function A(a,b,c,d){g(a,(J<<1)+(d?1:0),3),p(a,b,c,!0)}function B(a){g(a,K<<1,3),h(a,X,eb),j(a)}function C(a,b,c,d){var e,f,h=0;a.level>0?(a.strm.data_type===I&&(a.strm.data_type=y(a)),t(a,a.l_desc),t(a,a.d_desc),h=w(a),e=a.opt_len+3+7>>>3,f=a.static_len+3+7>>>3,e>=f&&(e=f)):e=f=c+5,e>=c+4&&-1!==b?A(a,b,c,d):a.strategy===F||f===e?(g(a,(K<<1)+(d?1:0),3),s(a,eb,fb)):(g(a,(L<<1)+(d?1:0),3),x(a,a.l_desc.max_code+1,a.d_desc.max_code+1,h+1),s(a,a.dyn_ltree,a.dyn_dtree)),n(a),d&&o(a)}function D(a,b,c){return a.pending_buf[a.d_buf+2*a.last_lit]=b>>>8&255,a.pending_buf[a.d_buf+2*a.last_lit+1]=255&b,a.pending_buf[a.l_buf+a.last_lit]=255&c,a.last_lit++,0===b?a.dyn_ltree[2*c]++:(a.matches++,b--,a.dyn_ltree[2*(hb[c]+P+1)]++,a.dyn_dtree[2*e(b)]++),a.last_lit===a.lit_bufsize-1}var E=a("../utils/common"),F=4,G=0,H=1,I=2,J=0,K=1,L=2,M=3,N=258,O=29,P=256,Q=P+1+O,R=30,S=19,T=2*Q+1,U=15,V=16,W=7,X=256,Y=16,Z=17,$=18,_=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0],ab=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13],bb=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7],cb=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],db=512,eb=new Array(2*(Q+2));d(eb);var fb=new Array(2*R);d(fb);var gb=new Array(db);d(gb);var hb=new Array(N-M+1);d(hb);var ib=new Array(O);d(ib);var jb=new Array(R);d(jb);var kb,lb,mb,nb=function(a,b,c,d,e){this.static_tree=a,this.extra_bits=b,this.extra_base=c,this.elems=d,this.max_length=e,this.has_stree=a&&a.length},ob=function(a,b){this.dyn_tree=a,this.max_code=0,this.stat_desc=b},pb=!1;c._tr_init=z,c._tr_stored_block=A,c._tr_flush_block=C,c._tr_tally=D,c._tr_align=B},{"../utils/common":27}],39:[function(a,b){"use strict";function c(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0}b.exports=c},{}]},{},[9])(9)});
\ No newline at end of file +!function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;b="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,b.JSZip=a()}}(function(){return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b,c){"use strict";var d=a("./utils"),e=a("./support"),f="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";c.encode=function(a){for(var b,c,e,g,h,i,j,k=[],l=0,m=a.length,n=m,o="string"!==d.getTypeOf(a);l<a.length;)n=m-l,o?(b=a[l++],c=l<m?a[l++]:0,e=l<m?a[l++]:0):(b=a.charCodeAt(l++),c=l<m?a.charCodeAt(l++):0,e=l<m?a.charCodeAt(l++):0),g=b>>2,h=(3&b)<<4|c>>4,i=n>1?(15&c)<<2|e>>6:64,j=n>2?63&e:64,k.push(f.charAt(g)+f.charAt(h)+f.charAt(i)+f.charAt(j));return k.join("")},c.decode=function(a){var b,c,d,g,h,i,j,k=0,l=0,m="data:";if(a.substr(0,m.length)===m)throw new Error("Invalid base64 input, it looks like a data url.");a=a.replace(/[^A-Za-z0-9\+\/\=]/g,"");var n=3*a.length/4;if(a.charAt(a.length-1)===f.charAt(64)&&n--,a.charAt(a.length-2)===f.charAt(64)&&n--,n%1!==0)throw new Error("Invalid base64 input, bad content length.");var o;for(o=e.uint8array?new Uint8Array(0|n):new Array(0|n);k<a.length;)g=f.indexOf(a.charAt(k++)),h=f.indexOf(a.charAt(k++)),i=f.indexOf(a.charAt(k++)),j=f.indexOf(a.charAt(k++)),b=g<<2|h>>4,c=(15&h)<<4|i>>2,d=(3&i)<<6|j,o[l++]=b,64!==i&&(o[l++]=c),64!==j&&(o[l++]=d);return o}},{"./support":30,"./utils":32}],2:[function(a,b,c){"use strict";function d(a,b,c,d,e){this.compressedSize=a,this.uncompressedSize=b,this.crc32=c,this.compression=d,this.compressedContent=e}var e=a("./external"),f=a("./stream/DataWorker"),g=a("./stream/DataLengthProbe"),h=a("./stream/Crc32Probe"),g=a("./stream/DataLengthProbe");d.prototype={getContentWorker:function(){var a=new f(e.Promise.resolve(this.compressedContent)).pipe(this.compression.uncompressWorker()).pipe(new g("data_length")),b=this;return a.on("end",function(){if(this.streamInfo.data_length!==b.uncompressedSize)throw new Error("Bug : uncompressed data size mismatch")}),a},getCompressedWorker:function(){return new f(e.Promise.resolve(this.compressedContent)).withStreamInfo("compressedSize",this.compressedSize).withStreamInfo("uncompressedSize",this.uncompressedSize).withStreamInfo("crc32",this.crc32).withStreamInfo("compression",this.compression)}},d.createWorkerFrom=function(a,b,c){return a.pipe(new h).pipe(new g("uncompressedSize")).pipe(b.compressWorker(c)).pipe(new g("compressedSize")).withStreamInfo("compression",b)},b.exports=d},{"./external":6,"./stream/Crc32Probe":25,"./stream/DataLengthProbe":26,"./stream/DataWorker":27}],3:[function(a,b,c){"use strict";var d=a("./stream/GenericWorker");c.STORE={magic:"\0\0",compressWorker:function(a){return new d("STORE compression")},uncompressWorker:function(){return new d("STORE decompression")}},c.DEFLATE=a("./flate")},{"./flate":7,"./stream/GenericWorker":28}],4:[function(a,b,c){"use strict";function d(){for(var a,b=[],c=0;c<256;c++){a=c;for(var d=0;d<8;d++)a=1&a?3988292384^a>>>1:a>>>1;b[c]=a}return b}function e(a,b,c,d){var e=h,f=d+c;a^=-1;for(var g=d;g<f;g++)a=a>>>8^e[255&(a^b[g])];return a^-1}function f(a,b,c,d){var e=h,f=d+c;a^=-1;for(var g=d;g<f;g++)a=a>>>8^e[255&(a^b.charCodeAt(g))];return a^-1}var g=a("./utils"),h=d();b.exports=function(a,b){if("undefined"==typeof a||!a.length)return 0;var c="string"!==g.getTypeOf(a);return c?e(0|b,a,a.length,0):f(0|b,a,a.length,0)}},{"./utils":32}],5:[function(a,b,c){"use strict";c.base64=!1,c.binary=!1,c.dir=!1,c.createFolders=!0,c.date=null,c.compression=null,c.compressionOptions=null,c.comment=null,c.unixPermissions=null,c.dosPermissions=null},{}],6:[function(a,b,c){"use strict";var d=null;d="undefined"!=typeof Promise?Promise:a("lie"),b.exports={Promise:d}},{lie:58}],7:[function(a,b,c){"use strict";function d(a,b){h.call(this,"FlateWorker/"+a),this._pako=null,this._pakoAction=a,this._pakoOptions=b,this.meta={}}var e="undefined"!=typeof Uint8Array&&"undefined"!=typeof Uint16Array&&"undefined"!=typeof Uint32Array,f=a("pako"),g=a("./utils"),h=a("./stream/GenericWorker"),i=e?"uint8array":"array";c.magic="\b\0",g.inherits(d,h),d.prototype.processChunk=function(a){this.meta=a.meta,null===this._pako&&this._createPako(),this._pako.push(g.transformTo(i,a.data),!1)},d.prototype.flush=function(){h.prototype.flush.call(this),null===this._pako&&this._createPako(),this._pako.push([],!0)},d.prototype.cleanUp=function(){h.prototype.cleanUp.call(this),this._pako=null},d.prototype._createPako=function(){this._pako=new f[this._pakoAction]({raw:!0,level:this._pakoOptions.level||-1});var a=this;this._pako.onData=function(b){a.push({data:b,meta:a.meta})}},c.compressWorker=function(a){return new d("Deflate",a)},c.uncompressWorker=function(){return new d("Inflate",{})}},{"./stream/GenericWorker":28,"./utils":32,pako:59}],8:[function(a,b,c){"use strict";function d(a,b,c,d){f.call(this,"ZipFileWorker"),this.bytesWritten=0,this.zipComment=b,this.zipPlatform=c,this.encodeFileName=d,this.streamFiles=a,this.accumulate=!1,this.contentBuffer=[],this.dirRecords=[],this.currentSourceOffset=0,this.entriesCount=0,this.currentFile=null,this._sources=[]}var e=a("../utils"),f=a("../stream/GenericWorker"),g=a("../utf8"),h=a("../crc32"),i=a("../signature"),j=function(a,b){var c,d="";for(c=0;c<b;c++)d+=String.fromCharCode(255&a),a>>>=8;return d},k=function(a,b){var c=a;return a||(c=b?16893:33204),(65535&c)<<16},l=function(a,b){return 63&(a||0)},m=function(a,b,c,d,f,m){var n,o,p=a.file,q=a.compression,r=m!==g.utf8encode,s=e.transformTo("string",m(p.name)),t=e.transformTo("string",g.utf8encode(p.name)),u=p.comment,v=e.transformTo("string",m(u)),w=e.transformTo("string",g.utf8encode(u)),x=t.length!==p.name.length,y=w.length!==u.length,z="",A="",B="",C=p.dir,D=p.date,E={crc32:0,compressedSize:0,uncompressedSize:0};b&&!c||(E.crc32=a.crc32,E.compressedSize=a.compressedSize,E.uncompressedSize=a.uncompressedSize);var F=0;b&&(F|=8),r||!x&&!y||(F|=2048);var G=0,H=0;C&&(G|=16),"UNIX"===f?(H=798,G|=k(p.unixPermissions,C)):(H=20,G|=l(p.dosPermissions,C)),n=D.getUTCHours(),n<<=6,n|=D.getUTCMinutes(),n<<=5,n|=D.getUTCSeconds()/2,o=D.getUTCFullYear()-1980,o<<=4,o|=D.getUTCMonth()+1,o<<=5,o|=D.getUTCDate(),x&&(A=j(1,1)+j(h(s),4)+t,z+="up"+j(A.length,2)+A),y&&(B=j(1,1)+j(h(v),4)+w,z+="uc"+j(B.length,2)+B);var I="";I+="\n\0",I+=j(F,2),I+=q.magic,I+=j(n,2),I+=j(o,2),I+=j(E.crc32,4),I+=j(E.compressedSize,4),I+=j(E.uncompressedSize,4),I+=j(s.length,2),I+=j(z.length,2);var J=i.LOCAL_FILE_HEADER+I+s+z,K=i.CENTRAL_FILE_HEADER+j(H,2)+I+j(v.length,2)+"\0\0\0\0"+j(G,4)+j(d,4)+s+z+v;return{fileRecord:J,dirRecord:K}},n=function(a,b,c,d,f){var g="",h=e.transformTo("string",f(d));return g=i.CENTRAL_DIRECTORY_END+"\0\0\0\0"+j(a,2)+j(a,2)+j(b,4)+j(c,4)+j(h.length,2)+h},o=function(a){var b="";return b=i.DATA_DESCRIPTOR+j(a.crc32,4)+j(a.compressedSize,4)+j(a.uncompressedSize,4)};e.inherits(d,f),d.prototype.push=function(a){var b=a.meta.percent||0,c=this.entriesCount,d=this._sources.length;this.accumulate?this.contentBuffer.push(a):(this.bytesWritten+=a.data.length,f.prototype.push.call(this,{data:a.data,meta:{currentFile:this.currentFile,percent:c?(b+100*(c-d-1))/c:100}}))},d.prototype.openedSource=function(a){this.currentSourceOffset=this.bytesWritten,this.currentFile=a.file.name;var b=this.streamFiles&&!a.file.dir;if(b){var c=m(a,b,!1,this.currentSourceOffset,this.zipPlatform,this.encodeFileName);this.push({data:c.fileRecord,meta:{percent:0}})}else this.accumulate=!0},d.prototype.closedSource=function(a){this.accumulate=!1;var b=this.streamFiles&&!a.file.dir,c=m(a,b,!0,this.currentSourceOffset,this.zipPlatform,this.encodeFileName);if(this.dirRecords.push(c.dirRecord),b)this.push({data:o(a),meta:{percent:100}});else for(this.push({data:c.fileRecord,meta:{percent:0}});this.contentBuffer.length;)this.push(this.contentBuffer.shift());this.currentFile=null},d.prototype.flush=function(){for(var a=this.bytesWritten,b=0;b<this.dirRecords.length;b++)this.push({data:this.dirRecords[b],meta:{percent:100}});var c=this.bytesWritten-a,d=n(this.dirRecords.length,c,a,this.zipComment,this.encodeFileName);this.push({data:d,meta:{percent:100}})},d.prototype.prepareNextSource=function(){this.previous=this._sources.shift(),this.openedSource(this.previous.streamInfo),this.isPaused?this.previous.pause():this.previous.resume()},d.prototype.registerPrevious=function(a){this._sources.push(a);var b=this;return a.on("data",function(a){b.processChunk(a)}),a.on("end",function(){b.closedSource(b.previous.streamInfo),b._sources.length?b.prepareNextSource():b.end()}),a.on("error",function(a){b.error(a)}),this},d.prototype.resume=function(){return!!f.prototype.resume.call(this)&&(!this.previous&&this._sources.length?(this.prepareNextSource(),!0):this.previous||this._sources.length||this.generatedError?void 0:(this.end(),!0))},d.prototype.error=function(a){var b=this._sources;if(!f.prototype.error.call(this,a))return!1;for(var c=0;c<b.length;c++)try{b[c].error(a)}catch(a){}return!0},d.prototype.lock=function(){f.prototype.lock.call(this);for(var a=this._sources,b=0;b<a.length;b++)a[b].lock()},b.exports=d},{"../crc32":4,"../signature":23,"../stream/GenericWorker":28,"../utf8":31,"../utils":32}],9:[function(a,b,c){"use strict";var d=a("../compressions"),e=a("./ZipFileWorker"),f=function(a,b){var c=a||b,e=d[c];if(!e)throw new Error(c+" is not a valid compression method !");return e};c.generateWorker=function(a,b,c){var d=new e(b.streamFiles,c,b.platform,b.encodeFileName),g=0;try{a.forEach(function(a,c){g++;var e=f(c.options.compression,b.compression),h=c.options.compressionOptions||b.compressionOptions||{},i=c.dir,j=c.date;c._compressWorker(e,h).withStreamInfo("file",{name:a,dir:i,date:j,comment:c.comment||"",unixPermissions:c.unixPermissions,dosPermissions:c.dosPermissions}).pipe(d)}),d.entriesCount=g}catch(h){d.error(h)}return d}},{"../compressions":3,"./ZipFileWorker":8}],10:[function(a,b,c){"use strict";function d(){if(!(this instanceof d))return new d;if(arguments.length)throw new Error("The constructor with parameters has been removed in JSZip 3.0, please check the upgrade guide.");this.files={},this.comment=null,this.root="",this.clone=function(){var a=new d;for(var b in this)"function"!=typeof this[b]&&(a[b]=this[b]);return a}}d.prototype=a("./object"),d.prototype.loadAsync=a("./load"),d.support=a("./support"),d.defaults=a("./defaults"),d.version="3.1.5",d.loadAsync=function(a,b){return(new d).loadAsync(a,b)},d.external=a("./external"),b.exports=d},{"./defaults":5,"./external":6,"./load":11,"./object":15,"./support":30}],11:[function(a,b,c){"use strict";function d(a){return new f.Promise(function(b,c){var d=a.decompressed.getContentWorker().pipe(new i);d.on("error",function(a){c(a)}).on("end",function(){d.streamInfo.crc32!==a.decompressed.crc32?c(new Error("Corrupted zip : CRC32 mismatch")):b()}).resume()})}var e=a("./utils"),f=a("./external"),g=a("./utf8"),e=a("./utils"),h=a("./zipEntries"),i=a("./stream/Crc32Probe"),j=a("./nodejsUtils");b.exports=function(a,b){var c=this;return b=e.extend(b||{},{base64:!1,checkCRC32:!1,optimizedBinaryString:!1,createFolders:!1,decodeFileName:g.utf8decode}),j.isNode&&j.isStream(a)?f.Promise.reject(new Error("JSZip can't accept a stream when loading a zip file.")):e.prepareContent("the loaded zip file",a,!0,b.optimizedBinaryString,b.base64).then(function(a){var c=new h(b);return c.load(a),c}).then(function(a){var c=[f.Promise.resolve(a)],e=a.files;if(b.checkCRC32)for(var g=0;g<e.length;g++)c.push(d(e[g]));return f.Promise.all(c)}).then(function(a){for(var d=a.shift(),e=d.files,f=0;f<e.length;f++){var g=e[f];c.file(g.fileNameStr,g.decompressed,{binary:!0,optimizedBinaryString:!0,date:g.date,dir:g.dir,comment:g.fileCommentStr.length?g.fileCommentStr:null,unixPermissions:g.unixPermissions,dosPermissions:g.dosPermissions,createFolders:b.createFolders})}return d.zipComment.length&&(c.comment=d.zipComment),c})}},{"./external":6,"./nodejsUtils":14,"./stream/Crc32Probe":25,"./utf8":31,"./utils":32,"./zipEntries":33}],12:[function(a,b,c){"use strict";function d(a,b){f.call(this,"Nodejs stream input adapter for "+a),this._upstreamEnded=!1,this._bindStream(b)}var e=a("../utils"),f=a("../stream/GenericWorker");e.inherits(d,f),d.prototype._bindStream=function(a){var b=this;this._stream=a,a.pause(),a.on("data",function(a){b.push({data:a,meta:{percent:0}})}).on("error",function(a){b.isPaused?this.generatedError=a:b.error(a)}).on("end",function(){b.isPaused?b._upstreamEnded=!0:b.end()})},d.prototype.pause=function(){return!!f.prototype.pause.call(this)&&(this._stream.pause(),!0)},d.prototype.resume=function(){return!!f.prototype.resume.call(this)&&(this._upstreamEnded?this.end():this._stream.resume(),!0)},b.exports=d},{"../stream/GenericWorker":28,"../utils":32}],13:[function(a,b,c){"use strict";function d(a,b,c){e.call(this,b),this._helper=a;var d=this;a.on("data",function(a,b){d.push(a)||d._helper.pause(),c&&c(b)}).on("error",function(a){d.emit("error",a)}).on("end",function(){d.push(null)})}var e=a("readable-stream").Readable,f=a("../utils");f.inherits(d,e),d.prototype._read=function(){this._helper.resume()},b.exports=d},{"../utils":32,"readable-stream":16}],14:[function(a,b,c){"use strict";b.exports={isNode:"undefined"!=typeof Buffer,newBufferFrom:function(a,b){return new Buffer(a,b)},allocBuffer:function(a){return Buffer.alloc?Buffer.alloc(a):new Buffer(a)},isBuffer:function(a){return Buffer.isBuffer(a)},isStream:function(a){return a&&"function"==typeof a.on&&"function"==typeof a.pause&&"function"==typeof a.resume}}},{}],15:[function(a,b,c){"use strict";function d(a){return"[object RegExp]"===Object.prototype.toString.call(a)}var e=a("./utf8"),f=a("./utils"),g=a("./stream/GenericWorker"),h=a("./stream/StreamHelper"),i=a("./defaults"),j=a("./compressedObject"),k=a("./zipObject"),l=a("./generate"),m=a("./nodejsUtils"),n=a("./nodejs/NodejsStreamInputAdapter"),o=function(a,b,c){var d,e=f.getTypeOf(b),h=f.extend(c||{},i);h.date=h.date||new Date,null!==h.compression&&(h.compression=h.compression.toUpperCase()),"string"==typeof h.unixPermissions&&(h.unixPermissions=parseInt(h.unixPermissions,8)),h.unixPermissions&&16384&h.unixPermissions&&(h.dir=!0),h.dosPermissions&&16&h.dosPermissions&&(h.dir=!0),h.dir&&(a=q(a)),h.createFolders&&(d=p(a))&&r.call(this,d,!0);var l="string"===e&&h.binary===!1&&h.base64===!1;c&&"undefined"!=typeof c.binary||(h.binary=!l);var o=b instanceof j&&0===b.uncompressedSize;(o||h.dir||!b||0===b.length)&&(h.base64=!1,h.binary=!0,b="",h.compression="STORE",e="string");var s=null;s=b instanceof j||b instanceof g?b:m.isNode&&m.isStream(b)?new n(a,b):f.prepareContent(a,b,h.binary,h.optimizedBinaryString,h.base64);var t=new k(a,s,h);this.files[a]=t},p=function(a){"/"===a.slice(-1)&&(a=a.substring(0,a.length-1));var b=a.lastIndexOf("/");return b>0?a.substring(0,b):""},q=function(a){return"/"!==a.slice(-1)&&(a+="/"),a},r=function(a,b){return b="undefined"!=typeof b?b:i.createFolders,a=q(a),this.files[a]||o.call(this,a,null,{dir:!0,createFolders:b}),this.files[a]},s={load:function(){throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.")},forEach:function(a){var b,c,d;for(b in this.files)this.files.hasOwnProperty(b)&&(d=this.files[b],c=b.slice(this.root.length,b.length),c&&b.slice(0,this.root.length)===this.root&&a(c,d))},filter:function(a){var b=[];return this.forEach(function(c,d){a(c,d)&&b.push(d)}),b},file:function(a,b,c){if(1===arguments.length){if(d(a)){var e=a;return this.filter(function(a,b){return!b.dir&&e.test(a)})}var f=this.files[this.root+a];return f&&!f.dir?f:null}return a=this.root+a,o.call(this,a,b,c),this},folder:function(a){if(!a)return this;if(d(a))return this.filter(function(b,c){return c.dir&&a.test(b)});var b=this.root+a,c=r.call(this,b),e=this.clone();return e.root=c.name,e},remove:function(a){a=this.root+a;var b=this.files[a];if(b||("/"!==a.slice(-1)&&(a+="/"),b=this.files[a]),b&&!b.dir)delete this.files[a];else for(var c=this.filter(function(b,c){return c.name.slice(0,a.length)===a}),d=0;d<c.length;d++)delete this.files[c[d].name];return this},generate:function(a){throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.")},generateInternalStream:function(a){var b,c={};try{if(c=f.extend(a||{},{streamFiles:!1,compression:"STORE",compressionOptions:null,type:"",platform:"DOS",comment:null,mimeType:"application/zip",encodeFileName:e.utf8encode}),c.type=c.type.toLowerCase(),c.compression=c.compression.toUpperCase(),"binarystring"===c.type&&(c.type="string"),!c.type)throw new Error("No output type specified.");f.checkSupport(c.type),"darwin"!==c.platform&&"freebsd"!==c.platform&&"linux"!==c.platform&&"sunos"!==c.platform||(c.platform="UNIX"),"win32"===c.platform&&(c.platform="DOS");var d=c.comment||this.comment||"";b=l.generateWorker(this,c,d)}catch(i){b=new g("error"),b.error(i)}return new h(b,c.type||"string",c.mimeType)},generateAsync:function(a,b){return this.generateInternalStream(a).accumulate(b)},generateNodeStream:function(a,b){return a=a||{},a.type||(a.type="nodebuffer"),this.generateInternalStream(a).toNodejsStream(b)}};b.exports=s},{"./compressedObject":2,"./defaults":5,"./generate":9,"./nodejs/NodejsStreamInputAdapter":12,"./nodejsUtils":14,"./stream/GenericWorker":28,"./stream/StreamHelper":29,"./utf8":31,"./utils":32,"./zipObject":35}],16:[function(a,b,c){b.exports=a("stream")},{stream:void 0}],17:[function(a,b,c){"use strict";function d(a){e.call(this,a);for(var b=0;b<this.data.length;b++)a[b]=255&a[b]}var e=a("./DataReader"),f=a("../utils");f.inherits(d,e),d.prototype.byteAt=function(a){return this.data[this.zero+a]},d.prototype.lastIndexOfSignature=function(a){for(var b=a.charCodeAt(0),c=a.charCodeAt(1),d=a.charCodeAt(2),e=a.charCodeAt(3),f=this.length-4;f>=0;--f)if(this.data[f]===b&&this.data[f+1]===c&&this.data[f+2]===d&&this.data[f+3]===e)return f-this.zero;return-1},d.prototype.readAndCheckSignature=function(a){var b=a.charCodeAt(0),c=a.charCodeAt(1),d=a.charCodeAt(2),e=a.charCodeAt(3),f=this.readData(4);return b===f[0]&&c===f[1]&&d===f[2]&&e===f[3]},d.prototype.readData=function(a){if(this.checkOffset(a),0===a)return[];var b=this.data.slice(this.zero+this.index,this.zero+this.index+a);return this.index+=a,b},b.exports=d},{"../utils":32,"./DataReader":18}],18:[function(a,b,c){"use strict";function d(a){this.data=a,this.length=a.length,this.index=0,this.zero=0}var e=a("../utils");d.prototype={checkOffset:function(a){this.checkIndex(this.index+a)},checkIndex:function(a){if(this.length<this.zero+a||a<0)throw new Error("End of data reached (data length = "+this.length+", asked index = "+a+"). Corrupted zip ?")},setIndex:function(a){this.checkIndex(a),this.index=a},skip:function(a){this.setIndex(this.index+a)},byteAt:function(a){},readInt:function(a){var b,c=0;for(this.checkOffset(a),b=this.index+a-1;b>=this.index;b--)c=(c<<8)+this.byteAt(b);return this.index+=a,c},readString:function(a){return e.transformTo("string",this.readData(a))},readData:function(a){},lastIndexOfSignature:function(a){},readAndCheckSignature:function(a){},readDate:function(){var a=this.readInt(4);return new Date(Date.UTC((a>>25&127)+1980,(a>>21&15)-1,a>>16&31,a>>11&31,a>>5&63,(31&a)<<1))}},b.exports=d},{"../utils":32}],19:[function(a,b,c){"use strict";function d(a){e.call(this,a)}var e=a("./Uint8ArrayReader"),f=a("../utils");f.inherits(d,e),d.prototype.readData=function(a){this.checkOffset(a);var b=this.data.slice(this.zero+this.index,this.zero+this.index+a);return this.index+=a,b},b.exports=d},{"../utils":32,"./Uint8ArrayReader":21}],20:[function(a,b,c){"use strict";function d(a){e.call(this,a)}var e=a("./DataReader"),f=a("../utils");f.inherits(d,e),d.prototype.byteAt=function(a){return this.data.charCodeAt(this.zero+a)},d.prototype.lastIndexOfSignature=function(a){return this.data.lastIndexOf(a)-this.zero},d.prototype.readAndCheckSignature=function(a){var b=this.readData(4);return a===b},d.prototype.readData=function(a){this.checkOffset(a);var b=this.data.slice(this.zero+this.index,this.zero+this.index+a);return this.index+=a,b},b.exports=d},{"../utils":32,"./DataReader":18}],21:[function(a,b,c){"use strict";function d(a){e.call(this,a)}var e=a("./ArrayReader"),f=a("../utils");f.inherits(d,e),d.prototype.readData=function(a){if(this.checkOffset(a),0===a)return new Uint8Array(0);var b=this.data.subarray(this.zero+this.index,this.zero+this.index+a);return this.index+=a,b},b.exports=d},{"../utils":32,"./ArrayReader":17}],22:[function(a,b,c){"use strict";var d=a("../utils"),e=a("../support"),f=a("./ArrayReader"),g=a("./StringReader"),h=a("./NodeBufferReader"),i=a("./Uint8ArrayReader");b.exports=function(a){var b=d.getTypeOf(a);return d.checkSupport(b),"string"!==b||e.uint8array?"nodebuffer"===b?new h(a):e.uint8array?new i(d.transformTo("uint8array",a)):new f(d.transformTo("array",a)):new g(a)}},{"../support":30,"../utils":32,"./ArrayReader":17,"./NodeBufferReader":19,"./StringReader":20,"./Uint8ArrayReader":21}],23:[function(a,b,c){"use strict";c.LOCAL_FILE_HEADER="PK",c.CENTRAL_FILE_HEADER="PK",c.CENTRAL_DIRECTORY_END="PK",c.ZIP64_CENTRAL_DIRECTORY_LOCATOR="PK",c.ZIP64_CENTRAL_DIRECTORY_END="PK",c.DATA_DESCRIPTOR="PK\b"},{}],24:[function(a,b,c){"use strict";function d(a){e.call(this,"ConvertWorker to "+a),this.destType=a}var e=a("./GenericWorker"),f=a("../utils");f.inherits(d,e),d.prototype.processChunk=function(a){this.push({data:f.transformTo(this.destType,a.data),meta:a.meta})},b.exports=d},{"../utils":32,"./GenericWorker":28}],25:[function(a,b,c){"use strict";function d(){e.call(this,"Crc32Probe"),this.withStreamInfo("crc32",0)}var e=a("./GenericWorker"),f=a("../crc32"),g=a("../utils");g.inherits(d,e),d.prototype.processChunk=function(a){this.streamInfo.crc32=f(a.data,this.streamInfo.crc32||0),this.push(a)},b.exports=d},{"../crc32":4,"../utils":32,"./GenericWorker":28}],26:[function(a,b,c){"use strict";function d(a){f.call(this,"DataLengthProbe for "+a),this.propName=a,this.withStreamInfo(a,0)}var e=a("../utils"),f=a("./GenericWorker");e.inherits(d,f),d.prototype.processChunk=function(a){if(a){var b=this.streamInfo[this.propName]||0;this.streamInfo[this.propName]=b+a.data.length}f.prototype.processChunk.call(this,a)},b.exports=d},{"../utils":32,"./GenericWorker":28}],27:[function(a,b,c){"use strict";function d(a){f.call(this,"DataWorker");var b=this;this.dataIsReady=!1,this.index=0,this.max=0,this.data=null,this.type="",this._tickScheduled=!1,a.then(function(a){b.dataIsReady=!0,b.data=a,b.max=a&&a.length||0,b.type=e.getTypeOf(a),b.isPaused||b._tickAndRepeat()},function(a){b.error(a)})}var e=a("../utils"),f=a("./GenericWorker"),g=16384;e.inherits(d,f),d.prototype.cleanUp=function(){f.prototype.cleanUp.call(this),this.data=null},d.prototype.resume=function(){return!!f.prototype.resume.call(this)&&(!this._tickScheduled&&this.dataIsReady&&(this._tickScheduled=!0,e.delay(this._tickAndRepeat,[],this)),!0)},d.prototype._tickAndRepeat=function(){this._tickScheduled=!1,this.isPaused||this.isFinished||(this._tick(),this.isFinished||(e.delay(this._tickAndRepeat,[],this),this._tickScheduled=!0))},d.prototype._tick=function(){if(this.isPaused||this.isFinished)return!1;var a=g,b=null,c=Math.min(this.max,this.index+a);if(this.index>=this.max)return this.end();switch(this.type){case"string":b=this.data.substring(this.index,c);break;case"uint8array":b=this.data.subarray(this.index,c);break;case"array":case"nodebuffer":b=this.data.slice(this.index,c)}return this.index=c,this.push({data:b,meta:{percent:this.max?this.index/this.max*100:0}})},b.exports=d},{"../utils":32,"./GenericWorker":28}],28:[function(a,b,c){"use strict";function d(a){this.name=a||"default",this.streamInfo={},this.generatedError=null,this.extraStreamInfo={},this.isPaused=!0,this.isFinished=!1,this.isLocked=!1,this._listeners={data:[],end:[],error:[]},this.previous=null}d.prototype={push:function(a){this.emit("data",a)},end:function(){if(this.isFinished)return!1;this.flush();try{this.emit("end"),this.cleanUp(),this.isFinished=!0}catch(a){this.emit("error",a)}return!0},error:function(a){return!this.isFinished&&(this.isPaused?this.generatedError=a:(this.isFinished=!0,this.emit("error",a),this.previous&&this.previous.error(a),this.cleanUp()),!0)},on:function(a,b){return this._listeners[a].push(b),this},cleanUp:function(){this.streamInfo=this.generatedError=this.extraStreamInfo=null,this._listeners=[]},emit:function(a,b){if(this._listeners[a])for(var c=0;c<this._listeners[a].length;c++)this._listeners[a][c].call(this,b)},pipe:function(a){return a.registerPrevious(this)},registerPrevious:function(a){if(this.isLocked)throw new Error("The stream '"+this+"' has already been used.");this.streamInfo=a.streamInfo,this.mergeStreamInfo(),this.previous=a;var b=this;return a.on("data",function(a){b.processChunk(a)}),a.on("end",function(){b.end()}),a.on("error",function(a){b.error(a)}),this},pause:function(){return!this.isPaused&&!this.isFinished&&(this.isPaused=!0,this.previous&&this.previous.pause(),!0)},resume:function(){if(!this.isPaused||this.isFinished)return!1;this.isPaused=!1;var a=!1;return this.generatedError&&(this.error(this.generatedError),a=!0),this.previous&&this.previous.resume(),!a},flush:function(){},processChunk:function(a){this.push(a)},withStreamInfo:function(a,b){return this.extraStreamInfo[a]=b,this.mergeStreamInfo(),this},mergeStreamInfo:function(){for(var a in this.extraStreamInfo)this.extraStreamInfo.hasOwnProperty(a)&&(this.streamInfo[a]=this.extraStreamInfo[a])},lock:function(){if(this.isLocked)throw new Error("The stream '"+this+"' has already been used.");this.isLocked=!0,this.previous&&this.previous.lock()},toString:function(){var a="Worker "+this.name;return this.previous?this.previous+" -> "+a:a}},b.exports=d},{}],29:[function(a,b,c){"use strict";function d(a,b,c){switch(a){case"blob":return h.newBlob(h.transformTo("arraybuffer",b),c);case"base64":return k.encode(b);default:return h.transformTo(a,b)}}function e(a,b){var c,d=0,e=null,f=0;for(c=0;c<b.length;c++)f+=b[c].length;switch(a){case"string":return b.join("");case"array":return Array.prototype.concat.apply([],b);case"uint8array":for(e=new Uint8Array(f),c=0;c<b.length;c++)e.set(b[c],d),d+=b[c].length;return e;case"nodebuffer":return Buffer.concat(b);default:throw new Error("concat : unsupported type '"+a+"'")}}function f(a,b){return new m.Promise(function(c,f){var g=[],h=a._internalType,i=a._outputType,j=a._mimeType;a.on("data",function(a,c){g.push(a),b&&b(c)}).on("error",function(a){g=[],f(a)}).on("end",function(){try{var a=d(i,e(h,g),j);c(a)}catch(b){f(b)}g=[]}).resume()})}function g(a,b,c){var d=b;switch(b){case"blob":case"arraybuffer":d="uint8array";break;case"base64":d="string"}try{this._internalType=d,this._outputType=b,this._mimeType=c,h.checkSupport(d),this._worker=a.pipe(new i(d)),a.lock()}catch(e){this._worker=new j("error"),this._worker.error(e)}}var h=a("../utils"),i=a("./ConvertWorker"),j=a("./GenericWorker"),k=a("../base64"),l=a("../support"),m=a("../external"),n=null;if(l.nodestream)try{n=a("../nodejs/NodejsStreamOutputAdapter")}catch(o){}g.prototype={accumulate:function(a){return f(this,a)},on:function(a,b){var c=this;return"data"===a?this._worker.on(a,function(a){b.call(c,a.data,a.meta)}):this._worker.on(a,function(){h.delay(b,arguments,c)}),this},resume:function(){return h.delay(this._worker.resume,[],this._worker),this},pause:function(){return this._worker.pause(),this},toNodejsStream:function(a){if(h.checkSupport("nodestream"),"nodebuffer"!==this._outputType)throw new Error(this._outputType+" is not supported by this method");return new n(this,{objectMode:"nodebuffer"!==this._outputType},a)}},b.exports=g},{"../base64":1,"../external":6,"../nodejs/NodejsStreamOutputAdapter":13,"../support":30,"../utils":32,"./ConvertWorker":24,"./GenericWorker":28}],30:[function(a,b,c){"use strict";if(c.base64=!0,c.array=!0,c.string=!0,c.arraybuffer="undefined"!=typeof ArrayBuffer&&"undefined"!=typeof Uint8Array,c.nodebuffer="undefined"!=typeof Buffer,c.uint8array="undefined"!=typeof Uint8Array,"undefined"==typeof ArrayBuffer)c.blob=!1;else{var d=new ArrayBuffer(0);try{c.blob=0===new Blob([d],{type:"application/zip"}).size}catch(e){try{var f=self.BlobBuilder||self.WebKitBlobBuilder||self.MozBlobBuilder||self.MSBlobBuilder,g=new f;g.append(d),c.blob=0===g.getBlob("application/zip").size}catch(e){c.blob=!1}}}try{c.nodestream=!!a("readable-stream").Readable}catch(e){c.nodestream=!1}},{"readable-stream":16}],31:[function(a,b,c){"use strict";function d(){i.call(this,"utf-8 decode"),this.leftOver=null}function e(){i.call(this,"utf-8 encode")}for(var f=a("./utils"),g=a("./support"),h=a("./nodejsUtils"),i=a("./stream/GenericWorker"),j=new Array(256),k=0;k<256;k++)j[k]=k>=252?6:k>=248?5:k>=240?4:k>=224?3:k>=192?2:1;j[254]=j[254]=1;var l=function(a){var b,c,d,e,f,h=a.length,i=0;for(e=0;e<h;e++)c=a.charCodeAt(e),55296===(64512&c)&&e+1<h&&(d=a.charCodeAt(e+1),56320===(64512&d)&&(c=65536+(c-55296<<10)+(d-56320),e++)),i+=c<128?1:c<2048?2:c<65536?3:4;for(b=g.uint8array?new Uint8Array(i):new Array(i),f=0,e=0;f<i;e++)c=a.charCodeAt(e),55296===(64512&c)&&e+1<h&&(d=a.charCodeAt(e+1),56320===(64512&d)&&(c=65536+(c-55296<<10)+(d-56320),e++)),c<128?b[f++]=c:c<2048?(b[f++]=192|c>>>6,b[f++]=128|63&c):c<65536?(b[f++]=224|c>>>12,b[f++]=128|c>>>6&63,b[f++]=128|63&c):(b[f++]=240|c>>>18,b[f++]=128|c>>>12&63,b[f++]=128|c>>>6&63,b[f++]=128|63&c);return b},m=function(a,b){var c;for(b=b||a.length,b>a.length&&(b=a.length),c=b-1;c>=0&&128===(192&a[c]);)c--;return c<0?b:0===c?b:c+j[a[c]]>b?c:b},n=function(a){var b,c,d,e,g=a.length,h=new Array(2*g);for(c=0,b=0;b<g;)if(d=a[b++],d<128)h[c++]=d;else if(e=j[d],e>4)h[c++]=65533,b+=e-1;else{for(d&=2===e?31:3===e?15:7;e>1&&b<g;)d=d<<6|63&a[b++],e--;e>1?h[c++]=65533:d<65536?h[c++]=d:(d-=65536,h[c++]=55296|d>>10&1023,h[c++]=56320|1023&d)}return h.length!==c&&(h.subarray?h=h.subarray(0,c):h.length=c),f.applyFromCharCode(h)};c.utf8encode=function(a){return g.nodebuffer?h.newBufferFrom(a,"utf-8"):l(a)},c.utf8decode=function(a){return g.nodebuffer?f.transformTo("nodebuffer",a).toString("utf-8"):(a=f.transformTo(g.uint8array?"uint8array":"array",a),n(a))},f.inherits(d,i),d.prototype.processChunk=function(a){var b=f.transformTo(g.uint8array?"uint8array":"array",a.data);if(this.leftOver&&this.leftOver.length){if(g.uint8array){var d=b;b=new Uint8Array(d.length+this.leftOver.length),b.set(this.leftOver,0),b.set(d,this.leftOver.length)}else b=this.leftOver.concat(b);this.leftOver=null}var e=m(b),h=b;e!==b.length&&(g.uint8array?(h=b.subarray(0,e),this.leftOver=b.subarray(e,b.length)):(h=b.slice(0,e),this.leftOver=b.slice(e,b.length))),this.push({data:c.utf8decode(h),meta:a.meta})},d.prototype.flush=function(){this.leftOver&&this.leftOver.length&&(this.push({data:c.utf8decode(this.leftOver),meta:{}}),this.leftOver=null)},c.Utf8DecodeWorker=d,f.inherits(e,i),e.prototype.processChunk=function(a){this.push({data:c.utf8encode(a.data),meta:a.meta})},c.Utf8EncodeWorker=e},{"./nodejsUtils":14,"./stream/GenericWorker":28,"./support":30,"./utils":32}],32:[function(a,b,c){"use strict";function d(a){var b=null;return b=i.uint8array?new Uint8Array(a.length):new Array(a.length),f(a,b)}function e(a){return a}function f(a,b){for(var c=0;c<a.length;++c)b[c]=255&a.charCodeAt(c);return b}function g(a){var b=65536,d=c.getTypeOf(a),e=!0;if("uint8array"===d?e=n.applyCanBeUsed.uint8array:"nodebuffer"===d&&(e=n.applyCanBeUsed.nodebuffer),e)for(;b>1;)try{return n.stringifyByChunk(a,d,b)}catch(f){b=Math.floor(b/2)}return n.stringifyByChar(a)}function h(a,b){for(var c=0;c<a.length;c++)b[c]=a[c]; +return b}var i=a("./support"),j=a("./base64"),k=a("./nodejsUtils"),l=a("core-js/library/fn/set-immediate"),m=a("./external");c.newBlob=function(a,b){c.checkSupport("blob");try{return new Blob([a],{type:b})}catch(d){try{var e=self.BlobBuilder||self.WebKitBlobBuilder||self.MozBlobBuilder||self.MSBlobBuilder,f=new e;return f.append(a),f.getBlob(b)}catch(d){throw new Error("Bug : can't construct the Blob.")}}};var n={stringifyByChunk:function(a,b,c){var d=[],e=0,f=a.length;if(f<=c)return String.fromCharCode.apply(null,a);for(;e<f;)"array"===b||"nodebuffer"===b?d.push(String.fromCharCode.apply(null,a.slice(e,Math.min(e+c,f)))):d.push(String.fromCharCode.apply(null,a.subarray(e,Math.min(e+c,f)))),e+=c;return d.join("")},stringifyByChar:function(a){for(var b="",c=0;c<a.length;c++)b+=String.fromCharCode(a[c]);return b},applyCanBeUsed:{uint8array:function(){try{return i.uint8array&&1===String.fromCharCode.apply(null,new Uint8Array(1)).length}catch(a){return!1}}(),nodebuffer:function(){try{return i.nodebuffer&&1===String.fromCharCode.apply(null,k.allocBuffer(1)).length}catch(a){return!1}}()}};c.applyFromCharCode=g;var o={};o.string={string:e,array:function(a){return f(a,new Array(a.length))},arraybuffer:function(a){return o.string.uint8array(a).buffer},uint8array:function(a){return f(a,new Uint8Array(a.length))},nodebuffer:function(a){return f(a,k.allocBuffer(a.length))}},o.array={string:g,array:e,arraybuffer:function(a){return new Uint8Array(a).buffer},uint8array:function(a){return new Uint8Array(a)},nodebuffer:function(a){return k.newBufferFrom(a)}},o.arraybuffer={string:function(a){return g(new Uint8Array(a))},array:function(a){return h(new Uint8Array(a),new Array(a.byteLength))},arraybuffer:e,uint8array:function(a){return new Uint8Array(a)},nodebuffer:function(a){return k.newBufferFrom(new Uint8Array(a))}},o.uint8array={string:g,array:function(a){return h(a,new Array(a.length))},arraybuffer:function(a){return a.buffer},uint8array:e,nodebuffer:function(a){return k.newBufferFrom(a)}},o.nodebuffer={string:g,array:function(a){return h(a,new Array(a.length))},arraybuffer:function(a){return o.nodebuffer.uint8array(a).buffer},uint8array:function(a){return h(a,new Uint8Array(a.length))},nodebuffer:e},c.transformTo=function(a,b){if(b||(b=""),!a)return b;c.checkSupport(a);var d=c.getTypeOf(b),e=o[d][a](b);return e},c.getTypeOf=function(a){return"string"==typeof a?"string":"[object Array]"===Object.prototype.toString.call(a)?"array":i.nodebuffer&&k.isBuffer(a)?"nodebuffer":i.uint8array&&a instanceof Uint8Array?"uint8array":i.arraybuffer&&a instanceof ArrayBuffer?"arraybuffer":void 0},c.checkSupport=function(a){var b=i[a.toLowerCase()];if(!b)throw new Error(a+" is not supported by this platform")},c.MAX_VALUE_16BITS=65535,c.MAX_VALUE_32BITS=-1,c.pretty=function(a){var b,c,d="";for(c=0;c<(a||"").length;c++)b=a.charCodeAt(c),d+="\\x"+(b<16?"0":"")+b.toString(16).toUpperCase();return d},c.delay=function(a,b,c){l(function(){a.apply(c||null,b||[])})},c.inherits=function(a,b){var c=function(){};c.prototype=b.prototype,a.prototype=new c},c.extend=function(){var a,b,c={};for(a=0;a<arguments.length;a++)for(b in arguments[a])arguments[a].hasOwnProperty(b)&&"undefined"==typeof c[b]&&(c[b]=arguments[a][b]);return c},c.prepareContent=function(a,b,e,f,g){var h=m.Promise.resolve(b).then(function(a){var b=i.blob&&(a instanceof Blob||["[object File]","[object Blob]"].indexOf(Object.prototype.toString.call(a))!==-1);return b&&"undefined"!=typeof FileReader?new m.Promise(function(b,c){var d=new FileReader;d.onload=function(a){b(a.target.result)},d.onerror=function(a){c(a.target.error)},d.readAsArrayBuffer(a)}):a});return h.then(function(b){var h=c.getTypeOf(b);return h?("arraybuffer"===h?b=c.transformTo("uint8array",b):"string"===h&&(g?b=j.decode(b):e&&f!==!0&&(b=d(b))),b):m.Promise.reject(new Error("Can't read the data of '"+a+"'. Is it in a supported JavaScript type (String, Blob, ArrayBuffer, etc) ?"))})}},{"./base64":1,"./external":6,"./nodejsUtils":14,"./support":30,"core-js/library/fn/set-immediate":36}],33:[function(a,b,c){"use strict";function d(a){this.files=[],this.loadOptions=a}var e=a("./reader/readerFor"),f=a("./utils"),g=a("./signature"),h=a("./zipEntry"),i=(a("./utf8"),a("./support"));d.prototype={checkSignature:function(a){if(!this.reader.readAndCheckSignature(a)){this.reader.index-=4;var b=this.reader.readString(4);throw new Error("Corrupted zip or bug: unexpected signature ("+f.pretty(b)+", expected "+f.pretty(a)+")")}},isSignature:function(a,b){var c=this.reader.index;this.reader.setIndex(a);var d=this.reader.readString(4),e=d===b;return this.reader.setIndex(c),e},readBlockEndOfCentral:function(){this.diskNumber=this.reader.readInt(2),this.diskWithCentralDirStart=this.reader.readInt(2),this.centralDirRecordsOnThisDisk=this.reader.readInt(2),this.centralDirRecords=this.reader.readInt(2),this.centralDirSize=this.reader.readInt(4),this.centralDirOffset=this.reader.readInt(4),this.zipCommentLength=this.reader.readInt(2);var a=this.reader.readData(this.zipCommentLength),b=i.uint8array?"uint8array":"array",c=f.transformTo(b,a);this.zipComment=this.loadOptions.decodeFileName(c)},readBlockZip64EndOfCentral:function(){this.zip64EndOfCentralSize=this.reader.readInt(8),this.reader.skip(4),this.diskNumber=this.reader.readInt(4),this.diskWithCentralDirStart=this.reader.readInt(4),this.centralDirRecordsOnThisDisk=this.reader.readInt(8),this.centralDirRecords=this.reader.readInt(8),this.centralDirSize=this.reader.readInt(8),this.centralDirOffset=this.reader.readInt(8),this.zip64ExtensibleData={};for(var a,b,c,d=this.zip64EndOfCentralSize-44,e=0;e<d;)a=this.reader.readInt(2),b=this.reader.readInt(4),c=this.reader.readData(b),this.zip64ExtensibleData[a]={id:a,length:b,value:c}},readBlockZip64EndOfCentralLocator:function(){if(this.diskWithZip64CentralDirStart=this.reader.readInt(4),this.relativeOffsetEndOfZip64CentralDir=this.reader.readInt(8),this.disksCount=this.reader.readInt(4),this.disksCount>1)throw new Error("Multi-volumes zip are not supported")},readLocalFiles:function(){var a,b;for(a=0;a<this.files.length;a++)b=this.files[a],this.reader.setIndex(b.localHeaderOffset),this.checkSignature(g.LOCAL_FILE_HEADER),b.readLocalPart(this.reader),b.handleUTF8(),b.processAttributes()},readCentralDir:function(){var a;for(this.reader.setIndex(this.centralDirOffset);this.reader.readAndCheckSignature(g.CENTRAL_FILE_HEADER);)a=new h({zip64:this.zip64},this.loadOptions),a.readCentralPart(this.reader),this.files.push(a);if(this.centralDirRecords!==this.files.length&&0!==this.centralDirRecords&&0===this.files.length)throw new Error("Corrupted zip or bug: expected "+this.centralDirRecords+" records in central dir, got "+this.files.length)},readEndOfCentral:function(){var a=this.reader.lastIndexOfSignature(g.CENTRAL_DIRECTORY_END);if(a<0){var b=!this.isSignature(0,g.LOCAL_FILE_HEADER);throw b?new Error("Can't find end of central directory : is this a zip file ? If it is, see https://stuk.github.io/jszip/documentation/howto/read_zip.html"):new Error("Corrupted zip: can't find end of central directory")}this.reader.setIndex(a);var c=a;if(this.checkSignature(g.CENTRAL_DIRECTORY_END),this.readBlockEndOfCentral(),this.diskNumber===f.MAX_VALUE_16BITS||this.diskWithCentralDirStart===f.MAX_VALUE_16BITS||this.centralDirRecordsOnThisDisk===f.MAX_VALUE_16BITS||this.centralDirRecords===f.MAX_VALUE_16BITS||this.centralDirSize===f.MAX_VALUE_32BITS||this.centralDirOffset===f.MAX_VALUE_32BITS){if(this.zip64=!0,a=this.reader.lastIndexOfSignature(g.ZIP64_CENTRAL_DIRECTORY_LOCATOR),a<0)throw new Error("Corrupted zip: can't find the ZIP64 end of central directory locator");if(this.reader.setIndex(a),this.checkSignature(g.ZIP64_CENTRAL_DIRECTORY_LOCATOR),this.readBlockZip64EndOfCentralLocator(),!this.isSignature(this.relativeOffsetEndOfZip64CentralDir,g.ZIP64_CENTRAL_DIRECTORY_END)&&(this.relativeOffsetEndOfZip64CentralDir=this.reader.lastIndexOfSignature(g.ZIP64_CENTRAL_DIRECTORY_END),this.relativeOffsetEndOfZip64CentralDir<0))throw new Error("Corrupted zip: can't find the ZIP64 end of central directory");this.reader.setIndex(this.relativeOffsetEndOfZip64CentralDir),this.checkSignature(g.ZIP64_CENTRAL_DIRECTORY_END),this.readBlockZip64EndOfCentral()}var d=this.centralDirOffset+this.centralDirSize;this.zip64&&(d+=20,d+=12+this.zip64EndOfCentralSize);var e=c-d;if(e>0)this.isSignature(c,g.CENTRAL_FILE_HEADER)||(this.reader.zero=e);else if(e<0)throw new Error("Corrupted zip: missing "+Math.abs(e)+" bytes.")},prepareReader:function(a){this.reader=e(a)},load:function(a){this.prepareReader(a),this.readEndOfCentral(),this.readCentralDir(),this.readLocalFiles()}},b.exports=d},{"./reader/readerFor":22,"./signature":23,"./support":30,"./utf8":31,"./utils":32,"./zipEntry":34}],34:[function(a,b,c){"use strict";function d(a,b){this.options=a,this.loadOptions=b}var e=a("./reader/readerFor"),f=a("./utils"),g=a("./compressedObject"),h=a("./crc32"),i=a("./utf8"),j=a("./compressions"),k=a("./support"),l=0,m=3,n=function(a){for(var b in j)if(j.hasOwnProperty(b)&&j[b].magic===a)return j[b];return null};d.prototype={isEncrypted:function(){return 1===(1&this.bitFlag)},useUTF8:function(){return 2048===(2048&this.bitFlag)},readLocalPart:function(a){var b,c;if(a.skip(22),this.fileNameLength=a.readInt(2),c=a.readInt(2),this.fileName=a.readData(this.fileNameLength),a.skip(c),this.compressedSize===-1||this.uncompressedSize===-1)throw new Error("Bug or corrupted zip : didn't get enough informations from the central directory (compressedSize === -1 || uncompressedSize === -1)");if(b=n(this.compressionMethod),null===b)throw new Error("Corrupted zip : compression "+f.pretty(this.compressionMethod)+" unknown (inner file : "+f.transformTo("string",this.fileName)+")");this.decompressed=new g(this.compressedSize,this.uncompressedSize,this.crc32,b,a.readData(this.compressedSize))},readCentralPart:function(a){this.versionMadeBy=a.readInt(2),a.skip(2),this.bitFlag=a.readInt(2),this.compressionMethod=a.readString(2),this.date=a.readDate(),this.crc32=a.readInt(4),this.compressedSize=a.readInt(4),this.uncompressedSize=a.readInt(4);var b=a.readInt(2);if(this.extraFieldsLength=a.readInt(2),this.fileCommentLength=a.readInt(2),this.diskNumberStart=a.readInt(2),this.internalFileAttributes=a.readInt(2),this.externalFileAttributes=a.readInt(4),this.localHeaderOffset=a.readInt(4),this.isEncrypted())throw new Error("Encrypted zip are not supported");a.skip(b),this.readExtraFields(a),this.parseZIP64ExtraField(a),this.fileComment=a.readData(this.fileCommentLength)},processAttributes:function(){this.unixPermissions=null,this.dosPermissions=null;var a=this.versionMadeBy>>8;this.dir=!!(16&this.externalFileAttributes),a===l&&(this.dosPermissions=63&this.externalFileAttributes),a===m&&(this.unixPermissions=this.externalFileAttributes>>16&65535),this.dir||"/"!==this.fileNameStr.slice(-1)||(this.dir=!0)},parseZIP64ExtraField:function(a){if(this.extraFields[1]){var b=e(this.extraFields[1].value);this.uncompressedSize===f.MAX_VALUE_32BITS&&(this.uncompressedSize=b.readInt(8)),this.compressedSize===f.MAX_VALUE_32BITS&&(this.compressedSize=b.readInt(8)),this.localHeaderOffset===f.MAX_VALUE_32BITS&&(this.localHeaderOffset=b.readInt(8)),this.diskNumberStart===f.MAX_VALUE_32BITS&&(this.diskNumberStart=b.readInt(4))}},readExtraFields:function(a){var b,c,d,e=a.index+this.extraFieldsLength;for(this.extraFields||(this.extraFields={});a.index<e;)b=a.readInt(2),c=a.readInt(2),d=a.readData(c),this.extraFields[b]={id:b,length:c,value:d}},handleUTF8:function(){var a=k.uint8array?"uint8array":"array";if(this.useUTF8())this.fileNameStr=i.utf8decode(this.fileName),this.fileCommentStr=i.utf8decode(this.fileComment);else{var b=this.findExtraFieldUnicodePath();if(null!==b)this.fileNameStr=b;else{var c=f.transformTo(a,this.fileName);this.fileNameStr=this.loadOptions.decodeFileName(c)}var d=this.findExtraFieldUnicodeComment();if(null!==d)this.fileCommentStr=d;else{var e=f.transformTo(a,this.fileComment);this.fileCommentStr=this.loadOptions.decodeFileName(e)}}},findExtraFieldUnicodePath:function(){var a=this.extraFields[28789];if(a){var b=e(a.value);return 1!==b.readInt(1)?null:h(this.fileName)!==b.readInt(4)?null:i.utf8decode(b.readData(a.length-5))}return null},findExtraFieldUnicodeComment:function(){var a=this.extraFields[25461];if(a){var b=e(a.value);return 1!==b.readInt(1)?null:h(this.fileComment)!==b.readInt(4)?null:i.utf8decode(b.readData(a.length-5))}return null}},b.exports=d},{"./compressedObject":2,"./compressions":3,"./crc32":4,"./reader/readerFor":22,"./support":30,"./utf8":31,"./utils":32}],35:[function(a,b,c){"use strict";var d=a("./stream/StreamHelper"),e=a("./stream/DataWorker"),f=a("./utf8"),g=a("./compressedObject"),h=a("./stream/GenericWorker"),i=function(a,b,c){this.name=a,this.dir=c.dir,this.date=c.date,this.comment=c.comment,this.unixPermissions=c.unixPermissions,this.dosPermissions=c.dosPermissions,this._data=b,this._dataBinary=c.binary,this.options={compression:c.compression,compressionOptions:c.compressionOptions}};i.prototype={internalStream:function(a){var b=null,c="string";try{if(!a)throw new Error("No output type specified.");c=a.toLowerCase();var e="string"===c||"text"===c;"binarystring"!==c&&"text"!==c||(c="string"),b=this._decompressWorker();var g=!this._dataBinary;g&&!e&&(b=b.pipe(new f.Utf8EncodeWorker)),!g&&e&&(b=b.pipe(new f.Utf8DecodeWorker))}catch(i){b=new h("error"),b.error(i)}return new d(b,c,"")},async:function(a,b){return this.internalStream(a).accumulate(b)},nodeStream:function(a,b){return this.internalStream(a||"nodebuffer").toNodejsStream(b)},_compressWorker:function(a,b){if(this._data instanceof g&&this._data.compression.magic===a.magic)return this._data.getCompressedWorker();var c=this._decompressWorker();return this._dataBinary||(c=c.pipe(new f.Utf8EncodeWorker)),g.createWorkerFrom(c,a,b)},_decompressWorker:function(){return this._data instanceof g?this._data.getContentWorker():this._data instanceof h?this._data:new e(this._data)}};for(var j=["asText","asBinary","asNodeBuffer","asUint8Array","asArrayBuffer"],k=function(){throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.")},l=0;l<j.length;l++)i.prototype[j[l]]=k;b.exports=i},{"./compressedObject":2,"./stream/DataWorker":27,"./stream/GenericWorker":28,"./stream/StreamHelper":29,"./utf8":31}],36:[function(a,b,c){a("../modules/web.immediate"),b.exports=a("../modules/_core").setImmediate},{"../modules/_core":40,"../modules/web.immediate":56}],37:[function(a,b,c){b.exports=function(a){if("function"!=typeof a)throw TypeError(a+" is not a function!");return a}},{}],38:[function(a,b,c){var d=a("./_is-object");b.exports=function(a){if(!d(a))throw TypeError(a+" is not an object!");return a}},{"./_is-object":51}],39:[function(a,b,c){var d={}.toString;b.exports=function(a){return d.call(a).slice(8,-1)}},{}],40:[function(a,b,c){var d=b.exports={version:"2.3.0"};"number"==typeof __e&&(__e=d)},{}],41:[function(a,b,c){var d=a("./_a-function");b.exports=function(a,b,c){if(d(a),void 0===b)return a;switch(c){case 1:return function(c){return a.call(b,c)};case 2:return function(c,d){return a.call(b,c,d)};case 3:return function(c,d,e){return a.call(b,c,d,e)}}return function(){return a.apply(b,arguments)}}},{"./_a-function":37}],42:[function(a,b,c){b.exports=!a("./_fails")(function(){return 7!=Object.defineProperty({},"a",{get:function(){return 7}}).a})},{"./_fails":45}],43:[function(a,b,c){var d=a("./_is-object"),e=a("./_global").document,f=d(e)&&d(e.createElement);b.exports=function(a){return f?e.createElement(a):{}}},{"./_global":46,"./_is-object":51}],44:[function(a,b,c){var d=a("./_global"),e=a("./_core"),f=a("./_ctx"),g=a("./_hide"),h="prototype",i=function(a,b,c){var j,k,l,m=a&i.F,n=a&i.G,o=a&i.S,p=a&i.P,q=a&i.B,r=a&i.W,s=n?e:e[b]||(e[b]={}),t=s[h],u=n?d:o?d[b]:(d[b]||{})[h];n&&(c=b);for(j in c)k=!m&&u&&void 0!==u[j],k&&j in s||(l=k?u[j]:c[j],s[j]=n&&"function"!=typeof u[j]?c[j]:q&&k?f(l,d):r&&u[j]==l?function(a){var b=function(b,c,d){if(this instanceof a){switch(arguments.length){case 0:return new a;case 1:return new a(b);case 2:return new a(b,c)}return new a(b,c,d)}return a.apply(this,arguments)};return b[h]=a[h],b}(l):p&&"function"==typeof l?f(Function.call,l):l,p&&((s.virtual||(s.virtual={}))[j]=l,a&i.R&&t&&!t[j]&&g(t,j,l)))};i.F=1,i.G=2,i.S=4,i.P=8,i.B=16,i.W=32,i.U=64,i.R=128,b.exports=i},{"./_core":40,"./_ctx":41,"./_global":46,"./_hide":47}],45:[function(a,b,c){b.exports=function(a){try{return!!a()}catch(b){return!0}}},{}],46:[function(a,b,c){var d=b.exports="undefined"!=typeof window&&window.Math==Math?window:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")();"number"==typeof __g&&(__g=d)},{}],47:[function(a,b,c){var d=a("./_object-dp"),e=a("./_property-desc");b.exports=a("./_descriptors")?function(a,b,c){return d.f(a,b,e(1,c))}:function(a,b,c){return a[b]=c,a}},{"./_descriptors":42,"./_object-dp":52,"./_property-desc":53}],48:[function(a,b,c){b.exports=a("./_global").document&&document.documentElement},{"./_global":46}],49:[function(a,b,c){b.exports=!a("./_descriptors")&&!a("./_fails")(function(){return 7!=Object.defineProperty(a("./_dom-create")("div"),"a",{get:function(){return 7}}).a})},{"./_descriptors":42,"./_dom-create":43,"./_fails":45}],50:[function(a,b,c){b.exports=function(a,b,c){var d=void 0===c;switch(b.length){case 0:return d?a():a.call(c);case 1:return d?a(b[0]):a.call(c,b[0]);case 2:return d?a(b[0],b[1]):a.call(c,b[0],b[1]);case 3:return d?a(b[0],b[1],b[2]):a.call(c,b[0],b[1],b[2]);case 4:return d?a(b[0],b[1],b[2],b[3]):a.call(c,b[0],b[1],b[2],b[3])}return a.apply(c,b)}},{}],51:[function(a,b,c){b.exports=function(a){return"object"==typeof a?null!==a:"function"==typeof a}},{}],52:[function(a,b,c){var d=a("./_an-object"),e=a("./_ie8-dom-define"),f=a("./_to-primitive"),g=Object.defineProperty;c.f=a("./_descriptors")?Object.defineProperty:function(a,b,c){if(d(a),b=f(b,!0),d(c),e)try{return g(a,b,c)}catch(h){}if("get"in c||"set"in c)throw TypeError("Accessors not supported!");return"value"in c&&(a[b]=c.value),a}},{"./_an-object":38,"./_descriptors":42,"./_ie8-dom-define":49,"./_to-primitive":55}],53:[function(a,b,c){b.exports=function(a,b){return{enumerable:!(1&a),configurable:!(2&a),writable:!(4&a),value:b}}},{}],54:[function(a,b,c){var d,e,f,g=a("./_ctx"),h=a("./_invoke"),i=a("./_html"),j=a("./_dom-create"),k=a("./_global"),l=k.process,m=k.setImmediate,n=k.clearImmediate,o=k.MessageChannel,p=0,q={},r="onreadystatechange",s=function(){var a=+this;if(q.hasOwnProperty(a)){var b=q[a];delete q[a],b()}},t=function(a){s.call(a.data)};m&&n||(m=function(a){for(var b=[],c=1;arguments.length>c;)b.push(arguments[c++]);return q[++p]=function(){h("function"==typeof a?a:Function(a),b)},d(p),p},n=function(a){delete q[a]},"process"==a("./_cof")(l)?d=function(a){l.nextTick(g(s,a,1))}:o?(e=new o,f=e.port2,e.port1.onmessage=t,d=g(f.postMessage,f,1)):k.addEventListener&&"function"==typeof postMessage&&!k.importScripts?(d=function(a){k.postMessage(a+"","*")},k.addEventListener("message",t,!1)):d=r in j("script")?function(a){i.appendChild(j("script"))[r]=function(){i.removeChild(this),s.call(a)}}:function(a){setTimeout(g(s,a,1),0)}),b.exports={set:m,clear:n}},{"./_cof":39,"./_ctx":41,"./_dom-create":43,"./_global":46,"./_html":48,"./_invoke":50}],55:[function(a,b,c){var d=a("./_is-object");b.exports=function(a,b){if(!d(a))return a;var c,e;if(b&&"function"==typeof(c=a.toString)&&!d(e=c.call(a)))return e;if("function"==typeof(c=a.valueOf)&&!d(e=c.call(a)))return e;if(!b&&"function"==typeof(c=a.toString)&&!d(e=c.call(a)))return e;throw TypeError("Can't convert object to primitive value")}},{"./_is-object":51}],56:[function(a,b,c){var d=a("./_export"),e=a("./_task");d(d.G+d.B,{setImmediate:e.set,clearImmediate:e.clear})},{"./_export":44,"./_task":54}],57:[function(a,b,c){(function(a){"use strict";function c(){k=!0;for(var a,b,c=l.length;c;){for(b=l,l=[],a=-1;++a<c;)b[a]();c=l.length}k=!1}function d(a){1!==l.push(a)||k||e()}var e,f=a.MutationObserver||a.WebKitMutationObserver;if(f){var g=0,h=new f(c),i=a.document.createTextNode("");h.observe(i,{characterData:!0}),e=function(){i.data=g=++g%2}}else if(a.setImmediate||"undefined"==typeof a.MessageChannel)e="document"in a&&"onreadystatechange"in a.document.createElement("script")?function(){var b=a.document.createElement("script");b.onreadystatechange=function(){c(),b.onreadystatechange=null,b.parentNode.removeChild(b),b=null},a.document.documentElement.appendChild(b)}:function(){setTimeout(c,0)};else{var j=new a.MessageChannel;j.port1.onmessage=c,e=function(){j.port2.postMessage(0)}}var k,l=[];b.exports=d}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],58:[function(a,b,c){"use strict";function d(){}function e(a){if("function"!=typeof a)throw new TypeError("resolver must be a function");this.state=s,this.queue=[],this.outcome=void 0,a!==d&&i(this,a)}function f(a,b,c){this.promise=a,"function"==typeof b&&(this.onFulfilled=b,this.callFulfilled=this.otherCallFulfilled),"function"==typeof c&&(this.onRejected=c,this.callRejected=this.otherCallRejected)}function g(a,b,c){o(function(){var d;try{d=b(c)}catch(e){return p.reject(a,e)}d===a?p.reject(a,new TypeError("Cannot resolve promise with itself")):p.resolve(a,d)})}function h(a){var b=a&&a.then;if(a&&("object"==typeof a||"function"==typeof a)&&"function"==typeof b)return function(){b.apply(a,arguments)}}function i(a,b){function c(b){f||(f=!0,p.reject(a,b))}function d(b){f||(f=!0,p.resolve(a,b))}function e(){b(d,c)}var f=!1,g=j(e);"error"===g.status&&c(g.value)}function j(a,b){var c={};try{c.value=a(b),c.status="success"}catch(d){c.status="error",c.value=d}return c}function k(a){return a instanceof this?a:p.resolve(new this(d),a)}function l(a){var b=new this(d);return p.reject(b,a)}function m(a){function b(a,b){function d(a){g[b]=a,++h!==e||f||(f=!0,p.resolve(j,g))}c.resolve(a).then(d,function(a){f||(f=!0,p.reject(j,a))})}var c=this;if("[object Array]"!==Object.prototype.toString.call(a))return this.reject(new TypeError("must be an array"));var e=a.length,f=!1;if(!e)return this.resolve([]);for(var g=new Array(e),h=0,i=-1,j=new this(d);++i<e;)b(a[i],i);return j}function n(a){function b(a){c.resolve(a).then(function(a){f||(f=!0,p.resolve(h,a))},function(a){f||(f=!0,p.reject(h,a))})}var c=this;if("[object Array]"!==Object.prototype.toString.call(a))return this.reject(new TypeError("must be an array"));var e=a.length,f=!1;if(!e)return this.resolve([]);for(var g=-1,h=new this(d);++g<e;)b(a[g]);return h}var o=a("immediate"),p={},q=["REJECTED"],r=["FULFILLED"],s=["PENDING"];b.exports=e,e.prototype["catch"]=function(a){return this.then(null,a)},e.prototype.then=function(a,b){if("function"!=typeof a&&this.state===r||"function"!=typeof b&&this.state===q)return this;var c=new this.constructor(d);if(this.state!==s){var e=this.state===r?a:b;g(c,e,this.outcome)}else this.queue.push(new f(c,a,b));return c},f.prototype.callFulfilled=function(a){p.resolve(this.promise,a)},f.prototype.otherCallFulfilled=function(a){g(this.promise,this.onFulfilled,a)},f.prototype.callRejected=function(a){p.reject(this.promise,a)},f.prototype.otherCallRejected=function(a){g(this.promise,this.onRejected,a)},p.resolve=function(a,b){var c=j(h,b);if("error"===c.status)return p.reject(a,c.value);var d=c.value;if(d)i(a,d);else{a.state=r,a.outcome=b;for(var e=-1,f=a.queue.length;++e<f;)a.queue[e].callFulfilled(b)}return a},p.reject=function(a,b){a.state=q,a.outcome=b;for(var c=-1,d=a.queue.length;++c<d;)a.queue[c].callRejected(b);return a},e.resolve=k,e.reject=l,e.all=m,e.race=n},{immediate:57}],59:[function(a,b,c){"use strict";var d=a("./lib/utils/common").assign,e=a("./lib/deflate"),f=a("./lib/inflate"),g=a("./lib/zlib/constants"),h={};d(h,e,f,g),b.exports=h},{"./lib/deflate":60,"./lib/inflate":61,"./lib/utils/common":62,"./lib/zlib/constants":65}],60:[function(a,b,c){"use strict";function d(a){if(!(this instanceof d))return new d(a);this.options=i.assign({level:s,method:u,chunkSize:16384,windowBits:15,memLevel:8,strategy:t,to:""},a||{});var b=this.options;b.raw&&b.windowBits>0?b.windowBits=-b.windowBits:b.gzip&&b.windowBits>0&&b.windowBits<16&&(b.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new l,this.strm.avail_out=0;var c=h.deflateInit2(this.strm,b.level,b.method,b.windowBits,b.memLevel,b.strategy);if(c!==p)throw new Error(k[c]);if(b.header&&h.deflateSetHeader(this.strm,b.header),b.dictionary){var e;if(e="string"==typeof b.dictionary?j.string2buf(b.dictionary):"[object ArrayBuffer]"===m.call(b.dictionary)?new Uint8Array(b.dictionary):b.dictionary,c=h.deflateSetDictionary(this.strm,e),c!==p)throw new Error(k[c]);this._dict_set=!0}}function e(a,b){var c=new d(b);if(c.push(a,!0),c.err)throw c.msg||k[c.err];return c.result}function f(a,b){return b=b||{},b.raw=!0,e(a,b)}function g(a,b){return b=b||{},b.gzip=!0,e(a,b)}var h=a("./zlib/deflate"),i=a("./utils/common"),j=a("./utils/strings"),k=a("./zlib/messages"),l=a("./zlib/zstream"),m=Object.prototype.toString,n=0,o=4,p=0,q=1,r=2,s=-1,t=0,u=8;d.prototype.push=function(a,b){var c,d,e=this.strm,f=this.options.chunkSize;if(this.ended)return!1;d=b===~~b?b:b===!0?o:n,"string"==typeof a?e.input=j.string2buf(a):"[object ArrayBuffer]"===m.call(a)?e.input=new Uint8Array(a):e.input=a,e.next_in=0,e.avail_in=e.input.length;do{if(0===e.avail_out&&(e.output=new i.Buf8(f),e.next_out=0,e.avail_out=f),c=h.deflate(e,d),c!==q&&c!==p)return this.onEnd(c),this.ended=!0,!1;0!==e.avail_out&&(0!==e.avail_in||d!==o&&d!==r)||("string"===this.options.to?this.onData(j.buf2binstring(i.shrinkBuf(e.output,e.next_out))):this.onData(i.shrinkBuf(e.output,e.next_out)))}while((e.avail_in>0||0===e.avail_out)&&c!==q);return d===o?(c=h.deflateEnd(this.strm),this.onEnd(c),this.ended=!0,c===p):d!==r||(this.onEnd(p),e.avail_out=0,!0)},d.prototype.onData=function(a){this.chunks.push(a)},d.prototype.onEnd=function(a){a===p&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=i.flattenChunks(this.chunks)),this.chunks=[],this.err=a,this.msg=this.strm.msg},c.Deflate=d,c.deflate=e,c.deflateRaw=f,c.gzip=g},{"./utils/common":62,"./utils/strings":63,"./zlib/deflate":67,"./zlib/messages":72,"./zlib/zstream":74}],61:[function(a,b,c){"use strict";function d(a){if(!(this instanceof d))return new d(a);this.options=h.assign({chunkSize:16384,windowBits:0,to:""},a||{});var b=this.options;b.raw&&b.windowBits>=0&&b.windowBits<16&&(b.windowBits=-b.windowBits,0===b.windowBits&&(b.windowBits=-15)),!(b.windowBits>=0&&b.windowBits<16)||a&&a.windowBits||(b.windowBits+=32),b.windowBits>15&&b.windowBits<48&&0===(15&b.windowBits)&&(b.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new l,this.strm.avail_out=0;var c=g.inflateInit2(this.strm,b.windowBits);if(c!==j.Z_OK)throw new Error(k[c]);this.header=new m,g.inflateGetHeader(this.strm,this.header)}function e(a,b){var c=new d(b);if(c.push(a,!0),c.err)throw c.msg||k[c.err];return c.result}function f(a,b){return b=b||{},b.raw=!0,e(a,b)}var g=a("./zlib/inflate"),h=a("./utils/common"),i=a("./utils/strings"),j=a("./zlib/constants"),k=a("./zlib/messages"),l=a("./zlib/zstream"),m=a("./zlib/gzheader"),n=Object.prototype.toString;d.prototype.push=function(a,b){var c,d,e,f,k,l,m=this.strm,o=this.options.chunkSize,p=this.options.dictionary,q=!1;if(this.ended)return!1;d=b===~~b?b:b===!0?j.Z_FINISH:j.Z_NO_FLUSH,"string"==typeof a?m.input=i.binstring2buf(a):"[object ArrayBuffer]"===n.call(a)?m.input=new Uint8Array(a):m.input=a,m.next_in=0,m.avail_in=m.input.length;do{if(0===m.avail_out&&(m.output=new h.Buf8(o),m.next_out=0,m.avail_out=o),c=g.inflate(m,j.Z_NO_FLUSH),c===j.Z_NEED_DICT&&p&&(l="string"==typeof p?i.string2buf(p):"[object ArrayBuffer]"===n.call(p)?new Uint8Array(p):p,c=g.inflateSetDictionary(this.strm,l)),c===j.Z_BUF_ERROR&&q===!0&&(c=j.Z_OK,q=!1),c!==j.Z_STREAM_END&&c!==j.Z_OK)return this.onEnd(c),this.ended=!0,!1;m.next_out&&(0!==m.avail_out&&c!==j.Z_STREAM_END&&(0!==m.avail_in||d!==j.Z_FINISH&&d!==j.Z_SYNC_FLUSH)||("string"===this.options.to?(e=i.utf8border(m.output,m.next_out),f=m.next_out-e,k=i.buf2string(m.output,e),m.next_out=f,m.avail_out=o-f,f&&h.arraySet(m.output,m.output,e,f,0),this.onData(k)):this.onData(h.shrinkBuf(m.output,m.next_out)))),0===m.avail_in&&0===m.avail_out&&(q=!0)}while((m.avail_in>0||0===m.avail_out)&&c!==j.Z_STREAM_END);return c===j.Z_STREAM_END&&(d=j.Z_FINISH),d===j.Z_FINISH?(c=g.inflateEnd(this.strm),this.onEnd(c),this.ended=!0,c===j.Z_OK):d!==j.Z_SYNC_FLUSH||(this.onEnd(j.Z_OK),m.avail_out=0,!0)},d.prototype.onData=function(a){this.chunks.push(a)},d.prototype.onEnd=function(a){a===j.Z_OK&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=h.flattenChunks(this.chunks)),this.chunks=[],this.err=a,this.msg=this.strm.msg},c.Inflate=d,c.inflate=e,c.inflateRaw=f,c.ungzip=e},{"./utils/common":62,"./utils/strings":63,"./zlib/constants":65,"./zlib/gzheader":68,"./zlib/inflate":70,"./zlib/messages":72,"./zlib/zstream":74}],62:[function(a,b,c){"use strict";var d="undefined"!=typeof Uint8Array&&"undefined"!=typeof Uint16Array&&"undefined"!=typeof Int32Array;c.assign=function(a){for(var b=Array.prototype.slice.call(arguments,1);b.length;){var c=b.shift();if(c){if("object"!=typeof c)throw new TypeError(c+"must be non-object");for(var d in c)c.hasOwnProperty(d)&&(a[d]=c[d])}}return a},c.shrinkBuf=function(a,b){return a.length===b?a:a.subarray?a.subarray(0,b):(a.length=b,a)};var e={arraySet:function(a,b,c,d,e){if(b.subarray&&a.subarray)return void a.set(b.subarray(c,c+d),e);for(var f=0;f<d;f++)a[e+f]=b[c+f]},flattenChunks:function(a){var b,c,d,e,f,g;for(d=0,b=0,c=a.length;b<c;b++)d+=a[b].length;for(g=new Uint8Array(d),e=0,b=0,c=a.length;b<c;b++)f=a[b],g.set(f,e),e+=f.length;return g}},f={arraySet:function(a,b,c,d,e){for(var f=0;f<d;f++)a[e+f]=b[c+f]},flattenChunks:function(a){return[].concat.apply([],a)}};c.setTyped=function(a){a?(c.Buf8=Uint8Array,c.Buf16=Uint16Array,c.Buf32=Int32Array,c.assign(c,e)):(c.Buf8=Array,c.Buf16=Array,c.Buf32=Array,c.assign(c,f))},c.setTyped(d)},{}],63:[function(a,b,c){"use strict";function d(a,b){if(b<65537&&(a.subarray&&g||!a.subarray&&f))return String.fromCharCode.apply(null,e.shrinkBuf(a,b));for(var c="",d=0;d<b;d++)c+=String.fromCharCode(a[d]);return c}var e=a("./common"),f=!0,g=!0;try{String.fromCharCode.apply(null,[0])}catch(h){f=!1}try{String.fromCharCode.apply(null,new Uint8Array(1))}catch(h){g=!1}for(var i=new e.Buf8(256),j=0;j<256;j++)i[j]=j>=252?6:j>=248?5:j>=240?4:j>=224?3:j>=192?2:1;i[254]=i[254]=1,c.string2buf=function(a){var b,c,d,f,g,h=a.length,i=0;for(f=0;f<h;f++)c=a.charCodeAt(f),55296===(64512&c)&&f+1<h&&(d=a.charCodeAt(f+1),56320===(64512&d)&&(c=65536+(c-55296<<10)+(d-56320),f++)),i+=c<128?1:c<2048?2:c<65536?3:4;for(b=new e.Buf8(i),g=0,f=0;g<i;f++)c=a.charCodeAt(f),55296===(64512&c)&&f+1<h&&(d=a.charCodeAt(f+1),56320===(64512&d)&&(c=65536+(c-55296<<10)+(d-56320),f++)),c<128?b[g++]=c:c<2048?(b[g++]=192|c>>>6,b[g++]=128|63&c):c<65536?(b[g++]=224|c>>>12,b[g++]=128|c>>>6&63,b[g++]=128|63&c):(b[g++]=240|c>>>18,b[g++]=128|c>>>12&63,b[g++]=128|c>>>6&63,b[g++]=128|63&c);return b},c.buf2binstring=function(a){return d(a,a.length)},c.binstring2buf=function(a){for(var b=new e.Buf8(a.length),c=0,d=b.length;c<d;c++)b[c]=a.charCodeAt(c);return b},c.buf2string=function(a,b){var c,e,f,g,h=b||a.length,j=new Array(2*h);for(e=0,c=0;c<h;)if(f=a[c++],f<128)j[e++]=f;else if(g=i[f],g>4)j[e++]=65533,c+=g-1;else{for(f&=2===g?31:3===g?15:7;g>1&&c<h;)f=f<<6|63&a[c++],g--;g>1?j[e++]=65533:f<65536?j[e++]=f:(f-=65536,j[e++]=55296|f>>10&1023,j[e++]=56320|1023&f)}return d(j,e)},c.utf8border=function(a,b){var c;for(b=b||a.length,b>a.length&&(b=a.length),c=b-1;c>=0&&128===(192&a[c]);)c--;return c<0?b:0===c?b:c+i[a[c]]>b?c:b}},{"./common":62}],64:[function(a,b,c){"use strict";function d(a,b,c,d){for(var e=65535&a|0,f=a>>>16&65535|0,g=0;0!==c;){g=c>2e3?2e3:c,c-=g;do e=e+b[d++]|0,f=f+e|0;while(--g);e%=65521,f%=65521}return e|f<<16|0; +}b.exports=d},{}],65:[function(a,b,c){"use strict";b.exports={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8}},{}],66:[function(a,b,c){"use strict";function d(){for(var a,b=[],c=0;c<256;c++){a=c;for(var d=0;d<8;d++)a=1&a?3988292384^a>>>1:a>>>1;b[c]=a}return b}function e(a,b,c,d){var e=f,g=d+c;a^=-1;for(var h=d;h<g;h++)a=a>>>8^e[255&(a^b[h])];return a^-1}var f=d();b.exports=e},{}],67:[function(a,b,c){"use strict";function d(a,b){return a.msg=I[b],b}function e(a){return(a<<1)-(a>4?9:0)}function f(a){for(var b=a.length;--b>=0;)a[b]=0}function g(a){var b=a.state,c=b.pending;c>a.avail_out&&(c=a.avail_out),0!==c&&(E.arraySet(a.output,b.pending_buf,b.pending_out,c,a.next_out),a.next_out+=c,b.pending_out+=c,a.total_out+=c,a.avail_out-=c,b.pending-=c,0===b.pending&&(b.pending_out=0))}function h(a,b){F._tr_flush_block(a,a.block_start>=0?a.block_start:-1,a.strstart-a.block_start,b),a.block_start=a.strstart,g(a.strm)}function i(a,b){a.pending_buf[a.pending++]=b}function j(a,b){a.pending_buf[a.pending++]=b>>>8&255,a.pending_buf[a.pending++]=255&b}function k(a,b,c,d){var e=a.avail_in;return e>d&&(e=d),0===e?0:(a.avail_in-=e,E.arraySet(b,a.input,a.next_in,e,c),1===a.state.wrap?a.adler=G(a.adler,b,e,c):2===a.state.wrap&&(a.adler=H(a.adler,b,e,c)),a.next_in+=e,a.total_in+=e,e)}function l(a,b){var c,d,e=a.max_chain_length,f=a.strstart,g=a.prev_length,h=a.nice_match,i=a.strstart>a.w_size-la?a.strstart-(a.w_size-la):0,j=a.window,k=a.w_mask,l=a.prev,m=a.strstart+ka,n=j[f+g-1],o=j[f+g];a.prev_length>=a.good_match&&(e>>=2),h>a.lookahead&&(h=a.lookahead);do if(c=b,j[c+g]===o&&j[c+g-1]===n&&j[c]===j[f]&&j[++c]===j[f+1]){f+=2,c++;do;while(j[++f]===j[++c]&&j[++f]===j[++c]&&j[++f]===j[++c]&&j[++f]===j[++c]&&j[++f]===j[++c]&&j[++f]===j[++c]&&j[++f]===j[++c]&&j[++f]===j[++c]&&f<m);if(d=ka-(m-f),f=m-ka,d>g){if(a.match_start=b,g=d,d>=h)break;n=j[f+g-1],o=j[f+g]}}while((b=l[b&k])>i&&0!==--e);return g<=a.lookahead?g:a.lookahead}function m(a){var b,c,d,e,f,g=a.w_size;do{if(e=a.window_size-a.lookahead-a.strstart,a.strstart>=g+(g-la)){E.arraySet(a.window,a.window,g,g,0),a.match_start-=g,a.strstart-=g,a.block_start-=g,c=a.hash_size,b=c;do d=a.head[--b],a.head[b]=d>=g?d-g:0;while(--c);c=g,b=c;do d=a.prev[--b],a.prev[b]=d>=g?d-g:0;while(--c);e+=g}if(0===a.strm.avail_in)break;if(c=k(a.strm,a.window,a.strstart+a.lookahead,e),a.lookahead+=c,a.lookahead+a.insert>=ja)for(f=a.strstart-a.insert,a.ins_h=a.window[f],a.ins_h=(a.ins_h<<a.hash_shift^a.window[f+1])&a.hash_mask;a.insert&&(a.ins_h=(a.ins_h<<a.hash_shift^a.window[f+ja-1])&a.hash_mask,a.prev[f&a.w_mask]=a.head[a.ins_h],a.head[a.ins_h]=f,f++,a.insert--,!(a.lookahead+a.insert<ja)););}while(a.lookahead<la&&0!==a.strm.avail_in)}function n(a,b){var c=65535;for(c>a.pending_buf_size-5&&(c=a.pending_buf_size-5);;){if(a.lookahead<=1){if(m(a),0===a.lookahead&&b===J)return ua;if(0===a.lookahead)break}a.strstart+=a.lookahead,a.lookahead=0;var d=a.block_start+c;if((0===a.strstart||a.strstart>=d)&&(a.lookahead=a.strstart-d,a.strstart=d,h(a,!1),0===a.strm.avail_out))return ua;if(a.strstart-a.block_start>=a.w_size-la&&(h(a,!1),0===a.strm.avail_out))return ua}return a.insert=0,b===M?(h(a,!0),0===a.strm.avail_out?wa:xa):a.strstart>a.block_start&&(h(a,!1),0===a.strm.avail_out)?ua:ua}function o(a,b){for(var c,d;;){if(a.lookahead<la){if(m(a),a.lookahead<la&&b===J)return ua;if(0===a.lookahead)break}if(c=0,a.lookahead>=ja&&(a.ins_h=(a.ins_h<<a.hash_shift^a.window[a.strstart+ja-1])&a.hash_mask,c=a.prev[a.strstart&a.w_mask]=a.head[a.ins_h],a.head[a.ins_h]=a.strstart),0!==c&&a.strstart-c<=a.w_size-la&&(a.match_length=l(a,c)),a.match_length>=ja)if(d=F._tr_tally(a,a.strstart-a.match_start,a.match_length-ja),a.lookahead-=a.match_length,a.match_length<=a.max_lazy_match&&a.lookahead>=ja){a.match_length--;do a.strstart++,a.ins_h=(a.ins_h<<a.hash_shift^a.window[a.strstart+ja-1])&a.hash_mask,c=a.prev[a.strstart&a.w_mask]=a.head[a.ins_h],a.head[a.ins_h]=a.strstart;while(0!==--a.match_length);a.strstart++}else a.strstart+=a.match_length,a.match_length=0,a.ins_h=a.window[a.strstart],a.ins_h=(a.ins_h<<a.hash_shift^a.window[a.strstart+1])&a.hash_mask;else d=F._tr_tally(a,0,a.window[a.strstart]),a.lookahead--,a.strstart++;if(d&&(h(a,!1),0===a.strm.avail_out))return ua}return a.insert=a.strstart<ja-1?a.strstart:ja-1,b===M?(h(a,!0),0===a.strm.avail_out?wa:xa):a.last_lit&&(h(a,!1),0===a.strm.avail_out)?ua:va}function p(a,b){for(var c,d,e;;){if(a.lookahead<la){if(m(a),a.lookahead<la&&b===J)return ua;if(0===a.lookahead)break}if(c=0,a.lookahead>=ja&&(a.ins_h=(a.ins_h<<a.hash_shift^a.window[a.strstart+ja-1])&a.hash_mask,c=a.prev[a.strstart&a.w_mask]=a.head[a.ins_h],a.head[a.ins_h]=a.strstart),a.prev_length=a.match_length,a.prev_match=a.match_start,a.match_length=ja-1,0!==c&&a.prev_length<a.max_lazy_match&&a.strstart-c<=a.w_size-la&&(a.match_length=l(a,c),a.match_length<=5&&(a.strategy===U||a.match_length===ja&&a.strstart-a.match_start>4096)&&(a.match_length=ja-1)),a.prev_length>=ja&&a.match_length<=a.prev_length){e=a.strstart+a.lookahead-ja,d=F._tr_tally(a,a.strstart-1-a.prev_match,a.prev_length-ja),a.lookahead-=a.prev_length-1,a.prev_length-=2;do++a.strstart<=e&&(a.ins_h=(a.ins_h<<a.hash_shift^a.window[a.strstart+ja-1])&a.hash_mask,c=a.prev[a.strstart&a.w_mask]=a.head[a.ins_h],a.head[a.ins_h]=a.strstart);while(0!==--a.prev_length);if(a.match_available=0,a.match_length=ja-1,a.strstart++,d&&(h(a,!1),0===a.strm.avail_out))return ua}else if(a.match_available){if(d=F._tr_tally(a,0,a.window[a.strstart-1]),d&&h(a,!1),a.strstart++,a.lookahead--,0===a.strm.avail_out)return ua}else a.match_available=1,a.strstart++,a.lookahead--}return a.match_available&&(d=F._tr_tally(a,0,a.window[a.strstart-1]),a.match_available=0),a.insert=a.strstart<ja-1?a.strstart:ja-1,b===M?(h(a,!0),0===a.strm.avail_out?wa:xa):a.last_lit&&(h(a,!1),0===a.strm.avail_out)?ua:va}function q(a,b){for(var c,d,e,f,g=a.window;;){if(a.lookahead<=ka){if(m(a),a.lookahead<=ka&&b===J)return ua;if(0===a.lookahead)break}if(a.match_length=0,a.lookahead>=ja&&a.strstart>0&&(e=a.strstart-1,d=g[e],d===g[++e]&&d===g[++e]&&d===g[++e])){f=a.strstart+ka;do;while(d===g[++e]&&d===g[++e]&&d===g[++e]&&d===g[++e]&&d===g[++e]&&d===g[++e]&&d===g[++e]&&d===g[++e]&&e<f);a.match_length=ka-(f-e),a.match_length>a.lookahead&&(a.match_length=a.lookahead)}if(a.match_length>=ja?(c=F._tr_tally(a,1,a.match_length-ja),a.lookahead-=a.match_length,a.strstart+=a.match_length,a.match_length=0):(c=F._tr_tally(a,0,a.window[a.strstart]),a.lookahead--,a.strstart++),c&&(h(a,!1),0===a.strm.avail_out))return ua}return a.insert=0,b===M?(h(a,!0),0===a.strm.avail_out?wa:xa):a.last_lit&&(h(a,!1),0===a.strm.avail_out)?ua:va}function r(a,b){for(var c;;){if(0===a.lookahead&&(m(a),0===a.lookahead)){if(b===J)return ua;break}if(a.match_length=0,c=F._tr_tally(a,0,a.window[a.strstart]),a.lookahead--,a.strstart++,c&&(h(a,!1),0===a.strm.avail_out))return ua}return a.insert=0,b===M?(h(a,!0),0===a.strm.avail_out?wa:xa):a.last_lit&&(h(a,!1),0===a.strm.avail_out)?ua:va}function s(a,b,c,d,e){this.good_length=a,this.max_lazy=b,this.nice_length=c,this.max_chain=d,this.func=e}function t(a){a.window_size=2*a.w_size,f(a.head),a.max_lazy_match=D[a.level].max_lazy,a.good_match=D[a.level].good_length,a.nice_match=D[a.level].nice_length,a.max_chain_length=D[a.level].max_chain,a.strstart=0,a.block_start=0,a.lookahead=0,a.insert=0,a.match_length=a.prev_length=ja-1,a.match_available=0,a.ins_h=0}function u(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=$,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new E.Buf16(2*ha),this.dyn_dtree=new E.Buf16(2*(2*fa+1)),this.bl_tree=new E.Buf16(2*(2*ga+1)),f(this.dyn_ltree),f(this.dyn_dtree),f(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new E.Buf16(ia+1),this.heap=new E.Buf16(2*ea+1),f(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new E.Buf16(2*ea+1),f(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}function v(a){var b;return a&&a.state?(a.total_in=a.total_out=0,a.data_type=Z,b=a.state,b.pending=0,b.pending_out=0,b.wrap<0&&(b.wrap=-b.wrap),b.status=b.wrap?na:sa,a.adler=2===b.wrap?0:1,b.last_flush=J,F._tr_init(b),O):d(a,Q)}function w(a){var b=v(a);return b===O&&t(a.state),b}function x(a,b){return a&&a.state?2!==a.state.wrap?Q:(a.state.gzhead=b,O):Q}function y(a,b,c,e,f,g){if(!a)return Q;var h=1;if(b===T&&(b=6),e<0?(h=0,e=-e):e>15&&(h=2,e-=16),f<1||f>_||c!==$||e<8||e>15||b<0||b>9||g<0||g>X)return d(a,Q);8===e&&(e=9);var i=new u;return a.state=i,i.strm=a,i.wrap=h,i.gzhead=null,i.w_bits=e,i.w_size=1<<i.w_bits,i.w_mask=i.w_size-1,i.hash_bits=f+7,i.hash_size=1<<i.hash_bits,i.hash_mask=i.hash_size-1,i.hash_shift=~~((i.hash_bits+ja-1)/ja),i.window=new E.Buf8(2*i.w_size),i.head=new E.Buf16(i.hash_size),i.prev=new E.Buf16(i.w_size),i.lit_bufsize=1<<f+6,i.pending_buf_size=4*i.lit_bufsize,i.pending_buf=new E.Buf8(i.pending_buf_size),i.d_buf=1*i.lit_bufsize,i.l_buf=3*i.lit_bufsize,i.level=b,i.strategy=g,i.method=c,w(a)}function z(a,b){return y(a,b,$,aa,ba,Y)}function A(a,b){var c,h,k,l;if(!a||!a.state||b>N||b<0)return a?d(a,Q):Q;if(h=a.state,!a.output||!a.input&&0!==a.avail_in||h.status===ta&&b!==M)return d(a,0===a.avail_out?S:Q);if(h.strm=a,c=h.last_flush,h.last_flush=b,h.status===na)if(2===h.wrap)a.adler=0,i(h,31),i(h,139),i(h,8),h.gzhead?(i(h,(h.gzhead.text?1:0)+(h.gzhead.hcrc?2:0)+(h.gzhead.extra?4:0)+(h.gzhead.name?8:0)+(h.gzhead.comment?16:0)),i(h,255&h.gzhead.time),i(h,h.gzhead.time>>8&255),i(h,h.gzhead.time>>16&255),i(h,h.gzhead.time>>24&255),i(h,9===h.level?2:h.strategy>=V||h.level<2?4:0),i(h,255&h.gzhead.os),h.gzhead.extra&&h.gzhead.extra.length&&(i(h,255&h.gzhead.extra.length),i(h,h.gzhead.extra.length>>8&255)),h.gzhead.hcrc&&(a.adler=H(a.adler,h.pending_buf,h.pending,0)),h.gzindex=0,h.status=oa):(i(h,0),i(h,0),i(h,0),i(h,0),i(h,0),i(h,9===h.level?2:h.strategy>=V||h.level<2?4:0),i(h,ya),h.status=sa);else{var m=$+(h.w_bits-8<<4)<<8,n=-1;n=h.strategy>=V||h.level<2?0:h.level<6?1:6===h.level?2:3,m|=n<<6,0!==h.strstart&&(m|=ma),m+=31-m%31,h.status=sa,j(h,m),0!==h.strstart&&(j(h,a.adler>>>16),j(h,65535&a.adler)),a.adler=1}if(h.status===oa)if(h.gzhead.extra){for(k=h.pending;h.gzindex<(65535&h.gzhead.extra.length)&&(h.pending!==h.pending_buf_size||(h.gzhead.hcrc&&h.pending>k&&(a.adler=H(a.adler,h.pending_buf,h.pending-k,k)),g(a),k=h.pending,h.pending!==h.pending_buf_size));)i(h,255&h.gzhead.extra[h.gzindex]),h.gzindex++;h.gzhead.hcrc&&h.pending>k&&(a.adler=H(a.adler,h.pending_buf,h.pending-k,k)),h.gzindex===h.gzhead.extra.length&&(h.gzindex=0,h.status=pa)}else h.status=pa;if(h.status===pa)if(h.gzhead.name){k=h.pending;do{if(h.pending===h.pending_buf_size&&(h.gzhead.hcrc&&h.pending>k&&(a.adler=H(a.adler,h.pending_buf,h.pending-k,k)),g(a),k=h.pending,h.pending===h.pending_buf_size)){l=1;break}l=h.gzindex<h.gzhead.name.length?255&h.gzhead.name.charCodeAt(h.gzindex++):0,i(h,l)}while(0!==l);h.gzhead.hcrc&&h.pending>k&&(a.adler=H(a.adler,h.pending_buf,h.pending-k,k)),0===l&&(h.gzindex=0,h.status=qa)}else h.status=qa;if(h.status===qa)if(h.gzhead.comment){k=h.pending;do{if(h.pending===h.pending_buf_size&&(h.gzhead.hcrc&&h.pending>k&&(a.adler=H(a.adler,h.pending_buf,h.pending-k,k)),g(a),k=h.pending,h.pending===h.pending_buf_size)){l=1;break}l=h.gzindex<h.gzhead.comment.length?255&h.gzhead.comment.charCodeAt(h.gzindex++):0,i(h,l)}while(0!==l);h.gzhead.hcrc&&h.pending>k&&(a.adler=H(a.adler,h.pending_buf,h.pending-k,k)),0===l&&(h.status=ra)}else h.status=ra;if(h.status===ra&&(h.gzhead.hcrc?(h.pending+2>h.pending_buf_size&&g(a),h.pending+2<=h.pending_buf_size&&(i(h,255&a.adler),i(h,a.adler>>8&255),a.adler=0,h.status=sa)):h.status=sa),0!==h.pending){if(g(a),0===a.avail_out)return h.last_flush=-1,O}else if(0===a.avail_in&&e(b)<=e(c)&&b!==M)return d(a,S);if(h.status===ta&&0!==a.avail_in)return d(a,S);if(0!==a.avail_in||0!==h.lookahead||b!==J&&h.status!==ta){var o=h.strategy===V?r(h,b):h.strategy===W?q(h,b):D[h.level].func(h,b);if(o!==wa&&o!==xa||(h.status=ta),o===ua||o===wa)return 0===a.avail_out&&(h.last_flush=-1),O;if(o===va&&(b===K?F._tr_align(h):b!==N&&(F._tr_stored_block(h,0,0,!1),b===L&&(f(h.head),0===h.lookahead&&(h.strstart=0,h.block_start=0,h.insert=0))),g(a),0===a.avail_out))return h.last_flush=-1,O}return b!==M?O:h.wrap<=0?P:(2===h.wrap?(i(h,255&a.adler),i(h,a.adler>>8&255),i(h,a.adler>>16&255),i(h,a.adler>>24&255),i(h,255&a.total_in),i(h,a.total_in>>8&255),i(h,a.total_in>>16&255),i(h,a.total_in>>24&255)):(j(h,a.adler>>>16),j(h,65535&a.adler)),g(a),h.wrap>0&&(h.wrap=-h.wrap),0!==h.pending?O:P)}function B(a){var b;return a&&a.state?(b=a.state.status,b!==na&&b!==oa&&b!==pa&&b!==qa&&b!==ra&&b!==sa&&b!==ta?d(a,Q):(a.state=null,b===sa?d(a,R):O)):Q}function C(a,b){var c,d,e,g,h,i,j,k,l=b.length;if(!a||!a.state)return Q;if(c=a.state,g=c.wrap,2===g||1===g&&c.status!==na||c.lookahead)return Q;for(1===g&&(a.adler=G(a.adler,b,l,0)),c.wrap=0,l>=c.w_size&&(0===g&&(f(c.head),c.strstart=0,c.block_start=0,c.insert=0),k=new E.Buf8(c.w_size),E.arraySet(k,b,l-c.w_size,c.w_size,0),b=k,l=c.w_size),h=a.avail_in,i=a.next_in,j=a.input,a.avail_in=l,a.next_in=0,a.input=b,m(c);c.lookahead>=ja;){d=c.strstart,e=c.lookahead-(ja-1);do c.ins_h=(c.ins_h<<c.hash_shift^c.window[d+ja-1])&c.hash_mask,c.prev[d&c.w_mask]=c.head[c.ins_h],c.head[c.ins_h]=d,d++;while(--e);c.strstart=d,c.lookahead=ja-1,m(c)}return c.strstart+=c.lookahead,c.block_start=c.strstart,c.insert=c.lookahead,c.lookahead=0,c.match_length=c.prev_length=ja-1,c.match_available=0,a.next_in=i,a.input=j,a.avail_in=h,c.wrap=g,O}var D,E=a("../utils/common"),F=a("./trees"),G=a("./adler32"),H=a("./crc32"),I=a("./messages"),J=0,K=1,L=3,M=4,N=5,O=0,P=1,Q=-2,R=-3,S=-5,T=-1,U=1,V=2,W=3,X=4,Y=0,Z=2,$=8,_=9,aa=15,ba=8,ca=29,da=256,ea=da+1+ca,fa=30,ga=19,ha=2*ea+1,ia=15,ja=3,ka=258,la=ka+ja+1,ma=32,na=42,oa=69,pa=73,qa=91,ra=103,sa=113,ta=666,ua=1,va=2,wa=3,xa=4,ya=3;D=[new s(0,0,0,0,n),new s(4,4,8,4,o),new s(4,5,16,8,o),new s(4,6,32,32,o),new s(4,4,16,16,p),new s(8,16,32,32,p),new s(8,16,128,128,p),new s(8,32,128,256,p),new s(32,128,258,1024,p),new s(32,258,258,4096,p)],c.deflateInit=z,c.deflateInit2=y,c.deflateReset=w,c.deflateResetKeep=v,c.deflateSetHeader=x,c.deflate=A,c.deflateEnd=B,c.deflateSetDictionary=C,c.deflateInfo="pako deflate (from Nodeca project)"},{"../utils/common":62,"./adler32":64,"./crc32":66,"./messages":72,"./trees":73}],68:[function(a,b,c){"use strict";function d(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1}b.exports=d},{}],69:[function(a,b,c){"use strict";var d=30,e=12;b.exports=function(a,b){var c,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C;c=a.state,f=a.next_in,B=a.input,g=f+(a.avail_in-5),h=a.next_out,C=a.output,i=h-(b-a.avail_out),j=h+(a.avail_out-257),k=c.dmax,l=c.wsize,m=c.whave,n=c.wnext,o=c.window,p=c.hold,q=c.bits,r=c.lencode,s=c.distcode,t=(1<<c.lenbits)-1,u=(1<<c.distbits)-1;a:do{q<15&&(p+=B[f++]<<q,q+=8,p+=B[f++]<<q,q+=8),v=r[p&t];b:for(;;){if(w=v>>>24,p>>>=w,q-=w,w=v>>>16&255,0===w)C[h++]=65535&v;else{if(!(16&w)){if(0===(64&w)){v=r[(65535&v)+(p&(1<<w)-1)];continue b}if(32&w){c.mode=e;break a}a.msg="invalid literal/length code",c.mode=d;break a}x=65535&v,w&=15,w&&(q<w&&(p+=B[f++]<<q,q+=8),x+=p&(1<<w)-1,p>>>=w,q-=w),q<15&&(p+=B[f++]<<q,q+=8,p+=B[f++]<<q,q+=8),v=s[p&u];c:for(;;){if(w=v>>>24,p>>>=w,q-=w,w=v>>>16&255,!(16&w)){if(0===(64&w)){v=s[(65535&v)+(p&(1<<w)-1)];continue c}a.msg="invalid distance code",c.mode=d;break a}if(y=65535&v,w&=15,q<w&&(p+=B[f++]<<q,q+=8,q<w&&(p+=B[f++]<<q,q+=8)),y+=p&(1<<w)-1,y>k){a.msg="invalid distance too far back",c.mode=d;break a}if(p>>>=w,q-=w,w=h-i,y>w){if(w=y-w,w>m&&c.sane){a.msg="invalid distance too far back",c.mode=d;break a}if(z=0,A=o,0===n){if(z+=l-w,w<x){x-=w;do C[h++]=o[z++];while(--w);z=h-y,A=C}}else if(n<w){if(z+=l+n-w,w-=n,w<x){x-=w;do C[h++]=o[z++];while(--w);if(z=0,n<x){w=n,x-=w;do C[h++]=o[z++];while(--w);z=h-y,A=C}}}else if(z+=n-w,w<x){x-=w;do C[h++]=o[z++];while(--w);z=h-y,A=C}for(;x>2;)C[h++]=A[z++],C[h++]=A[z++],C[h++]=A[z++],x-=3;x&&(C[h++]=A[z++],x>1&&(C[h++]=A[z++]))}else{z=h-y;do C[h++]=C[z++],C[h++]=C[z++],C[h++]=C[z++],x-=3;while(x>2);x&&(C[h++]=C[z++],x>1&&(C[h++]=C[z++]))}break}}break}}while(f<g&&h<j);x=q>>3,f-=x,q-=x<<3,p&=(1<<q)-1,a.next_in=f,a.next_out=h,a.avail_in=f<g?5+(g-f):5-(f-g),a.avail_out=h<j?257+(j-h):257-(h-j),c.hold=p,c.bits=q}},{}],70:[function(a,b,c){"use strict";function d(a){return(a>>>24&255)+(a>>>8&65280)+((65280&a)<<8)+((255&a)<<24)}function e(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new s.Buf16(320),this.work=new s.Buf16(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}function f(a){var b;return a&&a.state?(b=a.state,a.total_in=a.total_out=b.total=0,a.msg="",b.wrap&&(a.adler=1&b.wrap),b.mode=L,b.last=0,b.havedict=0,b.dmax=32768,b.head=null,b.hold=0,b.bits=0,b.lencode=b.lendyn=new s.Buf32(pa),b.distcode=b.distdyn=new s.Buf32(qa),b.sane=1,b.back=-1,D):G}function g(a){var b;return a&&a.state?(b=a.state,b.wsize=0,b.whave=0,b.wnext=0,f(a)):G}function h(a,b){var c,d;return a&&a.state?(d=a.state,b<0?(c=0,b=-b):(c=(b>>4)+1,b<48&&(b&=15)),b&&(b<8||b>15)?G:(null!==d.window&&d.wbits!==b&&(d.window=null),d.wrap=c,d.wbits=b,g(a))):G}function i(a,b){var c,d;return a?(d=new e,a.state=d,d.window=null,c=h(a,b),c!==D&&(a.state=null),c):G}function j(a){return i(a,sa)}function k(a){if(ta){var b;for(q=new s.Buf32(512),r=new s.Buf32(32),b=0;b<144;)a.lens[b++]=8;for(;b<256;)a.lens[b++]=9;for(;b<280;)a.lens[b++]=7;for(;b<288;)a.lens[b++]=8;for(w(y,a.lens,0,288,q,0,a.work,{bits:9}),b=0;b<32;)a.lens[b++]=5;w(z,a.lens,0,32,r,0,a.work,{bits:5}),ta=!1}a.lencode=q,a.lenbits=9,a.distcode=r,a.distbits=5}function l(a,b,c,d){var e,f=a.state;return null===f.window&&(f.wsize=1<<f.wbits,f.wnext=0,f.whave=0,f.window=new s.Buf8(f.wsize)),d>=f.wsize?(s.arraySet(f.window,b,c-f.wsize,f.wsize,0),f.wnext=0,f.whave=f.wsize):(e=f.wsize-f.wnext,e>d&&(e=d),s.arraySet(f.window,b,c-d,e,f.wnext),d-=e,d?(s.arraySet(f.window,b,c-d,d,0),f.wnext=d,f.whave=f.wsize):(f.wnext+=e,f.wnext===f.wsize&&(f.wnext=0),f.whave<f.wsize&&(f.whave+=e))),0}function m(a,b){var c,e,f,g,h,i,j,m,n,o,p,q,r,pa,qa,ra,sa,ta,ua,va,wa,xa,ya,za,Aa=0,Ba=new s.Buf8(4),Ca=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15];if(!a||!a.state||!a.output||!a.input&&0!==a.avail_in)return G;c=a.state,c.mode===W&&(c.mode=X),h=a.next_out,f=a.output,j=a.avail_out,g=a.next_in,e=a.input,i=a.avail_in,m=c.hold,n=c.bits,o=i,p=j,xa=D;a:for(;;)switch(c.mode){case L:if(0===c.wrap){c.mode=X;break}for(;n<16;){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}if(2&c.wrap&&35615===m){c.check=0,Ba[0]=255&m,Ba[1]=m>>>8&255,c.check=u(c.check,Ba,2,0),m=0,n=0,c.mode=M;break}if(c.flags=0,c.head&&(c.head.done=!1),!(1&c.wrap)||(((255&m)<<8)+(m>>8))%31){a.msg="incorrect header check",c.mode=ma;break}if((15&m)!==K){a.msg="unknown compression method",c.mode=ma;break}if(m>>>=4,n-=4,wa=(15&m)+8,0===c.wbits)c.wbits=wa;else if(wa>c.wbits){a.msg="invalid window size",c.mode=ma;break}c.dmax=1<<wa,a.adler=c.check=1,c.mode=512&m?U:W,m=0,n=0;break;case M:for(;n<16;){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}if(c.flags=m,(255&c.flags)!==K){a.msg="unknown compression method",c.mode=ma;break}if(57344&c.flags){a.msg="unknown header flags set",c.mode=ma;break}c.head&&(c.head.text=m>>8&1),512&c.flags&&(Ba[0]=255&m,Ba[1]=m>>>8&255,c.check=u(c.check,Ba,2,0)),m=0,n=0,c.mode=N;case N:for(;n<32;){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}c.head&&(c.head.time=m),512&c.flags&&(Ba[0]=255&m,Ba[1]=m>>>8&255,Ba[2]=m>>>16&255,Ba[3]=m>>>24&255,c.check=u(c.check,Ba,4,0)),m=0,n=0,c.mode=O;case O:for(;n<16;){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}c.head&&(c.head.xflags=255&m,c.head.os=m>>8),512&c.flags&&(Ba[0]=255&m,Ba[1]=m>>>8&255,c.check=u(c.check,Ba,2,0)),m=0,n=0,c.mode=P;case P:if(1024&c.flags){for(;n<16;){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}c.length=m,c.head&&(c.head.extra_len=m),512&c.flags&&(Ba[0]=255&m,Ba[1]=m>>>8&255,c.check=u(c.check,Ba,2,0)),m=0,n=0}else c.head&&(c.head.extra=null);c.mode=Q;case Q:if(1024&c.flags&&(q=c.length,q>i&&(q=i),q&&(c.head&&(wa=c.head.extra_len-c.length,c.head.extra||(c.head.extra=new Array(c.head.extra_len)),s.arraySet(c.head.extra,e,g,q,wa)),512&c.flags&&(c.check=u(c.check,e,q,g)),i-=q,g+=q,c.length-=q),c.length))break a;c.length=0,c.mode=R;case R:if(2048&c.flags){if(0===i)break a;q=0;do wa=e[g+q++],c.head&&wa&&c.length<65536&&(c.head.name+=String.fromCharCode(wa));while(wa&&q<i);if(512&c.flags&&(c.check=u(c.check,e,q,g)),i-=q,g+=q,wa)break a}else c.head&&(c.head.name=null);c.length=0,c.mode=S;case S:if(4096&c.flags){if(0===i)break a;q=0;do wa=e[g+q++],c.head&&wa&&c.length<65536&&(c.head.comment+=String.fromCharCode(wa));while(wa&&q<i);if(512&c.flags&&(c.check=u(c.check,e,q,g)),i-=q,g+=q,wa)break a}else c.head&&(c.head.comment=null);c.mode=T;case T:if(512&c.flags){for(;n<16;){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}if(m!==(65535&c.check)){a.msg="header crc mismatch",c.mode=ma;break}m=0,n=0}c.head&&(c.head.hcrc=c.flags>>9&1,c.head.done=!0),a.adler=c.check=0,c.mode=W;break;case U:for(;n<32;){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}a.adler=c.check=d(m),m=0,n=0,c.mode=V;case V:if(0===c.havedict)return a.next_out=h,a.avail_out=j,a.next_in=g,a.avail_in=i,c.hold=m,c.bits=n,F;a.adler=c.check=1,c.mode=W;case W:if(b===B||b===C)break a;case X:if(c.last){m>>>=7&n,n-=7&n,c.mode=ja;break}for(;n<3;){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}switch(c.last=1&m,m>>>=1,n-=1,3&m){case 0:c.mode=Y;break;case 1:if(k(c),c.mode=ca,b===C){m>>>=2,n-=2;break a}break;case 2:c.mode=_;break;case 3:a.msg="invalid block type",c.mode=ma}m>>>=2,n-=2;break;case Y:for(m>>>=7&n,n-=7&n;n<32;){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}if((65535&m)!==(m>>>16^65535)){a.msg="invalid stored block lengths",c.mode=ma;break}if(c.length=65535&m,m=0,n=0,c.mode=Z,b===C)break a;case Z:c.mode=$;case $:if(q=c.length){if(q>i&&(q=i),q>j&&(q=j),0===q)break a;s.arraySet(f,e,g,q,h),i-=q,g+=q,j-=q,h+=q,c.length-=q;break}c.mode=W;break;case _:for(;n<14;){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}if(c.nlen=(31&m)+257,m>>>=5,n-=5,c.ndist=(31&m)+1,m>>>=5,n-=5,c.ncode=(15&m)+4,m>>>=4,n-=4,c.nlen>286||c.ndist>30){a.msg="too many length or distance symbols",c.mode=ma;break}c.have=0,c.mode=aa;case aa:for(;c.have<c.ncode;){for(;n<3;){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}c.lens[Ca[c.have++]]=7&m,m>>>=3,n-=3}for(;c.have<19;)c.lens[Ca[c.have++]]=0;if(c.lencode=c.lendyn,c.lenbits=7,ya={bits:c.lenbits},xa=w(x,c.lens,0,19,c.lencode,0,c.work,ya),c.lenbits=ya.bits,xa){a.msg="invalid code lengths set",c.mode=ma;break}c.have=0,c.mode=ba;case ba:for(;c.have<c.nlen+c.ndist;){for(;Aa=c.lencode[m&(1<<c.lenbits)-1],qa=Aa>>>24,ra=Aa>>>16&255,sa=65535&Aa,!(qa<=n);){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}if(sa<16)m>>>=qa,n-=qa,c.lens[c.have++]=sa;else{if(16===sa){for(za=qa+2;n<za;){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}if(m>>>=qa,n-=qa,0===c.have){a.msg="invalid bit length repeat",c.mode=ma;break}wa=c.lens[c.have-1],q=3+(3&m),m>>>=2,n-=2}else if(17===sa){for(za=qa+3;n<za;){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}m>>>=qa,n-=qa,wa=0,q=3+(7&m),m>>>=3,n-=3}else{for(za=qa+7;n<za;){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}m>>>=qa,n-=qa,wa=0,q=11+(127&m),m>>>=7,n-=7}if(c.have+q>c.nlen+c.ndist){a.msg="invalid bit length repeat",c.mode=ma;break}for(;q--;)c.lens[c.have++]=wa}}if(c.mode===ma)break;if(0===c.lens[256]){a.msg="invalid code -- missing end-of-block",c.mode=ma;break}if(c.lenbits=9,ya={bits:c.lenbits},xa=w(y,c.lens,0,c.nlen,c.lencode,0,c.work,ya),c.lenbits=ya.bits,xa){a.msg="invalid literal/lengths set",c.mode=ma;break}if(c.distbits=6,c.distcode=c.distdyn,ya={bits:c.distbits},xa=w(z,c.lens,c.nlen,c.ndist,c.distcode,0,c.work,ya),c.distbits=ya.bits,xa){a.msg="invalid distances set",c.mode=ma;break}if(c.mode=ca,b===C)break a;case ca:c.mode=da;case da:if(i>=6&&j>=258){a.next_out=h,a.avail_out=j,a.next_in=g,a.avail_in=i,c.hold=m,c.bits=n,v(a,p),h=a.next_out,f=a.output,j=a.avail_out,g=a.next_in,e=a.input,i=a.avail_in,m=c.hold,n=c.bits,c.mode===W&&(c.back=-1);break}for(c.back=0;Aa=c.lencode[m&(1<<c.lenbits)-1],qa=Aa>>>24,ra=Aa>>>16&255,sa=65535&Aa,!(qa<=n);){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}if(ra&&0===(240&ra)){for(ta=qa,ua=ra,va=sa;Aa=c.lencode[va+((m&(1<<ta+ua)-1)>>ta)],qa=Aa>>>24,ra=Aa>>>16&255,sa=65535&Aa,!(ta+qa<=n);){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}m>>>=ta,n-=ta,c.back+=ta}if(m>>>=qa,n-=qa,c.back+=qa,c.length=sa,0===ra){c.mode=ia;break}if(32&ra){c.back=-1,c.mode=W;break}if(64&ra){a.msg="invalid literal/length code",c.mode=ma;break}c.extra=15&ra,c.mode=ea;case ea:if(c.extra){for(za=c.extra;n<za;){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}c.length+=m&(1<<c.extra)-1,m>>>=c.extra,n-=c.extra,c.back+=c.extra}c.was=c.length,c.mode=fa;case fa:for(;Aa=c.distcode[m&(1<<c.distbits)-1],qa=Aa>>>24,ra=Aa>>>16&255,sa=65535&Aa,!(qa<=n);){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}if(0===(240&ra)){for(ta=qa,ua=ra,va=sa;Aa=c.distcode[va+((m&(1<<ta+ua)-1)>>ta)],qa=Aa>>>24,ra=Aa>>>16&255,sa=65535&Aa,!(ta+qa<=n);){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}m>>>=ta,n-=ta,c.back+=ta}if(m>>>=qa,n-=qa,c.back+=qa,64&ra){a.msg="invalid distance code",c.mode=ma;break}c.offset=sa,c.extra=15&ra,c.mode=ga;case ga:if(c.extra){for(za=c.extra;n<za;){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}c.offset+=m&(1<<c.extra)-1,m>>>=c.extra,n-=c.extra,c.back+=c.extra}if(c.offset>c.dmax){a.msg="invalid distance too far back",c.mode=ma;break}c.mode=ha;case ha:if(0===j)break a;if(q=p-j,c.offset>q){if(q=c.offset-q,q>c.whave&&c.sane){a.msg="invalid distance too far back",c.mode=ma;break}q>c.wnext?(q-=c.wnext,r=c.wsize-q):r=c.wnext-q,q>c.length&&(q=c.length),pa=c.window}else pa=f,r=h-c.offset,q=c.length;q>j&&(q=j),j-=q,c.length-=q;do f[h++]=pa[r++];while(--q);0===c.length&&(c.mode=da);break;case ia:if(0===j)break a;f[h++]=c.length,j--,c.mode=da;break;case ja:if(c.wrap){for(;n<32;){if(0===i)break a;i--,m|=e[g++]<<n,n+=8}if(p-=j,a.total_out+=p,c.total+=p,p&&(a.adler=c.check=c.flags?u(c.check,f,p,h-p):t(c.check,f,p,h-p)),p=j,(c.flags?m:d(m))!==c.check){a.msg="incorrect data check",c.mode=ma;break}m=0,n=0}c.mode=ka;case ka:if(c.wrap&&c.flags){for(;n<32;){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}if(m!==(4294967295&c.total)){a.msg="incorrect length check",c.mode=ma;break}m=0,n=0}c.mode=la;case la:xa=E;break a;case ma:xa=H;break a;case na:return I;case oa:default:return G}return a.next_out=h,a.avail_out=j,a.next_in=g,a.avail_in=i,c.hold=m,c.bits=n,(c.wsize||p!==a.avail_out&&c.mode<ma&&(c.mode<ja||b!==A))&&l(a,a.output,a.next_out,p-a.avail_out)?(c.mode=na,I):(o-=a.avail_in,p-=a.avail_out,a.total_in+=o,a.total_out+=p,c.total+=p,c.wrap&&p&&(a.adler=c.check=c.flags?u(c.check,f,p,a.next_out-p):t(c.check,f,p,a.next_out-p)),a.data_type=c.bits+(c.last?64:0)+(c.mode===W?128:0)+(c.mode===ca||c.mode===Z?256:0),(0===o&&0===p||b===A)&&xa===D&&(xa=J),xa)}function n(a){if(!a||!a.state)return G;var b=a.state;return b.window&&(b.window=null),a.state=null,D}function o(a,b){var c;return a&&a.state?(c=a.state,0===(2&c.wrap)?G:(c.head=b,b.done=!1,D)):G}function p(a,b){var c,d,e,f=b.length;return a&&a.state?(c=a.state,0!==c.wrap&&c.mode!==V?G:c.mode===V&&(d=1,d=t(d,b,f,0),d!==c.check)?H:(e=l(a,b,f,f))?(c.mode=na,I):(c.havedict=1,D)):G}var q,r,s=a("../utils/common"),t=a("./adler32"),u=a("./crc32"),v=a("./inffast"),w=a("./inftrees"),x=0,y=1,z=2,A=4,B=5,C=6,D=0,E=1,F=2,G=-2,H=-3,I=-4,J=-5,K=8,L=1,M=2,N=3,O=4,P=5,Q=6,R=7,S=8,T=9,U=10,V=11,W=12,X=13,Y=14,Z=15,$=16,_=17,aa=18,ba=19,ca=20,da=21,ea=22,fa=23,ga=24,ha=25,ia=26,ja=27,ka=28,la=29,ma=30,na=31,oa=32,pa=852,qa=592,ra=15,sa=ra,ta=!0;c.inflateReset=g,c.inflateReset2=h,c.inflateResetKeep=f,c.inflateInit=j,c.inflateInit2=i,c.inflate=m,c.inflateEnd=n,c.inflateGetHeader=o,c.inflateSetDictionary=p,c.inflateInfo="pako inflate (from Nodeca project)"},{"../utils/common":62,"./adler32":64,"./crc32":66,"./inffast":69,"./inftrees":71}],71:[function(a,b,c){"use strict";var d=a("../utils/common"),e=15,f=852,g=592,h=0,i=1,j=2,k=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0],l=[16,16,16,16,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,16,72,78],m=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0],n=[16,16,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,64,64];b.exports=function(a,b,c,o,p,q,r,s){var t,u,v,w,x,y,z,A,B,C=s.bits,D=0,E=0,F=0,G=0,H=0,I=0,J=0,K=0,L=0,M=0,N=null,O=0,P=new d.Buf16(e+1),Q=new d.Buf16(e+1),R=null,S=0;for(D=0;D<=e;D++)P[D]=0;for(E=0;E<o;E++)P[b[c+E]]++;for(H=C,G=e;G>=1&&0===P[G];G--);if(H>G&&(H=G),0===G)return p[q++]=20971520,p[q++]=20971520,s.bits=1,0;for(F=1;F<G&&0===P[F];F++);for(H<F&&(H=F),K=1,D=1;D<=e;D++)if(K<<=1,K-=P[D],K<0)return-1;if(K>0&&(a===h||1!==G))return-1;for(Q[1]=0,D=1;D<e;D++)Q[D+1]=Q[D]+P[D];for(E=0;E<o;E++)0!==b[c+E]&&(r[Q[b[c+E]]++]=E);if(a===h?(N=R=r,y=19):a===i?(N=k,O-=257,R=l,S-=257,y=256):(N=m,R=n,y=-1),M=0,E=0,D=F,x=q,I=H,J=0,v=-1,L=1<<H,w=L-1,a===i&&L>f||a===j&&L>g)return 1;for(;;){z=D-J,r[E]<y?(A=0,B=r[E]):r[E]>y?(A=R[S+r[E]],B=N[O+r[E]]):(A=96,B=0),t=1<<D-J,u=1<<I,F=u;do u-=t,p[x+(M>>J)+u]=z<<24|A<<16|B|0;while(0!==u);for(t=1<<D-1;M&t;)t>>=1;if(0!==t?(M&=t-1,M+=t):M=0,E++,0===--P[D]){if(D===G)break;D=b[c+r[E]]}if(D>H&&(M&w)!==v){for(0===J&&(J=H),x+=F,I=D-J,K=1<<I;I+J<G&&(K-=P[I+J],!(K<=0));)I++,K<<=1;if(L+=1<<I,a===i&&L>f||a===j&&L>g)return 1;v=M&w,p[v]=H<<24|I<<16|x-q|0}}return 0!==M&&(p[x+M]=D-J<<24|64<<16|0),s.bits=H,0}},{"../utils/common":62}],72:[function(a,b,c){"use strict";b.exports={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"}},{}],73:[function(a,b,c){"use strict";function d(a){for(var b=a.length;--b>=0;)a[b]=0}function e(a,b,c,d,e){this.static_tree=a,this.extra_bits=b,this.extra_base=c,this.elems=d,this.max_length=e,this.has_stree=a&&a.length}function f(a,b){this.dyn_tree=a,this.max_code=0,this.stat_desc=b}function g(a){return a<256?ia[a]:ia[256+(a>>>7)]}function h(a,b){a.pending_buf[a.pending++]=255&b,a.pending_buf[a.pending++]=b>>>8&255}function i(a,b,c){a.bi_valid>X-c?(a.bi_buf|=b<<a.bi_valid&65535,h(a,a.bi_buf),a.bi_buf=b>>X-a.bi_valid,a.bi_valid+=c-X):(a.bi_buf|=b<<a.bi_valid&65535,a.bi_valid+=c)}function j(a,b,c){i(a,c[2*b],c[2*b+1])}function k(a,b){var c=0;do c|=1&a,a>>>=1,c<<=1;while(--b>0);return c>>>1}function l(a){16===a.bi_valid?(h(a,a.bi_buf),a.bi_buf=0,a.bi_valid=0):a.bi_valid>=8&&(a.pending_buf[a.pending++]=255&a.bi_buf,a.bi_buf>>=8,a.bi_valid-=8)}function m(a,b){var c,d,e,f,g,h,i=b.dyn_tree,j=b.max_code,k=b.stat_desc.static_tree,l=b.stat_desc.has_stree,m=b.stat_desc.extra_bits,n=b.stat_desc.extra_base,o=b.stat_desc.max_length,p=0;for(f=0;f<=W;f++)a.bl_count[f]=0;for(i[2*a.heap[a.heap_max]+1]=0, +c=a.heap_max+1;c<V;c++)d=a.heap[c],f=i[2*i[2*d+1]+1]+1,f>o&&(f=o,p++),i[2*d+1]=f,d>j||(a.bl_count[f]++,g=0,d>=n&&(g=m[d-n]),h=i[2*d],a.opt_len+=h*(f+g),l&&(a.static_len+=h*(k[2*d+1]+g)));if(0!==p){do{for(f=o-1;0===a.bl_count[f];)f--;a.bl_count[f]--,a.bl_count[f+1]+=2,a.bl_count[o]--,p-=2}while(p>0);for(f=o;0!==f;f--)for(d=a.bl_count[f];0!==d;)e=a.heap[--c],e>j||(i[2*e+1]!==f&&(a.opt_len+=(f-i[2*e+1])*i[2*e],i[2*e+1]=f),d--)}}function n(a,b,c){var d,e,f=new Array(W+1),g=0;for(d=1;d<=W;d++)f[d]=g=g+c[d-1]<<1;for(e=0;e<=b;e++){var h=a[2*e+1];0!==h&&(a[2*e]=k(f[h]++,h))}}function o(){var a,b,c,d,f,g=new Array(W+1);for(c=0,d=0;d<Q-1;d++)for(ka[d]=c,a=0;a<1<<ba[d];a++)ja[c++]=d;for(ja[c-1]=d,f=0,d=0;d<16;d++)for(la[d]=f,a=0;a<1<<ca[d];a++)ia[f++]=d;for(f>>=7;d<T;d++)for(la[d]=f<<7,a=0;a<1<<ca[d]-7;a++)ia[256+f++]=d;for(b=0;b<=W;b++)g[b]=0;for(a=0;a<=143;)ga[2*a+1]=8,a++,g[8]++;for(;a<=255;)ga[2*a+1]=9,a++,g[9]++;for(;a<=279;)ga[2*a+1]=7,a++,g[7]++;for(;a<=287;)ga[2*a+1]=8,a++,g[8]++;for(n(ga,S+1,g),a=0;a<T;a++)ha[2*a+1]=5,ha[2*a]=k(a,5);ma=new e(ga,ba,R+1,S,W),na=new e(ha,ca,0,T,W),oa=new e(new Array(0),da,0,U,Y)}function p(a){var b;for(b=0;b<S;b++)a.dyn_ltree[2*b]=0;for(b=0;b<T;b++)a.dyn_dtree[2*b]=0;for(b=0;b<U;b++)a.bl_tree[2*b]=0;a.dyn_ltree[2*Z]=1,a.opt_len=a.static_len=0,a.last_lit=a.matches=0}function q(a){a.bi_valid>8?h(a,a.bi_buf):a.bi_valid>0&&(a.pending_buf[a.pending++]=a.bi_buf),a.bi_buf=0,a.bi_valid=0}function r(a,b,c,d){q(a),d&&(h(a,c),h(a,~c)),G.arraySet(a.pending_buf,a.window,b,c,a.pending),a.pending+=c}function s(a,b,c,d){var e=2*b,f=2*c;return a[e]<a[f]||a[e]===a[f]&&d[b]<=d[c]}function t(a,b,c){for(var d=a.heap[c],e=c<<1;e<=a.heap_len&&(e<a.heap_len&&s(b,a.heap[e+1],a.heap[e],a.depth)&&e++,!s(b,d,a.heap[e],a.depth));)a.heap[c]=a.heap[e],c=e,e<<=1;a.heap[c]=d}function u(a,b,c){var d,e,f,h,k=0;if(0!==a.last_lit)do d=a.pending_buf[a.d_buf+2*k]<<8|a.pending_buf[a.d_buf+2*k+1],e=a.pending_buf[a.l_buf+k],k++,0===d?j(a,e,b):(f=ja[e],j(a,f+R+1,b),h=ba[f],0!==h&&(e-=ka[f],i(a,e,h)),d--,f=g(d),j(a,f,c),h=ca[f],0!==h&&(d-=la[f],i(a,d,h)));while(k<a.last_lit);j(a,Z,b)}function v(a,b){var c,d,e,f=b.dyn_tree,g=b.stat_desc.static_tree,h=b.stat_desc.has_stree,i=b.stat_desc.elems,j=-1;for(a.heap_len=0,a.heap_max=V,c=0;c<i;c++)0!==f[2*c]?(a.heap[++a.heap_len]=j=c,a.depth[c]=0):f[2*c+1]=0;for(;a.heap_len<2;)e=a.heap[++a.heap_len]=j<2?++j:0,f[2*e]=1,a.depth[e]=0,a.opt_len--,h&&(a.static_len-=g[2*e+1]);for(b.max_code=j,c=a.heap_len>>1;c>=1;c--)t(a,f,c);e=i;do c=a.heap[1],a.heap[1]=a.heap[a.heap_len--],t(a,f,1),d=a.heap[1],a.heap[--a.heap_max]=c,a.heap[--a.heap_max]=d,f[2*e]=f[2*c]+f[2*d],a.depth[e]=(a.depth[c]>=a.depth[d]?a.depth[c]:a.depth[d])+1,f[2*c+1]=f[2*d+1]=e,a.heap[1]=e++,t(a,f,1);while(a.heap_len>=2);a.heap[--a.heap_max]=a.heap[1],m(a,b),n(f,j,a.bl_count)}function w(a,b,c){var d,e,f=-1,g=b[1],h=0,i=7,j=4;for(0===g&&(i=138,j=3),b[2*(c+1)+1]=65535,d=0;d<=c;d++)e=g,g=b[2*(d+1)+1],++h<i&&e===g||(h<j?a.bl_tree[2*e]+=h:0!==e?(e!==f&&a.bl_tree[2*e]++,a.bl_tree[2*$]++):h<=10?a.bl_tree[2*_]++:a.bl_tree[2*aa]++,h=0,f=e,0===g?(i=138,j=3):e===g?(i=6,j=3):(i=7,j=4))}function x(a,b,c){var d,e,f=-1,g=b[1],h=0,k=7,l=4;for(0===g&&(k=138,l=3),d=0;d<=c;d++)if(e=g,g=b[2*(d+1)+1],!(++h<k&&e===g)){if(h<l){do j(a,e,a.bl_tree);while(0!==--h)}else 0!==e?(e!==f&&(j(a,e,a.bl_tree),h--),j(a,$,a.bl_tree),i(a,h-3,2)):h<=10?(j(a,_,a.bl_tree),i(a,h-3,3)):(j(a,aa,a.bl_tree),i(a,h-11,7));h=0,f=e,0===g?(k=138,l=3):e===g?(k=6,l=3):(k=7,l=4)}}function y(a){var b;for(w(a,a.dyn_ltree,a.l_desc.max_code),w(a,a.dyn_dtree,a.d_desc.max_code),v(a,a.bl_desc),b=U-1;b>=3&&0===a.bl_tree[2*ea[b]+1];b--);return a.opt_len+=3*(b+1)+5+5+4,b}function z(a,b,c,d){var e;for(i(a,b-257,5),i(a,c-1,5),i(a,d-4,4),e=0;e<d;e++)i(a,a.bl_tree[2*ea[e]+1],3);x(a,a.dyn_ltree,b-1),x(a,a.dyn_dtree,c-1)}function A(a){var b,c=4093624447;for(b=0;b<=31;b++,c>>>=1)if(1&c&&0!==a.dyn_ltree[2*b])return I;if(0!==a.dyn_ltree[18]||0!==a.dyn_ltree[20]||0!==a.dyn_ltree[26])return J;for(b=32;b<R;b++)if(0!==a.dyn_ltree[2*b])return J;return I}function B(a){pa||(o(),pa=!0),a.l_desc=new f(a.dyn_ltree,ma),a.d_desc=new f(a.dyn_dtree,na),a.bl_desc=new f(a.bl_tree,oa),a.bi_buf=0,a.bi_valid=0,p(a)}function C(a,b,c,d){i(a,(L<<1)+(d?1:0),3),r(a,b,c,!0)}function D(a){i(a,M<<1,3),j(a,Z,ga),l(a)}function E(a,b,c,d){var e,f,g=0;a.level>0?(a.strm.data_type===K&&(a.strm.data_type=A(a)),v(a,a.l_desc),v(a,a.d_desc),g=y(a),e=a.opt_len+3+7>>>3,f=a.static_len+3+7>>>3,f<=e&&(e=f)):e=f=c+5,c+4<=e&&b!==-1?C(a,b,c,d):a.strategy===H||f===e?(i(a,(M<<1)+(d?1:0),3),u(a,ga,ha)):(i(a,(N<<1)+(d?1:0),3),z(a,a.l_desc.max_code+1,a.d_desc.max_code+1,g+1),u(a,a.dyn_ltree,a.dyn_dtree)),p(a),d&&q(a)}function F(a,b,c){return a.pending_buf[a.d_buf+2*a.last_lit]=b>>>8&255,a.pending_buf[a.d_buf+2*a.last_lit+1]=255&b,a.pending_buf[a.l_buf+a.last_lit]=255&c,a.last_lit++,0===b?a.dyn_ltree[2*c]++:(a.matches++,b--,a.dyn_ltree[2*(ja[c]+R+1)]++,a.dyn_dtree[2*g(b)]++),a.last_lit===a.lit_bufsize-1}var G=a("../utils/common"),H=4,I=0,J=1,K=2,L=0,M=1,N=2,O=3,P=258,Q=29,R=256,S=R+1+Q,T=30,U=19,V=2*S+1,W=15,X=16,Y=7,Z=256,$=16,_=17,aa=18,ba=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0],ca=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13],da=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7],ea=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],fa=512,ga=new Array(2*(S+2));d(ga);var ha=new Array(2*T);d(ha);var ia=new Array(fa);d(ia);var ja=new Array(P-O+1);d(ja);var ka=new Array(Q);d(ka);var la=new Array(T);d(la);var ma,na,oa,pa=!1;c._tr_init=B,c._tr_stored_block=C,c._tr_flush_block=E,c._tr_tally=F,c._tr_align=D},{"../utils/common":62}],74:[function(a,b,c){"use strict";function d(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0}b.exports=d},{}]},{},[10])(10)});
\ No newline at end of file @@ -14,7 +14,6 @@ <script src="lib/zip.min.js"></script> <script src="lib/localforage.min.js"></script> <script src="lib/epub.js"></script> - <script src="lib/smartimages.js"></script> <script src="js/read.js"></script> <script src="js/common.js"></script> @@ -351,12 +350,12 @@ if (navigator.onLine) { var book_url = "backend.php?op=download&id=" + $.urlParam("id"); - RSVP.on('error', function(error) { + /*RSVP.on('error', function(error) { if ($(".loading").is(":visible")) { $(".loading_message").html("Unable to load book (remote)."); } console.log(error); - }); + });*/ fetch(book_url, {credentials: 'same-origin'}).then(function(resp) { @@ -399,6 +398,10 @@ } else { $(".loading_message").html("Unable to download book: " + resp.status + "."); } + }).catch(function() { + if ($(".loading").is(":visible")) { + $(".loading_message").html("Unable to load book (remote)."); + } }); } else { @@ -411,7 +414,7 @@ _enable_fullscreen = enable; }); - EPUBJS.Hooks.register("beforeChapterDisplay").applyTheme = function(callback, renderer) { + /*EPUBJS.Hooks.register("beforeChapterDisplay").applyTheme = function(callback, renderer) { localforage.getItem("epube.theme").then(function(theme) { var base_url = window.location.href.match(/^.*\//)[0]; @@ -464,7 +467,7 @@ }); if (callback) callback(); - } + }*/ /* EPUBJS.Renderer.prototype.onResized = function(e) { this.trigger('renderer:beforeResize'); @@ -488,30 +491,36 @@ }); } - var fontSize; - var fontFamily; - var lineHeight; - var themeName; - - Promise.all([ - localforage.getItem("epube.fontSize"), - localforage.getItem("epube.fontFamily"), - localforage.getItem("epube.lineHeight"), - localforage.getItem("epube.theme") - ]).then(function(res) { - fontSize = res[0] ? res[0] + "px" : DEFAULT_FONT_SIZE + "px"; - fontFamily = res[1] ? res[1] : DEFAULT_FONT_FAMILY; - lineHeight = res[2] ? res[2] + "%" : DEFAULT_LINE_HEIGHT + "%"; - themeName = res[3] ? res[3] : 'default'; - - book.setStyle("fontSize", fontSize); - book.setStyle("fontFamily", fontFamily); - book.setStyle("lineHeight", lineHeight); - book.setStyle("textAlign", "justify"); - }); - window.book = book; - var rendered = book.renderTo("reader"); + + var rendition = book.renderTo("reader", {width: '100%', height: '100%'}); + var displayed = rendition.display(); + + rendition.hooks.content.register(function(contents) { + + var fontSize; + var fontFamily; + var lineHeight; + var themeName; + + Promise.all([ + localforage.getItem("epube.fontSize"), + localforage.getItem("epube.fontFamily"), + localforage.getItem("epube.lineHeight"), + localforage.getItem("epube.theme") + ]).then(function(res) { + fontSize = res[0] ? res[0] + "px" : DEFAULT_FONT_SIZE + "px"; + fontFamily = res[1] ? res[1] : DEFAULT_FONT_FAMILY; + lineHeight = res[2] ? res[2] + "%" : DEFAULT_LINE_HEIGHT + "%"; + themeName = res[3] ? res[3] : 'default'; + + contents.css("font-size", fontSize, 1); + contents.css("font-family", fontFamily, 1); + contents.css("line-height", lineHeight, 1); + contents.css("text-align", "justify", 1); + }); + + }); $('#settings-modal').on('shown.bs.modal', function() { @@ -754,12 +763,12 @@ book.on("renderer:keydown", hotkey_handler); - book.getMetadata().then(function(meta){ + /*book.getMetadata().then(function(meta){ document.title = meta.bookTitle + " – " + meta.creator; $(".title").html("<b>" + meta.bookTitle + "</b> - " + meta.creator); - }); + });*/ - rendered.then(function() { + /*book.ready.then(function() { localforage.getItem(cacheId("pagination")).then(function(pageList) { @@ -784,10 +793,46 @@ } }); - }); + }); */ + + book.ready.then(function() { + + var meta = book.package.metadata; + + document.title = meta.title + " – " + meta.creator; + $(".title").html("<b>" + meta.title + "</b> - " + meta.creator); + + return localforage.getItem(cacheId("locations")).then(function(locations) { - book.pageListReady.then(function(pageList) { - if (!_pagination_stored) { + // legacy format is array of objects {cfi: ..., page: ...} + if (locations && typeof locations[0] == "string") { + _pagination_stored = 1; + return book.locations.load(locations); + } else { + var url = "backend.php?op=getpagination&id=" + encodeURIComponent($.urlParam("id")); + + return fetch(url, {credentials:'same-origin'}).then(function(resp) { + + if (resp.ok) { + return resp.json().then(function(locations) { + if (locations && typeof locations[0] == "string") { + _pagination_stored = 1; + return book.locations.load(locations); + } else { + return book.locations.generate(1600); + } + }); + } else { + return book.locations.generate(1600); + } + }).catch(function() { + return book.locations.generate(1600); + }); + } + + }); + + /*if (!_pagination_stored) { if (navigator.onLine) { $.post("backend.php", { op: "storepagination", id: $.urlParam("id"), payload: JSON.stringify(pageList), total: book.pagination.totalPages }); @@ -822,28 +867,43 @@ book.gotoPage(page); } - }); + }); */ + }).then(function(locations) { + + if (locations && !_pagination_stored) { + if (navigator.onLine) { + $.post("backend.php", { op: "storepagination", id: $.urlParam("id"), + payload: JSON.stringify(locations), total: 100}); + } + + localforage.setItem(cacheId("locations"), locations); + + } + + $(".loading").hide(); + }); - book.on('book:pageChanged', function(location) { + rendition.on('relocated', function(location) { - $("#cur_page").html(location.anchorPage); + /*$("#cur_page").html(location.anchorPage); var total = book.pagination.totalPages; if (book.pagination.totalPages > 0) { var pct = parseInt(location.anchorPage / book.pagination.totalPages * 100); $("#page_pct").html(pct + "%"); - } + } */ + + var currentPage = book.locations.percentageFromCfi(location.start.cfi); + var currentCfi = location.start.cfi; + + $("#page_pct").html(currentPage + '%'); if (_store_position && new Date().getTime()/1000 - _last_position_sync > 15) { console.log("storing lastread"); - var currentCfi = book.getCurrentLocationCfi(); - var currentPage = location.anchorPage; - var totalPages = book.pagination.totalPages; - if (navigator.onLine) { $.post("backend.php", { op: "storelastread", id: $.urlParam("id"), page: currentPage, @@ -856,13 +916,12 @@ }); _store_position = 0; - } else { _last_position_sync = 0; } localforage.setItem(cacheId("lastread"), - {cfi: currentCfi, page: currentPage, total: totalPages}); + {cfi: currentCfi, page: currentPage, total: 100}); } }); |