diff --git a/dist/epub.js b/dist/epub.js index cb500b9..d5b22bd 100644 --- a/dist/epub.js +++ b/dist/epub.js @@ -32,709 +32,1469 @@ EPUBJS.Render = {}; })(this); -/*! - * @overview RSVP - a tiny implementation of Promises/A+. - * @copyright Copyright (c) 2014 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.0.13 - */ +(function(global) { +/** + @class RSVP + @module RSVP + */ +var define, require; (function() { - "use strict"; + var registry = {}, seen = {}; - function $$rsvp$events$$indexOf(callbacks, callback) { - for (var i=0, l=callbacks.length; i 1) { - throw new Error('Second argument not supported'); + if (part === '..') { parentBase.pop(); } + else if (part === '.') { continue; } + else { parentBase.push(part); } } - if (typeof o !== 'object') { - throw new TypeError('Argument must be an object'); - } - $$utils$$F.prototype = o; - return new $$utils$$F(); - }); - var $$instrument$$queue = []; - - var $$instrument$$default = function instrument(eventName, promise, child) { - if (1 === $$instrument$$queue.push({ - name: eventName, - payload: { - guid: promise._guidKey + promise._id, - eventName: eventName, - detail: promise._result, - childGuid: child && promise._guidKey + child._id, - label: promise._label, - timeStamp: $$utils$$now(), - stack: new Error(promise._label).stack - }})) { - - setTimeout(function() { - var entry; - for (var i = 0; i < $$instrument$$queue.length; i++) { - entry = $$instrument$$queue[i]; - $$rsvp$config$$config.trigger(entry.name, entry.payload); - } - $$instrument$$queue.length = 0; - }, 50); - } - }; - - function $$$internal$$noop() {} - var $$$internal$$PENDING = void 0; - var $$$internal$$FULFILLED = 1; - var $$$internal$$REJECTED = 2; - var $$$internal$$GET_THEN_ERROR = new $$$internal$$ErrorObject(); - - function $$$internal$$getThen(promise) { - try { - return promise.then; - } catch(error) { - $$$internal$$GET_THEN_ERROR.error = error; - return $$$internal$$GET_THEN_ERROR; - } + return parentBase.join("/"); } + }; - function $$$internal$$tryThen(then, value, fulfillmentHandler, rejectionHandler) { - try { - then.call(value, fulfillmentHandler, rejectionHandler); - } catch(e) { - return e; - } + require.entries = registry; +})(); + +define('rsvp/-internal', [ + './utils', + './instrument', + './config', + 'exports' +], function (__dependency1__, __dependency2__, __dependency3__, __exports__) { + 'use strict'; + var objectOrFunction = __dependency1__.objectOrFunction; + var isFunction = __dependency1__.isFunction; + var now = __dependency1__.now; + var instrument = __dependency2__['default']; + var config = __dependency3__.config; + function noop() { } - - function $$$internal$$handleForeignThenable(promise, thenable, then) { - $$rsvp$config$$config.async(function(promise) { - var sealed = false; - var error = $$$internal$$tryThen(then, thenable, function(value) { - if (sealed) { return; } - sealed = true; - if (thenable !== value) { - $$$internal$$resolve(promise, value); - } else { - $$$internal$$fulfill(promise, value); - } - }, function(reason) { - if (sealed) { return; } - sealed = true; - - $$$internal$$reject(promise, reason); - }, 'Settle: ' + (promise._label || ' unknown promise')); - - if (!sealed && error) { - sealed = true; - $$$internal$$reject(promise, error); + 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; } - }, promise); } - - function $$$internal$$handleOwnThenable(promise, thenable) { - if (thenable._state === $$$internal$$FULFILLED) { - $$$internal$$fulfill(promise, thenable._result); - } else if (promise._state === $$$internal$$REJECTED) { - $$$internal$$reject(promise, thenable._result); - } else { - $$$internal$$subscribe(thenable, undefined, function(value) { - if (thenable !== value) { - $$$internal$$resolve(promise, value); - } else { - $$$internal$$fulfill(promise, value); - } - }, function(reason) { - $$$internal$$reject(promise, reason); - }); - } + function tryThen(then, value, fulfillmentHandler, rejectionHandler) { + try { + then.call(value, fulfillmentHandler, rejectionHandler); + } catch (e) { + return e; + } } - - function $$$internal$$handleMaybeThenable(promise, maybeThenable) { - if (maybeThenable.constructor === promise.constructor) { - $$$internal$$handleOwnThenable(promise, maybeThenable); - } else { - var then = $$$internal$$getThen(maybeThenable); - - if (then === $$$internal$$GET_THEN_ERROR) { - $$$internal$$reject(promise, $$$internal$$GET_THEN_ERROR.error); - } else if (then === undefined) { - $$$internal$$fulfill(promise, maybeThenable); - } else if ($$utils$$isFunction(then)) { - $$$internal$$handleForeignThenable(promise, maybeThenable, then); + function handleForeignThenable(promise, thenable, then) { + config.async(function (promise$2) { + var sealed = false; + var error = tryThen(then, thenable, function (value) { + if (sealed) { + return; + } + sealed = true; + if (thenable !== value) { + resolve(promise$2, value); + } else { + fulfill(promise$2, value); + } + }, function (reason) { + if (sealed) { + return; + } + sealed = true; + reject(promise$2, reason); + }, 'Settle: ' + (promise$2._label || ' unknown promise')); + if (!sealed && error) { + sealed = true; + reject(promise$2, error); + } + }, promise); + } + function handleOwnThenable(promise, thenable) { + promise._onerror = null; + if (thenable._state === FULFILLED) { + fulfill(promise, thenable._result); + } else if (promise._state === REJECTED) { + reject(promise, thenable._result); } else { - $$$internal$$fulfill(promise, maybeThenable); + subscribe(thenable, undefined, function (value) { + if (thenable !== value) { + resolve(promise, value); + } else { + fulfill(promise, value); + } + }, function (reason) { + reject(promise, reason); + }); } - } } - - function $$$internal$$resolve(promise, value) { - if (promise === value) { - $$$internal$$fulfill(promise, value); - } else if ($$utils$$objectOrFunction(value)) { - $$$internal$$handleMaybeThenable(promise, value); - } else { - $$$internal$$fulfill(promise, value); - } - } - - function $$$internal$$publishRejection(promise) { - if (promise._onerror) { - promise._onerror(promise._result); - } - - $$$internal$$publish(promise); - } - - function $$$internal$$fulfill(promise, value) { - if (promise._state !== $$$internal$$PENDING) { return; } - - promise._result = value; - promise._state = $$$internal$$FULFILLED; - - if (promise._subscribers.length === 0) { - if ($$rsvp$config$$config.instrument) { - $$instrument$$default('fulfilled', promise); - } - } else { - $$rsvp$config$$config.async($$$internal$$publish, promise); - } - } - - function $$$internal$$reject(promise, reason) { - if (promise._state !== $$$internal$$PENDING) { return; } - promise._state = $$$internal$$REJECTED; - promise._result = reason; - - $$rsvp$config$$config.async($$$internal$$publishRejection, promise); - } - - function $$$internal$$subscribe(parent, child, onFulfillment, onRejection) { - var subscribers = parent._subscribers; - var length = subscribers.length; - - parent._onerror = null; - - subscribers[length] = child; - subscribers[length + $$$internal$$FULFILLED] = onFulfillment; - subscribers[length + $$$internal$$REJECTED] = onRejection; - - if (length === 0 && parent._state) { - $$rsvp$config$$config.async($$$internal$$publish, parent); - } - } - - function $$$internal$$publish(promise) { - var subscribers = promise._subscribers; - var settled = promise._state; - - if ($$rsvp$config$$config.instrument) { - $$instrument$$default(settled === $$$internal$$FULFILLED ? 'fulfilled' : 'rejected', promise); - } - - if (subscribers.length === 0) { return; } - - var child, callback, detail = promise._result; - - for (var i = 0; i < subscribers.length; i += 3) { - child = subscribers[i]; - callback = subscribers[i + settled]; - - if (child) { - $$$internal$$invokeCallback(settled, child, callback, detail); + function handleMaybeThenable(promise, maybeThenable) { + if (maybeThenable instanceof promise.constructor) { + handleOwnThenable(promise, maybeThenable); } else { - callback(detail); + var then = getThen(maybeThenable); + if (then === GET_THEN_ERROR) { + reject(promise, GET_THEN_ERROR.error); + } else if (then === undefined) { + fulfill(promise, maybeThenable); + } else if (isFunction(then)) { + handleForeignThenable(promise, maybeThenable, then); + } else { + fulfill(promise, maybeThenable); + } } - } - - promise._subscribers.length = 0; } - - function $$$internal$$ErrorObject() { - this.error = null; - } - - var $$$internal$$TRY_CATCH_ERROR = new $$$internal$$ErrorObject(); - - function $$$internal$$tryCatch(callback, detail) { - try { - return callback(detail); - } catch(e) { - $$$internal$$TRY_CATCH_ERROR.error = e; - return $$$internal$$TRY_CATCH_ERROR; - } - } - - function $$$internal$$invokeCallback(settled, promise, callback, detail) { - var hasCallback = $$utils$$isFunction(callback), - value, error, succeeded, failed; - - if (hasCallback) { - value = $$$internal$$tryCatch(callback, detail); - - if (value === $$$internal$$TRY_CATCH_ERROR) { - failed = true; - error = value.error; - value = null; - } else { - succeeded = true; - } - + function resolve(promise, value) { if (promise === value) { - $$$internal$$reject(promise, new TypeError('A promises callback cannot return that same promise.')); - return; - } - - } else { - value = detail; - succeeded = true; - } - - if (promise._state !== $$$internal$$PENDING) { - // noop - } else if (hasCallback && succeeded) { - $$$internal$$resolve(promise, value); - } else if (failed) { - $$$internal$$reject(promise, error); - } else if (settled === $$$internal$$FULFILLED) { - $$$internal$$fulfill(promise, value); - } else if (settled === $$$internal$$REJECTED) { - $$$internal$$reject(promise, value); - } - } - - function $$$internal$$initializePromise(promise, resolver) { - try { - resolver(function resolvePromise(value){ - $$$internal$$resolve(promise, value); - }, function rejectPromise(reason) { - $$$internal$$reject(promise, reason); - }); - } catch(e) { - $$$internal$$reject(promise, e); - } - } - - function $$enumerator$$makeSettledResult(state, position, value) { - if (state === $$$internal$$FULFILLED) { - return { - state: 'fulfilled', - value: value - }; - } else { - return { - state: 'rejected', - reason: value - }; - } - } - - function $$enumerator$$Enumerator(Constructor, input, abortOnReject, label) { - this._instanceConstructor = Constructor; - this.promise = new Constructor($$$internal$$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) { - $$$internal$$fulfill(this.promise, this._result); + fulfill(promise, value); + } else if (objectOrFunction(value)) { + handleMaybeThenable(promise, value); } else { - this.length = this.length || 0; - this._enumerate(); - if (this._remaining === 0) { - $$$internal$$fulfill(this.promise, this._result); - } + fulfill(promise, value); } - } else { - $$$internal$$reject(this.promise, this._validationError()); - } } - - $$enumerator$$Enumerator.prototype._validateInput = function(input) { - return $$utils$$isArray(input); - }; - - $$enumerator$$Enumerator.prototype._validationError = function() { - return new Error('Array Methods must be provided an Array'); - }; - - $$enumerator$$Enumerator.prototype._init = function() { - this._result = new Array(this.length); - }; - - var $$enumerator$$default = $$enumerator$$Enumerator; - - $$enumerator$$Enumerator.prototype._enumerate = function() { - var length = this.length; - var promise = this.promise; - var input = this._input; - - for (var i = 0; promise._state === $$$internal$$PENDING && i < length; i++) { - this._eachEntry(input[i], i); - } - }; - - $$enumerator$$Enumerator.prototype._eachEntry = function(entry, i) { - var c = this._instanceConstructor; - if ($$utils$$isMaybeThenable(entry)) { - if (entry.constructor === c && entry._state !== $$$internal$$PENDING) { - entry._onerror = null; - this._settledAt(entry._state, i, entry._result); - } else { - this._willSettleAt(c.resolve(entry), i); + function publishRejection(promise) { + if (promise._onerror) { + promise._onerror(promise._result); } - } else { - this._remaining--; - this._result[i] = this._makeResult($$$internal$$FULFILLED, i, entry); - } - }; - - $$enumerator$$Enumerator.prototype._settledAt = function(state, i, value) { - var promise = this.promise; - - if (promise._state === $$$internal$$PENDING) { - this._remaining--; - - if (this._abortOnReject && state === $$$internal$$REJECTED) { - $$$internal$$reject(promise, value); - } else { - this._result[i] = this._makeResult(state, i, value); + publish(promise); + } + function fulfill(promise, value) { + if (promise._state !== PENDING) { + return; } - } - - if (this._remaining === 0) { - $$$internal$$fulfill(promise, this._result); - } + promise._result = value; + promise._state = FULFILLED; + if (promise._subscribers.length === 0) { + if (config.instrument) { + instrument('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(settled === FULFILLED ? 'fulfilled' : 'rejected', promise); + } + if (subscribers.length === 0) { + return; + } + var child, callback, 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, error, succeeded, failed; + if (hasCallback) { + value = tryCatch(callback, detail); + if (value === TRY_CATCH_ERROR) { + failed = true; + error = value.error; + value = null; + } else { + succeeded = true; + } + if (promise === value) { + reject(promise, new TypeError('A promises callback cannot return that same promise.')); + 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) { + try { + resolver(function resolvePromise(value) { + resolve(promise, value); + }, function rejectPromise(reason) { + reject(promise, reason); + }); + } catch (e) { + reject(promise, e); + } + } + __exports__.noop = noop; + __exports__.resolve = resolve; + __exports__.reject = reject; + __exports__.fulfill = fulfill; + __exports__.subscribe = subscribe; + __exports__.publish = publish; + __exports__.publishRejection = publishRejection; + __exports__.initializePromise = initializePromise; + __exports__.invokeCallback = invokeCallback; + __exports__.FULFILLED = FULFILLED; + __exports__.REJECTED = REJECTED; +}); +define('rsvp/all-settled', [ + './enumerator', + './promise', + './utils', + 'exports' +], function (__dependency1__, __dependency2__, __dependency3__, __exports__) { + 'use strict'; + var Enumerator = __dependency1__['default']; + var makeSettledResult = __dependency1__.makeSettledResult; + var Promise = __dependency2__['default']; + var o_create = __dependency3__.o_create; + function AllSettled(Constructor, entries, label) { + this._superConstructor(Constructor, entries, false, 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. - $$enumerator$$Enumerator.prototype._makeResult = function(state, i, value) { - return value; - }; + 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. - $$enumerator$$Enumerator.prototype._willSettleAt = function(promise, i) { - var enumerator = this; + 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: - $$$internal$$subscribe(promise, undefined, function(value) { - enumerator._settledAt($$$internal$$FULFILLED, i, value); - }, function(reason) { - enumerator._settledAt($$$internal$$REJECTED, i, reason); + ```javascript + { state: 'fulfilled', value: value } + or + { state: 'rejected', reason: reason } + ``` + + Example: + + ```javascript + var promise1 = RSVP.Promise.resolve(1); + var promise2 = RSVP.Promise.reject(new Error('2')); + var promise3 = RSVP.Promise.reject(new Error('3')); + var 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} promises + @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. + */ + __exports__['default'] = function allSettled(entries, label) { + return new AllSettled(Promise, entries, label).promise; }; +}); +define('rsvp/all', [ + './promise', + 'exports' +], function (__dependency1__, __exports__) { + 'use strict'; + var Promise = __dependency1__['default']; + /** + This is a convenient alias for `RSVP.Promise.all`. - var $$promise$all$$default = function all(entries, label) { - return new $$enumerator$$default(this, entries, true /* abort on reject */, label).promise; + @method all + @static + @for RSVP + @param {Array} array Array of promises. + @param {String} label An optional label. This is useful + for tooling. + */ + __exports__['default'] = function all(array, label) { + return Promise.all(array, label); }; - - var $$promise$race$$default = function race(entries, label) { - /*jshint validthis:true */ - var Constructor = this; - - var promise = new Constructor($$$internal$$noop, label); - - if (!$$utils$$isArray(entries)) { - $$$internal$$reject(promise, new TypeError('You must pass an array to race.')); - return promise; - } - - var length = entries.length; - - function onFulfillment(value) { - $$$internal$$resolve(promise, value); - } - - function onRejection(reason) { - $$$internal$$reject(promise, reason); - } - - for (var i = 0; promise._state === $$$internal$$PENDING && i < length; i++) { - $$$internal$$subscribe(Constructor.resolve(entries[i]), undefined, onFulfillment, onRejection); - } - - return promise; +}); +define('rsvp/asap', ['exports'], function (__exports__) { + 'use strict'; + var length = 0; + __exports__['default'] = function asap(callback, arg) { + queue[length] = callback; + queue[length + 1] = arg; + length += 2; + if (length === 2) { + // If length 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(); + } }; - - var $$promise$resolve$$default = function resolve(object, label) { - /*jshint validthis:true */ - var Constructor = this; - - if (object && typeof object === 'object' && object.constructor === Constructor) { - return object; - } - - var promise = new Constructor($$$internal$$noop, label); - $$$internal$$resolve(promise, object); - return promise; - }; - - var $$promise$reject$$default = function reject(reason, label) { - /*jshint validthis:true */ - var Constructor = this; - var promise = new Constructor($$$internal$$noop, label); - $$$internal$$reject(promise, reason); - return promise; - }; - - var $$rsvp$promise$$guidKey = 'rsvp_' + $$utils$$now() + '-'; - var $$rsvp$promise$$counter = 0; - - function $$rsvp$promise$$needsResolver() { - throw new TypeError('You must pass a resolver function as the first argument to the promise constructor'); + var browserGlobal = typeof window !== 'undefined' ? window : {}; + var BrowserMutationObserver = browserGlobal.MutationObserver || browserGlobal.WebKitMutationObserver; + // test for web worker but not in IE10 + var isWorker = typeof Uint8ClampedArray !== 'undefined' && typeof importScripts !== 'undefined' && typeof MessageChannel !== 'undefined'; + // node + function useNextTick() { + return function () { + process.nextTick(flush); + }; } - - function $$rsvp$promise$$needsNew() { - throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function."); + function useMutationObserver() { + var iterations = 0; + var observer = new BrowserMutationObserver(flush); + var node = document.createTextNode(''); + observer.observe(node, { characterData: true }); + return function () { + node.data = iterations = ++iterations % 2; + }; } + // web worker + function useMessageChannel() { + var channel = new MessageChannel(); + channel.port1.onmessage = flush; + return function () { + channel.port2.postMessage(0); + }; + } + function useSetTimeout() { + return function () { + setTimeout(flush, 1); + }; + } + var queue = new Array(1000); + function flush() { + for (var i = 0; i < length; i += 2) { + var callback = queue[i]; + var arg = queue[i + 1]; + callback(arg); + queue[i] = undefined; + queue[i + 1] = undefined; + } + length = 0; + } + var scheduleFlush; + // Decide what async method to use to triggering processing of queued callbacks: + if (typeof process !== 'undefined' && {}.toString.call(process) === '[object process]') { + scheduleFlush = useNextTick(); + } else if (BrowserMutationObserver) { + scheduleFlush = useMutationObserver(); + } else if (isWorker) { + scheduleFlush = useMessageChannel(); + } else { + scheduleFlush = useSetTimeout(); + } +}); +define('rsvp/config', [ + './events', + 'exports' +], function (__dependency1__, __exports__) { + 'use strict'; + var EventTarget = __dependency1__['default']; + 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]; + } + } + __exports__.config = config; + __exports__.configure = configure; +}); +define('rsvp/defer', [ + './promise', + 'exports' +], function (__dependency1__, __exports__) { + 'use strict'; + var Promise = __dependency1__['default']; + /** + `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. - var $$rsvp$promise$$default = $$rsvp$promise$$Promise; + 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 + var deferred = RSVP.defer(); + + deferred.resolve("Success!"); + + defered.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} + */ + __exports__['default'] = function defer(label) { + var deferred = {}; + deferred.promise = new Promise(function (resolve, reject) { + deferred.resolve = resolve; + deferred.reject = reject; + }, label); + return deferred; + }; +}); +define('rsvp/enumerator', [ + './utils', + './-internal', + 'exports' +], function (__dependency1__, __dependency2__, __exports__) { + 'use strict'; + var isArray = __dependency1__.isArray; + var isMaybeThenable = __dependency1__.isMaybeThenable; + var noop = __dependency2__.noop; + var reject = __dependency2__.reject; + var fulfill = __dependency2__.fulfill; + var subscribe = __dependency2__.subscribe; + var FULFILLED = __dependency2__.FULFILLED; + var REJECTED = __dependency2__.REJECTED; + var PENDING = __dependency2__.PENDING; + var ABORT_ON_REJECTION = true; + __exports__.ABORT_ON_REJECTION = ABORT_ON_REJECTION; + function makeSettledResult(state, position, value) { + if (state === FULFILLED) { + return { + state: 'fulfilled', + value: value + }; + } else { + return { + state: 'rejected', + reason: value + }; + } + } + __exports__.makeSettledResult = makeSettledResult; + 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); + }; + __exports__['default'] = Enumerator; + 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._eachEntry = function (entry, i) { + var c = this._instanceConstructor; + if (isMaybeThenable(entry)) { + if (entry.constructor === c && entry._state !== PENDING) { + entry._onerror = null; + this._settledAt(entry._state, i, entry._result); + } else { + this._willSettleAt(c.resolve(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) { + enumerator._settledAt(FULFILLED, i, value); + }, function (reason) { + enumerator._settledAt(REJECTED, i, reason); + }); + }; +}); +define('rsvp/events', ['exports'], 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 + */ + __exports__['default'] = { + mixin: function (object) { + object.on = this.on; + object.off = this.off; + object.trigger = this.trigger; + object._promiseCallbacks = undefined; + return object; + }, + on: function (eventName, callback) { + var allCallbacks = callbacksFor(this), callbacks; + callbacks = allCallbacks[eventName]; + if (!callbacks) { + callbacks = allCallbacks[eventName] = []; + } + if (indexOf(callbacks, callback) === -1) { + callbacks.push(callback); + } + }, + off: function (eventName, callback) { + var allCallbacks = callbacksFor(this), callbacks, index; + if (!callback) { + allCallbacks[eventName] = []; + return; + } + callbacks = allCallbacks[eventName]; + index = indexOf(callbacks, callback); + if (index !== -1) { + callbacks.splice(index, 1); + } + }, + trigger: function (eventName, options) { + var allCallbacks = callbacksFor(this), callbacks, callbackTuple, callback, binding; + 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); + } + } + } + }; +}); +define('rsvp/filter', [ + './promise', + './utils', + 'exports' +], function (__dependency1__, __dependency2__, __exports__) { + 'use strict'; + var Promise = __dependency1__['default']; + var isFunction = __dependency2__.isFunction; + var isMaybeThenable = __dependency2__.isMaybeThenable; + /** + `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 + + var promise1 = RSVP.resolve(1); + var promise2 = RSVP.resolve(2); + var promise3 = RSVP.resolve(3); + + var promises = [promise1, promise2, promise3]; + + var 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 + var promise1 = RSVP.resolve(1); + var promise2 = RSVP.reject(new Error("2")); + var promise3 = RSVP.reject(new Error("3")); + var promises = [ promise1, promise2, promise3 ]; + + var 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 + + var alice = { name: 'alice' }; + var bob = { name: 'bob' }; + var users = [ alice, bob ]; + + var promises = users.map(function(user){ + return RSVP.resolve(user); + }); + + var 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} + */ + __exports__['default'] = function filter(promises, filterFn, label) { + return Promise.all(promises, label).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 Promise.all(filtered, label).then(function (filtered$2) { + var results = new Array(length); + var newLength = 0; + for (var i$2 = 0; i$2 < length; i$2++) { + if (filtered$2[i$2]) { + results[newLength] = values[i$2]; + newLength++; + } + } + results.length = newLength; + return results; + }); + }); + }; +}); +define('rsvp/hash-settled', [ + './promise', + './enumerator', + './promise-hash', + './utils', + 'exports' +], function (__dependency1__, __dependency2__, __dependency3__, __dependency4__, __exports__) { + 'use strict'; + var Promise = __dependency1__['default']; + var makeSettledResult = __dependency2__.makeSettledResult; + var PromiseHash = __dependency3__['default']; + var Enumerator = __dependency2__['default']; + var o_create = __dependency4__.o_create; + 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 + var 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 + var 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') + }; + + var 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} promises + @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 + */ + __exports__['default'] = function hashSettled(object, label) { + return new HashSettled(Promise, object, label).promise; + }; +}); +define('rsvp/hash', [ + './promise', + './promise-hash', + './enumerator', + 'exports' +], function (__dependency1__, __dependency2__, __dependency3__, __exports__) { + 'use strict'; + var Promise = __dependency1__['default']; + var PromiseHash = __dependency2__['default']; + var ABORT_ON_REJECTION = __dependency3__.ABORT_ON_REJECTION; + /** + `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 + var 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 + var 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") + }; + + var 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} promises + @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. + */ + __exports__['default'] = function hash(object, label) { + return new PromiseHash(Promise, object, label).promise; + }; +}); +define('rsvp/instrument', [ + './config', + './utils', + 'exports' +], function (__dependency1__, __dependency2__, __exports__) { + 'use strict'; + var config = __dependency1__.config; + var now = __dependency2__.now; + var queue = []; + __exports__['default'] = function instrument(eventName, promise, child) { + if (1 === queue.push({ + name: eventName, + payload: { + guid: promise._guidKey + promise._id, + eventName: eventName, + detail: promise._result, + childGuid: child && promise._guidKey + child._id, + label: promise._label, + timeStamp: now(), + stack: new Error(promise._label).stack + } + })) { + setTimeout(function () { + var entry; + for (var i = 0; i < queue.length; i++) { + entry = queue[i]; + config.trigger(entry.name, entry.payload); + } + queue.length = 0; + }, 50); + } + }; +}); +define('rsvp/map', [ + './promise', + './utils', + 'exports' +], function (__dependency1__, __dependency2__, __exports__) { + 'use strict'; + var Promise = __dependency1__['default']; + var isArray = __dependency2__.isArray; + var isFunction = __dependency2__.isFunction; + /** + `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 + + var promise1 = RSVP.resolve(1); + var promise2 = RSVP.resolve(2); + var promise3 = RSVP.resolve(3); + var promises = [ promise1, promise2, promise3 ]; + + var 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 + var promise1 = RSVP.resolve(1); + var promise2 = RSVP.reject(new Error("2")); + var promise3 = RSVP.reject(new Error("3")); + var promises = [ promise1, promise2, promise3 ]; + + var 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 + + var 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 + */ + __exports__['default'] = function map(promises, mapFn, label) { + return Promise.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.all(results, label); + }); + }; +}); +define('rsvp/node', [ + './promise', + './utils', + 'exports' +], function (__dependency1__, __dependency2__, __exports__) { + 'use strict'; + /* global arraySlice */ + var Promise = __dependency1__['default']; + var isArray = __dependency2__.isArray; + /** + `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 + var fs = require('fs'); + + fs.readFile('myfile.txt', function(err, data){ + if (err) return handleError(err); + handleData(data); + }); + ``` + + into: + + ```javascript + var fs = require('fs'); + var 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 + var 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 + var 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 + var 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 + var app = require('express')(); + var 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 + var 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 + var 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 + var fs = require('fs'); + var readFile = RSVP.denodeify(fs.readFile); + var 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} argumentNames 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 + */ + __exports__['default'] = function denodeify(nodeFunc, argumentNames) { + var asArray = argumentNames === true; + var asHash = isArray(argumentNames); + function denodeifiedFunction() { + var length = arguments.length; + var nodeArgs = new Array(length); + for (var i = 0; i < length; i++) { + nodeArgs[i] = arguments[i]; + } + var thisArg; + if (!asArray && !asHash && argumentNames) { + if (typeof console === 'object') { + console.warn('Deprecation: RSVP.denodeify() doesn\'t allow setting the ' + '"this" binding anymore. Use yourFunction.bind(yourThis) instead.'); + } + thisArg = argumentNames; + } else { + thisArg = this; + } + return Promise.all(nodeArgs).then(function (nodeArgs$2) { + return new Promise(resolver); + // sweet.js has a bug, this resolver can't be defined in the constructor + // or the arraySlice macro doesn't work + function resolver(resolve, reject) { + function callback() { + var length$2 = arguments.length; + var args = new Array(length$2); + for (var i$2 = 0; i$2 < length$2; i$2++) { + args[i$2] = arguments[i$2]; + } + var error = args[0]; + var value = args[1]; + if (error) { + reject(error); + } else if (asArray) { + resolve(args.slice(1)); + } else if (asHash) { + var obj = {}; + var successArguments = args.slice(1); + var name; + var i$3; + for (i$3 = 0; i$3 < argumentNames.length; i$3++) { + name = argumentNames[i$3]; + obj[name] = successArguments[i$3]; + } + resolve(obj); + } else { + resolve(value); + } + } + nodeArgs$2.push(callback); + nodeFunc.apply(thisArg, nodeArgs$2); + } + }); + } + denodeifiedFunction.__proto__ = nodeFunc; + return denodeifiedFunction; + }; +}); +define('rsvp/promise-hash', [ + './enumerator', + './-internal', + './utils', + 'exports' +], function (__dependency1__, __dependency2__, __dependency3__, __exports__) { + 'use strict'; + var Enumerator = __dependency1__['default']; + var PENDING = __dependency2__.PENDING; + var FULFILLED = __dependency2__.FULFILLED; + var o_create = __dependency3__.o_create; + function PromiseHash(Constructor, object, label) { + this._superConstructor(Constructor, object, true, label); + } + __exports__['default'] = PromiseHash; + 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 promise = this.promise; + var input = this._input; + var results = []; + for (var key in input) { + if (promise._state === PENDING && input.hasOwnProperty(key)) { + results.push({ + position: key, + entry: input[key] + }); + } + } + var length = results.length; + this._remaining = length; + var result; + for (var i = 0; promise._state === PENDING && i < length; i++) { + result = results[i]; + this._eachEntry(result.entry, result.position); + } + }; +}); +define('rsvp/promise', [ + './config', + './events', + './instrument', + './utils', + './-internal', + './promise/cast', + './promise/all', + './promise/race', + './promise/resolve', + './promise/reject', + 'exports' +], function (__dependency1__, __dependency2__, __dependency3__, __dependency4__, __dependency5__, __dependency6__, __dependency7__, __dependency8__, __dependency9__, __dependency10__, __exports__) { + 'use strict'; + var config = __dependency1__.config; + var EventTarget = __dependency2__['default']; + var instrument = __dependency3__['default']; + var objectOrFunction = __dependency4__.objectOrFunction; + var isFunction = __dependency4__.isFunction; + var now = __dependency4__.now; + var noop = __dependency5__.noop; + var resolve = __dependency5__.resolve; + var reject = __dependency5__.reject; + var fulfill = __dependency5__.fulfill; + var subscribe = __dependency5__.subscribe; + var initializePromise = __dependency5__.initializePromise; + var invokeCallback = __dependency5__.invokeCallback; + var FULFILLED = __dependency5__.FULFILLED; + var cast = __dependency6__['default']; + var all = __dependency7__['default']; + var race = __dependency8__['default']; + var Resolve = __dependency9__['default']; + var Reject = __dependency10__['default']; + 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.'); + } + __exports__['default'] = Promise; /** Promise objects represent the eventual result of an asynchronous operation. The primary way of interacting with a promise is through its `then` method, which @@ -805,7 +1565,7 @@ EPUBJS.Render = {}; if (this.status === 200) { resolve(this.response); } else { - reject(new Error('getJSON: `' + url + '` failed with status: [' + this.status + ']')); + reject(new Error("getJSON: `" + url + "` failed with status: [" + this.status + "]")); } } }; @@ -839,809 +1599,637 @@ EPUBJS.Render = {}; Useful for tooling. @constructor */ - function $$rsvp$promise$$Promise(resolver, label) { - this._id = $$rsvp$promise$$counter++; - this._label = label; - this._state = undefined; - this._result = undefined; - this._subscribers = []; - - if ($$rsvp$config$$config.instrument) { - $$instrument$$default('created', this); - } - - if ($$$internal$$noop !== resolver) { - if (!$$utils$$isFunction(resolver)) { - $$rsvp$promise$$needsResolver(); + function Promise(resolver, label) { + this._id = counter++; + this._label = label; + this._subscribers = []; + if (config.instrument) { + instrument('created', this); } - - if (!(this instanceof $$rsvp$promise$$Promise)) { - $$rsvp$promise$$needsNew(); - } - - $$$internal$$initializePromise(this, resolver); - } - } - - // deprecated - $$rsvp$promise$$Promise.cast = $$promise$resolve$$default; - - $$rsvp$promise$$Promise.all = $$promise$all$$default; - $$rsvp$promise$$Promise.race = $$promise$race$$default; - $$rsvp$promise$$Promise.resolve = $$promise$resolve$$default; - $$rsvp$promise$$Promise.reject = $$promise$reject$$default; - - $$rsvp$promise$$Promise.prototype = { - constructor: $$rsvp$promise$$Promise, - - _guidKey: $$rsvp$promise$$guidKey, - - _onerror: function (reason) { - $$rsvp$config$$config.trigger('error', reason); - }, - - /** - 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 - var 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 - var 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} onFulfilled - @param {Function} onRejected - @param {String} label optional string for labeling the promise. - Useful for tooling. - @return {Promise} - */ - then: function(onFulfillment, onRejection, label) { - var parent = this; - var state = parent._state; - - if (state === $$$internal$$FULFILLED && !onFulfillment || state === $$$internal$$REJECTED && !onRejection) { - if ($$rsvp$config$$config.instrument) { - $$instrument$$default('chained', this, this); - } - return this; - } - - parent._onerror = null; - - var child = new this.constructor($$$internal$$noop, label); - var result = parent._result; - - if ($$rsvp$config$$config.instrument) { - $$instrument$$default('chained', parent, child); - } - - if (state) { - var callback = arguments[state - 1]; - $$rsvp$config$$config.async(function(){ - $$$internal$$invokeCallback(state, child, callback, result); - }); - } else { - $$$internal$$subscribe(parent, child, onFulfillment, onRejection); - } - - return child; - }, - - /** - `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(onRejection, label) { - return this.then(null, 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 findOtherAuther(); - } finally { - // always runs - // doesn't affect the return value - } - ``` - - Asynchronous example: - - ```js - findAuthor().catch(function(reason){ - return findOtherAuther(); - }).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(callback, label) { - var constructor = this.constructor; - - return this.then(function(value) { - return constructor.resolve(callback()).then(function(){ - return value; - }); - }, function(reason) { - return constructor.resolve(callback()).then(function(){ - throw reason; - }); - }, label); - } - }; - - function $$rsvp$node$$Result() { - this.value = undefined; - } - - var $$rsvp$node$$ERROR = new $$rsvp$node$$Result(); - var $$rsvp$node$$GET_THEN_ERROR = new $$rsvp$node$$Result(); - - function $$rsvp$node$$getThen(obj) { - try { - return obj.then; - } catch(error) { - $$rsvp$node$$ERROR.value= error; - return $$rsvp$node$$ERROR; - } - } - - function $$rsvp$node$$tryApply(f, s, a) { - try { - f.apply(s, a); - } catch(error) { - $$rsvp$node$$ERROR.value = error; - return $$rsvp$node$$ERROR; - } - } - - function $$rsvp$node$$makeObject(_, argumentNames) { - var obj = {}; - var name; - var i; - var length = _.length; - var args = new Array(length); - - for (var x = 0; x < length; x++) { - args[x] = _[x]; - } - - for (i = 0; i < argumentNames.length; i++) { - name = argumentNames[i]; - obj[name] = args[i + 1]; - } - - return obj; - } - - function $$rsvp$node$$arrayResult(_) { - var length = _.length; - var args = new Array(length - 1); - - for (var i = 1; i < length; i++) { - args[i - 1] = _[i]; - } - - return args; - } - - function $$rsvp$node$$wrapThenable(then, promise) { - return { - then: function(onFulFillment, onRejection) { - return then.call(promise, onFulFillment, onRejection); - } - }; - } - - var $$rsvp$node$$default = function denodeify(nodeFunc, options) { - var fn = function() { - var self = this; - var l = arguments.length; - var args = new Array(l + 1); - var arg; - var promiseInput = false; - - for (var i = 0; i < l; ++i) { - arg = arguments[i]; - - if (!promiseInput) { - // TODO: clean this up - promiseInput = $$rsvp$node$$needsPromiseInput(arg); - if (promiseInput === $$rsvp$node$$GET_THEN_ERROR) { - var p = new $$rsvp$promise$$default($$$internal$$noop); - $$$internal$$reject(p, $$rsvp$node$$GET_THEN_ERROR.value); - return p; - } else if (promiseInput && promiseInput !== true) { - arg = $$rsvp$node$$wrapThenable(promiseInput, arg); + if (noop !== resolver) { + if (!isFunction(resolver)) { + needsResolver(); } - } - args[i] = arg; + if (!(this instanceof Promise)) { + needsNew(); + } + initializePromise(this, resolver); } - - var promise = new $$rsvp$promise$$default($$$internal$$noop); - - args[l] = function(err, val) { - if (err) - $$$internal$$reject(promise, err); - else if (options === undefined) - $$$internal$$resolve(promise, val); - else if (options === true) - $$$internal$$resolve(promise, $$rsvp$node$$arrayResult(arguments)); - else if ($$utils$$isArray(options)) - $$$internal$$resolve(promise, $$rsvp$node$$makeObject(arguments, options)); - else - $$$internal$$resolve(promise, val); - }; - - if (promiseInput) { - return $$rsvp$node$$handlePromiseInput(promise, args, nodeFunc, self); - } else { - return $$rsvp$node$$handleValueInput(promise, args, nodeFunc, self); - } - }; - - fn.__proto__ = nodeFunc; - - return fn; - }; - - function $$rsvp$node$$handleValueInput(promise, args, nodeFunc, self) { - var result = $$rsvp$node$$tryApply(nodeFunc, self, args); - if (result === $$rsvp$node$$ERROR) { - $$$internal$$reject(promise, result.value); - } - return promise; } + Promise.cast = cast; + Promise.all = all; + Promise.race = race; + Promise.resolve = Resolve; + Promise.reject = Reject; + Promise.prototype = { + constructor: Promise, + _id: undefined, + _guidKey: guidKey, + _label: undefined, + _state: undefined, + _result: undefined, + _subscribers: undefined, + _onerror: function (reason) { + config.trigger('error', reason); + }, + then: function (onFulfillment, onRejection, label) { + var parent = this; + parent._onerror = null; + var child = new this.constructor(noop, label); + var state = parent._state; + var result = parent._result; + if (config.instrument) { + instrument('chained', parent, child); + } + if (state === FULFILLED && onFulfillment) { + config.async(function () { + invokeCallback(state, child, onFulfillment, result); + }); + } else { + subscribe(parent, child, onFulfillment, onRejection); + } + return child; + }, + 'catch': function (onRejection, label) { + return this.then(null, onRejection, label); + }, + 'finally': function (callback, label) { + var constructor = this.constructor; + return this.then(function (value) { + return constructor.resolve(callback()).then(function () { + return value; + }); + }, function (reason) { + return constructor.resolve(callback()).then(function () { + throw reason; + }); + }, label); + } + }; +}); +define('rsvp/promise/all', [ + '../enumerator', + 'exports' +], function (__dependency1__, __exports__) { + 'use strict'; + var Enumerator = __dependency1__['default']; + /** + `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. - function $$rsvp$node$$handlePromiseInput(promise, args, nodeFunc, self){ - return $$rsvp$promise$$default.all(args).then(function(args){ - var result = $$rsvp$node$$tryApply(nodeFunc, self, args); - if (result === $$rsvp$node$$ERROR) { - $$$internal$$reject(promise, result.value); + Example: + + ```javascript + var promise1 = RSVP.resolve(1); + var promise2 = RSVP.resolve(2); + var promise3 = RSVP.resolve(3); + var 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 + var promise1 = RSVP.resolve(1); + var promise2 = RSVP.reject(new Error("2")); + var promise3 = RSVP.reject(new Error("3")); + var 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 + */ + __exports__['default'] = function all(entries, label) { + return new Enumerator(this, entries, true, label).promise; + }; +}); +define('rsvp/promise/cast', [ + './resolve', + 'exports' +], function (__dependency1__, __exports__) { + 'use strict'; + var resolve = __dependency1__['default']; + /** + @deprecated + + `RSVP.Promise.cast` coerces its argument to a promise, or returns the + argument if it is already a promise which shares a constructor with the caster. + + Example: + + ```javascript + var promise = RSVP.Promise.resolve(1); + var casted = RSVP.Promise.cast(promise); + + console.log(promise === casted); // true + ``` + + In the case of a promise whose constructor does not match, it is assimilated. + The resulting promise will fulfill or reject based on the outcome of the + promise being casted. + + Example: + + ```javascript + var thennable = $.getJSON('/api/foo'); + var casted = RSVP.Promise.cast(thennable); + + console.log(thennable === casted); // false + console.log(casted instanceof RSVP.Promise) // true + + casted.then(function(data) { + // data is the value getJSON fulfills with + }); + ``` + + In the case of a non-promise, a promise which will fulfill with that value is + returned. + + Example: + + ```javascript + var value = 1; // could be a number, boolean, string, undefined... + var casted = RSVP.Promise.cast(value); + + console.log(value === casted); // false + console.log(casted instanceof RSVP.Promise) // true + + casted.then(function(val) { + val === value // => true + }); + ``` + + `RSVP.Promise.cast` is similar to `RSVP.Promise.resolve`, but `RSVP.Promise.cast` differs in the + following ways: + + * `RSVP.Promise.cast` serves as a memory-efficient way of getting a promise, when you + have something that could either be a promise or a value. RSVP.resolve + will have the same effect but will create a new promise wrapper if the + argument is a promise. + * `RSVP.Promise.cast` is a way of casting incoming thenables or promise subclasses to + promises of the exact class specified, so that the resulting object's `then` is + ensured to have the behavior of the constructor you are calling cast on (i.e., RSVP.Promise). + + @method cast + @static + @param {Object} object to be casted + @param {String} label optional string for labeling the promise. + Useful for tooling. + @return {Promise} promise + */ + __exports__['default'] = resolve; +}); +define('rsvp/promise/race', [ + '../utils', + '../-internal', + 'exports' +], function (__dependency1__, __dependency2__, __exports__) { + 'use strict'; + var isArray = __dependency1__.isArray; + var isFunction = __dependency1__.isFunction; + var isMaybeThenable = __dependency1__.isMaybeThenable; + var noop = __dependency2__.noop; + var resolve = __dependency2__.resolve; + var reject = __dependency2__.reject; + var subscribe = __dependency2__.subscribe; + var PENDING = __dependency2__.PENDING; + /** + `RSVP.Promise.race` returns a new promise which is settled in the same way as the + first passed promise to settle. + + Example: + + ```javascript + var promise1 = new RSVP.Promise(function(resolve, reject){ + setTimeout(function(){ + resolve("promise 1"); + }, 200); + }); + + var 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 + var promise1 = new RSVP.Promise(function(resolve, reject){ + setTimeout(function(){ + resolve("promise 1"); + }, 200); + }); + + var 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} promises 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. + */ + __exports__['default'] = function race(entries, label) { + /*jshint validthis:true */ + var Constructor = this, entry; + var promise = new Constructor(noop, label); + if (!isArray(entries)) { + reject(promise, new TypeError('You must pass an array to race.')); + return promise; + } + var length = entries.length; + function onFulfillment(value) { + resolve(promise, value); + } + function onRejection(reason) { + reject(promise, reason); + } + for (var i = 0; promise._state === PENDING && i < length; i++) { + subscribe(Constructor.resolve(entries[i]), undefined, onFulfillment, onRejection); } return promise; + }; +}); +define('rsvp/promise/reject', [ + '../-internal', + 'exports' +], function (__dependency1__, __exports__) { + 'use strict'; + var noop = __dependency1__.noop; + var _reject = __dependency1__.reject; + /** + `RSVP.Promise.reject` returns a promise rejected with the passed `reason`. + It is shorthand for the following: + + ```javascript + var promise = new RSVP.Promise(function(resolve, reject){ + reject(new Error('WHOOPS')); }); - } - function $$rsvp$node$$needsPromiseInput(arg) { - if (arg && typeof arg === 'object') { - if (arg.constructor === $$rsvp$promise$$default) { - return true; - } else { - return $$rsvp$node$$getThen(arg); + 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 + var 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 {Any} 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`. + */ + __exports__['default'] = function reject(reason, label) { + /*jshint validthis:true */ + var Constructor = this; + var promise = new Constructor(noop, label); + _reject(promise, reason); + return promise; + }; +}); +define('rsvp/promise/resolve', [ + '../-internal', + 'exports' +], function (__dependency1__, __exports__) { + 'use strict'; + var noop = __dependency1__.noop; + var _resolve = __dependency1__.resolve; + /** + `RSVP.Promise.resolve` returns a promise that will become resolved with the + passed `value`. It is shorthand for the following: + + ```javascript + var 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 + var promise = RSVP.Promise.resolve(1); + + promise.then(function(value){ + // value === 1 + }); + ``` + + @method resolve + @static + @param {Any} 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` + */ + __exports__['default'] = function resolve(object, label) { + /*jshint validthis:true */ + var Constructor = this; + if (object && typeof object === 'object' && object.constructor === Constructor) { + return object; } - } else { - return false; - } - } - - var $$rsvp$all$$default = function all(array, label) { - return $$rsvp$promise$$default.all(array, label); + var promise = new Constructor(noop, label); + _resolve(promise, object); + return promise; }; +}); +define('rsvp/race', [ + './promise', + 'exports' +], function (__dependency1__, __exports__) { + 'use strict'; + var Promise = __dependency1__['default']; + /** + This is a convenient alias for `RSVP.Promise.race`. - function $$rsvp$all$settled$$AllSettled(Constructor, entries, label) { - this._superConstructor(Constructor, entries, false /* don't abort on reject */, label); - } - - $$rsvp$all$settled$$AllSettled.prototype = $$utils$$o_create($$enumerator$$default.prototype); - $$rsvp$all$settled$$AllSettled.prototype._superConstructor = $$enumerator$$default; - $$rsvp$all$settled$$AllSettled.prototype._makeResult = $$enumerator$$makeSettledResult; - - $$rsvp$all$settled$$AllSettled.prototype._validationError = function() { - return new Error('allSettled must be called with an array'); + @method race + @static + @for RSVP + @param {Array} array Array of promises. + @param {String} label An optional label. This is useful + for tooling. + */ + __exports__['default'] = function race(array, label) { + return Promise.race(array, label); }; +}); +define('rsvp/reject', [ + './promise', + 'exports' +], function (__dependency1__, __exports__) { + 'use strict'; + var Promise = __dependency1__['default']; + /** + This is a convenient alias for `RSVP.Promise.reject`. - var $$rsvp$all$settled$$default = function allSettled(entries, label) { - return new $$rsvp$all$settled$$AllSettled($$rsvp$promise$$default, entries, label).promise; + @method reject + @static + @for RSVP + @param {Any} 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`. + */ + __exports__['default'] = function reject(reason, label) { + return Promise.reject(reason, label); }; +}); +define('rsvp/resolve', [ + './promise', + 'exports' +], function (__dependency1__, __exports__) { + 'use strict'; + var Promise = __dependency1__['default']; + /** + This is a convenient alias for `RSVP.Promise.resolve`. - var $$rsvp$race$$default = function race(array, label) { - return $$rsvp$promise$$default.race(array, label); + @method resolve + @static + @for RSVP + @param {Any} 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` + */ + __exports__['default'] = function resolve(value, label) { + return Promise.resolve(value, label); }; +}); +define('rsvp/rethrow', ['exports'], function (__exports__) { + 'use strict'; + /** + `RSVP.rethrow` will rethrow an error on the next turn of the JavaScript event + loop in order to aid debugging. - function $$promise$hash$$PromiseHash(Constructor, object, label) { - this._superConstructor(Constructor, object, true, label); - } + 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. - var $$promise$hash$$default = $$promise$hash$$PromiseHash; - $$promise$hash$$PromiseHash.prototype = $$utils$$o_create($$enumerator$$default.prototype); - $$promise$hash$$PromiseHash.prototype._superConstructor = $$enumerator$$default; - - $$promise$hash$$PromiseHash.prototype._init = function() { - this._result = {}; - }; - - $$promise$hash$$PromiseHash.prototype._validateInput = function(input) { - return input && typeof input === 'object'; - }; - - $$promise$hash$$PromiseHash.prototype._validationError = function() { - return new Error('Promise.hash must be called with an object'); - }; - - $$promise$hash$$PromiseHash.prototype._enumerate = function() { - var promise = this.promise; - var input = this._input; - var results = []; - - for (var key in input) { - if (promise._state === $$$internal$$PENDING && input.hasOwnProperty(key)) { - results.push({ - position: key, - entry: input[key] - }); - } + ```javascript + function throws(){ + throw new Error('Whoops!'); } - var length = results.length; - this._remaining = length; - var result; - - for (var i = 0; promise._state === $$$internal$$PENDING && i < length; i++) { - result = results[i]; - this._eachEntry(result.entry, result.position); - } - }; - - var $$rsvp$hash$$default = function hash(object, label) { - return new $$promise$hash$$default($$rsvp$promise$$default, object, label).promise; - }; - - function $$rsvp$hash$settled$$HashSettled(Constructor, object, label) { - this._superConstructor(Constructor, object, false, label); - } - - $$rsvp$hash$settled$$HashSettled.prototype = $$utils$$o_create($$promise$hash$$default.prototype); - $$rsvp$hash$settled$$HashSettled.prototype._superConstructor = $$enumerator$$default; - $$rsvp$hash$settled$$HashSettled.prototype._makeResult = $$enumerator$$makeSettledResult; - - $$rsvp$hash$settled$$HashSettled.prototype._validationError = function() { - return new Error('hashSettled must be called with an object'); - }; - - var $$rsvp$hash$settled$$default = function hashSettled(object, label) { - return new $$rsvp$hash$settled$$HashSettled($$rsvp$promise$$default, object, label).promise; - }; - - var $$rsvp$rethrow$$default = function rethrow(reason) { - setTimeout(function() { - throw reason; + var promise = new RSVP.Promise(function(resolve, reject){ + throws(); }); - throw reason; - }; - var $$rsvp$defer$$default = function defer(label) { - var deferred = { }; - - deferred.promise = new $$rsvp$promise$$default(function(resolve, reject) { - deferred.resolve = resolve; - deferred.reject = reject; - }, label); - - return deferred; - }; - - var $$rsvp$map$$default = function map(promises, mapFn, label) { - return $$rsvp$promise$$default.all(promises, label).then(function(values) { - if (!$$utils$$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 $$rsvp$promise$$default.all(results, label); + 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 }); - }; + ``` - var $$rsvp$resolve$$default = function resolve(value, label) { - return $$rsvp$promise$$default.resolve(value, label); - }; + 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. - var $$rsvp$reject$$default = function reject(reason, label) { - return $$rsvp$promise$$default.reject(reason, label); - }; - - var $$rsvp$filter$$default = function filter(promises, filterFn, label) { - return $$rsvp$promise$$default.all(promises, label).then(function(values) { - if (!$$utils$$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 $$rsvp$promise$$default.all(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; + @method rethrow + @static + @for RSVP + @param {Error} reason reason the promise became rejected. + @throws Error + @static + */ + __exports__['default'] = function rethrow(reason) { + setTimeout(function () { + throw reason; }); - }); + throw reason; }; - - var $$rsvp$asap$$len = 0; - - var $$rsvp$asap$$default = function asap(callback, arg) { - $$rsvp$asap$$queue[$$rsvp$asap$$len] = callback; - $$rsvp$asap$$queue[$$rsvp$asap$$len + 1] = arg; - $$rsvp$asap$$len += 2; - if ($$rsvp$asap$$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. - $$rsvp$asap$$scheduleFlush(); - } - }; - - var $$rsvp$asap$$browserGlobal = (typeof window !== 'undefined') ? window : {}; - var $$rsvp$asap$$BrowserMutationObserver = $$rsvp$asap$$browserGlobal.MutationObserver || $$rsvp$asap$$browserGlobal.WebKitMutationObserver; - - // test for web worker but not in IE10 - var $$rsvp$asap$$isWorker = typeof Uint8ClampedArray !== 'undefined' && - typeof importScripts !== 'undefined' && - typeof MessageChannel !== 'undefined'; - - // node - function $$rsvp$asap$$useNextTick() { - return function() { - process.nextTick($$rsvp$asap$$flush); - }; +}); +define('rsvp/utils', ['exports'], function (__exports__) { + 'use strict'; + function objectOrFunction(x) { + return typeof x === 'function' || typeof x === 'object' && x !== null; } - - function $$rsvp$asap$$useMutationObserver() { - var iterations = 0; - var observer = new $$rsvp$asap$$BrowserMutationObserver($$rsvp$asap$$flush); - var node = document.createTextNode(''); - observer.observe(node, { characterData: true }); - - return function() { - node.data = (iterations = ++iterations % 2); - }; + __exports__.objectOrFunction = objectOrFunction; + function isFunction(x) { + return typeof x === 'function'; } - - // web worker - function $$rsvp$asap$$useMessageChannel() { - var channel = new MessageChannel(); - channel.port1.onmessage = $$rsvp$asap$$flush; - return function () { - channel.port2.postMessage(0); - }; + __exports__.isFunction = isFunction; + function isMaybeThenable(x) { + return typeof x === 'object' && x !== null; } - - function $$rsvp$asap$$useSetTimeout() { - return function() { - setTimeout($$rsvp$asap$$flush, 1); - }; - } - - var $$rsvp$asap$$queue = new Array(1000); - - function $$rsvp$asap$$flush() { - for (var i = 0; i < $$rsvp$asap$$len; i+=2) { - var callback = $$rsvp$asap$$queue[i]; - var arg = $$rsvp$asap$$queue[i+1]; - - callback(arg); - - $$rsvp$asap$$queue[i] = undefined; - $$rsvp$asap$$queue[i+1] = undefined; - } - - $$rsvp$asap$$len = 0; - } - - var $$rsvp$asap$$scheduleFlush; - - // Decide what async method to use to triggering processing of queued callbacks: - if (typeof process !== 'undefined' && {}.toString.call(process) === '[object process]') { - $$rsvp$asap$$scheduleFlush = $$rsvp$asap$$useNextTick(); - } else if ($$rsvp$asap$$BrowserMutationObserver) { - $$rsvp$asap$$scheduleFlush = $$rsvp$asap$$useMutationObserver(); - } else if ($$rsvp$asap$$isWorker) { - $$rsvp$asap$$scheduleFlush = $$rsvp$asap$$useMessageChannel(); + __exports__.isMaybeThenable = isMaybeThenable; + var _isArray; + if (!Array.isArray) { + _isArray = function (x) { + return Object.prototype.toString.call(x) === '[object Array]'; + }; } else { - $$rsvp$asap$$scheduleFlush = $$rsvp$asap$$useSetTimeout(); + _isArray = Array.isArray; } - + var isArray = _isArray; + __exports__.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(); + }; + __exports__.now = now; + var o_create = Object.create || function (object) { + var o = function () { + }; + o.prototype = object; + return o; + }; + __exports__.o_create = o_create; +}); +define('rsvp', [ + './rsvp/promise', + './rsvp/events', + './rsvp/node', + './rsvp/all', + './rsvp/all-settled', + './rsvp/race', + './rsvp/hash', + './rsvp/hash-settled', + './rsvp/rethrow', + './rsvp/defer', + './rsvp/config', + './rsvp/map', + './rsvp/resolve', + './rsvp/reject', + './rsvp/filter', + './rsvp/asap', + 'exports' +], function (__dependency1__, __dependency2__, __dependency3__, __dependency4__, __dependency5__, __dependency6__, __dependency7__, __dependency8__, __dependency9__, __dependency10__, __dependency11__, __dependency12__, __dependency13__, __dependency14__, __dependency15__, __dependency16__, __exports__) { + 'use strict'; + var Promise = __dependency1__['default']; + var EventTarget = __dependency2__['default']; + var denodeify = __dependency3__['default']; + var all = __dependency4__['default']; + var allSettled = __dependency5__['default']; + var race = __dependency6__['default']; + var hash = __dependency7__['default']; + var hashSettled = __dependency8__['default']; + var rethrow = __dependency9__['default']; + var defer = __dependency10__['default']; + var config = __dependency11__.config; + var configure = __dependency11__.configure; + var map = __dependency12__['default']; + var resolve = __dependency13__['default']; + var reject = __dependency14__['default']; + var filter = __dependency15__['default']; + var asap = __dependency16__['default']; + config.async = asap; // default async is asap; - $$rsvp$config$$config.async = $$rsvp$asap$$default; - - var $$rsvp$$cast = $$rsvp$resolve$$default; - - function $$rsvp$$async(callback, arg) { - $$rsvp$config$$config.async(callback, arg); + function async(callback, arg) { + config.async(callback, arg); } - - function $$rsvp$$on() { - $$rsvp$config$$config.on.apply($$rsvp$config$$config, arguments); + function on() { + config.on.apply(config, arguments); } - - function $$rsvp$$off() { - $$rsvp$config$$config.off.apply($$rsvp$config$$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 $$rsvp$$callbacks = window['__PROMISE_INSTRUMENTATION__']; - $$rsvp$config$$configure('instrument', true); - for (var $$rsvp$$eventName in $$rsvp$$callbacks) { - if ($$rsvp$$callbacks.hasOwnProperty($$rsvp$$eventName)) { - $$rsvp$$on($$rsvp$$eventName, $$rsvp$$callbacks[$$rsvp$$eventName]); + 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$umd$$RSVP = { - 'race': $$rsvp$race$$default, - 'Promise': $$rsvp$promise$$default, - 'allSettled': $$rsvp$all$settled$$default, - 'hash': $$rsvp$hash$$default, - 'hashSettled': $$rsvp$hash$settled$$default, - 'denodeify': $$rsvp$node$$default, - 'on': $$rsvp$$on, - 'off': $$rsvp$$off, - 'map': $$rsvp$map$$default, - 'filter': $$rsvp$filter$$default, - 'resolve': $$rsvp$resolve$$default, - 'reject': $$rsvp$reject$$default, - 'all': $$rsvp$all$$default, - 'rethrow': $$rsvp$rethrow$$default, - 'defer': $$rsvp$defer$$default, - 'EventTarget': $$rsvp$events$$default, - 'configure': $$rsvp$config$$configure, - 'async': $$rsvp$$async - }; - - /* global define:true module:true window: true */ - if (typeof define === 'function' && define.amd) { - define(function() { return rsvp$umd$$RSVP; }); - } else if (typeof module !== 'undefined' && module.exports) { - module.exports = rsvp$umd$$RSVP; - } else if (typeof this !== 'undefined') { - this['RSVP'] = rsvp$umd$$RSVP; - } -}).call(this); + __exports__.Promise = Promise; + __exports__.EventTarget = EventTarget; + __exports__.all = all; + __exports__.allSettled = allSettled; + __exports__.race = race; + __exports__.hash = hash; + __exports__.hashSettled = hashSettled; + __exports__.rethrow = rethrow; + __exports__.defer = defer; + __exports__.denodeify = denodeify; + __exports__.configure = configure; + __exports__.on = on; + __exports__.off = off; + __exports__.resolve = resolve; + __exports__.reject = reject; + __exports__.async = async; + __exports__.map = map; + __exports__.filter = filter; +}); +global.RSVP = require('rsvp'); +}(self)); EPUBJS.Book = function(_url){ // Promises this.opening = new RSVP.defer(); @@ -3273,7 +3861,7 @@ EPUBJS.Layout.ReflowableSpreads.prototype.format = function(_width, _height, _ga this.colWidth = colWidth; this.gap = gap; - this.view.document.body.style.paddingRight = gap + "px"; + // this.view.document.body.style.paddingRight = gap + "px"; // view.iframe.style.width = this.spreadWidth+"px"; // this.view.element.style.paddingRight = gap+"px"; // view.iframe.style.paddingLeft = gap+"px"; diff --git a/dist/epub.min.js b/dist/epub.min.js index 5bf9e2c..3eabe73 100644 --- a/dist/epub.min.js +++ b/dist/epub.min.js @@ -1,3 +1,3 @@ -"undefined"==typeof EPUBJS&&(("undefined"!=typeof window?window:this).EPUBJS={}),EPUBJS.VERSION="0.3.0",EPUBJS.Render={},function(t){"use strict";var e=function(t){return new EPUBJS.Book(t)};e.Render={register:function(t,i){e.Render[t]=i}},"object"==typeof exports?(t.RSVP=require("rsvp"),module.exports=e):"function"==typeof define&&define.amd?define(e):t.ePub=e}(this),function(){"use strict";function t(t,e){for(var i=0,n=t.length;n>i;i++)if(t[i]===e)return i;return-1}function e(t){var e=t._promiseCallbacks;return e||(e=t._promiseCallbacks={}),e}function i(t,e){return"onerror"===t?(K.on("error",e),void 0):2!==arguments.length?K[t]:(K[t]=e,void 0)}function n(t){return"function"==typeof t||"object"==typeof t&&null!==t}function r(t){return"function"==typeof t}function o(t){return"object"==typeof t&&null!==t}function s(){}function h(){}function a(t){try{return t.then}catch(e){return oe.error=e,oe}}function c(t,e,i,n){try{t.call(e,i,n)}catch(r){return r}}function p(t,e,i){K.async(function(t){var n=!1,r=c(i,e,function(i){n||(n=!0,e!==i?u(t,i):g(t,i))},function(e){n||(n=!0,m(t,e))},"Settle: "+(t._label||" unknown promise"));!n&&r&&(n=!0,m(t,r))},t)}function l(t,e){e._state===ne?g(t,e._result):t._state===re?m(t,e._result):y(e,void 0,function(i){e!==i?u(t,i):g(t,i)},function(e){m(t,e)})}function d(t,e){if(e.constructor===t.constructor)l(t,e);else{var i=a(e);i===oe?m(t,oe.error):void 0===i?g(t,e):r(i)?p(t,e,i):g(t,e)}}function u(t,e){t===e?g(t,e):n(e)?d(t,e):g(t,e)}function f(t){t._onerror&&t._onerror(t._result),v(t)}function g(t,e){t._state===ie&&(t._result=e,t._state=ne,0===t._subscribers.length?K.instrument&&ee("fulfilled",t):K.async(v,t))}function m(t,e){t._state===ie&&(t._state=re,t._result=e,K.async(f,t))}function y(t,e,i,n){var r=t._subscribers,o=r.length;t._onerror=null,r[o]=e,r[o+ne]=i,r[o+re]=n,0===o&&t._state&&K.async(v,t)}function v(t){var e=t._subscribers,i=t._state;if(K.instrument&&ee(i===ne?"fulfilled":"rejected",t),0!==e.length){for(var n,r,o=t._result,s=0;sh;h++)s[h]=t[h];for(n=0;nn;n++)i[n-1]=t[n];return i}function I(t,e){return{then:function(i,n){return t.call(e,i,n)}}}function F(t,e,i,n){var r=k(i,n,e);return r===ge&&m(t,r.value),t}function N(t,e,i,n){return fe.all(e).then(function(e){var r=k(i,n,e);return r===ge&&m(t,r.value),t})}function V(t){return t&&"object"==typeof t?t.constructor===fe?!0:C(t):!1}function L(t,e,i){this._superConstructor(t,e,!1,i)}function A(t,e,i){this._superConstructor(t,e,!0,i)}function q(t,e,i){this._superConstructor(t,e,!1,i)}function O(){return function(){process.nextTick(H)}}function z(){var t=0,e=new Fe(H),i=document.createTextNode("");return e.observe(i,{characterData:!0}),function(){i.data=t=++t%2}}function M(){var t=new MessageChannel;return t.port1.onmessage=H,function(){t.port2.postMessage(0)}}function j(){return function(){setTimeout(H,1)}}function H(){for(var t=0;_e>t;t+=2){var e=Ve[t],i=Ve[t+1];e(i),Ve[t]=void 0,Ve[t+1]=void 0}_e=0}function D(t,e){K.async(t,e)}function W(){K.on.apply(K,arguments)}function X(){K.off.apply(K,arguments)}var Q={mixin:function(t){return t.on=this.on,t.off=this.off,t.trigger=this.trigger,t._promiseCallbacks=void 0,t},on:function(i,n){var r,o=e(this);r=o[i],r||(r=o[i]=[]),-1===t(r,n)&&r.push(n)},off:function(i,n){var r,o,s=e(this);return n?(r=s[i],o=t(r,n),-1!==o&&r.splice(o,1),void 0):(s[i]=[],void 0)},trigger:function(t,i){var n,r,o=e(this);if(n=o[t])for(var s=0;s1)throw new Error("Second argument not supported");if("object"!=typeof t)throw new TypeError("Argument must be an object");return s.prototype=t,new s},te=[],ee=function(t,e,i){1===te.push({name:t,payload:{guid:e._guidKey+e._id,eventName:t,detail:e._result,childGuid:i&&e._guidKey+i._id,label:e._label,timeStamp:Z(),stack:new Error(e._label).stack}})&&setTimeout(function(){for(var t,e=0;en;n++)this._eachEntry(i[n],n)},b.prototype._eachEntry=function(t,e){var i=this._instanceConstructor;o(t)?t.constructor===i&&t._state!==ie?(t._onerror=null,this._settledAt(t._state,e,t._result)):this._willSettleAt(i.resolve(t),e):(this._remaining--,this._result[e]=this._makeResult(ne,e,t))},b.prototype._settledAt=function(t,e,i){var n=this.promise;n._state===ie&&(this._remaining--,this._abortOnReject&&t===re?m(n,i):this._result[e]=this._makeResult(t,e,i)),0===this._remaining&&g(n,this._result)},b.prototype._makeResult=function(t,e,i){return i},b.prototype._willSettleAt=function(t,e){var i=this;y(t,void 0,function(t){i._settledAt(ne,e,t)},function(t){i._settledAt(re,e,t)})};var ae=function(t,e){return new he(this,t,!0,e).promise},ce=function(t,e){function i(t){u(o,t)}function n(t){m(o,t)}var r=this,o=new r(h,e);if(!G(t))return m(o,new TypeError("You must pass an array to race.")),o;for(var s=t.length,a=0;o._state===ie&&s>a;a++)y(r.resolve(t[a]),void 0,i,n);return o},pe=function(t,e){var i=this;if(t&&"object"==typeof t&&t.constructor===i)return t;var n=new i(h,e);return u(n,t),n},le=function(t,e){var i=this,n=new i(h,e);return m(n,t),n},de="rsvp_"+Z()+"-",ue=0,fe=x;x.cast=pe,x.all=ae,x.race=ce,x.resolve=pe,x.reject=le,x.prototype={constructor:x,_guidKey:de,_onerror:function(t){K.trigger("error",t)},then:function(t,e,i){var n=this,r=n._state;if(r===ne&&!t||r===re&&!e)return K.instrument&&ee("chained",this,this),this;n._onerror=null;var o=new this.constructor(h,i),s=n._result;if(K.instrument&&ee("chained",n,o),r){var a=arguments[r-1];K.async(function(){E(r,o,a,s)})}else y(n,o,t,e);return o},"catch":function(t,e){return this.then(null,t,e)},"finally":function(t,e){var i=this.constructor;return this.then(function(e){return i.resolve(t()).then(function(){return e})},function(e){return i.resolve(t()).then(function(){throw e})},e)}};var ge=new R,me=new R,ye=function(t,e){var i=function(){for(var i,n=this,r=arguments.length,o=new Array(r+1),s=!1,a=0;r>a;++a){if(i=arguments[a],!s){if(s=V(i),s===me){var c=new fe(h);return m(c,me.value),c}s&&s!==!0&&(i=I(s,i))}o[a]=i}var p=new fe(h);return o[r]=function(t,i){t?m(p,t):void 0===e?u(p,i):e===!0?u(p,T(arguments)):G(e)?u(p,_(arguments,e)):u(p,i)},s?N(p,o,t,n):F(p,o,t,n)};return i.__proto__=t,i},ve=function(t,e){return fe.all(t,e)};L.prototype=$(he.prototype),L.prototype._superConstructor=he,L.prototype._makeResult=B,L.prototype._validationError=function(){return new Error("allSettled must be called with an array")};var Se=function(t,e){return new L(fe,t,e).promise},we=function(t,e){return fe.race(t,e)},Ee=A;A.prototype=$(he.prototype),A.prototype._superConstructor=he,A.prototype._init=function(){this._result={}},A.prototype._validateInput=function(t){return t&&"object"==typeof t},A.prototype._validationError=function(){return new Error("Promise.hash must be called with an object")},A.prototype._enumerate=function(){var t=this.promise,e=this._input,i=[];for(var n in e)t._state===ie&&e.hasOwnProperty(n)&&i.push({position:n,entry:e[n]});var r=i.length;this._remaining=r;for(var o,s=0;t._state===ie&&r>s;s++)o=i[s],this._eachEntry(o.entry,o.position)};var Pe=function(t,e){return new Ee(fe,t,e).promise};q.prototype=$(Ee.prototype),q.prototype._superConstructor=he,q.prototype._makeResult=B,q.prototype._validationError=function(){return new Error("hashSettled must be called with an object")};var Be,be=function(t,e){return new q(fe,t,e).promise},Ue=function(t){throw setTimeout(function(){throw t}),t},Je=function(t){var e={};return e.promise=new fe(function(t,i){e.resolve=t,e.reject=i},t),e},xe=function(t,e,i){return fe.all(t,i).then(function(t){if(!r(e))throw new TypeError("You must pass a function as map's second argument.");for(var n=t.length,o=new Array(n),s=0;n>s;s++)o[s]=e(t[s]);return fe.all(o,i)})},Re=function(t,e){return fe.resolve(t,e)},Ce=function(t,e){return fe.reject(t,e)},ke=function(t,e,i){return fe.all(t,i).then(function(t){if(!r(e))throw new TypeError("You must pass a function as filter's second argument.");for(var n=t.length,o=new Array(n),s=0;n>s;s++)o[s]=e(t[s]);return fe.all(o,i).then(function(e){for(var i=new Array(n),r=0,o=0;n>o;o++)e[o]&&(i[r]=t[o],r++);return i.length=r,i})})},_e=0,Te=function(t,e){Ve[_e]=t,Ve[_e+1]=e,_e+=2,2===_e&&Be()},Ie="undefined"!=typeof window?window:{},Fe=Ie.MutationObserver||Ie.WebKitMutationObserver,Ne="undefined"!=typeof Uint8ClampedArray&&"undefined"!=typeof importScripts&&"undefined"!=typeof MessageChannel,Ve=new Array(1e3);Be="undefined"!=typeof process&&"[object process]"==={}.toString.call(process)?O():Fe?z():Ne?M():j(),K.async=Te;if("undefined"!=typeof window&&"object"==typeof window.__PROMISE_INSTRUMENTATION__){var Le=window.__PROMISE_INSTRUMENTATION__;i("instrument",!0);for(var Ae in Le)Le.hasOwnProperty(Ae)&&W(Ae,Le[Ae])}var qe={race:we,Promise:fe,allSettled:Se,hash:Pe,hashSettled:be,denodeify:ye,on:W,off:X,map:xe,filter:ke,resolve:Re,reject:Ce,all:ve,rethrow:Ue,defer:Je,EventTarget:Q,configure:i,async:D};"function"==typeof define&&define.amd?define(function(){return qe}):"undefined"!=typeof module&&module.exports?module.exports=qe:"undefined"!=typeof this&&(this.RSVP=qe)}.call(this),EPUBJS.Book=function(t){this.opening=new RSVP.defer,this.opened=this.opening.promise,this.isOpen=!1,this.url=void 0,this.spine=new EPUBJS.Spine(this.request),this.loading={manifest:new RSVP.defer,spine:new RSVP.defer,metadata:new RSVP.defer,cover:new RSVP.defer,navigation:new RSVP.defer,pageList:new RSVP.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},this.ready=RSVP.hash(this.loaded),this.isRendered=!1,this._q=EPUBJS.core.queue(this),this.request=this.requestMethod.bind(this),t&&this.open(t)},EPUBJS.Book.prototype.open=function(t){var e,i,n,r=new EPUBJS.Parser,o=this,s="META-INF/container.xml";return t?(e="object"==typeof t?t:EPUBJS.core.uri(t),"opf"===e.extension?(this.packageUrl=e.href,this.containerUrl="",e.origin?this.url=e.base:window?(n=EPUBJS.core.uri(window.location.href),this.url=EPUBJS.core.resolveUrl(n.base,e.directory)):this.url=e.directory,i=this.request(this.packageUrl)):"epub"===e.extension||"zip"===e.extension?(this.archived=!0,this.url=""):e.extension||(this.containerUrl=t+s,i=this.request(this.containerUrl).then(function(t){return r.container(t)}).then(function(e){var i=EPUBJS.core.uri(e.packagePath);return o.packageUrl=t+e.packagePath,o.url=t+i.directory,o.encoding=e.encoding,o.request(o.packageUrl)}).catch(function(t){console.error("Could not load book at: "+(this.packageUrl||this.containerPath)),o.trigger("book:loadFailed",this.packageUrl||this.containerPath),o.opening.reject(t)})),i.then(function(t){o.unpack(t),o.loading.manifest.resolve(o.package.manifest),o.loading.metadata.resolve(o.package.metadata),o.loading.spine.resolve(o.spine),o.loading.cover.resolve(o.cover),this.isOpen=!0,o.opening.resolve(o)}).catch(function(t){console.error(t.message,t.stack),o.opening.reject(t)}),this.opened):(this.opening.resolve(this),this.opened)},EPUBJS.Book.prototype.unpack=function(t){var e=this,i=new EPUBJS.Parser;e.package=i.packageContents(t),e.package.baseUrl=e.url,this.spine.load(e.package),e.navigation=new EPUBJS.Navigation(e.package,this.request),e.navigation.load().then(function(t){e.toc=t,e.loading.navigation.resolve(e.toc)}),e.cover=e.url+e.package.coverPath},EPUBJS.Book.prototype.section=function(t){return this.spine.get(t)},EPUBJS.Book.prototype.renderTo=function(t,e){return this.rendition=new EPUBJS.Rendition(this,e),this.rendition.attachTo(t),this.rendition},EPUBJS.Book.prototype.requestMethod=function(t){return this.archived?void 0:EPUBJS.core.request(t,"xml",this.requestCredentials,this.requestHeaders)},EPUBJS.Book.prototype.setRequestCredentials=function(t){this.requestCredentials=t},EPUBJS.Book.prototype.setRequestHeaders=function(t){this.requestHeaders=t},RSVP.EventTarget.mixin(EPUBJS.Book.prototype),RSVP.on("error",function(){}),RSVP.configure("instrument",!0),RSVP.on("rejected",function(t){console.error(t.detail.message,t.detail.stack)}),EPUBJS.Continuous=function(){this.views=[],this.container=container,this.limit=limit||4},EPUBJS.Continuous.prototype.append=function(t){this.views.push(t),this.container.appendChild(t.element()),t.onDisplayed=function(){var t,e=this.views.indexOf(t),i=t.section.next();e+1===this.views.length&&i&&(t=new EPUBJS.View(i),this.append(t))}.bind(this),this.resizeView(t)},EPUBJS.Continuous.prototype.prepend=function(t){this.views.unshift(t),this.container.insertBefore(t.element,this.container.firstChild),t.onDisplayed=function(){var t,e=(this.views.indexOf(t),t.section.prev());e&&(t=new EPUBJS.View(e),this.append(t))}.bind(this),this.resizeView(t)},EPUBJS.Continuous.prototype.fill=function(t){this.views.length&&this.clear(),this.views.push(t),this.container.appendChild(t.element),t.onDisplayed=function(){var e,i,n=t.section.next(),r=t.section.prev(),o=this.views.indexOf(t);o+1===this.views.length&&n&&(e=new EPUBJS.View(n),this.append(e)),0===o&&r&&(i=new EPUBJS.View(r),this.append(i)),this.resizeView(t)}.bind(this)},EPUBJS.Continuous.prototype.insert=function(t,e){this.views.splice(e,0,t),e-1&&this.views.splice(e,1)},EPUBJS.Continuous.prototype.clear=function(){this.views.forEach(function(t){t.destroy()}),this.views=[]},EPUBJS.Continuous.prototype.first=function(){return this.views[0]},EPUBJS.Continuous.prototype.last=function(){return this.views[this.views.length-1]},EPUBJS.Continuous.prototype.each=function(t){return this.views.forEach(t)},EPUBJS.Continuous.prototype.check=function(){{var t=this.container.getBoundingClientRect();(function(e){var i=e.bounds();i.bottom>=t.top&&!(i.top>t.bottom)&&i.right>=t.left&&!(i.left>t.right)?(console.log("visible",e.index),this.resizeView(e),this.display(e)):(console.log("off screen",e.index),e.destroy())}).bind(this)}this.views.forEach(this.isVisible)},EPUBJS.Continuous.prototype.displayView=function(t){return t.display(this.book.request).then(function(){return this.hooks.display.trigger(t)}.bind(this)).then(function(){return this.hooks.replacements.trigger(t,this)}.bind(this)).then(function(){return t.expand()}.bind(this)).then(function(){return this.rendering=!1,t.show(),this.trigger("rendered",section),t}.bind(this)).catch(function(t){this.trigger("loaderror",t)}.bind(this))},EPUBJS.Continuous.prototype.resizeView=function(t){var e=this.container.getBoundingClientRect(),i=window.getComputedStyle(this.container),n={left:parseFloat(i["padding-left"])||0,right:parseFloat(i["padding-right"])||0,top:parseFloat(i["padding-top"])||0,bottom:parseFloat(i["padding-bottom"])||0},r=e.width-n.left-n.right,o=e.height-n.top-n.bottom,s=100,h=200;"vertical"===this.settings.axis?t.resize(r,s):t.resize(h,o)},EPUBJS.core={},EPUBJS.core.request=function(t,e,i,n){function r(){if(this.readyState===this.DONE)if(200===this.status||this.responseXML){var t;t="xml"==e?this.responseXML?this.responseXML:(new DOMParser).parseFromString(this.response,"text/xml"):"json"==e?JSON.parse(this.response):"blob"==e?s?this.response:new Blob([this.response]):this.response,a.resolve(t)}else a.reject({status:this.status,message:this.response,stack:(new Error).stack})}var o,s=window.URL,h=s?"blob":"arraybuffer",a=new RSVP.defer,c=new XMLHttpRequest,p=XMLHttpRequest.prototype;"overrideMimeType"in p||Object.defineProperty(p,"overrideMimeType",{value:function(){}}),i&&(c.withCredentials=!0),c.open("GET",t,!0);for(o in n)c.setRequestHeader(o,n[o]);return c.onreadystatechange=r,"blob"==e&&(c.responseType=h),"json"==e&&c.setRequestHeader("Accept","application/json"),"xml"==e&&c.overrideMimeType("text/xml"),c.send(),a.promise},EPUBJS.core.uri=function(t){var e,i,n,r={protocol:"",host:"",path:"",origin:"",directory:"",base:"",filename:"",extension:"",fragment:"",href:t},o=t.indexOf("://"),s=t.indexOf("?"),h=t.indexOf("#");return-1!=h&&(r.fragment=t.slice(h+1),t=t.slice(0,h)),-1!=s&&(r.search=t.slice(s+1),t=t.slice(0,s),href=t),-1!=o?(r.protocol=t.slice(0,o),e=t.slice(o+3),n=e.indexOf("/"),-1===n?(r.host=r.path,r.path=""):(r.host=e.slice(0,n),r.path=e.slice(n)),r.origin=r.protocol+"://"+r.host,r.directory=EPUBJS.core.folder(r.path),r.base=r.origin+r.directory):(r.path=t,r.directory=EPUBJS.core.folder(t),r.base=r.directory),r.filename=t.replace(r.base,""),i=r.filename.lastIndexOf("."),-1!=i&&(r.extension=r.filename.slice(i+1)),r},EPUBJS.core.folder=function(t){var e=t.lastIndexOf("/");if(-1==e)var i="";return i=t.slice(0,e+1)},EPUBJS.core.queue=function(t){var e=[],i=t,n=function(t,i,n){return e.push({funcName:t,args:i,context:n}),e},r=function(){var t;e.length&&(t=e.shift(),i[t.funcName].apply(t.context||i,t.args))},o=function(){for(;e.length;)r()},s=function(){e=[]},h=function(){return e.length};return{enqueue:n,dequeue:r,flush:o,clear:s,length:h}},EPUBJS.core.isElement=function(t){return!(!t||1!=t.nodeType)},EPUBJS.core.uuid=function(){var t=(new Date).getTime(),e="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var i=(t+16*Math.random())%16|0;return t=Math.floor(t/16),("x"==e?i:7&i|8).toString(16)});return e},EPUBJS.core.values=function(t){for(var e=-1,i=Object.keys(t),n=i.length,r=Array(n);++er;r++)if("undefined"!=typeof document.body.style[e[r]+i])return e[r]+i;return t},EPUBJS.core.defaults=function(t){for(var e=1,i=arguments.length;i>e;e++){var n=arguments[e];for(var r in n)void 0===t[r]&&(t[r]=n[r])}return t},EPUBJS.core.insert=function(t,e,i){var n=EPUBJS.core.locationOf(t,e,i);return e.splice(n,0,t),n},EPUBJS.core.locationOf=function(t,e,i,n,r){var o,s=n||0,h=r||e.length,a=parseInt(s+(h-s)/2);return i||(i=function(t,e){return t>e?1:e>t?-1:(t=e)?0:void 0}),0>=h-s?a:(o=i(e[a],t),h-s===1?o>0?a:a+1:0===o?a:-1===o?EPUBJS.core.locationOf(t,e,i,a,h):EPUBJS.core.locationOf(t,e,i,s,a))},EPUBJS.core.indexOfSorted=function(t,e,i,n,r){var o,s=n||0,h=r||e.length,a=parseInt(s+(h-s)/2);return i||(i=function(t,e){return t>e?1:e>t?-1:(t=e)?0:void 0}),0>=h-s?-1:(o=i(e[a],t),h-s===1?0===o?a:-1:0===o?a:-1===o?EPUBJS.core.indexOfSorted(t,e,i,a,h):EPUBJS.core.indexOfSorted(t,e,i,s,a))},EPUBJS.core.requestAnimationFrame=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame,EPUBJS.EpubCFI=function(t){return t?this.parse(t):void 0},EPUBJS.EpubCFI.prototype.generateChapterComponent=function(t,e,i){var n=parseInt(e),r=t+1,o="/"+r+"/";return o+=2*(n+1),i&&(o+="["+i+"]"),o},EPUBJS.EpubCFI.prototype.generatePathComponent=function(t){var e=[];return t.forEach(function(t){var i="";i+=2*(t.index+1),t.id&&(i+="["+t.id+"]"),e.push(i)}),e.join("/")},EPUBJS.EpubCFI.prototype.generateCfiFromElement=function(t,e){var i=this.pathTo(t),n=this.generatePathComponent(i);return n.length?"epubcfi("+e+"!"+n+"/1:0)":"epubcfi("+e+"!/4/)"},EPUBJS.EpubCFI.prototype.pathTo=function(t){for(var e,i=[];t&&null!==t.parentNode&&9!=t.parentNode.nodeType;)e=t.parentNode.children,i.unshift({id:t.id,tagName:t.tagName,index:e?Array.prototype.indexOf.call(e,t):0}),t=t.parentNode;return i},EPUBJS.EpubCFI.prototype.getChapterComponent=function(t){var e=t.split("!");return e[0]},EPUBJS.EpubCFI.prototype.getPathComponent=function(t){var e=t.split("!"),i=e[1]?e[1].split(":"):"";return i[0]},EPUBJS.EpubCFI.prototype.getCharecterOffsetComponent=function(t){var e=t.split(":");return e[1]||""},EPUBJS.EpubCFI.prototype.parse=function(t){var e,i,n,r,o,s,h,a,c,p={},l=function(t){var e,i,n,r;return e="element",i=parseInt(t)/2-1,n=t.match(/\[(.*)\]/),n&&n[1]&&(r=n[1]),{type:e,index:i,id:r||!1}};return"string"!=typeof t?{spinePos:-1}:(p.str=t,0===t.indexOf("epubcfi(")&&")"===t[t.length-1]&&(t=t.slice(8,t.length-1)),i=this.getChapterComponent(t),n=this.getPathComponent(t)||"",r=this.getCharecterOffsetComponent(t),i?(e=i.split("/")[2]||"")?(p.spinePos=parseInt(e)/2-1||0,s=e.match(/\[(.*)\]/),p.spineId=s?s[1]:!1,-1!=n.indexOf(",")&&console.warn("CFI Ranges are not supported"),h=n.split("/"),a=h.pop(),p.steps=[],h.forEach(function(t){var e;t&&(e=l(t),p.steps.push(e))}),c=parseInt(a),isNaN(c)||(c%2===0?p.steps.push(l(a)):p.steps.push({type:"text",index:(c-1)/2})),o=r.match(/\[(.*)\]/),o&&o[1]?(p.characterOffset=parseInt(r.split("[")[0]),p.textLocationAssertion=o[1]):p.characterOffset=parseInt(r),p):{spinePos:-1}:{spinePos:-1})},EPUBJS.EpubCFI.prototype.addMarker=function(t,e,i){var n,r,o,s,h=e||document,a=i||this.createMarker(h);return"string"==typeof t&&(t=this.parse(t)),r=t.steps[t.steps.length-1],-1===t.spinePos?!1:(n=this.findParent(t,h))?(r&&"text"===r.type?(o=n.childNodes[r.index],t.characterOffset?(s=o.splitText(t.characterOffset),a.classList.add("EPUBJS-CFI-SPLIT"),n.insertBefore(a,s)):n.insertBefore(a,o)):n.insertBefore(a,n.firstChild),a):!1},EPUBJS.EpubCFI.prototype.createMarker=function(t){var e=t||document,i=e.createElement("span");return i.id="EPUBJS-CFI-MARKER:"+EPUBJS.core.uuid(),i.classList.add("EPUBJS-CFI-MARKER"),i},EPUBJS.EpubCFI.prototype.removeMarker=function(t,e){t.classList.contains("EPUBJS-CFI-SPLIT")?(nextSib=t.nextSibling,prevSib=t.previousSibling,nextSib&&prevSib&&3===nextSib.nodeType&&3===prevSib.nodeType&&(prevSib.textContent+=nextSib.textContent,t.parentNode.removeChild(nextSib)),t.parentNode.removeChild(t)):t.classList.contains("EPUBJS-CFI-MARKER")&&t.parentNode.removeChild(t)},EPUBJS.EpubCFI.prototype.findParent=function(t,e){var i,n,r,o=e||document,s=o.getElementsByTagName("html")[0],h=Array.prototype.slice.call(s.children);if("string"==typeof t&&(t=this.parse(t)),n=t.steps.slice(0),!n.length)return o.getElementsByTagName("body")[0];for(;n&&n.length>0;){if(i=n.shift(),"text"===i.type?(r=s.childNodes[i.index],s=r.parentNode||s):s=i.id?o.getElementById(i.id):h[i.index],"undefined"==typeof s)return console.error("No Element For",i,t.str),!1;h=Array.prototype.slice.call(s.children)}return s},EPUBJS.EpubCFI.prototype.compare=function(t,e){if("string"==typeof t&&(t=new EPUBJS.EpubCFI(t)),"string"==typeof e&&(e=new EPUBJS.EpubCFI(e)),t.spinePos>e.spinePos)return 1;if(t.spinePose.steps[i].index)return 1;if(t.steps[i].indexe.characterOffset?1:t.characterOffset=0?(o=r.length,t.characterOffseti?this.hooks[i].apply(this.context,r):void 0}.bind(this))):(t=n.promise,n.resolve()),t},EPUBJS.Infinite=function(t){this.container=t,this.windowHeight=window.innerHeight,this.tick=EPUBJS.core.requestAnimationFrame,this.scrolled=!1,this.ignore=!1,this.tolerance=100,this.prevScrollTop=0,this.prevScrollLeft=0,t&&this.start()},EPUBJS.Infinite.prototype.start=function(){this.container.addEventListener("scroll",function(){this.ignore?this.ignore=!1:this.scrolled=!0}.bind(this)),window.addEventListener("unload",function(){this.ignore=!0}),this.tick.call(window,this.check.bind(this)),this.scrolled=!1},EPUBJS.Infinite.prototype.forwards=function(){this.trigger("forwards")},EPUBJS.Infinite.prototype.backwards=function(){this.trigger("backwards")},EPUBJS.Infinite.prototype.check=function(){this.scrolled&&!this.ignore?(scrollTop=this.container.scrollTop,scrollLeft=this.container.scrollLeft,this.trigger("scroll",{top:scrollTop,left:scrollLeft}),scrollTop-this.prevScrollTop>this.tolerance&&this.forwards(),scrollTop-this.prevScrollTop<-this.tolerance&&this.backwards(),scrollLeft-this.prevScrollLeft>this.tolerance&&this.forwards(),scrollLeft-this.prevScrollLeft<-this.tolerance&&this.backwards(),this.prevScrollTop=scrollTop,this.prevScrollLeft=scrollLeft,this.scrolled=!1):(this.ignore=!1,this.scrolled=!1),this.tick.call(window,this.check.bind(this))},EPUBJS.Infinite.prototype.scrollBy=function(t,e,i){i&&(this.ignore=!0),this.container.scrollLeft+=t,this.container.scrollTop+=e,this.scrolled=!0,this.check()},EPUBJS.Infinite.prototype.scrollTo=function(t,e,i){i&&(this.ignore=!0),this.container.scrollLeft=t,this.container.scrollTop=e,this.scrolled=!0,this.check()},RSVP.EventTarget.mixin(EPUBJS.Infinite.prototype),EPUBJS.Layout=EPUBJS.Layout||{},EPUBJS.Layout.Reflowable=function(t){this.view=t,this.spreadWidth=null},EPUBJS.Layout.Reflowable.prototype.format=function(t,e,i,n){var r=EPUBJS.core.prefixed("columnAxis"),o=EPUBJS.core.prefixed("columnGap"),s=EPUBJS.core.prefixed("columnWidth"),h=EPUBJS.core.prefixed("columnFill"),a=Math.floor(e),c=Math.floor(a/8),p=n>=0?n:c%2===0?c:c-1;return this.documentElement=t,this.spreadWidth=a+p,t.style.overflow="hidden",t.style.width=a+"px",t.style.height=i+"px",t.style[r]="horizontal",t.style[h]="auto",t.style[s]=a+"px",t.style[o]=p+"px",this.colWidth=a,this.gap=p,{pageWidth:this.spreadWidth,pageHeight:i}},EPUBJS.Layout.Reflowable.prototype.calculatePages=function(){var t,e;return this.documentElement.style.width="auto",t=this.documentElement.scrollWidth,e=Math.ceil(t/this.spreadWidth),{displayedPages:e,pageCount:e}},EPUBJS.Layout.ReflowableSpreads=function(t){this.view=t,this.documentElement=t.document.documentElement,this.spreadWidth=null},EPUBJS.Layout.ReflowableSpreads.prototype.format=function(t,e,i){var n=EPUBJS.core.prefixed("columnAxis"),r=EPUBJS.core.prefixed("columnGap"),o=EPUBJS.core.prefixed("columnWidth"),s=EPUBJS.core.prefixed("columnFill"),h=2,a=Math.floor(t),c=a%2===0?a:a-1,p=Math.floor(c/8),l=i>=0?i:p%2===0?p:p-1,d=Math.floor((c-l)/h);return this.spreadWidth=(d+l)*h,this.view.document.documentElement.style.overflow="hidden",this.view.document.body.style.width=c+"px",this.view.document.body.style.height=e+"px",this.view.document.body.style[n]="horizontal",this.view.document.body.style[s]="auto",this.view.document.body.style[r]=l+"px",this.view.document.body.style[o]=d+"px",this.colWidth=d,this.gap=l,this.view.document.body.style.paddingRight=l+"px",{pageWidth:this.spreadWidth,pageHeight:e}},EPUBJS.Layout.ReflowableSpreads.prototype.calculatePages=function(){var t=this.documentElement.scrollWidth,e=Math.ceil(t/this.spreadWidth);return{displayedPages:e,pageCount:2*e}},EPUBJS.Layout.Fixed=function(){this.documentElement=null -},EPUBJS.Layout.Fixed=function(t){var e,i,n,r,o=EPUBJS.core.prefixed("columnWidth"),s=t.querySelector("[name=viewport");return this.documentElement=t,s&&s.hasAttribute("content")&&(e=s.getAttribute("content"),i=e.split(","),i[0]&&(n=i[0].replace("width=","")),i[1]&&(r=i[1].replace("height=",""))),t.style.width=n+"px"||"auto",t.style.height=r+"px"||"auto",t.style[o]="auto",t.style.overflow="auto",this.colWidth=n,this.gap=0,{pageWidth:n,pageHeight:r}},EPUBJS.Layout.Fixed.prototype.calculatePages=function(){return{displayedPages:1,pageCount:1}},EPUBJS.Navigation=function(t,e){var i=this,n=new EPUBJS.Parser,r=e||EPUBJS.core.request;this.package=t,this.toc=[],this.tocByHref={},this.tocById={},t.navPath&&(this.navUrl=t.baseUrl+t.navPath,this.nav={},this.nav.load=function(){var t=new RSVP.defer,e=t.promise;return r(i.navUrl,"xml").then(function(e){i.toc=n.nav(e),i.loaded(i.toc),t.resolve(i.toc)}),e}),t.ncxPath&&(this.ncxUrl=t.baseUrl+t.ncxPath,this.ncx={},this.ncx.load=function(){var t=new RSVP.defer,e=t.promise;return r(i.ncxUrl,"xml").then(function(e){i.toc=n.ncx(e),i.loaded(i.toc),t.resolve(i.toc)}),e})},EPUBJS.Navigation.prototype.load=function(t){{var e,i;t||EPUBJS.core.request}return this.nav?e=this.nav.load():this.ncx?e=this.ncx.load():(i=new RSVP.defer,i.resolve([]),e=i.promise),e},EPUBJS.Navigation.prototype.loaded=function(t){for(var e,i=0;i=0;s--){var h=r.snapshotItem(s),a=h.getAttribute("id")||!1,c=h.querySelector("content"),p=c.getAttribute("src"),l=h.querySelector("navLabel"),d=l.textContent?l.textContent:"",u=p.split("#"),f=(u[0],e(h));n.unshift({id:a,href:p,label:d,subitems:f,parent:i?i.getAttribute("id"):null})}return n}var i=t.querySelector("navMap");return i?e(i):[]},EPUBJS.Queue=function(t){this._q=[],this.context=t,this.tick=EPUBJS.core.requestAnimationFrame,this.running=!1},EPUBJS.Queue.prototype.enqueue=function(t,e,i){var n,r,o;return e&&!e.length&&(e=[e]),"function"==typeof t?(n=new RSVP.defer,r=n.promise,o={task:t,args:e,context:i,deferred:n,promise:r}):o={promise:t},this._q.push(o),o.promise},EPUBJS.Queue.prototype.dequeue=function(){var t,e;return this._q.length?(t=this._q.shift(),e=t.task,e?e.apply(t.context||this.context,t.args).then(function(){t.deferred.resolve.apply(t.context||this.context,arguments)}.bind(this)):t.promise):null},EPUBJS.Queue.prototype.flush=function(){for(;this._q.length;)this.dequeue()},EPUBJS.Queue.prototype.run=function(){!this.running&&this._q.length&&(this.running=!0,this.dequeue().then(function(){this.running=!1}.bind(this))),this.tick.call(window,this.run.bind(this))},EPUBJS.Queue.prototype.clear=function(){this._q=[]},EPUBJS.Queue.prototype.length=function(){return this._q.length},EPUBJS.Task=function(t){return function(){var e=arguments||[];return new RSVP.Promise(function(i){var n=function(t){i(t)};e.push(n),t.apply(this,e)}.bind(this))}},EPUBJS.Renderer=function(t,e){var i=e||{};this.settings={infinite:"undefined"==typeof i.infinite?!0:i.infinite,hidden:"undefined"==typeof i.hidden?!1:i.hidden,axis:i.axis||"vertical",viewsLimit:i.viewsLimit||5,width:"undefined"==typeof i.width?!1:i.width,height:"undefined"==typeof i.height?!1:i.height,overflow:"undefined"==typeof i.overflow?"auto":i.overflow,padding:i.padding||"",offset:400},this.book=t,this.epubcfi=new EPUBJS.EpubCFI,this.layoutSettings={},this._q=EPUBJS.core.queue(this),this.position=1,this.initialize({width:this.settings.width,height:this.settings.height}),this.rendering=!1,this.filling=!1,this.displaying=!1,this.views=[],this.positions=[],this.hooks={},this.hooks.display=new EPUBJS.Hook(this),this.hooks.replacements=new EPUBJS.Hook(this),this.settings.infinite||(this.settings.viewsLimit=1)},EPUBJS.Renderer.prototype.initialize=function(t){{var e=t||{},i=e.height!==!1?e.height:"100%",n=e.width!==!1?e.width:"100%";e.hidden||!1}return e.height&&EPUBJS.core.isNumber(e.height)&&(i=e.height+"px"),e.width&&EPUBJS.core.isNumber(e.width)&&(n=e.width+"px"),this.container=document.createElement("div"),this.settings.infinite&&(this.infinite=new EPUBJS.Infinite(this.container,this.settings.axis),this.infinite.on("scroll",this.checkCurrent.bind(this))),"horizontal"===this.settings.axis&&(this.container.style.whiteSpace="nowrap"),this.container.style.width=n,this.container.style.height=i,this.container.style.overflow=this.settings.overflow,e.hidden?(this.wrapper=document.createElement("div"),this.wrapper.style.visibility="hidden",this.wrapper.style.overflow="hidden",this.wrapper.style.width="0",this.wrapper.style.height="0",this.wrapper.appendChild(this.container),this.wrapper):this.container},EPUBJS.Renderer.prototype.resize=function(t,e){var i=t,n=e,r=window.getComputedStyle(this.container),o={left:parseFloat(r["padding-left"])||0,right:parseFloat(r["padding-right"])||0,top:parseFloat(r["padding-top"])||0,bottom:parseFloat(r["padding-bottom"])||0},s=i-o.left-o.right,h=n-o.top-o.bottom;t||(i=window.innerWidth),e||(n=window.innerHeight),this.trigger("resized",{width:this.width,height:this.height}),this.views.forEach(function(t){"vertical"===this.settings.axis?t.resize(s,0):t.resize(0,h)}.bind(this))},EPUBJS.Renderer.prototype.onResized=function(){var t=this.element.getBoundingClientRect();this.resize(t.width,t.height)},EPUBJS.Renderer.prototype.attachTo=function(t){var e;return EPUBJS.core.isElement(t)?this.element=t:"string"==typeof t&&(this.element=document.getElementById(t)),this.element?(this.element.appendChild(this.container),this.settings.height||this.settings.width||(e=this.element.getBoundingClientRect(),this.resize(e.width,e.height)),this.settings.infinite&&(this.infinite.start(),this.infinite.on("forwards",function(){var t=this.last().section.index+1;!this.rendering&&!this.filling&&!this.displaying&&t0&&this.backwards()}.bind(this))),window.addEventListener("resize",this.onResized.bind(this),!1),this.hooks.replacements.register(this.replacements.bind(this)),this.hooks.display.register(this.afterDisplay.bind(this)),void 0):(console.error("Not an Element"),void 0)},EPUBJS.Renderer.prototype.clear=function(){this.views.forEach(function(t){t.destroy()}),this.views=[]},EPUBJS.Renderer.prototype.display=function(t){var e=new RSVP.defer,i=e.promise;return"string"==typeof t&&(t=t.split("#")[0]),this.book.opened.then(function(){var i,n=this.book.spine.get(t);this.displaying=!0,n?(this.clear(),i=this.render(n),this.settings.infinite&&i.then(function(){return this.fill.call(this)}.bind(this)),i.then(function(){this.trigger("displayed",n),this.displaying=!1,e.resolve(this)}.bind(this))):e.reject(new Error("No Section Found"))}.bind(this)),i},EPUBJS.Renderer.prototype.render=function(t){var e,i,n=this.container.getBoundingClientRect(),r=window.getComputedStyle(this.container),o={left:parseFloat(r["padding-left"])||0,right:parseFloat(r["padding-right"])||0,top:parseFloat(r["padding-top"])||0,bottom:parseFloat(r["padding-bottom"])||0},s=n.width-o.left-o.right,h=n.height-o.top-o.bottom;return t?(i=new EPUBJS.View(t),"vertical"===this.settings.axis?i.create(s,0):i.create(0,h),this.insert(i,t.index),e=i.render(this.book.request),e.then(function(){return this.hooks.display.trigger(i)}.bind(this)).then(function(){return this.hooks.replacements.trigger(i,this)}.bind(this)).then(function(){return i.expand()}.bind(this)).then(function(){return this.rendering=!1,i.show(),this.trigger("rendered",i.section),i}.bind(this)).catch(function(t){this.trigger("loaderror",t)}.bind(this))):(e=new RSVP.defer,e.reject(new Error("No Section Provided")),e.promise)},EPUBJS.Renderer.prototype.forwards=function(){var t,e,i;return t=this.last().section.index+1,this.rendering||t===this.book.spine.length?(e=new RSVP.defer,e.reject(new Error("Reject Forwards")),e.promise):(this.rendering=!0,i=this.book.spine.get(t),e=this.render(i),e.then(function(){var t=this.first(),e=t.bounds(),i=(this.last().bounds(),this.container.scrollTop),n=this.container.scrollLeft;this.views.length>this.settings.viewsLimit&&this.container.scrollTop-e.height>100&&(this.remove(t),this.settings.infinite&&("vertical"===this.settings.axis?this.infinite.scrollTo(0,i-e.height,!0):this.infinite.scrollTo(n-e.width,!0))),this.rendering=!1}.bind(this)),e)},EPUBJS.Renderer.prototype.backwards=function(){var t,e,i;return t=this.first().section.index-1,this.rendering||0>t?(e=new RSVP.defer,e.reject(new Error("Reject Backwards")),e.promise):(this.rendering=!0,i=this.book.spine.get(t),e=this.render(i),e.then(function(){var t;this.settings.infinite&&("vertical"===this.settings.axis?this.infinite.scrollBy(0,this.first().bounds().height,!0):this.infinite.scrollBy(this.first().bounds().width,0,!0)),this.views.length>this.settings.viewsLimit&&(t=this.last(),this.remove(t),this.container.scrollTop-this.first().bounds().height>100&&this.remove(t)),this.rendering=!1}.bind(this)),e)},EPUBJS.Renderer.prototype.fill=function(){var t=this.first().section.index-1,e=this.forwards();return this.filling=!0,"vertical"===this.settings.axis?e.then(this.fillVertical.bind(this)):e.then(this.fillHorizontal.bind(this)),t>0&&e.then(this.backwards.bind(this)),e.then(function(){this.filling=!1}.bind(this))},EPUBJS.Renderer.prototype.fillVertical=function(){var t=this.container.getBoundingClientRect().height,e=this.last().bounds().bottom,i=new RSVP.defer;return t&&e&&t>e?this.forwards().then(this.fillVertical.bind(this)):(this.rendering=!1,i.resolve(),i.promise)},EPUBJS.Renderer.prototype.fillHorizontal=function(){var t=this.container.getBoundingClientRect().width,e=this.last().bounds().right,i=new RSVP.defer;return t&&e&&t>=e?this.forwards().then(this.fillHorizontal.bind(this)):(this.rendering=!1,i.resolve(),i.promise)},EPUBJS.Renderer.prototype.append=function(t){this.views.push(t),t.appendTo(this.container)},EPUBJS.Renderer.prototype.prepend=function(t){this.views.unshift(t),t.prependTo(this.container)},EPUBJS.Renderer.prototype.insert=function(t,e){this.first()?e-this.first().section.index>=0?this.append(t):e-this.last().section.index<=0&&this.prepend(t):this.append(t)},EPUBJS.Renderer.prototype.remove=function(t){var e=this.views.indexOf(t);t.destroy(),e>-1&&this.views.splice(e,1)},EPUBJS.Renderer.prototype.first=function(){return this.views[0]},EPUBJS.Renderer.prototype.last=function(){return this.views[this.views.length-1]},EPUBJS.Renderer.prototype.replacements=function(t,e){for(var i=new RSVP.defer,n=t.document.querySelectorAll("a[href]"),r=function(t){var i=t.getAttribute("href"),n=new EPUBJS.core.uri(i);n.protocol?t.setAttribute("target","_blank"):0===i.indexOf("#")||(t.onclick=function(){return e.display(i),!1})},o=0;o=0;r--)if(t=this.views[r],e=t.bounds().top,e-1&&this.views.splice(e,1),this.container.removeChild(t.element),t.shown&&t.destroy(),t=null},EPUBJS.Rendition.prototype.clear=function(){this.views.forEach(function(t){t.destroy()}),this.views=[]},EPUBJS.Rendition.prototype.first=function(){return this.views[0]},EPUBJS.Rendition.prototype.last=function(){return this.views[this.views.length-1]},EPUBJS.Rendition.prototype.each=function(t){return this.views.forEach(t)},EPUBJS.Rendition.prototype.isVisible=function(t,e){var i=t.position(),n=e||this.container.getBoundingClientRect();i.bottom>=n.top-this.settings.offset&&!(i.top>n.bottom)&&i.right>=n.left&&!(i.left>n.right+this.settings.offset)?t.shown||this.rendering||this.render(t):t.shown&&t.destroy()},EPUBJS.Rendition.prototype.check=function(){var t=this.container.getBoundingClientRect();this.views.forEach(function(e){this.isVisible(e,t)}.bind(this)),clearTimeout(this.trimTimeout),this.trimTimeout=setTimeout(function(){this.trim()}.bind(this),250)},EPUBJS.Rendition.prototype.trim=function(){for(var t=!0,e=0;e0?this.views[e-1].shown:!1,r=e+1=0;r--)if(t=this.views[r],e=t.bounds().top,e-1?(delete this.spineByHref[t.href],delete this.spineById[t.idref],this.spineItems.splice(e,1)):void 0},EPUBJS.View=function(t){this.id="epubjs-view:"+EPUBJS.core.uuid(),this.displaying=new RSVP.defer,this.displayed=this.displaying.promise,this.section=t,this.index=t.index,this.element=document.createElement("div"),this.element.classList.add("epub-view"),this.element.style.display="inline-block",this.element.style.height="0px",this.element.style.width="0px",this.element.style.overflow="hidden",this.shown=!1,this.rendered=!1,this.observe=!1,this.width=0,this.height=0},EPUBJS.View.prototype.create=function(t,e){return this.iframe?this.iframe:(this.iframe=document.createElement("iframe"),this.iframe.id=this.id,this.iframe.scrolling="no",this.iframe.seamless="seamless",this.iframe.style.border="none",this.resizing=!0,this.iframe.style.visibility="hidden",this.element.appendChild(this.iframe),this.rendered=!0,(t||e)&&this.resize(t,e),this.width&&this.height&&this.resize(this.width,this.height),this.iframe)},EPUBJS.View.prototype.resize=function(t,e){var i=this.borders();t&&(this.iframe&&(this.iframe.style.width=t+"px"),this.shown&&(this.element.style.width=t+i.width+"px")),e&&(this.iframe&&(this.iframe.style.height=e+"px"),this.shown&&(this.element.style.height=e+i.height+"px")),this.resizing||(this.resizing=!0,this.iframe&&this.expand())},EPUBJS.View.prototype.resized=function(){this.resizing?this.resizing=!1:this.iframe},EPUBJS.View.prototype.display=function(t){return this.section.render(t).then(function(t){return this.load(t)}.bind(this)).then(this.afterLoad.bind(this)).then(this.displaying.resolve.call(this))},EPUBJS.View.prototype.load=function(t){var e=new RSVP.defer,i=e.promise;return this.document=this.iframe.contentDocument,this.document?(this.iframe.addEventListener("load",function(){this.window=this.iframe.contentWindow,this.document=this.iframe.contentDocument,e.resolve(this)}.bind(this)),this.document.open(),this.document.write(t),this.document.close(),i):(e.reject(new Error("No Document Available")),i)},EPUBJS.View.prototype.afterLoad=function(){this.iframe.style.display="inline-block",this.document.body.style.margin="0",this.document.body.style.display="inline-block",this.document.documentElement.style.width="auto",setTimeout(function(){this.window.addEventListener("resize",this.resized.bind(this),!1)}.bind(this),10),"loading"===this.document.fonts.status&&(this.document.fonts.onloading=function(){this.expand()}.bind(this)),this.observe&&(this.observer=this.observe(this.document.body))},EPUBJS.View.prototype.expand=function(t,e,i){var n,r,o,s=t||new RSVP.defer,h=s.promise,a=10,c=e||1,p=10*e;return this.resizing=!0,n=this.document.body.getBoundingClientRect(),!n||0===n.height&&0===n.width?(console.error("View not shown"),h):(o=n.height,r=this.document.documentElement.scrollWidth,a>=c&&(this.width!=r||this.height!=o)?(this.resize(r,o),setTimeout(function(){c+=1,i&&i(this),this.expand(s,c,i)}.bind(this),p)):s.resolve(),this.width=r,this.height=o,h)},EPUBJS.View.prototype.observe=function(t){var e=this,i=new MutationObserver(function(){e.expand()}),n={attributes:!0,childList:!0,characterData:!0,subtree:!0};return i.observe(t,n),i},EPUBJS.View.prototype.show=function(){var t=this.borders();this.element.style.width=this.width+t.width+"px",this.element.style.height=this.height+t.height+"px",this.iframe.style.visibility="visible",this.shown=!0,this.onShown(this),this.trigger("shown",this)},EPUBJS.View.prototype.hide=function(){this.trigger("hidden")},EPUBJS.View.prototype.position=function(){return this.element.getBoundingClientRect() -},EPUBJS.View.prototype.onShown=function(){},EPUBJS.View.prototype.borders=function(){return this.iframe&&!this.iframeStyle&&(this.iframeStyle=window.getComputedStyle(this.iframe),this.paddingTopBottom=parseInt(this.iframeStyle.paddingTop)+parseInt(this.iframeStyle.paddingBottom)||0,this.paddingLeftRight=parseInt(this.iframeStyle.paddingLeft)+parseInt(this.iframeStyle.paddingRight)||0,this.marginTopBottom=parseInt(this.iframeStyle.marginTop)+parseInt(this.iframeStyle.marginBottom)||0,this.marginLeftRight=parseInt(this.iframeStyle.marginLeft)+parseInt(this.iframeStyle.marginRight)||0,this.borderTopBottom=parseInt(this.iframeStyle.borderTop)+parseInt(this.iframeStyle.borderBottom)||0,this.borderLeftRight=parseInt(this.iframeStyle.borderLeft)+parseInt(this.iframeStyle.borderRight)||0),this.element&&!this.elementStyle&&(this.elementStyle=window.getComputedStyle(this.element),this.elpaddingTopBottom=parseInt(this.elementStyle.paddingTop)+parseInt(this.elementStyle.paddingBottom)||0,this.elpaddingLeftRight=parseInt(this.elementStyle.paddingLeft)+parseInt(this.elementStyle.paddingRight)||0,this.elmarginTopBottom=parseInt(this.elementStyle.marginTop)+parseInt(this.elementStyle.marginBottom)||0,this.elmarginLeftRight=parseInt(this.elementStyle.marginLeft)+parseInt(this.elementStyle.marginRight)||0,this.elborderTopBottom=parseInt(this.elementStyle.borderTop)+parseInt(this.elementStyle.borderBottom)||0,this.elborderLeftRight=parseInt(this.elementStyle.borderLeft)+parseInt(this.elementStyle.borderRight)||0),{height:this.paddingTopBottom+this.marginTopBottom+this.borderTopBottom,width:this.paddingLeftRight+this.marginLeftRight+this.borderLeftRight}},EPUBJS.View.prototype.bounds=function(){return{height:this.height+this.paddingTopBottom+this.marginTopBottom+this.borderTopBottom+this.elpaddingTopBottom+this.elmarginTopBottom+this.elborderTopBottom,width:this.width+this.paddingLeftRight+this.marginLeftRight+this.borderLeftRight+this.elpaddingLeftRight+this.elmarginLeftRight+this.elborderLeftRight}},EPUBJS.View.prototype.destroy=function(){this.iframe&&(this.element.removeChild(this.iframe),this.shown=!1,this.iframe=null)},RSVP.EventTarget.mixin(EPUBJS.View.prototype),EPUBJS.ViewManager=function(t){this.views=[],this.container=t},EPUBJS.ViewManager.prototype.append=function(t){this.views.push(t),this.container.appendChild(t.element())},EPUBJS.ViewManager.prototype.prepend=function(t){this.views.unshift(t),this.container.insertBefore(t.element(),this.container.firstChild)},EPUBJS.ViewManager.prototype.insert=function(t,e){this.views.splice(e,0,t),ethis.last().index?(this.append(t),e=this.views.length):t.indexb.index?1:a.index-1&&this.views.splice(e,1)},EPUBJS.ViewManager.prototype.clear=function(){this.views.forEach(function(t){t.destroy()}),this.views=[]},EPUBJS.ViewManager.prototype.first=function(){return this.views[0]},EPUBJS.ViewManager.prototype.last=function(){return this.views[this.views.length-1]},EPUBJS.ViewManager.prototype.map=function(t){return this.views.map(t)}; \ No newline at end of file +"undefined"==typeof EPUBJS&&(("undefined"!=typeof window?window:this).EPUBJS={}),EPUBJS.VERSION="0.3.0",EPUBJS.Render={},function(t){"use strict";var e=function(t){return new EPUBJS.Book(t)};e.Render={register:function(t,i){e.Render[t]=i}},"object"==typeof exports?(t.RSVP=require("rsvp"),module.exports=e):"function"==typeof define&&define.amd?define(e):t.ePub=e}(this),function(t){var e,i;!function(){var t={},n={};e=function(e,i,n){t[e]={deps:i,callback:n}},i=function(e){function r(t){if("."!==t.charAt(0))return t;for(var i=t.split("/"),n=e.split("/").slice(0,-1),r=0,o=i.length;o>r;r++){var s=i[r];if(".."===s)n.pop();else{if("."===s)continue;n.push(s)}}return n.join("/")}if(n[e])return n[e];if(n[e]={},!t[e])throw new Error("Could not find module "+e);for(var o,s=t[e],a=s.deps,h=s.callback,c=[],p=0,l=a.length;l>p;p++)c.push("exports"===a[p]?o={}:i(r(a[p])));var u=h.apply(this,c);return n[e]=o||u},i.entries=t}(),e("rsvp/-internal",["./utils","./instrument","./config","exports"],function(t,e,i,n){"use strict";function r(){}function o(t){try{return t.then}catch(e){return x.error=e,x}}function s(t,e,i,n){try{t.call(e,i,n)}catch(r){return r}}function a(t,e,i){b.async(function(t){var n=!1,r=s(i,e,function(i){n||(n=!0,e!==i?p(t,i):u(t,i))},function(e){n||(n=!0,d(t,e))},"Settle: "+(t._label||" unknown promise"));!n&&r&&(n=!0,d(t,r))},t)}function h(t,e){t._onerror=null,e._state===U?u(t,e._result):t._state===J?d(t,e._result):f(e,void 0,function(i){e!==i?p(t,i):u(t,i)},function(e){d(t,e)})}function c(t,e){if(e instanceof t.constructor)h(t,e);else{var i=o(e);i===x?d(t,x.error):void 0===i?u(t,e):E(i)?a(t,e,i):u(t,e)}}function p(t,e){t===e?u(t,e):w(e)?c(t,e):u(t,e)}function l(t){t._onerror&&t._onerror(t._result),g(t)}function u(t,e){t._state===B&&(t._result=e,t._state=U,0===t._subscribers.length?b.instrument&&P("fulfilled",t):b.async(g,t))}function d(t,e){t._state===B&&(t._state=J,t._result=e,b.async(l,t))}function f(t,e,i,n){var r=t._subscribers,o=r.length;t._onerror=null,r[o]=e,r[o+U]=i,r[o+J]=n,0===o&&t._state&&b.async(g,t)}function g(t){var e=t._subscribers,i=t._state;if(b.instrument&&P(i===U?"fulfilled":"rejected",t),0!==e.length){for(var n,r,o=t._result,s=0;st;t+=2){var e=l[t],i=l[t+1];e(i),l[t]=void 0,l[t+1]=void 0}s=0}var s=0;t["default"]=function(t,e){l[s]=t,l[s+1]=e,s+=2,2===s&&a()};var a,h="undefined"!=typeof window?window:{},c=h.MutationObserver||h.WebKitMutationObserver,p="undefined"!=typeof Uint8ClampedArray&&"undefined"!=typeof importScripts&&"undefined"!=typeof MessageChannel,l=new Array(1e3);a="undefined"!=typeof process&&"[object process]"==={}.toString.call(process)?e():c?i():p?n():r()}),e("rsvp/config",["./events","exports"],function(t,e){"use strict";function i(t,e){return"onerror"===t?void r.on("error",e):2!==arguments.length?r[t]:void(r[t]=e)}var n=t["default"],r={instrument:!1};n.mixin(r),e.config=r,e.configure=i}),e("rsvp/defer",["./promise","exports"],function(t,e){"use strict";var i=t["default"];e["default"]=function(t){var e={};return e.promise=new i(function(t,i){e.resolve=t,e.reject=i},t),e}}),e("rsvp/enumerator",["./utils","./-internal","exports"],function(t,e,i){"use strict";function n(t,e,i){return t===l?{state:"fulfilled",value:i}:{state:"rejected",reason:i}}function r(t,e,i,n){this._instanceConstructor=t,this.promise=new t(a,n),this._abortOnReject=i,this._validateInput(e)?(this._input=e,this.length=e.length,this._remaining=e.length,this._init(),0===this.length?c(this.promise,this._result):(this.length=this.length||0,this._enumerate(),0===this._remaining&&c(this.promise,this._result))):h(this.promise,this._validationError())}var o=t.isArray,s=t.isMaybeThenable,a=e.noop,h=e.reject,c=e.fulfill,p=e.subscribe,l=e.FULFILLED,u=e.REJECTED,d=e.PENDING,f=!0;i.ABORT_ON_REJECTION=f,i.makeSettledResult=n,r.prototype._validateInput=function(t){return o(t)},r.prototype._validationError=function(){return new Error("Array Methods must be provided an Array")},r.prototype._init=function(){this._result=new Array(this.length)},i["default"]=r,r.prototype._enumerate=function(){for(var t=this.length,e=this.promise,i=this._input,n=0;e._state===d&&t>n;n++)this._eachEntry(i[n],n)},r.prototype._eachEntry=function(t,e){var i=this._instanceConstructor;s(t)?t.constructor===i&&t._state!==d?(t._onerror=null,this._settledAt(t._state,e,t._result)):this._willSettleAt(i.resolve(t),e):(this._remaining--,this._result[e]=this._makeResult(l,e,t))},r.prototype._settledAt=function(t,e,i){var n=this.promise;n._state===d&&(this._remaining--,this._abortOnReject&&t===u?h(n,i):this._result[e]=this._makeResult(t,e,i)),0===this._remaining&&c(n,this._result)},r.prototype._makeResult=function(t,e,i){return i},r.prototype._willSettleAt=function(t,e){var i=this;p(t,void 0,function(t){i._settledAt(l,e,t)},function(t){i._settledAt(u,e,t)})}}),e("rsvp/events",["exports"],function(t){"use strict";function e(t,e){for(var i=0,n=t.length;n>i;i++)if(t[i]===e)return i;return-1}function i(t){var e=t._promiseCallbacks;return e||(e=t._promiseCallbacks={}),e}t["default"]={mixin:function(t){return t.on=this.on,t.off=this.off,t.trigger=this.trigger,t._promiseCallbacks=void 0,t},on:function(t,n){var r,o=i(this);r=o[t],r||(r=o[t]=[]),-1===e(r,n)&&r.push(n)},off:function(t,n){var r,o,s=i(this);return n?(r=s[t],o=e(r,n),void(-1!==o&&r.splice(o,1))):void(s[t]=[])},trigger:function(t,e){var n,r,o=i(this);if(n=o[t])for(var s=0;sa;a++)s[a]=e(t[a]);return n.all(s,i).then(function(e){for(var i=new Array(o),n=0,r=0;o>r;r++)e[r]&&(i[n]=t[r],n++);return i.length=n,i})})}}),e("rsvp/hash-settled",["./promise","./enumerator","./promise-hash","./utils","exports"],function(t,e,i,n,r){"use strict";function o(t,e,i){this._superConstructor(t,e,!1,i)}var s=t["default"],a=e.makeSettledResult,h=i["default"],c=e["default"],p=n.o_create;o.prototype=p(h.prototype),o.prototype._superConstructor=c,o.prototype._makeResult=a,o.prototype._validationError=function(){return new Error("hashSettled must be called with an object")},r["default"]=function(t,e){return new o(s,t,e).promise}}),e("rsvp/hash",["./promise","./promise-hash","./enumerator","exports"],function(t,e,i,n){"use strict";{var r=t["default"],o=e["default"];i.ABORT_ON_REJECTION}n["default"]=function(t,e){return new o(r,t,e).promise}}),e("rsvp/instrument",["./config","./utils","exports"],function(t,e,i){"use strict";var n=t.config,r=e.now,o=[];i["default"]=function(t,e,i){1===o.push({name:t,payload:{guid:e._guidKey+e._id,eventName:t,detail:e._result,childGuid:i&&e._guidKey+i._id,label:e._label,timeStamp:r(),stack:new Error(e._label).stack}})&&setTimeout(function(){for(var t,e=0;ea;a++)s[a]=e(t[a]);return n.all(s,i)})}}),e("rsvp/node",["./promise","./utils","exports"],function(t,e,i){"use strict";var n=t["default"],r=e.isArray;i["default"]=function(t,e){function i(){for(var i=arguments.length,r=new Array(i),a=0;i>a;a++)r[a]=arguments[a];var h;return o||s||!e?h=this:("object"==typeof console&&console.warn('Deprecation: RSVP.denodeify() doesn\'t allow setting the "this" binding anymore. Use yourFunction.bind(yourThis) instead.'),h=e),n.all(r).then(function(i){function r(n,r){function a(){for(var t=arguments.length,i=new Array(t),a=0;t>a;a++)i[a]=arguments[a];var h=i[0],c=i[1];if(h)r(h);else if(o)n(i.slice(1));else if(s){var p,l,u={},d=i.slice(1);for(l=0;la;a++)o=i[a],this._eachEntry(o.entry,o.position)}}),e("rsvp/promise",["./config","./events","./instrument","./utils","./-internal","./promise/cast","./promise/all","./promise/race","./promise/resolve","./promise/reject","exports"],function(t,e,i,n,r,o,s,a,h,c,p){"use strict";function l(){throw new TypeError("You must pass a resolver function as the first argument to the promise constructor")}function u(){throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.")}function d(t,e){this._id=C++,this._label=e,this._subscribers=[],f.instrument&&g("created",this),v!==t&&(m(t)||l(),this instanceof d||u(),w(this,t))}var f=t.config,g=(e["default"],i["default"]),m=(n.objectOrFunction,n.isFunction),y=n.now,v=r.noop,S=(r.resolve,r.reject,r.fulfill,r.subscribe),w=r.initializePromise,E=r.invokeCallback,P=r.FULFILLED,b=o["default"],B=s["default"],U=a["default"],J=h["default"],x=c["default"],R="rsvp_"+y()+"-",C=0;p["default"]=d,d.cast=b,d.all=B,d.race=U,d.resolve=J,d.reject=x,d.prototype={constructor:d,_id:void 0,_guidKey:R,_label:void 0,_state:void 0,_result:void 0,_subscribers:void 0,_onerror:function(t){f.trigger("error",t)},then:function(t,e,i){var n=this;n._onerror=null;var r=new this.constructor(v,i),o=n._state,s=n._result;return f.instrument&&g("chained",n,r),o===P&&t?f.async(function(){E(o,r,t,s)}):S(n,r,t,e),r},"catch":function(t,e){return this.then(null,t,e)},"finally":function(t,e){var i=this.constructor;return this.then(function(e){return i.resolve(t()).then(function(){return e})},function(e){return i.resolve(t()).then(function(){throw e})},e)}}}),e("rsvp/promise/all",["../enumerator","exports"],function(t,e){"use strict";var i=t["default"];e["default"]=function(t,e){return new i(this,t,!0,e).promise}}),e("rsvp/promise/cast",["./resolve","exports"],function(t,e){"use strict";var i=t["default"];e["default"]=i}),e("rsvp/promise/race",["../utils","../-internal","exports"],function(t,e,i){"use strict";var n=t.isArray,r=(t.isFunction,t.isMaybeThenable,e.noop),o=e.resolve,s=e.reject,a=e.subscribe,h=e.PENDING;i["default"]=function(t,e){function i(t){o(l,t)}function c(t){s(l,t)}var p=this,l=new p(r,e);if(!n(t))return s(l,new TypeError("You must pass an array to race.")),l;for(var u=t.length,d=0;l._state===h&&u>d;d++)a(p.resolve(t[d]),void 0,i,c);return l}}),e("rsvp/promise/reject",["../-internal","exports"],function(t,e){"use strict";var i=t.noop,n=t.reject;e["default"]=function(t,e){var r=this,o=new r(i,e);return n(o,t),o}}),e("rsvp/promise/resolve",["../-internal","exports"],function(t,e){"use strict";var i=t.noop,n=t.resolve;e["default"]=function(t,e){var r=this;if(t&&"object"==typeof t&&t.constructor===r)return t;var o=new r(i,e);return n(o,t),o}}),e("rsvp/race",["./promise","exports"],function(t,e){"use strict";var i=t["default"];e["default"]=function(t,e){return i.race(t,e)}}),e("rsvp/reject",["./promise","exports"],function(t,e){"use strict";var i=t["default"];e["default"]=function(t,e){return i.reject(t,e)}}),e("rsvp/resolve",["./promise","exports"],function(t,e){"use strict";var i=t["default"];e["default"]=function(t,e){return i.resolve(t,e)}}),e("rsvp/rethrow",["exports"],function(t){"use strict";t["default"]=function(t){throw setTimeout(function(){throw t}),t}}),e("rsvp/utils",["exports"],function(t){"use strict";function e(t){return"function"==typeof t||"object"==typeof t&&null!==t}function i(t){return"function"==typeof t}function n(t){return"object"==typeof t&&null!==t}t.objectOrFunction=e,t.isFunction=i,t.isMaybeThenable=n;var r;r=Array.isArray?Array.isArray:function(t){return"[object Array]"===Object.prototype.toString.call(t)};var o=r;t.isArray=o;var s=Date.now||function(){return(new Date).getTime()};t.now=s;var a=Object.create||function(t){var e=function(){};return e.prototype=t,e};t.o_create=a}),e("rsvp",["./rsvp/promise","./rsvp/events","./rsvp/node","./rsvp/all","./rsvp/all-settled","./rsvp/race","./rsvp/hash","./rsvp/hash-settled","./rsvp/rethrow","./rsvp/defer","./rsvp/config","./rsvp/map","./rsvp/resolve","./rsvp/reject","./rsvp/filter","./rsvp/asap","exports"],function(t,e,i,n,r,o,s,a,h,c,p,l,u,d,f,g,m){"use strict";function y(t,e){k.async(t,e)}function v(){k.on.apply(k,arguments)}function S(){k.off.apply(k,arguments)}var w=t["default"],E=e["default"],P=i["default"],b=n["default"],B=r["default"],U=o["default"],J=s["default"],x=a["default"],R=h["default"],C=c["default"],k=p.config,_=p.configure,T=l["default"],I=u["default"],F=d["default"],N=f["default"],L=g["default"];if(k.async=L,"undefined"!=typeof window&&"object"==typeof window.__PROMISE_INSTRUMENTATION__){var V=window.__PROMISE_INSTRUMENTATION__;_("instrument",!0);for(var A in V)V.hasOwnProperty(A)&&v(A,V[A])}m.Promise=w,m.EventTarget=E,m.all=b,m.allSettled=B,m.race=U,m.hash=J,m.hashSettled=x,m.rethrow=R,m.defer=C,m.denodeify=P,m.configure=_,m.on=v,m.off=S,m.resolve=I,m.reject=F,m.async=y,m.map=T,m.filter=N}),t.RSVP=i("rsvp")}(self),EPUBJS.Book=function(t){this.opening=new RSVP.defer,this.opened=this.opening.promise,this.isOpen=!1,this.url=void 0,this.spine=new EPUBJS.Spine(this.request),this.loading={manifest:new RSVP.defer,spine:new RSVP.defer,metadata:new RSVP.defer,cover:new RSVP.defer,navigation:new RSVP.defer,pageList:new RSVP.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},this.ready=RSVP.hash(this.loaded),this.isRendered=!1,this._q=EPUBJS.core.queue(this),this.request=this.requestMethod.bind(this),t&&this.open(t)},EPUBJS.Book.prototype.open=function(t){var e,i,n,r=new EPUBJS.Parser,o=this,s="META-INF/container.xml";return t?(e="object"==typeof t?t:EPUBJS.core.uri(t),"opf"===e.extension?(this.packageUrl=e.href,this.containerUrl="",e.origin?this.url=e.base:window?(n=EPUBJS.core.uri(window.location.href),this.url=EPUBJS.core.resolveUrl(n.base,e.directory)):this.url=e.directory,i=this.request(this.packageUrl)):"epub"===e.extension||"zip"===e.extension?(this.archived=!0,this.url=""):e.extension||(this.containerUrl=t+s,i=this.request(this.containerUrl).then(function(t){return r.container(t)}).then(function(e){var i=EPUBJS.core.uri(e.packagePath);return o.packageUrl=t+e.packagePath,o.url=t+i.directory,o.encoding=e.encoding,o.request(o.packageUrl)}).catch(function(t){console.error("Could not load book at: "+(this.packageUrl||this.containerPath)),o.trigger("book:loadFailed",this.packageUrl||this.containerPath),o.opening.reject(t)})),i.then(function(t){o.unpack(t),o.loading.manifest.resolve(o.package.manifest),o.loading.metadata.resolve(o.package.metadata),o.loading.spine.resolve(o.spine),o.loading.cover.resolve(o.cover),this.isOpen=!0,o.opening.resolve(o)}).catch(function(t){console.error(t.message,t.stack),o.opening.reject(t)}),this.opened):(this.opening.resolve(this),this.opened)},EPUBJS.Book.prototype.unpack=function(t){var e=this,i=new EPUBJS.Parser;e.package=i.packageContents(t),e.package.baseUrl=e.url,this.spine.load(e.package),e.navigation=new EPUBJS.Navigation(e.package,this.request),e.navigation.load().then(function(t){e.toc=t,e.loading.navigation.resolve(e.toc)}),e.cover=e.url+e.package.coverPath},EPUBJS.Book.prototype.section=function(t){return this.spine.get(t)},EPUBJS.Book.prototype.renderTo=function(t,e){return this.rendition=new EPUBJS.Rendition(this,e),this.rendition.attachTo(t),this.rendition},EPUBJS.Book.prototype.requestMethod=function(t){return this.archived?void 0:EPUBJS.core.request(t,"xml",this.requestCredentials,this.requestHeaders)},EPUBJS.Book.prototype.setRequestCredentials=function(t){this.requestCredentials=t},EPUBJS.Book.prototype.setRequestHeaders=function(t){this.requestHeaders=t},RSVP.EventTarget.mixin(EPUBJS.Book.prototype),RSVP.on("error",function(){}),RSVP.configure("instrument",!0),RSVP.on("rejected",function(t){console.error(t.detail.message,t.detail.stack)}),EPUBJS.Continuous=function(){this.views=[],this.container=container,this.limit=limit||4},EPUBJS.Continuous.prototype.append=function(t){this.views.push(t),this.container.appendChild(t.element()),t.onDisplayed=function(){var t,e=this.views.indexOf(t),i=t.section.next();e+1===this.views.length&&i&&(t=new EPUBJS.View(i),this.append(t))}.bind(this),this.resizeView(t)},EPUBJS.Continuous.prototype.prepend=function(t){this.views.unshift(t),this.container.insertBefore(t.element,this.container.firstChild),t.onDisplayed=function(){var t,e=(this.views.indexOf(t),t.section.prev());e&&(t=new EPUBJS.View(e),this.append(t))}.bind(this),this.resizeView(t)},EPUBJS.Continuous.prototype.fill=function(t){this.views.length&&this.clear(),this.views.push(t),this.container.appendChild(t.element),t.onDisplayed=function(){var e,i,n=t.section.next(),r=t.section.prev(),o=this.views.indexOf(t);o+1===this.views.length&&n&&(e=new EPUBJS.View(n),this.append(e)),0===o&&r&&(i=new EPUBJS.View(r),this.append(i)),this.resizeView(t)}.bind(this)},EPUBJS.Continuous.prototype.insert=function(t,e){this.views.splice(e,0,t),e-1&&this.views.splice(e,1)},EPUBJS.Continuous.prototype.clear=function(){this.views.forEach(function(t){t.destroy()}),this.views=[]},EPUBJS.Continuous.prototype.first=function(){return this.views[0]},EPUBJS.Continuous.prototype.last=function(){return this.views[this.views.length-1]},EPUBJS.Continuous.prototype.each=function(t){return this.views.forEach(t)},EPUBJS.Continuous.prototype.check=function(){{var t=this.container.getBoundingClientRect();(function(e){var i=e.bounds();i.bottom>=t.top&&!(i.top>t.bottom)&&i.right>=t.left&&!(i.left>t.right)?(console.log("visible",e.index),this.resizeView(e),this.display(e)):(console.log("off screen",e.index),e.destroy())}).bind(this)}this.views.forEach(this.isVisible)},EPUBJS.Continuous.prototype.displayView=function(t){return t.display(this.book.request).then(function(){return this.hooks.display.trigger(t)}.bind(this)).then(function(){return this.hooks.replacements.trigger(t,this)}.bind(this)).then(function(){return t.expand()}.bind(this)).then(function(){return this.rendering=!1,t.show(),this.trigger("rendered",section),t}.bind(this)).catch(function(t){this.trigger("loaderror",t)}.bind(this))},EPUBJS.Continuous.prototype.resizeView=function(t){var e=this.container.getBoundingClientRect(),i=window.getComputedStyle(this.container),n={left:parseFloat(i["padding-left"])||0,right:parseFloat(i["padding-right"])||0,top:parseFloat(i["padding-top"])||0,bottom:parseFloat(i["padding-bottom"])||0},r=e.width-n.left-n.right,o=e.height-n.top-n.bottom,s=100,a=200;"vertical"===this.settings.axis?t.resize(r,s):t.resize(a,o)},EPUBJS.core={},EPUBJS.core.request=function(t,e,i,n){function r(){if(this.readyState===this.DONE)if(200===this.status||this.responseXML){var t;t="xml"==e?this.responseXML?this.responseXML:(new DOMParser).parseFromString(this.response,"text/xml"):"json"==e?JSON.parse(this.response):"blob"==e?s?this.response:new Blob([this.response]):this.response,h.resolve(t)}else h.reject({status:this.status,message:this.response,stack:(new Error).stack})}var o,s=window.URL,a=s?"blob":"arraybuffer",h=new RSVP.defer,c=new XMLHttpRequest,p=XMLHttpRequest.prototype;"overrideMimeType"in p||Object.defineProperty(p,"overrideMimeType",{value:function(){}}),i&&(c.withCredentials=!0),c.open("GET",t,!0);for(o in n)c.setRequestHeader(o,n[o]);return c.onreadystatechange=r,"blob"==e&&(c.responseType=a),"json"==e&&c.setRequestHeader("Accept","application/json"),"xml"==e&&c.overrideMimeType("text/xml"),c.send(),h.promise},EPUBJS.core.uri=function(t){var e,i,n,r={protocol:"",host:"",path:"",origin:"",directory:"",base:"",filename:"",extension:"",fragment:"",href:t},o=t.indexOf("://"),s=t.indexOf("?"),a=t.indexOf("#");return-1!=a&&(r.fragment=t.slice(a+1),t=t.slice(0,a)),-1!=s&&(r.search=t.slice(s+1),t=t.slice(0,s),href=t),-1!=o?(r.protocol=t.slice(0,o),e=t.slice(o+3),n=e.indexOf("/"),-1===n?(r.host=r.path,r.path=""):(r.host=e.slice(0,n),r.path=e.slice(n)),r.origin=r.protocol+"://"+r.host,r.directory=EPUBJS.core.folder(r.path),r.base=r.origin+r.directory):(r.path=t,r.directory=EPUBJS.core.folder(t),r.base=r.directory),r.filename=t.replace(r.base,""),i=r.filename.lastIndexOf("."),-1!=i&&(r.extension=r.filename.slice(i+1)),r},EPUBJS.core.folder=function(t){var e=t.lastIndexOf("/");if(-1==e)var i="";return i=t.slice(0,e+1)},EPUBJS.core.queue=function(t){var e=[],i=t,n=function(t,i,n){return e.push({funcName:t,args:i,context:n}),e},r=function(){var t;e.length&&(t=e.shift(),i[t.funcName].apply(t.context||i,t.args))},o=function(){for(;e.length;)r()},s=function(){e=[]},a=function(){return e.length};return{enqueue:n,dequeue:r,flush:o,clear:s,length:a}},EPUBJS.core.isElement=function(t){return!(!t||1!=t.nodeType)},EPUBJS.core.uuid=function(){var t=(new Date).getTime(),e="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var i=(t+16*Math.random())%16|0;return t=Math.floor(t/16),("x"==e?i:7&i|8).toString(16)});return e},EPUBJS.core.values=function(t){for(var e=-1,i=Object.keys(t),n=i.length,r=Array(n);++er;r++)if("undefined"!=typeof document.body.style[e[r]+i])return e[r]+i;return t},EPUBJS.core.defaults=function(t){for(var e=1,i=arguments.length;i>e;e++){var n=arguments[e];for(var r in n)void 0===t[r]&&(t[r]=n[r])}return t},EPUBJS.core.insert=function(t,e,i){var n=EPUBJS.core.locationOf(t,e,i);return e.splice(n,0,t),n},EPUBJS.core.locationOf=function(t,e,i,n,r){var o,s=n||0,a=r||e.length,h=parseInt(s+(a-s)/2);return i||(i=function(t,e){return t>e?1:e>t?-1:(t=e)?0:void 0}),0>=a-s?h:(o=i(e[h],t),a-s===1?o>0?h:h+1:0===o?h:-1===o?EPUBJS.core.locationOf(t,e,i,h,a):EPUBJS.core.locationOf(t,e,i,s,h))},EPUBJS.core.indexOfSorted=function(t,e,i,n,r){var o,s=n||0,a=r||e.length,h=parseInt(s+(a-s)/2);return i||(i=function(t,e){return t>e?1:e>t?-1:(t=e)?0:void 0}),0>=a-s?-1:(o=i(e[h],t),a-s===1?0===o?h:-1:0===o?h:-1===o?EPUBJS.core.indexOfSorted(t,e,i,h,a):EPUBJS.core.indexOfSorted(t,e,i,s,h))},EPUBJS.core.requestAnimationFrame=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame,EPUBJS.EpubCFI=function(t){return t?this.parse(t):void 0},EPUBJS.EpubCFI.prototype.generateChapterComponent=function(t,e,i){var n=parseInt(e),r=t+1,o="/"+r+"/";return o+=2*(n+1),i&&(o+="["+i+"]"),o},EPUBJS.EpubCFI.prototype.generatePathComponent=function(t){var e=[];return t.forEach(function(t){var i="";i+=2*(t.index+1),t.id&&(i+="["+t.id+"]"),e.push(i)}),e.join("/")},EPUBJS.EpubCFI.prototype.generateCfiFromElement=function(t,e){var i=this.pathTo(t),n=this.generatePathComponent(i);return n.length?"epubcfi("+e+"!"+n+"/1:0)":"epubcfi("+e+"!/4/)"},EPUBJS.EpubCFI.prototype.pathTo=function(t){for(var e,i=[];t&&null!==t.parentNode&&9!=t.parentNode.nodeType;)e=t.parentNode.children,i.unshift({id:t.id,tagName:t.tagName,index:e?Array.prototype.indexOf.call(e,t):0}),t=t.parentNode;return i},EPUBJS.EpubCFI.prototype.getChapterComponent=function(t){var e=t.split("!");return e[0]},EPUBJS.EpubCFI.prototype.getPathComponent=function(t){var e=t.split("!"),i=e[1]?e[1].split(":"):"";return i[0]},EPUBJS.EpubCFI.prototype.getCharecterOffsetComponent=function(t){var e=t.split(":");return e[1]||""},EPUBJS.EpubCFI.prototype.parse=function(t){var e,i,n,r,o,s,a,h,c,p={},l=function(t){var e,i,n,r;return e="element",i=parseInt(t)/2-1,n=t.match(/\[(.*)\]/),n&&n[1]&&(r=n[1]),{type:e,index:i,id:r||!1}};return"string"!=typeof t?{spinePos:-1}:(p.str=t,0===t.indexOf("epubcfi(")&&")"===t[t.length-1]&&(t=t.slice(8,t.length-1)),i=this.getChapterComponent(t),n=this.getPathComponent(t)||"",r=this.getCharecterOffsetComponent(t),i&&(e=i.split("/")[2]||"")?(p.spinePos=parseInt(e)/2-1||0,s=e.match(/\[(.*)\]/),p.spineId=s?s[1]:!1,-1!=n.indexOf(",")&&console.warn("CFI Ranges are not supported"),a=n.split("/"),h=a.pop(),p.steps=[],a.forEach(function(t){var e;t&&(e=l(t),p.steps.push(e))}),c=parseInt(h),isNaN(c)||p.steps.push(c%2===0?l(h):{type:"text",index:(c-1)/2}),o=r.match(/\[(.*)\]/),o&&o[1]?(p.characterOffset=parseInt(r.split("[")[0]),p.textLocationAssertion=o[1]):p.characterOffset=parseInt(r),p):{spinePos:-1})},EPUBJS.EpubCFI.prototype.addMarker=function(t,e,i){var n,r,o,s,a=e||document,h=i||this.createMarker(a);return"string"==typeof t&&(t=this.parse(t)),r=t.steps[t.steps.length-1],-1===t.spinePos?!1:(n=this.findParent(t,a))?(r&&"text"===r.type?(o=n.childNodes[r.index],t.characterOffset?(s=o.splitText(t.characterOffset),h.classList.add("EPUBJS-CFI-SPLIT"),n.insertBefore(h,s)):n.insertBefore(h,o)):n.insertBefore(h,n.firstChild),h):!1},EPUBJS.EpubCFI.prototype.createMarker=function(t){var e=t||document,i=e.createElement("span");return i.id="EPUBJS-CFI-MARKER:"+EPUBJS.core.uuid(),i.classList.add("EPUBJS-CFI-MARKER"),i},EPUBJS.EpubCFI.prototype.removeMarker=function(t,e){t.classList.contains("EPUBJS-CFI-SPLIT")?(nextSib=t.nextSibling,prevSib=t.previousSibling,nextSib&&prevSib&&3===nextSib.nodeType&&3===prevSib.nodeType&&(prevSib.textContent+=nextSib.textContent,t.parentNode.removeChild(nextSib)),t.parentNode.removeChild(t)):t.classList.contains("EPUBJS-CFI-MARKER")&&t.parentNode.removeChild(t)},EPUBJS.EpubCFI.prototype.findParent=function(t,e){var i,n,r,o=e||document,s=o.getElementsByTagName("html")[0],a=Array.prototype.slice.call(s.children);if("string"==typeof t&&(t=this.parse(t)),n=t.steps.slice(0),!n.length)return o.getElementsByTagName("body")[0];for(;n&&n.length>0;){if(i=n.shift(),"text"===i.type?(r=s.childNodes[i.index],s=r.parentNode||s):s=i.id?o.getElementById(i.id):a[i.index],"undefined"==typeof s)return console.error("No Element For",i,t.str),!1;a=Array.prototype.slice.call(s.children)}return s},EPUBJS.EpubCFI.prototype.compare=function(t,e){if("string"==typeof t&&(t=new EPUBJS.EpubCFI(t)),"string"==typeof e&&(e=new EPUBJS.EpubCFI(e)),t.spinePos>e.spinePos)return 1;if(t.spinePose.steps[i].index)return 1;if(t.steps[i].indexe.characterOffset?1:t.characterOffset=0?(o=r.length,t.characterOffseti?this.hooks[i].apply(this.context,r):void 0}.bind(this))):(t=n.promise,n.resolve()),t},EPUBJS.Infinite=function(t){this.container=t,this.windowHeight=window.innerHeight,this.tick=EPUBJS.core.requestAnimationFrame,this.scrolled=!1,this.ignore=!1,this.tolerance=100,this.prevScrollTop=0,this.prevScrollLeft=0,t&&this.start()},EPUBJS.Infinite.prototype.start=function(){this.container.addEventListener("scroll",function(){this.ignore?this.ignore=!1:this.scrolled=!0}.bind(this)),window.addEventListener("unload",function(){this.ignore=!0}),this.tick.call(window,this.check.bind(this)),this.scrolled=!1},EPUBJS.Infinite.prototype.forwards=function(){this.trigger("forwards")},EPUBJS.Infinite.prototype.backwards=function(){this.trigger("backwards")},EPUBJS.Infinite.prototype.check=function(){this.scrolled&&!this.ignore?(scrollTop=this.container.scrollTop,scrollLeft=this.container.scrollLeft,this.trigger("scroll",{top:scrollTop,left:scrollLeft}),scrollTop-this.prevScrollTop>this.tolerance&&this.forwards(),scrollTop-this.prevScrollTop<-this.tolerance&&this.backwards(),scrollLeft-this.prevScrollLeft>this.tolerance&&this.forwards(),scrollLeft-this.prevScrollLeft<-this.tolerance&&this.backwards(),this.prevScrollTop=scrollTop,this.prevScrollLeft=scrollLeft,this.scrolled=!1):(this.ignore=!1,this.scrolled=!1),this.tick.call(window,this.check.bind(this))},EPUBJS.Infinite.prototype.scrollBy=function(t,e,i){i&&(this.ignore=!0),this.container.scrollLeft+=t,this.container.scrollTop+=e,this.scrolled=!0,this.check()},EPUBJS.Infinite.prototype.scrollTo=function(t,e,i){i&&(this.ignore=!0),this.container.scrollLeft=t,this.container.scrollTop=e,this.scrolled=!0,this.check()},RSVP.EventTarget.mixin(EPUBJS.Infinite.prototype),EPUBJS.Layout=EPUBJS.Layout||{},EPUBJS.Layout.Reflowable=function(t){this.view=t,this.spreadWidth=null},EPUBJS.Layout.Reflowable.prototype.format=function(t,e,i,n){var r=EPUBJS.core.prefixed("columnAxis"),o=EPUBJS.core.prefixed("columnGap"),s=EPUBJS.core.prefixed("columnWidth"),a=EPUBJS.core.prefixed("columnFill"),h=Math.floor(e),c=Math.floor(h/8),p=n>=0?n:c%2===0?c:c-1;return this.documentElement=t,this.spreadWidth=h+p,t.style.overflow="hidden",t.style.width=h+"px",t.style.height=i+"px",t.style[r]="horizontal",t.style[a]="auto",t.style[s]=h+"px",t.style[o]=p+"px",this.colWidth=h,this.gap=p,{pageWidth:this.spreadWidth,pageHeight:i}},EPUBJS.Layout.Reflowable.prototype.calculatePages=function(){var t,e;return this.documentElement.style.width="auto",t=this.documentElement.scrollWidth,e=Math.ceil(t/this.spreadWidth),{displayedPages:e,pageCount:e}},EPUBJS.Layout.ReflowableSpreads=function(t){this.view=t,this.documentElement=t.document.documentElement,this.spreadWidth=null},EPUBJS.Layout.ReflowableSpreads.prototype.format=function(t,e,i){var n=EPUBJS.core.prefixed("columnAxis"),r=EPUBJS.core.prefixed("columnGap"),o=EPUBJS.core.prefixed("columnWidth"),s=EPUBJS.core.prefixed("columnFill"),a=2,h=Math.floor(t),c=h%2===0?h:h-1,p=Math.floor(c/8),l=i>=0?i:p%2===0?p:p-1,u=Math.floor((c-l)/a);return this.spreadWidth=(u+l)*a,this.view.document.documentElement.style.overflow="hidden",this.view.document.body.style.width=c+"px",this.view.document.body.style.height=e+"px",this.view.document.body.style[n]="horizontal",this.view.document.body.style[s]="auto",this.view.document.body.style[r]=l+"px",this.view.document.body.style[o]=u+"px",this.colWidth=u,this.gap=l,{pageWidth:this.spreadWidth,pageHeight:e}},EPUBJS.Layout.ReflowableSpreads.prototype.calculatePages=function(){var t=this.documentElement.scrollWidth,e=Math.ceil(t/this.spreadWidth);return{displayedPages:e,pageCount:2*e}},EPUBJS.Layout.Fixed=function(){this.documentElement=null},EPUBJS.Layout.Fixed=function(t){var e,i,n,r,o=EPUBJS.core.prefixed("columnWidth"),s=t.querySelector("[name=viewport");return this.documentElement=t,s&&s.hasAttribute("content")&&(e=s.getAttribute("content"),i=e.split(","),i[0]&&(n=i[0].replace("width=","")),i[1]&&(r=i[1].replace("height=",""))),t.style.width=n+"px"||"auto",t.style.height=r+"px"||"auto",t.style[o]="auto",t.style.overflow="auto",this.colWidth=n,this.gap=0,{pageWidth:n,pageHeight:r}},EPUBJS.Layout.Fixed.prototype.calculatePages=function(){return{displayedPages:1,pageCount:1}},EPUBJS.Navigation=function(t,e){var i=this,n=new EPUBJS.Parser,r=e||EPUBJS.core.request;this.package=t,this.toc=[],this.tocByHref={},this.tocById={},t.navPath&&(this.navUrl=t.baseUrl+t.navPath,this.nav={},this.nav.load=function(){var t=new RSVP.defer,e=t.promise;return r(i.navUrl,"xml").then(function(e){i.toc=n.nav(e),i.loaded(i.toc),t.resolve(i.toc)}),e}),t.ncxPath&&(this.ncxUrl=t.baseUrl+t.ncxPath,this.ncx={},this.ncx.load=function(){var t=new RSVP.defer,e=t.promise;return r(i.ncxUrl,"xml").then(function(e){i.toc=n.ncx(e),i.loaded(i.toc),t.resolve(i.toc)}),e})},EPUBJS.Navigation.prototype.load=function(t){{var e,i;t||EPUBJS.core.request}return this.nav?e=this.nav.load():this.ncx?e=this.ncx.load():(i=new RSVP.defer,i.resolve([]),e=i.promise),e},EPUBJS.Navigation.prototype.loaded=function(t){for(var e,i=0;i=0;s--){var a=r.snapshotItem(s),h=a.getAttribute("id")||!1,c=a.querySelector("content"),p=c.getAttribute("src"),l=a.querySelector("navLabel"),u=l.textContent?l.textContent:"",d=p.split("#"),f=(d[0],e(a));n.unshift({id:h,href:p,label:u,subitems:f,parent:i?i.getAttribute("id"):null})}return n}var i=t.querySelector("navMap");return i?e(i):[]},EPUBJS.Queue=function(t){this._q=[],this.context=t,this.tick=EPUBJS.core.requestAnimationFrame,this.running=!1},EPUBJS.Queue.prototype.enqueue=function(t,e,i){var n,r,o;return e&&!e.length&&(e=[e]),"function"==typeof t?(n=new RSVP.defer,r=n.promise,o={task:t,args:e,context:i,deferred:n,promise:r}):o={promise:t},this._q.push(o),o.promise},EPUBJS.Queue.prototype.dequeue=function(){var t,e;return this._q.length?(t=this._q.shift(),e=t.task,e?e.apply(t.context||this.context,t.args).then(function(){t.deferred.resolve.apply(t.context||this.context,arguments)}.bind(this)):t.promise):null},EPUBJS.Queue.prototype.flush=function(){for(;this._q.length;)this.dequeue()},EPUBJS.Queue.prototype.run=function(){!this.running&&this._q.length&&(this.running=!0,this.dequeue().then(function(){this.running=!1}.bind(this))),this.tick.call(window,this.run.bind(this))},EPUBJS.Queue.prototype.clear=function(){this._q=[]},EPUBJS.Queue.prototype.length=function(){return this._q.length},EPUBJS.Task=function(t){return function(){var e=arguments||[];return new RSVP.Promise(function(i){var n=function(t){i(t)};e.push(n),t.apply(this,e)}.bind(this))}},EPUBJS.Renderer=function(t,e){var i=e||{};this.settings={infinite:"undefined"==typeof i.infinite?!0:i.infinite,hidden:"undefined"==typeof i.hidden?!1:i.hidden,axis:i.axis||"vertical",viewsLimit:i.viewsLimit||5,width:"undefined"==typeof i.width?!1:i.width,height:"undefined"==typeof i.height?!1:i.height,overflow:"undefined"==typeof i.overflow?"auto":i.overflow,padding:i.padding||"",offset:400},this.book=t,this.epubcfi=new EPUBJS.EpubCFI,this.layoutSettings={},this._q=EPUBJS.core.queue(this),this.position=1,this.initialize({width:this.settings.width,height:this.settings.height}),this.rendering=!1,this.filling=!1,this.displaying=!1,this.views=[],this.positions=[],this.hooks={},this.hooks.display=new EPUBJS.Hook(this),this.hooks.replacements=new EPUBJS.Hook(this),this.settings.infinite||(this.settings.viewsLimit=1)},EPUBJS.Renderer.prototype.initialize=function(t){{var e=t||{},i=e.height!==!1?e.height:"100%",n=e.width!==!1?e.width:"100%";e.hidden||!1}return e.height&&EPUBJS.core.isNumber(e.height)&&(i=e.height+"px"),e.width&&EPUBJS.core.isNumber(e.width)&&(n=e.width+"px"),this.container=document.createElement("div"),this.settings.infinite&&(this.infinite=new EPUBJS.Infinite(this.container,this.settings.axis),this.infinite.on("scroll",this.checkCurrent.bind(this))),"horizontal"===this.settings.axis&&(this.container.style.whiteSpace="nowrap"),this.container.style.width=n,this.container.style.height=i,this.container.style.overflow=this.settings.overflow,e.hidden?(this.wrapper=document.createElement("div"),this.wrapper.style.visibility="hidden",this.wrapper.style.overflow="hidden",this.wrapper.style.width="0",this.wrapper.style.height="0",this.wrapper.appendChild(this.container),this.wrapper):this.container},EPUBJS.Renderer.prototype.resize=function(t,e){var i=t,n=e,r=window.getComputedStyle(this.container),o={left:parseFloat(r["padding-left"])||0,right:parseFloat(r["padding-right"])||0,top:parseFloat(r["padding-top"])||0,bottom:parseFloat(r["padding-bottom"])||0},s=i-o.left-o.right,a=n-o.top-o.bottom;t||(i=window.innerWidth),e||(n=window.innerHeight),this.trigger("resized",{width:this.width,height:this.height}),this.views.forEach(function(t){"vertical"===this.settings.axis?t.resize(s,0):t.resize(0,a)}.bind(this))},EPUBJS.Renderer.prototype.onResized=function(){var t=this.element.getBoundingClientRect();this.resize(t.width,t.height)},EPUBJS.Renderer.prototype.attachTo=function(t){var e;return EPUBJS.core.isElement(t)?this.element=t:"string"==typeof t&&(this.element=document.getElementById(t)),this.element?(this.element.appendChild(this.container),this.settings.height||this.settings.width||(e=this.element.getBoundingClientRect(),this.resize(e.width,e.height)),this.settings.infinite&&(this.infinite.start(),this.infinite.on("forwards",function(){var t=this.last().section.index+1;!this.rendering&&!this.filling&&!this.displaying&&t0&&this.backwards()}.bind(this))),window.addEventListener("resize",this.onResized.bind(this),!1),this.hooks.replacements.register(this.replacements.bind(this)),void this.hooks.display.register(this.afterDisplay.bind(this))):void console.error("Not an Element")},EPUBJS.Renderer.prototype.clear=function(){this.views.forEach(function(t){t.destroy()}),this.views=[]},EPUBJS.Renderer.prototype.display=function(t){var e=new RSVP.defer,i=e.promise;return"string"==typeof t&&(t=t.split("#")[0]),this.book.opened.then(function(){var i,n=this.book.spine.get(t);this.displaying=!0,n?(this.clear(),i=this.render(n),this.settings.infinite&&i.then(function(){return this.fill.call(this)}.bind(this)),i.then(function(){this.trigger("displayed",n),this.displaying=!1,e.resolve(this)}.bind(this))):e.reject(new Error("No Section Found"))}.bind(this)),i},EPUBJS.Renderer.prototype.render=function(t){var e,i,n=this.container.getBoundingClientRect(),r=window.getComputedStyle(this.container),o={left:parseFloat(r["padding-left"])||0,right:parseFloat(r["padding-right"])||0,top:parseFloat(r["padding-top"])||0,bottom:parseFloat(r["padding-bottom"])||0},s=n.width-o.left-o.right,a=n.height-o.top-o.bottom;return t?(i=new EPUBJS.View(t),"vertical"===this.settings.axis?i.create(s,0):i.create(0,a),this.insert(i,t.index),e=i.render(this.book.request),e.then(function(){return this.hooks.display.trigger(i)}.bind(this)).then(function(){return this.hooks.replacements.trigger(i,this)}.bind(this)).then(function(){return i.expand()}.bind(this)).then(function(){return this.rendering=!1,i.show(),this.trigger("rendered",i.section),i}.bind(this)).catch(function(t){this.trigger("loaderror",t)}.bind(this))):(e=new RSVP.defer,e.reject(new Error("No Section Provided")),e.promise)},EPUBJS.Renderer.prototype.forwards=function(){var t,e,i;return t=this.last().section.index+1,this.rendering||t===this.book.spine.length?(e=new RSVP.defer,e.reject(new Error("Reject Forwards")),e.promise):(this.rendering=!0,i=this.book.spine.get(t),e=this.render(i),e.then(function(){var t=this.first(),e=t.bounds(),i=(this.last().bounds(),this.container.scrollTop),n=this.container.scrollLeft;this.views.length>this.settings.viewsLimit&&this.container.scrollTop-e.height>100&&(this.remove(t),this.settings.infinite&&("vertical"===this.settings.axis?this.infinite.scrollTo(0,i-e.height,!0):this.infinite.scrollTo(n-e.width,!0))),this.rendering=!1}.bind(this)),e)},EPUBJS.Renderer.prototype.backwards=function(){var t,e,i;return t=this.first().section.index-1,this.rendering||0>t?(e=new RSVP.defer,e.reject(new Error("Reject Backwards")),e.promise):(this.rendering=!0,i=this.book.spine.get(t),e=this.render(i),e.then(function(){var t;this.settings.infinite&&("vertical"===this.settings.axis?this.infinite.scrollBy(0,this.first().bounds().height,!0):this.infinite.scrollBy(this.first().bounds().width,0,!0)),this.views.length>this.settings.viewsLimit&&(t=this.last(),this.remove(t),this.container.scrollTop-this.first().bounds().height>100&&this.remove(t)),this.rendering=!1}.bind(this)),e)},EPUBJS.Renderer.prototype.fill=function(){var t=this.first().section.index-1,e=this.forwards();return this.filling=!0,e.then("vertical"===this.settings.axis?this.fillVertical.bind(this):this.fillHorizontal.bind(this)),t>0&&e.then(this.backwards.bind(this)),e.then(function(){this.filling=!1}.bind(this))},EPUBJS.Renderer.prototype.fillVertical=function(){var t=this.container.getBoundingClientRect().height,e=this.last().bounds().bottom,i=new RSVP.defer;return t&&e&&t>e?this.forwards().then(this.fillVertical.bind(this)):(this.rendering=!1,i.resolve(),i.promise)},EPUBJS.Renderer.prototype.fillHorizontal=function(){var t=this.container.getBoundingClientRect().width,e=this.last().bounds().right,i=new RSVP.defer;return t&&e&&t>=e?this.forwards().then(this.fillHorizontal.bind(this)):(this.rendering=!1,i.resolve(),i.promise)},EPUBJS.Renderer.prototype.append=function(t){this.views.push(t),t.appendTo(this.container)},EPUBJS.Renderer.prototype.prepend=function(t){this.views.unshift(t),t.prependTo(this.container)},EPUBJS.Renderer.prototype.insert=function(t,e){this.first()?e-this.first().section.index>=0?this.append(t):e-this.last().section.index<=0&&this.prepend(t):this.append(t)},EPUBJS.Renderer.prototype.remove=function(t){var e=this.views.indexOf(t);t.destroy(),e>-1&&this.views.splice(e,1)},EPUBJS.Renderer.prototype.first=function(){return this.views[0]},EPUBJS.Renderer.prototype.last=function(){return this.views[this.views.length-1]},EPUBJS.Renderer.prototype.replacements=function(t,e){for(var i=new RSVP.defer,n=t.document.querySelectorAll("a[href]"),r=function(t){var i=t.getAttribute("href"),n=new EPUBJS.core.uri(i);n.protocol?t.setAttribute("target","_blank"):0===i.indexOf("#")||(t.onclick=function(){return e.display(i),!1})},o=0;o=0;r--)if(t=this.views[r],e=t.bounds().top,e-1&&this.views.splice(e,1),this.container.removeChild(t.element),t.shown&&t.destroy(),t=null},EPUBJS.Rendition.prototype.clear=function(){this.views.forEach(function(t){t.destroy()}),this.views=[]},EPUBJS.Rendition.prototype.first=function(){return this.views[0]},EPUBJS.Rendition.prototype.last=function(){return this.views[this.views.length-1]},EPUBJS.Rendition.prototype.each=function(t){return this.views.forEach(t)},EPUBJS.Rendition.prototype.isVisible=function(t,e){var i=t.position(),n=e||this.container.getBoundingClientRect();i.bottom>=n.top-this.settings.offset&&!(i.top>n.bottom)&&i.right>=n.left&&!(i.left>n.right+this.settings.offset)?t.shown||this.rendering||this.render(t):t.shown&&t.destroy()},EPUBJS.Rendition.prototype.check=function(){var t=this.container.getBoundingClientRect();this.views.forEach(function(e){this.isVisible(e,t)}.bind(this)),clearTimeout(this.trimTimeout),this.trimTimeout=setTimeout(function(){this.trim()}.bind(this),250)},EPUBJS.Rendition.prototype.trim=function(){for(var t=!0,e=0;e0?this.views[e-1].shown:!1,r=e+1=0;r--)if(t=this.views[r],e=t.bounds().top,e-1?(delete this.spineByHref[t.href],delete this.spineById[t.idref],this.spineItems.splice(e,1)):void 0},EPUBJS.View=function(t){this.id="epubjs-view:"+EPUBJS.core.uuid(),this.displaying=new RSVP.defer,this.displayed=this.displaying.promise,this.section=t,this.index=t.index,this.element=document.createElement("div"),this.element.classList.add("epub-view"),this.element.style.display="inline-block",this.element.style.height="0px",this.element.style.width="0px",this.element.style.overflow="hidden",this.shown=!1,this.rendered=!1,this.observe=!1,this.width=0,this.height=0},EPUBJS.View.prototype.create=function(t,e){return this.iframe?this.iframe:(this.iframe=document.createElement("iframe"),this.iframe.id=this.id,this.iframe.scrolling="no",this.iframe.seamless="seamless",this.iframe.style.border="none",this.resizing=!0,this.iframe.style.visibility="hidden",this.element.appendChild(this.iframe),this.rendered=!0,(t||e)&&this.resize(t,e),this.width&&this.height&&this.resize(this.width,this.height),this.iframe)},EPUBJS.View.prototype.resize=function(t,e){var i=this.borders();t&&(this.iframe&&(this.iframe.style.width=t+"px"),this.shown&&(this.element.style.width=t+i.width+"px")),e&&(this.iframe&&(this.iframe.style.height=e+"px"),this.shown&&(this.element.style.height=e+i.height+"px")),this.resizing||(this.resizing=!0,this.iframe&&this.expand())},EPUBJS.View.prototype.resized=function(){this.resizing?this.resizing=!1:this.iframe},EPUBJS.View.prototype.display=function(t){return this.section.render(t).then(function(t){return this.load(t)}.bind(this)).then(this.afterLoad.bind(this)).then(this.displaying.resolve.call(this))},EPUBJS.View.prototype.load=function(t){var e=new RSVP.defer,i=e.promise;return this.document=this.iframe.contentDocument,this.document?(this.iframe.addEventListener("load",function(){this.window=this.iframe.contentWindow,this.document=this.iframe.contentDocument,e.resolve(this)}.bind(this)),this.document.open(),this.document.write(t),this.document.close(),i):(e.reject(new Error("No Document Available")),i)},EPUBJS.View.prototype.afterLoad=function(){this.iframe.style.display="inline-block",this.document.body.style.margin="0",this.document.body.style.display="inline-block",this.document.documentElement.style.width="auto",setTimeout(function(){this.window.addEventListener("resize",this.resized.bind(this),!1)}.bind(this),10),"loading"===this.document.fonts.status&&(this.document.fonts.onloading=function(){this.expand()}.bind(this)),this.observe&&(this.observer=this.observe(this.document.body))},EPUBJS.View.prototype.expand=function(t,e,i){var n,r,o,s=t||new RSVP.defer,a=s.promise,h=10,c=e||1,p=10*e;return this.resizing=!0,n=this.document.body.getBoundingClientRect(),!n||0===n.height&&0===n.width?(console.error("View not shown"),a):(o=n.height,r=this.document.documentElement.scrollWidth,h>=c&&(this.width!=r||this.height!=o)?(this.resize(r,o),setTimeout(function(){c+=1,i&&i(this),this.expand(s,c,i)}.bind(this),p)):s.resolve(),this.width=r,this.height=o,a)},EPUBJS.View.prototype.observe=function(t){var e=this,i=new MutationObserver(function(){e.expand()}),n={attributes:!0,childList:!0,characterData:!0,subtree:!0};return i.observe(t,n),i},EPUBJS.View.prototype.show=function(){var t=this.borders();this.element.style.width=this.width+t.width+"px",this.element.style.height=this.height+t.height+"px",this.iframe.style.visibility="visible",this.shown=!0,this.onShown(this),this.trigger("shown",this)},EPUBJS.View.prototype.hide=function(){this.trigger("hidden")},EPUBJS.View.prototype.position=function(){return this.element.getBoundingClientRect()},EPUBJS.View.prototype.onShown=function(){},EPUBJS.View.prototype.borders=function(){return this.iframe&&!this.iframeStyle&&(this.iframeStyle=window.getComputedStyle(this.iframe),this.paddingTopBottom=parseInt(this.iframeStyle.paddingTop)+parseInt(this.iframeStyle.paddingBottom)||0,this.paddingLeftRight=parseInt(this.iframeStyle.paddingLeft)+parseInt(this.iframeStyle.paddingRight)||0,this.marginTopBottom=parseInt(this.iframeStyle.marginTop)+parseInt(this.iframeStyle.marginBottom)||0,this.marginLeftRight=parseInt(this.iframeStyle.marginLeft)+parseInt(this.iframeStyle.marginRight)||0,this.borderTopBottom=parseInt(this.iframeStyle.borderTop)+parseInt(this.iframeStyle.borderBottom)||0,this.borderLeftRight=parseInt(this.iframeStyle.borderLeft)+parseInt(this.iframeStyle.borderRight)||0),this.element&&!this.elementStyle&&(this.elementStyle=window.getComputedStyle(this.element),this.elpaddingTopBottom=parseInt(this.elementStyle.paddingTop)+parseInt(this.elementStyle.paddingBottom)||0,this.elpaddingLeftRight=parseInt(this.elementStyle.paddingLeft)+parseInt(this.elementStyle.paddingRight)||0,this.elmarginTopBottom=parseInt(this.elementStyle.marginTop)+parseInt(this.elementStyle.marginBottom)||0,this.elmarginLeftRight=parseInt(this.elementStyle.marginLeft)+parseInt(this.elementStyle.marginRight)||0,this.elborderTopBottom=parseInt(this.elementStyle.borderTop)+parseInt(this.elementStyle.borderBottom)||0,this.elborderLeftRight=parseInt(this.elementStyle.borderLeft)+parseInt(this.elementStyle.borderRight)||0),{height:this.paddingTopBottom+this.marginTopBottom+this.borderTopBottom,width:this.paddingLeftRight+this.marginLeftRight+this.borderLeftRight}},EPUBJS.View.prototype.bounds=function(){return{height:this.height+this.paddingTopBottom+this.marginTopBottom+this.borderTopBottom+this.elpaddingTopBottom+this.elmarginTopBottom+this.elborderTopBottom,width:this.width+this.paddingLeftRight+this.marginLeftRight+this.borderLeftRight+this.elpaddingLeftRight+this.elmarginLeftRight+this.elborderLeftRight}},EPUBJS.View.prototype.destroy=function(){this.iframe&&(this.element.removeChild(this.iframe),this.shown=!1,this.iframe=null)},RSVP.EventTarget.mixin(EPUBJS.View.prototype),EPUBJS.ViewManager=function(t){this.views=[],this.container=t},EPUBJS.ViewManager.prototype.append=function(t){this.views.push(t),this.container.appendChild(t.element())},EPUBJS.ViewManager.prototype.prepend=function(t){this.views.unshift(t),this.container.insertBefore(t.element(),this.container.firstChild)},EPUBJS.ViewManager.prototype.insert=function(t,e){this.views.splice(e,0,t),ethis.last().index?(this.append(t),e=this.views.length):t.indexb.index?1:a.index-1&&this.views.splice(e,1)},EPUBJS.ViewManager.prototype.clear=function(){this.views.forEach(function(t){t.destroy()}),this.views=[]},EPUBJS.ViewManager.prototype.first=function(){return this.views[0]},EPUBJS.ViewManager.prototype.last=function(){return this.views[this.views.length-1]},EPUBJS.ViewManager.prototype.map=function(t){return this.views.map(t)}; \ No newline at end of file diff --git a/lib/epubjs/layout.js b/lib/epubjs/layout.js index 7b01208..ada2cdf 100644 --- a/lib/epubjs/layout.js +++ b/lib/epubjs/layout.js @@ -102,7 +102,7 @@ EPUBJS.Layout.ReflowableSpreads.prototype.format = function(_width, _height, _ga this.colWidth = colWidth; this.gap = gap; - this.view.document.body.style.paddingRight = gap + "px"; + // this.view.document.body.style.paddingRight = gap + "px"; // view.iframe.style.width = this.spreadWidth+"px"; // this.view.element.style.paddingRight = gap+"px"; // view.iframe.style.paddingLeft = gap+"px";