1
0
Fork 0
mirror of https://github.com/futurepress/epub.js.git synced 2025-10-03 14:59:18 +02:00
epub.js/demo/js/epub.min.js

2 lines
No EOL
44 KiB
JavaScript

!function(){var a=this,b=a._,c={},d=Array.prototype,e=Object.prototype,f=Function.prototype,g=d.push,h=d.slice,i=d.concat,j=e.toString,k=e.hasOwnProperty,l=d.forEach,m=d.map,n=d.reduce,o=d.reduceRight,p=d.filter,q=d.every,r=d.some,s=d.indexOf,t=d.lastIndexOf,u=Array.isArray,v=Object.keys,w=f.bind,x=function(a){return a instanceof x?a:this instanceof x?(this._wrapped=a,void 0):new x(a)};"undefined"!=typeof exports?("undefined"!=typeof module&&module.exports&&(exports=module.exports=x),exports._=x):a._=x,x.VERSION="1.4.4";var y=x.each=x.forEach=function(a,b,d){if(null!=a)if(l&&a.forEach===l)a.forEach(b,d);else if(a.length===+a.length){for(var e=0,f=a.length;f>e;e++)if(b.call(d,a[e],e,a)===c)return}else for(var g in a)if(x.has(a,g)&&b.call(d,a[g],g,a)===c)return};x.map=x.collect=function(a,b,c){var d=[];return null==a?d:m&&a.map===m?a.map(b,c):(y(a,function(a,e,f){d[d.length]=b.call(c,a,e,f)}),d)};var z="Reduce of empty array with no initial value";x.reduce=x.foldl=x.inject=function(a,b,c,d){var e=arguments.length>2;if(null==a&&(a=[]),n&&a.reduce===n)return d&&(b=x.bind(b,d)),e?a.reduce(b,c):a.reduce(b);if(y(a,function(a,f,g){e?c=b.call(d,c,a,f,g):(c=a,e=!0)}),!e)throw new TypeError(z);return c},x.reduceRight=x.foldr=function(a,b,c,d){var e=arguments.length>2;if(null==a&&(a=[]),o&&a.reduceRight===o)return d&&(b=x.bind(b,d)),e?a.reduceRight(b,c):a.reduceRight(b);var f=a.length;if(f!==+f){var g=x.keys(a);f=g.length}if(y(a,function(h,i,j){i=g?g[--f]:--f,e?c=b.call(d,c,a[i],i,j):(c=a[i],e=!0)}),!e)throw new TypeError(z);return c},x.find=x.detect=function(a,b,c){var d;return A(a,function(a,e,f){return b.call(c,a,e,f)?(d=a,!0):void 0}),d},x.filter=x.select=function(a,b,c){var d=[];return null==a?d:p&&a.filter===p?a.filter(b,c):(y(a,function(a,e,f){b.call(c,a,e,f)&&(d[d.length]=a)}),d)},x.reject=function(a,b,c){return x.filter(a,function(a,d,e){return!b.call(c,a,d,e)},c)},x.every=x.all=function(a,b,d){b||(b=x.identity);var e=!0;return null==a?e:q&&a.every===q?a.every(b,d):(y(a,function(a,f,g){return(e=e&&b.call(d,a,f,g))?void 0:c}),!!e)};var A=x.some=x.any=function(a,b,d){b||(b=x.identity);var e=!1;return null==a?e:r&&a.some===r?a.some(b,d):(y(a,function(a,f,g){return e||(e=b.call(d,a,f,g))?c:void 0}),!!e)};x.contains=x.include=function(a,b){return null==a?!1:s&&a.indexOf===s?-1!=a.indexOf(b):A(a,function(a){return a===b})},x.invoke=function(a,b){var c=h.call(arguments,2),d=x.isFunction(b);return x.map(a,function(a){return(d?b:a[b]).apply(a,c)})},x.pluck=function(a,b){return x.map(a,function(a){return a[b]})},x.where=function(a,b,c){return x.isEmpty(b)?c?null:[]:x[c?"find":"filter"](a,function(a){for(var c in b)if(b[c]!==a[c])return!1;return!0})},x.findWhere=function(a,b){return x.where(a,b,!0)},x.max=function(a,b,c){if(!b&&x.isArray(a)&&a[0]===+a[0]&&65535>a.length)return Math.max.apply(Math,a);if(!b&&x.isEmpty(a))return-1/0;var d={computed:-1/0,value:-1/0};return y(a,function(a,e,f){var g=b?b.call(c,a,e,f):a;g>=d.computed&&(d={value:a,computed:g})}),d.value},x.min=function(a,b,c){if(!b&&x.isArray(a)&&a[0]===+a[0]&&65535>a.length)return Math.min.apply(Math,a);if(!b&&x.isEmpty(a))return 1/0;var d={computed:1/0,value:1/0};return y(a,function(a,e,f){var g=b?b.call(c,a,e,f):a;d.computed>g&&(d={value:a,computed:g})}),d.value},x.shuffle=function(a){var b,c=0,d=[];return y(a,function(a){b=x.random(c++),d[c-1]=d[b],d[b]=a}),d};var B=function(a){return x.isFunction(a)?a:function(b){return b[a]}};x.sortBy=function(a,b,c){var d=B(b);return x.pluck(x.map(a,function(a,b,e){return{value:a,index:b,criteria:d.call(c,a,b,e)}}).sort(function(a,b){var c=a.criteria,d=b.criteria;if(c!==d){if(c>d||void 0===c)return 1;if(d>c||void 0===d)return-1}return a.index<b.index?-1:1}),"value")};var C=function(a,b,c,d){var e={},f=B(b||x.identity);return y(a,function(b,g){var h=f.call(c,b,g,a);d(e,h,b)}),e};x.groupBy=function(a,b,c){return C(a,b,c,function(a,b,c){(x.has(a,b)?a[b]:a[b]=[]).push(c)})},x.countBy=function(a,b,c){return C(a,b,c,function(a,b){x.has(a,b)||(a[b]=0),a[b]++})},x.sortedIndex=function(a,b,c,d){c=null==c?x.identity:B(c);for(var e=c.call(d,b),f=0,g=a.length;g>f;){var h=f+g>>>1;e>c.call(d,a[h])?f=h+1:g=h}return f},x.toArray=function(a){return a?x.isArray(a)?h.call(a):a.length===+a.length?x.map(a,x.identity):x.values(a):[]},x.size=function(a){return null==a?0:a.length===+a.length?a.length:x.keys(a).length},x.first=x.head=x.take=function(a,b,c){return null==a?void 0:null==b||c?a[0]:h.call(a,0,b)},x.initial=function(a,b,c){return h.call(a,0,a.length-(null==b||c?1:b))},x.last=function(a,b,c){return null==a?void 0:null==b||c?a[a.length-1]:h.call(a,Math.max(a.length-b,0))},x.rest=x.tail=x.drop=function(a,b,c){return h.call(a,null==b||c?1:b)},x.compact=function(a){return x.filter(a,x.identity)};var D=function(a,b,c){return y(a,function(a){x.isArray(a)?b?g.apply(c,a):D(a,b,c):c.push(a)}),c};x.flatten=function(a,b){return D(a,b,[])},x.without=function(a){return x.difference(a,h.call(arguments,1))},x.uniq=x.unique=function(a,b,c,d){x.isFunction(b)&&(d=c,c=b,b=!1);var e=c?x.map(a,c,d):a,f=[],g=[];return y(e,function(c,d){(b?d&&g[g.length-1]===c:x.contains(g,c))||(g.push(c),f.push(a[d]))}),f},x.union=function(){return x.uniq(i.apply(d,arguments))},x.intersection=function(a){var b=h.call(arguments,1);return x.filter(x.uniq(a),function(a){return x.every(b,function(b){return x.indexOf(b,a)>=0})})},x.difference=function(a){var b=i.apply(d,h.call(arguments,1));return x.filter(a,function(a){return!x.contains(b,a)})},x.zip=function(){for(var a=h.call(arguments),b=x.max(x.pluck(a,"length")),c=Array(b),d=0;b>d;d++)c[d]=x.pluck(a,""+d);return c},x.object=function(a,b){if(null==a)return{};for(var c={},d=0,e=a.length;e>d;d++)b?c[a[d]]=b[d]:c[a[d][0]]=a[d][1];return c},x.indexOf=function(a,b,c){if(null==a)return-1;var d=0,e=a.length;if(c){if("number"!=typeof c)return d=x.sortedIndex(a,b),a[d]===b?d:-1;d=0>c?Math.max(0,e+c):c}if(s&&a.indexOf===s)return a.indexOf(b,c);for(;e>d;d++)if(a[d]===b)return d;return-1},x.lastIndexOf=function(a,b,c){if(null==a)return-1;var d=null!=c;if(t&&a.lastIndexOf===t)return d?a.lastIndexOf(b,c):a.lastIndexOf(b);for(var e=d?c:a.length;e--;)if(a[e]===b)return e;return-1},x.range=function(a,b,c){1>=arguments.length&&(b=a||0,a=0),c=arguments[2]||1;for(var d=Math.max(Math.ceil((b-a)/c),0),e=0,f=Array(d);d>e;)f[e++]=a,a+=c;return f},x.bind=function(a,b){if(a.bind===w&&w)return w.apply(a,h.call(arguments,1));var c=h.call(arguments,2);return function(){return a.apply(b,c.concat(h.call(arguments)))}},x.partial=function(a){var b=h.call(arguments,1);return function(){return a.apply(this,b.concat(h.call(arguments)))}},x.bindAll=function(a){var b=h.call(arguments,1);return 0===b.length&&(b=x.functions(a)),y(b,function(b){a[b]=x.bind(a[b],a)}),a},x.memoize=function(a,b){var c={};return b||(b=x.identity),function(){var d=b.apply(this,arguments);return x.has(c,d)?c[d]:c[d]=a.apply(this,arguments)}},x.delay=function(a,b){var c=h.call(arguments,2);return setTimeout(function(){return a.apply(null,c)},b)},x.defer=function(a){return x.delay.apply(x,[a,1].concat(h.call(arguments,1)))},x.throttle=function(a,b){var c,d,e,f,g=0,h=function(){g=new Date,e=null,f=a.apply(c,d)};return function(){var i=new Date,j=b-(i-g);return c=this,d=arguments,0>=j?(clearTimeout(e),e=null,g=i,f=a.apply(c,d)):e||(e=setTimeout(h,j)),f}},x.debounce=function(a,b,c){var d,e;return function(){var f=this,g=arguments,h=function(){d=null,c||(e=a.apply(f,g))},i=c&&!d;return clearTimeout(d),d=setTimeout(h,b),i&&(e=a.apply(f,g)),e}},x.once=function(a){var b,c=!1;return function(){return c?b:(c=!0,b=a.apply(this,arguments),a=null,b)}},x.wrap=function(a,b){return function(){var c=[a];return g.apply(c,arguments),b.apply(this,c)}},x.compose=function(){var a=arguments;return function(){for(var b=arguments,c=a.length-1;c>=0;c--)b=[a[c].apply(this,b)];return b[0]}},x.after=function(a,b){return 0>=a?b():function(){return 1>--a?b.apply(this,arguments):void 0}},x.keys=v||function(a){if(a!==Object(a))throw new TypeError("Invalid object");var b=[];for(var c in a)x.has(a,c)&&(b[b.length]=c);return b},x.values=function(a){var b=[];for(var c in a)x.has(a,c)&&b.push(a[c]);return b},x.pairs=function(a){var b=[];for(var c in a)x.has(a,c)&&b.push([c,a[c]]);return b},x.invert=function(a){var b={};for(var c in a)x.has(a,c)&&(b[a[c]]=c);return b},x.functions=x.methods=function(a){var b=[];for(var c in a)x.isFunction(a[c])&&b.push(c);return b.sort()},x.extend=function(a){return y(h.call(arguments,1),function(b){if(b)for(var c in b)a[c]=b[c]}),a},x.pick=function(a){var b={},c=i.apply(d,h.call(arguments,1));return y(c,function(c){c in a&&(b[c]=a[c])}),b},x.omit=function(a){var b={},c=i.apply(d,h.call(arguments,1));for(var e in a)x.contains(c,e)||(b[e]=a[e]);return b},x.defaults=function(a){return y(h.call(arguments,1),function(b){if(b)for(var c in b)null==a[c]&&(a[c]=b[c])}),a},x.clone=function(a){return x.isObject(a)?x.isArray(a)?a.slice():x.extend({},a):a},x.tap=function(a,b){return b(a),a};var E=function(a,b,c,d){if(a===b)return 0!==a||1/a==1/b;if(null==a||null==b)return a===b;a instanceof x&&(a=a._wrapped),b instanceof x&&(b=b._wrapped);var e=j.call(a);if(e!=j.call(b))return!1;switch(e){case"[object String]":return a==b+"";case"[object Number]":return a!=+a?b!=+b:0==a?1/a==1/b:a==+b;case"[object Date]":case"[object Boolean]":return+a==+b;case"[object RegExp]":return a.source==b.source&&a.global==b.global&&a.multiline==b.multiline&&a.ignoreCase==b.ignoreCase}if("object"!=typeof a||"object"!=typeof b)return!1;for(var f=c.length;f--;)if(c[f]==a)return d[f]==b;c.push(a),d.push(b);var g=0,h=!0;if("[object Array]"==e){if(g=a.length,h=g==b.length)for(;g--&&(h=E(a[g],b[g],c,d)););}else{var i=a.constructor,k=b.constructor;if(i!==k&&!(x.isFunction(i)&&i instanceof i&&x.isFunction(k)&&k instanceof k))return!1;for(var l in a)if(x.has(a,l)&&(g++,!(h=x.has(b,l)&&E(a[l],b[l],c,d))))break;if(h){for(l in b)if(x.has(b,l)&&!g--)break;h=!g}}return c.pop(),d.pop(),h};x.isEqual=function(a,b){return E(a,b,[],[])},x.isEmpty=function(a){if(null==a)return!0;if(x.isArray(a)||x.isString(a))return 0===a.length;for(var b in a)if(x.has(a,b))return!1;return!0},x.isElement=function(a){return!(!a||1!==a.nodeType)},x.isArray=u||function(a){return"[object Array]"==j.call(a)},x.isObject=function(a){return a===Object(a)},y(["Arguments","Function","String","Number","Date","RegExp"],function(a){x["is"+a]=function(b){return j.call(b)=="[object "+a+"]"}}),x.isArguments(arguments)||(x.isArguments=function(a){return!(!a||!x.has(a,"callee"))}),"function"!=typeof/./&&(x.isFunction=function(a){return"function"==typeof a}),x.isFinite=function(a){return isFinite(a)&&!isNaN(parseFloat(a))},x.isNaN=function(a){return x.isNumber(a)&&a!=+a},x.isBoolean=function(a){return a===!0||a===!1||"[object Boolean]"==j.call(a)},x.isNull=function(a){return null===a},x.isUndefined=function(a){return void 0===a},x.has=function(a,b){return k.call(a,b)},x.noConflict=function(){return a._=b,this},x.identity=function(a){return a},x.times=function(a,b,c){for(var d=Array(a),e=0;a>e;e++)d[e]=b.call(c,e);return d},x.random=function(a,b){return null==b&&(b=a,a=0),a+Math.floor(Math.random()*(b-a+1))};var F={escape:{"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;","/":"&#x2F;"}};F.unescape=x.invert(F.escape);var G={escape:RegExp("["+x.keys(F.escape).join("")+"]","g"),unescape:RegExp("("+x.keys(F.unescape).join("|")+")","g")};x.each(["escape","unescape"],function(a){x[a]=function(b){return null==b?"":(""+b).replace(G[a],function(b){return F[a][b]})}}),x.result=function(a,b){if(null==a)return null;var c=a[b];return x.isFunction(c)?c.call(a):c},x.mixin=function(a){y(x.functions(a),function(b){var c=x[b]=a[b];x.prototype[b]=function(){var a=[this._wrapped];return g.apply(a,arguments),L.call(this,c.apply(x,a))}})};var H=0;x.uniqueId=function(a){var b=++H+"";return a?a+b:b},x.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var I=/(.)^/,J={"'":"'","\\":"\\","\r":"r","\n":"n"," ":"t","\u2028":"u2028","\u2029":"u2029"},K=/\\|'|\r|\n|\t|\u2028|\u2029/g;x.template=function(a,b,c){var d;c=x.defaults({},c,x.templateSettings);var e=RegExp([(c.escape||I).source,(c.interpolate||I).source,(c.evaluate||I).source].join("|")+"|$","g"),f=0,g="__p+='";a.replace(e,function(b,c,d,e,h){return g+=a.slice(f,h).replace(K,function(a){return"\\"+J[a]}),c&&(g+="'+\n((__t=("+c+"))==null?'':_.escape(__t))+\n'"),d&&(g+="'+\n((__t=("+d+"))==null?'':__t)+\n'"),e&&(g+="';\n"+e+"\n__p+='"),f=h+b.length,b}),g+="';\n",c.variable||(g="with(obj||{}){\n"+g+"}\n"),g="var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};\n"+g+"return __p;\n";try{d=Function(c.variable||"obj","_",g)}catch(h){throw h.source=g,h}if(b)return d(b,x);var i=function(a){return d.call(this,a,x)};return i.source="function("+(c.variable||"obj")+"){\n"+g+"}",i},x.chain=function(a){return x(a).chain()};var L=function(a){return this._chain?x(a).chain():a};x.mixin(x),y(["pop","push","reverse","shift","sort","splice","unshift"],function(a){var b=d[a];x.prototype[a]=function(){var c=this._wrapped;return b.apply(c,arguments),"shift"!=a&&"splice"!=a||0!==c.length||delete c[0],L.call(this,c)}}),y(["concat","join","slice"],function(a){var b=d[a];x.prototype[a]=function(){return L.call(this,b.apply(this._wrapped,arguments))}}),x.extend(x.prototype,{chain:function(){return this._chain=!0,this},value:function(){return this._wrapped}})}.call(this),function(a){"use strict";function b(a,b){f.async(function(){a.trigger("promise:resolved",{detail:b}),a.isResolved=!0,a.resolvedValue=b})}function c(a,b){f.async(function(){a.trigger("promise:failed",{detail:b}),a.isRejected=!0,a.rejectedValue=b})}function d(a){var b,c=[],d=new p,e=a.length;0===e&&d.resolve([]);var f=function(a){return function(b){g(a,b)}},g=function(a,b){c[a]=b,0===--e&&d.resolve(c)},h=function(a){d.reject(a)};for(b=0;e>b;b++)a[b].then(f(b),h);return d}function e(a,b){f[a]=b}var f={},g="undefined"!=typeof window?window:{},h=g.MutationObserver||g.WebKitMutationObserver;if("undefined"!=typeof process&&"[object process]"==={}.toString.call(process))f.async=function(a,b){process.nextTick(function(){a.call(b)})};else if(h){var i=[],j=new h(function(){var a=i.slice();i=[],a.forEach(function(a){var b=a[0],c=a[1];b.call(c)})}),k=document.createElement("div");j.observe(k,{attributes:!0}),window.addEventListener("unload",function(){j.disconnect(),j=null}),f.async=function(a,b){i.push([a,b]),k.setAttribute("drainQueue","drainQueue")}}else f.async=function(a,b){setTimeout(function(){a.call(b)},1)};var l=function(a,b){this.type=a;for(var c in b)b.hasOwnProperty(c)&&(this[c]=b[c])},m=function(a,b){for(var c=0,d=a.length;d>c;c++)if(a[c][0]===b)return c;return-1},n=function(a){var b=a._promiseCallbacks;return b||(b=a._promiseCallbacks={}),b},o={mixin:function(a){return a.on=this.on,a.off=this.off,a.trigger=this.trigger,a},on:function(a,b,c){var d,e,f=n(this);for(a=a.split(/\s+/),c=c||this;e=a.shift();)d=f[e],d||(d=f[e]=[]),-1===m(d,b)&&d.push([b,c])},off:function(a,b){var c,d,e,f=n(this);for(a=a.split(/\s+/);d=a.shift();)b?(c=f[d],e=m(c,b),-1!==e&&c.splice(e,1)):f[d]=[]},trigger:function(a,b){var c,d,e,f,g,h=n(this);if(c=h[a])for(var i=0,j=c.length;j>i;i++)d=c[i],e=d[0],f=d[1],"object"!=typeof b&&(b={detail:b}),g=new l(a,b),e.call(f,g)}},p=function(){this.on("promise:resolved",function(a){this.trigger("success",{detail:a.detail})},this),this.on("promise:failed",function(a){this.trigger("error",{detail:a.detail})},this)},q=function(){},r=function(a,b,c,d){var e,f,g,h,i="function"==typeof c;if(i)try{e=c(d.detail),g=!0}catch(j){h=!0,f=j}else e=d.detail,g=!0;e&&"function"==typeof e.then?e.then(function(a){b.resolve(a)},function(a){b.reject(a)}):i&&g?b.resolve(e):h?b.reject(f):b[a](e)};p.prototype={then:function(a,b){var c=new p;return this.isResolved&&f.async(function(){r("resolve",c,a,{detail:this.resolvedValue})},this),this.isRejected&&f.async(function(){r("reject",c,b,{detail:this.rejectedValue})},this),this.on("promise:resolved",function(b){r("resolve",c,a,b)}),this.on("promise:failed",function(a){r("reject",c,b,a)}),c},resolve:function(a){b(this,a),this.resolve=q,this.reject=q},reject:function(a){c(this,a),this.resolve=q,this.reject=q}},o.mixin(p.prototype),a.Promise=p,a.Event=l,a.EventTarget=o,a.all=d,a.configure=e}(window.RSVP={});var EPUBJS=EPUBJS||{};EPUBJS.VERSION="0.1.5",EPUBJS.plugins=EPUBJS.plugins||{},EPUBJS.filePath=EPUBJS.filePath||"/epubjs/",EPUBJS.Book=function(a,b){this.settings=_.defaults(b||{},{element:!1,storage:!1,fromStorage:!1,saved:!1,online:!0,contained:!1,width:!1,height:!1,spreads:!0,responsive:!0,version:1.1,restore:!0}),this.settings.EPUBJSVERSION=EPUBJS.VERSION,this.spinePos=0,this.stored=!1,this.hooks={beforeChapterDisplay:[]},this.getHooks(),this.online=this.settings.online||navigator.onLine,this.networkListeners(),0!=this.settings.storage&&(this.storage=new fileStorage.storage(this.settings.storage)),this.ready={manifest:new RSVP.Promise,spine:new RSVP.Promise,metadata:new RSVP.Promise,cover:new RSVP.Promise,toc:new RSVP.Promise},this.ready.all=RSVP.all(_.values(this.ready)),a&&(this.opened=this.open(a)),a&&this.settings.element&&this.opened.then(function(){this.rendered=this.renderTo(el)})},EPUBJS.Book.prototype.open=function(a,b){var c,d=this,e=this.isSaved(a);return this.settings.bookPath=a,this.bookUrl=this.urlFrom(a),e&&!b&&this.applySavedSettings(),this.settings.contained||this.isContained(a)?(this.settings.contained=this.contained=!0,this.bookUrl="",c=this.unarchive(a).then(function(){return e&&d.settings.restore&&!b?d.restore():d.unpack()})):c=e&&this.settings.restore&&!b?this.restore():this.unpack(),this.online&&this.settings.storage&&!this.settings.contained&&(this.settings.stored||c.then(d.storeOffline())),c},EPUBJS.Book.prototype.unpack=function(a){var b=this,c=new EPUBJS.Parser,a=a||"META-INF/container.xml";return b.loadXml(b.bookUrl+a).then(function(a){return c.container(a)}).then(function(a){return b.settings.contentsPath=b.bookUrl+a.basePath,b.settings.packageUrl=b.bookUrl+a.packagePath,b.loadXml(b.settings.packageUrl)}).then(function(a){return c.package(a,b.settings.contentsPath)}).then(function(a){return b.contents=a,b.manifest=b.contents.manifest,b.spine=b.contents.spine,b.spineIndexByURL=b.contents.spineIndexByURL,b.metadata=b.contents.metadata,b.cover=b.contents.cover=b.settings.contentsPath+a.coverPath,b.spineNodeIndex=b.contents.spineNodeIndex=a.spineNodeIndex,b.ready.manifest.resolve(b.contents.manifest),b.ready.spine.resolve(b.contents.spine),b.ready.metadata.resolve(b.contents.metadata),b.ready.cover.resolve(b.contents.cover),b.settings.tocUrl=b.settings.contentsPath+a.tocPath,b.loadXml(b.settings.tocUrl)}).then(function(a){return c.toc(a)}).then(function(a){b.toc=b.contents.toc=a,b.ready.toc.resolve(b.contents.toc)}).then(null,function(a){console.error(a)})},EPUBJS.Book.prototype.getMetadata=function(){return this.ready.metadata},EPUBJS.Book.prototype.getToc=function(){return this.ready.toc},EPUBJS.Book.prototype.networkListeners=function(){var a=this;window.addEventListener("offline",function(){a.online=!1,a.trigger("book:offline")},!1),window.addEventListener("online",function(){a.online=!0,a.trigger("book:online")},!1),window.addEventListener("beforeunload",function(){a.saveSettings(),a.settings.restore&&a.saveContents(),a.trigger("book:unload")},!1)},EPUBJS.Book.prototype.loadXml=function(a){return this.settings.fromStorage?this.storage.getXml(a):this.settings.contained?this.zip.getXml(a):EPUBJS.core.request(a,"xml")},EPUBJS.Book.prototype.urlFrom=function(a){var b=-1!=a.search("://"),c="/"==a[0],d=window.location,e=d.origin||d.protocol+"//"+d.host;return b?a:!b&&c?e+a:b||c?void 0:e+EPUBJS.core.folder(d.pathname)+a},EPUBJS.Book.prototype.unarchive=function(a){return this.zip=new EPUBJS.Unarchiver,this.zip.openZip(a)},EPUBJS.Book.prototype.isContained=function(a){var b=a.lastIndexOf("."),c=a.slice(b+1);return!c||"epub"!=c&&"zip"!=c?!1:!0},EPUBJS.Book.prototype.isSaved=function(a){var b=a+":"+this.settings.version,c=localStorage.getItem(b);return localStorage&&null!==c?!0:!1},EPUBJS.Book.prototype.removeSavedSettings=function(){var a=this.settings.bookPath+":"+this.settings.version;localStorage.removeItem(a),this.settings.stored=!1},EPUBJS.Book.prototype.applySavedSettings=function(){var a=this.settings.bookPath+":"+this.settings.version;return stored=JSON.parse(localStorage.getItem(a)),EPUBJS.VERSION!=stored.EPUBJSVERSION?!1:(this.settings=_.defaults(this.settings,stored),void 0)},EPUBJS.Book.prototype.saveSettings=function(){var a=this.settings.bookPath+":"+this.settings.version;this.render&&(this.settings.previousLocationCfi=this.render.currentLocationCfi),localStorage.setItem(a,JSON.stringify(this.settings))},EPUBJS.Book.prototype.saveContents=function(){var a=this.settings.bookPath+":contents:"+this.settings.version;localStorage.setItem(a,JSON.stringify(this.contents))},EPUBJS.Book.prototype.renderTo=function(a){var b=this;return this.settings.element=a,this.opened.then(function(){return b.render=new EPUBJS.Renderer(b),b.startDisplay()})},EPUBJS.Book.prototype.startDisplay=function(){var a;return a=this.settings.restore&&this.settings.previousLocationCfi?this.displayChapter(this.settings.previousLocationCfi):this.displayChapter(this.spinePos)},EPUBJS.Book.prototype.restore=function(){var a=this,b=this.settings.bookPath+":contents:"+this.settings.version,c=new RSVP.Promise,d=["manifest","spine","metadata","cover","toc","spineNodeIndex","spineIndexByURL"],e=!1,f=localStorage.getItem(b);return"undefined"!=f&&"null"!=f&&(this.contents=JSON.parse(f),d.forEach(function(b){a[b]=a.contents[b],a[b]||(e=!0)})),!e&&f&&this.contents&&this.settings.contentsPath?(this.ready.manifest.resolve(this.manifest),this.ready.spine.resolve(this.spine),this.ready.metadata.resolve(this.metadata),this.ready.cover.resolve(this.cover),this.ready.toc.resolve(this.toc),c.resolve(),c):this.open(this.settings.bookPath,!0)},EPUBJS.Book.prototype.displayChapter=function(a,b){var c,d,e,f=this;return _.isNumber(a)?e=a:(d=new EPUBJS.EpubCFI(a),e=d.spinePos),e>=this.spine.length?!1:0>e?!1:(this.spinePos=e,this.chapter=new EPUBJS.Chapter(this.spine[e]),c=f.render.chapter(this.chapter),d?c.then(function(b){b.currentLocationCfi=a,b.gotoCfiFragment(d)}):b&&c.then(function(a){a.gotoChapterEnd()}),this.settings.fromStorage||this.settings.contained||c.then(function(){f.preloadNextChapter()}),c)},EPUBJS.Book.prototype.nextPage=function(){var a=this.render.nextPage();return a?void 0:this.nextChapter()},EPUBJS.Book.prototype.prevPage=function(){var a=this.render.prevPage();return a?void 0:this.prevChapter()},EPUBJS.Book.prototype.nextChapter=function(){return this.spinePos++,this.displayChapter(this.spinePos)},EPUBJS.Book.prototype.prevChapter=function(){return this.spinePos--,this.displayChapter(this.spinePos,!0)},EPUBJS.Book.prototype.goto=function(a){var b,c=a.split("#"),d=c[0],e=c[1]||!1,f=-1==d.search("://")?this.settings.contentsPath+d:d,g=this.spineIndexByURL[f];return d||(g=this.chapter.spinePos),"number"!=typeof g?!1:g==this.chapter.spinePos&&this.chapter?(e&&this.render.section(e),(new RSVP.Promise).resolve(this.currentChapter)):this.displayChapter(g).then(function(){e&&b.render.section(e)})},EPUBJS.Book.prototype.preloadNextChapter=function(){return document.createElement("iframe"),this.spinePos>=this.spine.length?!1:(next=new EPUBJS.Chapter(this.spine[this.spinePos+1]),EPUBJS.core.request(next.href),void 0)},EPUBJS.Book.prototype.storeOffline=function(){var a=this,b=_.values(this.manifest);return EPUBJS.storage.batch(b).then(function(){a.settings.stored=!0,a.trigger("book:stored")})},EPUBJS.Book.prototype.availableOffline=function(){return this.settings.stored>0?!0:!1},EPUBJS.Book.prototype.setStyle=function(a,b,c){this.renderer.setStyle(a,b,c),this.settings.styles[a]=b},EPUBJS.Book.prototype.removeStyle=function(a){this.renderer.removeStyle(a),delete this.settings.styles[a]},EPUBJS.Book.prototype.getHooks=function(){var a,b=this;plugTypes=_.values(this.hooks);for(plugType in this.hooks)a=_.values(EPUBJS.Hooks[plugType]),a.forEach(function(a){b.registerHook(plugType,a)})},EPUBJS.Book.prototype.registerHook=function(a,b,c){var d=this;"undefined"!=typeof this.hooks[a]?"function"==typeof b?c?this.hooks[a].unshift(b):this.hooks[a].push(b):Array.isArray(b)&&b.forEach(function(b){c?d.hooks[a].unshift(b):d.hooks[a].push(b)}):this.hooks[a]=[func]},EPUBJS.Book.prototype.triggerHooks=function(a,b,c){function d(){f--,0>=f&&b&&b()}var e,f;return"undefined"==typeof this.hooks[a]?!1:(e=this.hooks[a],f=e.length,e.forEach(function(a){a(d,c)}),void 0)},RSVP.EventTarget.mixin(EPUBJS.Book.prototype),EPUBJS.Chapter=function(a){this.href=a.href,this.id=a.id,this.spinePos=a.index,this.properties=a.properties,this.linear=a.linear,this.pages=1},EPUBJS.Chapter.prototype.contents=function(a){return a?a.get(href):EPUBJS.core.request(href,"xml")},EPUBJS.Chapter.prototype.url=function(a){var b=new RSVP.Promise;return a?(this.tempUrl||(this.tempUrl=a.getUrl(this.href)),this.tempUrl):(b.resolve(this.href),b)},EPUBJS.Chapter.prototype.setPages=function(a){this.pages=a},EPUBJS.Chapter.prototype.getPages=function(){return this.pages},EPUBJS.Chapter.prototype.getID=function(){return this.ID},EPUBJS.Chapter.prototype.unload=function(a){this.tempUrl&&a&&(a.revokeUrl(this.tempUrl),this.tempUrl=!1)};var EPUBJS=EPUBJS||{};EPUBJS.core={},EPUBJS.core.getEl=function(a){return document.getElementById(a)},EPUBJS.core.getEls=function(a){return document.getElementsByClassName(a)},EPUBJS.core.request=function(a,b){function c(){if(this.readyState===this.DONE)if(200===this.status||this.responseXML){var a;a="xml"==b?this.responseXML:"json"==b?JSON.parse(this.response):this.response,d.resolve(a)}else d.reject(this)}var d=new RSVP.Promise,e=new XMLHttpRequest;return e.open("GET",a),e.onreadystatechange=c,"blob"==b&&(e.responseType=b),"json"==b&&e.setRequestHeader("Accept","application/json"),"xml"==b&&e.overrideMimeType("text/xml"),e.send(),d},EPUBJS.core.toArray=function(a){var b=[];for(member in a){var c;a.hasOwnProperty(member)&&(c=a[member],c.ident=member,b.push(c))}return b},EPUBJS.core.folder=function(a){var b=a.lastIndexOf("/"),c=a.slice(0,b+1);return c},EPUBJS.core.dataURLToBlob=function(a){var b=";base64,";if(-1==a.indexOf(b)){var c=a.split(","),d=c[0].split(":")[1],e=c[1];return new Blob([e],{type:d})}for(var c=a.split(b),d=c[0].split(":")[1],e=window.atob(c[1]),f=e.length,g=new Uint8Array(f),h=0;f>h;++h)g[h]=e.charCodeAt(h);return new Blob([g],{type:d})},EPUBJS.core.addScript=function(a,b,c){var d,e;e=!1,d=document.createElement("script"),d.type="text/javascript",d.async=!1,d.src=a,d.onload=d.onreadystatechange=function(){e||this.readyState&&"complete"!=this.readyState||(e=!0,b&&b())},c=c||document.body,c.appendChild(d)},EPUBJS.core.addScripts=function(a,b,c){var d=a.length,e=0,f=function(){e++,d==e?b&&b():EPUBJS.core.loadScript(a[e],f,c)};EPUBJS.core.addScript(a[e],f,c)},EPUBJS.core.addCss=function(a,b,c){var d,e;e=!1,d=document.createElement("link"),d.type="text/css",d.rel="stylesheet",d.href=a,d.onload=d.onreadystatechange=function(){e||this.readyState&&"complete"!=this.readyState||(e=!0,b&&b())},c=c||document.body,c.appendChild(d)},EPUBJS.core.prefixed=function(a){var b=["Webkit","Moz","O","ms"],c=a[0].toUpperCase()+a.slice(1),d=b.length,e=0;if("undefined"!=typeof document.body.style[a])return a;for(;d>e;e++)if("undefined"!=typeof document.body.style[b[e]+c])return b[e]+c;return a},EPUBJS.core.resolveUrl=function(a,b){var c,d,e=[],f=a.split("/");return f.pop(),d=b.split("/"),d.forEach(function(a){".."===a?f.pop():e.push(a)}),c=f.concat(e),c.join("/")},EPUBJS.EpubCFI=function(a){return a?this.parse(a):void 0},EPUBJS.EpubCFI.prototype.generateChapter=function(a,b,c){var a=a+1,d="/"+a+"/";return d+=2*(b+1),c&&(d+="["+c+"]"),d+="!"},EPUBJS.EpubCFI.prototype.generateFragment=function(a,b){var c=this.pathTo(a),d=[];return b&&d.push(b),c.forEach(function(a){d.push(2*(a.index+1)),a.id&&"EPUBJS"!=a.id.slice(0,6)&&d.push("["+a.id+"]")}),d.join("/")},EPUBJS.EpubCFI.prototype.pathTo=function(a){for(var b,c=[];a&&null!==a.parentNode;)b=a.parentNode.children,c.unshift({id:a.id,tagName:a.tagName,index:b?Array.prototype.indexOf.call(b,a):0}),a=a.parentNode;return c},EPUBJS.EpubCFI.prototype.getChapter=function(a){var b=a.split("!");return b[0]},EPUBJS.EpubCFI.prototype.getFragment=function(a){var b=a.split("!");return b[1]},EPUBJS.EpubCFI.prototype.getOffset=function(a){var b=a.split(":");return[b[0],b[1]]},EPUBJS.EpubCFI.prototype.parse=function(a){var b,c,d,e,f={};return f.chapter=this.getChapter(a),f.fragment=this.getFragment(a),f.spinePos=parseInt(f.chapter.split("/")[2])/2-1||0,b=f.chapter.match(/\[(.*)\]/),f.spineId=b[1]||!1,c=f.fragment.split("/"),d=c[c.length-1],f.sections=[],parseInt(d)%2&&(e=this.getOffset(),f.text=parseInt(e[0]),f.character=parseInt(e[1]),c.pop()),c.forEach(function(a){var b,c,d;a&&(b=parseInt(a)/2-1,c=a.match(/\[(.*)\]/),c&&c[1]&&(d=c[1]),f.sections.push({index:b,id:d||!1}))}),f},EPUBJS.EpubCFI.prototype.getElement=function(a,b){var c,b=b||document,d=a.sections,e=b.getElementsByTagName("html")[0],f=Array.prototype.slice.call(e.children);for(d.shift();d.length>0;)c=d.shift(),c.id?e=b.querySelector("#"+c.id):(e=f[c.index],f||console.error("No Kids",e)),e||console.error("No Element For",c),f=Array.prototype.slice.call(e.children);return e},EPUBJS.Events=function(a,b){return this.events={},this.el=b?b:document.createElement("div"),a.createEvent=this.createEvent,a.tell=this.tell,a.listen=this.listen,a.deafen=this.deafen,a.listenUntil=this.listenUntil,this},EPUBJS.Events.prototype.createEvent=function(a){var b=new CustomEvent(a);return this.events[a]=b,b},EPUBJS.Events.prototype.tell=function(a,b){var c;this.events[a]?c=this.events[a]:(console.warn("No event:",a,"defined yet, creating."),c=this.createEvent(a)),b&&(c.msg=b),this.el.dispatchEvent(c)},EPUBJS.Events.prototype.listen=function(a,b,c){return this.events[a]?(c?this.el.addEventListener(a,b.bind(c),!1):this.el.addEventListener(a,b,!1),void 0):(console.warn("No event:",a,"defined yet, creating."),this.createEvent(a),void 0)},EPUBJS.Events.prototype.deafen=function(a,b){this.el.removeEventListener(a,b,!1)},EPUBJS.Events.prototype.listenUntil=function(a,b,c,d){function e(){this.deafen(a,c),this.deafen(b,e)}this.listen(a,c,d),this.listen(b,e,this)},EPUBJS.Hooks=function(){"use strict";return{register:function(a){if(void 0===this[a]&&(this[a]={}),"object"!=typeof this[a])throw"Already registered: "+a;return this[a]}}}(),EPUBJS.Parser=function(a){this.baseUrl=a||""},EPUBJS.Parser.prototype.container=function(a){var b=a.querySelector("rootfile"),c=b.getAttribute("full-path"),d=EPUBJS.core.folder(c);return{packagePath:c,basePath:d}},EPUBJS.Parser.prototype.package=function(a,b){var c=this;b&&(this.baseUrl=b);var d=a.querySelector("metadata"),e=a.querySelector("manifest"),f=a.querySelector("spine"),g=c.manifest(e),h=c.findTocPath(e),i=c.findCoverPath(e),j=Array.prototype.indexOf.call(f.parentNode.childNodes,f),k=c.spine(f,g),l={};return k.forEach(function(a){l[a.href]=a.index}),{metadata:c.metadata(d),spine:k,manifest:g,tocPath:h,coverPath:i,spineNodeIndex:j,spineIndexByURL:l}},EPUBJS.Parser.prototype.findTocPath=function(a){var b=a.querySelector("item[media-type='application/x-dtbncx+xml']");return b?b.getAttribute("href"):!1},EPUBJS.Parser.prototype.findCoverPath=function(a){var b=a.querySelector("item[properties='cover-image']");return b?b.getAttribute("href"):!1},EPUBJS.Parser.prototype.metadata=function(a){var b={},c=this;return b.bookTitle=c.getElement(a,"title"),b.creator=c.getElement(a,"creator"),b.description=c.getElement(a,"description"),b.pubdate=c.getElement(a,"date"),b.publisher=c.getElement(a,"publisher"),b.identifier=c.getElement(a,"identifier"),b.language=c.getElement(a,"language"),b.rights=c.getElement(a,"rights"),b.modified_date=c.querySelector(a,"meta[property='dcterms:modified']"),b.layout=c.querySelector(a,"meta[property='rendition:orientation']"),b.orientation=c.querySelector(a,"meta[property='rendition:orientation']"),b.spread=c.querySelector(a,"meta[property='rendition:spread']"),b
},EPUBJS.Parser.prototype.getElement=function(a,b){var c,d=a.getElementsByTagNameNS("http://purl.org/dc/elements/1.1/",b);return d?(c=d[0],c?c.childNodes[0].nodeValue:""):""},EPUBJS.Parser.prototype.querySelector=function(a,b){var c=a.querySelector(b);return c?c.childNodes[0].nodeValue:""},EPUBJS.Parser.prototype.manifest=function(a){var b=this.baseUrl,c={},d=a.querySelectorAll("item"),e=Array.prototype.slice.call(d);return e.forEach(function(a){var d=a.getAttribute("id"),e=a.getAttribute("href")||"",f=a.getAttribute("media-type")||"";c[d]={href:b+e,type:f}}),c},EPUBJS.Parser.prototype.spine=function(a,b){var c=[],d=a.getElementsByTagName("itemref"),e=Array.prototype.slice.call(d);return e.forEach(function(a,d){var e=a.getAttribute("idref"),f={id:e,linear:a.getAttribute("linear")||"",properties:a.getAttribute("properties")||"",href:b[e].href,index:d};c.push(f)}),c},EPUBJS.Parser.prototype.toc=function(a){function b(a){var c,d=[],e=[],f=a.childNodes,g=Array.prototype.slice.call(f),h=g.length,i=h;if(0==h)return!1;for(;i--;)c=g[i],"navPoint"===c.nodeName&&e.push(c);return e.forEach(function(a){var c=a.getAttribute("id"),e=a.querySelector("content"),f=e.getAttribute("src"),g=(f.split("#"),a.querySelector("navLabel")),h=g.textContent?g.textContent:"",i=b(a);d.unshift({id:c,href:f,label:h,subitems:i})}),d}var c=a.querySelector("navMap");return b(c)},EPUBJS.Renderer=function(a){var b=a.settings.element;if(this.book=a,this.settings=a.settings,_.isElement(b))this.el=b;else{if("string"!=typeof b)return console.error("Not an Element"),void 0;this.el=EPUBJS.core.getEl(b)}a.registerHook("beforeChapterDisplay",[this.replaceLinks.bind(this),this.replaceResources.bind(this),this.replaceHead.bind(this)],!0),this.crossBrowserColumnCss(),this.epubcfi=new EPUBJS.EpubCFI,this.initialize(),this.listeners()},EPUBJS.Renderer.prototype.initialize=function(){this.iframe=document.createElement("iframe"),this.resizeIframe(!1,this.el.clientWidth,this.el.clientHeight),this.on("book:resized",this.resizeIframe,this),this.el.appendChild(this.iframe)},EPUBJS.Renderer.prototype.listeners=function(){this.resized=_.debounce(this.onResized.bind(this),10),window.addEventListener("resize",this.resized,!1)},EPUBJS.Renderer.prototype.chapter=function(a){var b=this,c=!1;return this.book.settings.contained&&(c=this.book.zip),this.currentChapter&&(this.currentChapter.unload(),this.trigger("book:chapterDestroyed")),this.currentChapter=a,this.chapterPos=1,this.pageIds={},this.leftPos=0,this.currentChapterCfi=this.epubcfi.generateChapter(this.book.spineNodeIndex,a.spinePos,a.id),this.visibileEl=!1,a.url(c).then(function(a){return b.setIframeSrc(a)})},EPUBJS.Renderer.prototype.onResized=function(){this.trigger("book:resized",{width:this.el.clientWidth,height:this.el.clientHeight}),this.reformat()},EPUBJS.Renderer.prototype.reformat=function(){var a=this;this.formatSpread(),setTimeout(function(){a.calcPages(),a.currentLocationCfi&&a.gotoCfiFragment(a.currentLocationCfi)},10)},EPUBJS.Renderer.prototype.destroy=function(){window.removeEventListener("resize",this.resized,!1)},EPUBJS.Renderer.prototype.resizeIframe=function(a,b,c){var d,e;a?(d=a.width,e=a.height):(d=b,e=c),this.iframe.height=e,0!=d%2&&(d+=1),this.iframe.width=d},EPUBJS.Renderer.prototype.crossBrowserColumnCss=function(){EPUBJS.Renderer.columnAxis=EPUBJS.core.prefixed("columnAxis"),EPUBJS.Renderer.columnGap=EPUBJS.core.prefixed("columnGap"),EPUBJS.Renderer.columnWidth=EPUBJS.core.prefixed("columnWidth"),EPUBJS.Renderer.transform=EPUBJS.core.prefixed("transform")},EPUBJS.Renderer.prototype.setIframeSrc=function(a){var b=this,c=new RSVP.Promise;return this.visible(!1),this.iframe.src=a,this.iframe.onload=function(){b.doc=b.iframe.contentDocument,b.docEl=b.doc.documentElement,b.bodyEl=b.doc.body,b.applyStyles(),b.formatSpread(),b.beforeDisplay(function(){b.calcPages(),c.resolve(b),b.currentLocationCfi=b.getPageCfi(),b.trigger("book:chapterDisplayed"),b.visible(!0)})},c},EPUBJS.Renderer.prototype.formatSpread=function(){var a=2,b=800;this.colWidth&&(this.OldcolWidth=this.colWidth,this.OldspreadWidth=this.spreadWidth),this.elWidth=this.iframe.width,this.gap=this.gap||Math.ceil(this.elWidth/8),this.elWidth<b||!this.book.settings.spreads?(this.spread=!1,a=1,this.colWidth=Math.floor(this.elWidth/a)):(this.spread=!0,this.colWidth=Math.floor((this.elWidth-this.gap)/a)),this.spreadWidth=(this.colWidth+this.gap)*a,this.bodyEl&&(this.bodyEl.style.margin=0),this.docEl.style.overflow="hidden",this.docEl.style.width=this.elWidth,this.docEl.style.height=this.el.clientHeight+"px",this.docEl.style[EPUBJS.Renderer.columnAxis]="horizontal",this.docEl.style[EPUBJS.Renderer.columnGap]=this.gap+"px",this.docEl.style[EPUBJS.Renderer.columnWidth]=this.colWidth+"px"},EPUBJS.Renderer.prototype.fixedLayout=function(){this.paginated=!1,this.setLeft(0),this.docEl.style.width=this.elWidth,this.docEl.style.height="auto",this.docEl.style[EPUBJS.core.columnWidth]="auto",this.docEl.style.overflow="auto",this.displayedPages=1},EPUBJS.Renderer.prototype.setStyle=function(a,b,c){c&&(a=EPUBJS.core.prefixed(a)),this.bodyEl&&(this.bodyEl.style[a]=b)},EPUBJS.Renderer.prototype.removeStyle=function(a){this.bodyEl&&(this.bodyEl.style[a]="")},EPUBJS.Renderer.prototype.applyStyles=function(){var a=this.book.settings.styles;for(style in a)this.setStyle(style,a[style])},EPUBJS.Renderer.prototype.gotoChapterEnd=function(){this.chapterEnd()},EPUBJS.Renderer.prototype.visible=function(a){return"undefined"==typeof a?this.iframe.style.visibility:(1==a?this.iframe.style.visibility="visible":0==a&&(this.iframe.style.visibility="hidden"),void 0)},EPUBJS.Renderer.prototype.calcPages=function(){this.totalWidth=this.docEl.scrollWidth,this.displayedPages=Math.ceil(this.totalWidth/this.spreadWidth),this.currentChapter.pages=this.displayedPages},EPUBJS.Renderer.prototype.nextPage=function(){return this.chapterPos<this.displayedPages?(this.chapterPos++,this.leftPos+=this.spreadWidth,this.setLeft(this.leftPos),this.currentLocationCfi=this.getPageCfi(),this.trigger("book:pageChanged",this.currentLocationCfi),this.chapterPos):!1},EPUBJS.Renderer.prototype.prevPage=function(){return this.chapterPos>1?(this.chapterPos--,this.leftPos-=this.spreadWidth,this.setLeft(this.leftPos),this.currentLocationCfi=this.getPageCfi(),this.trigger("book:pageChanged",this.currentLocationCfi),this.chapterPos):!1},EPUBJS.Renderer.prototype.chapterEnd=function(){this.page(this.displayedPages),this.currentLocationCfi=this.getPageCfi()},EPUBJS.Renderer.prototype.setLeft=function(a){this.doc.defaultView.scrollTo(a,0)},EPUBJS.Renderer.prototype.replace=function(a,b,c){var d,e,f;d=this.doc.querySelectorAll(a),e=Array.prototype.slice.call(d),f=e.length,e.forEach(function(a){b(a,function(){f--,0>=f&&c&&c()})}.bind(this)),0===f&&c()},EPUBJS.Renderer.prototype.determineStore=function(){return this.book.fromStorage?"filesystem"==this.book.storage.getStorageType()?!1:this.book.store:this.book.contained?this.book.zip:!1},EPUBJS.Renderer.prototype.replaceHead=function(a){var b,c,d,e,f={},g=this,h=this.determineStore(),i=function(a,b){a.setAttribute("href",b),a.onload=function(){d--,0>=d&&j()}},j=function(){a&&a(),_.each(e,function(a){h.revokeUrl(a)}),g.urlCache=f};return h?(b=this.doc.head.querySelectorAll("[href]"),c=Array.prototype.slice.call(b),d=c.length,this.urlCache||(this.urlCache={}),e=_.clone(this.urlCache),c.forEach(function(a){var b=a.getAttribute("href"),c=this.book.settings.contentsPath+b;c in e?(i(a,e[c]),f[c]=e[c],delete e[c]):"stylesheet"===a.getAttribute("rel")?h.getText(c).then(function(b){g.replaceUrlsInCss(c,b).then(function(b){var d=window.URL||window.webkitURL||window.mozURL,e=new Blob([b],{type:"text/css"}),g=d.createObjectURL(e);i(a,g),f[c]=g},function(a){console.error(a)})}):h.getUrl(c).then(function(b){i(a,b),f[c]=b})}.bind(this)),0===d&&j(),void 0):(a&&a(),!1)},EPUBJS.Renderer.prototype.replaceUrlsInCss=function(a,b){var c=new RSVP.Promise,d=[],e=this.determineStore(),f=b.match(/url\(\'?\"?([^\'|^\"]*)\'?\"?\)/g);return f.forEach(function(c){var f=EPUBJS.core.resolveUrl(a,c.replace(/url\(|[|\)|\'|\"]/g,""));replaced=e.getUrl(f).then(function(a){b=b.replace(c,'url("'+a+'")')},function(a){console.error(a)}),d.push(replaced)}),RSVP.all(d).then(function(){c.resolve(b)}),c},EPUBJS.Renderer.prototype.replaceLinks=function(a){var b=this.doc.querySelectorAll("a"),c=Array.prototype.slice.call(b),d=this;c.forEach(function(a){var b,c,e=a.getAttribute("href");e&&(b=e.search("://"),c="#"==e[0],-1!=b?a.setAttribute("target","_blank"):a.onclick=function(){return d.book.goto(e),!1})}),a&&a()},EPUBJS.Renderer.prototype.replaceResources=function(a){var b,c,d,e=this.determineStore();return e?(b=this.doc.querySelectorAll("[src]"),c=Array.prototype.slice.call(b),d=c.length,c.forEach(function(b){var c=b.getAttribute("src"),f=this.book.settings.contentsPath+c;e.getUrl(f).then(function(c){b.src=c,b.onload=function(){d--,0>=d&&a&&a()}})}.bind(this)),0===d&&a(),void 0):(a&&a(),!1)},EPUBJS.Renderer.prototype.page=function(a){return a>=1&&a<=this.displayedPages?(this.chapterPos=a,this.leftPos=this.spreadWidth*(a-1),this.setLeft(this.leftPos),!0):!1},EPUBJS.Renderer.prototype.section=function(a){var b=this.doc.getElementById(a);b&&this.pageByElement(b)},EPUBJS.Renderer.prototype.pageByElement=function(a){var b,c;a&&(b=this.leftPos+a.getBoundingClientRect().left,c=Math.floor(b/this.spreadWidth)+1,this.page(c))},EPUBJS.Renderer.prototype.beforeDisplay=function(a){this.book.triggerHooks("beforeChapterDisplay",a.bind(this),this)},EPUBJS.Renderer.prototype.walk=function(a){for(var b,a,c,d,e,f=a,g=[f],h=1e4,i=0;!b&&g.length;){if(a=g.shift(),this.isElementVisible(a)&&(b=a),!b&&a&&a.childElementCount>0){c=a.children,d=c.length;for(var j=0;d>j;j++)c[j]!=e&&g.push(c[j])}if(!b&&0==g.length&&f&&null!==f.parentNode&&(g.push(f.parentNode),e=f,f=f.parentNode),i++,i>h){console.error("ENDLESS LOOP");break}}return b},EPUBJS.Renderer.prototype.getPageCfi=function(){var a=this.visibileEl;return this.visibileEl=this.findFirstVisible(a),this.visibileEl.id||(this.visibileEl.id="EPUBJS-PAGE-"+this.chapterPos),this.pageIds[this.chapterPos]=this.visibileEl.id,this.epubcfi.generateFragment(this.visibileEl,this.currentChapterCfi)},EPUBJS.Renderer.prototype.gotoCfiFragment=function(a){var b;_.isString(a)&&(a=this.epubcfi.parse(a)),b=this.epubcfi.getElement(a,this.doc),this.pageByElement(b)},EPUBJS.Renderer.prototype.findFirstVisible=function(a){var b,c=a||this.bodyEl;return b=this.walk(c),b?b:a},EPUBJS.Renderer.prototype.isElementVisible=function(a){var b;return a&&(b=a.getBoundingClientRect().left,b>=0&&b<this.spreadWidth)?!0:!1},EPUBJS.Renderer.prototype.height=function(){return this.docEl.offsetHeight},RSVP.EventTarget.mixin(EPUBJS.Renderer.prototype),EPUBJS.Unarchiver=function(a){return this.libPath=EPUBJS.filePath,this.zipUrl=a,this.loadLib(),this.urlCache={},this.zipFs=new zip.fs.FS,this.promise},EPUBJS.Unarchiver.prototype.loadLib=function(){"undefined"==typeof zip&&console.error("Zip lib not loaded"),zip.workerScriptsPath=this.libPath},EPUBJS.Unarchiver.prototype.openZip=function(a){var b=new RSVP.Promise,c=this.zipFs;return c.importHttpContent(a,!1,function(){b.resolve(c)},this.failed),b},EPUBJS.Unarchiver.prototype.getXml=function(a){return this.getText(a).then(function(a){var b=new DOMParser;return b.parseFromString(a,"application/xml")})},EPUBJS.Unarchiver.prototype.getUrl=function(a,b){var c=this,d=new RSVP.Promise,e=this.zipFs.find(a),f=window.URL||window.webkitURL||window.mozURL;return e||console.error(a),a in this.urlCache?(d.resolve(this.urlCache[a]),d):(e.getBlob(b||zip.getMimeType(e.name),function(b){var e=f.createObjectURL(b);d.resolve(e),c.urlCache[a]=e}),d)},EPUBJS.Unarchiver.prototype.getText=function(a){var b=new RSVP.Promise,c=this.zipFs.find(a);return window.URL||window.webkitURL||window.mozURL,c||console.error(a),c.getText(function(a){b.resolve(a)},null,null,"ISO-8859-1"),b},EPUBJS.Unarchiver.prototype.revokeUrl=function(a){var b=window.URL||window.webkitURL||window.mozURL,c=unarchiver.urlCache[a];console.log("revoke",c),c&&b.revokeObjectURL(c)},EPUBJS.Unarchiver.prototype.failed=function(a){console.error(a)},EPUBJS.Unarchiver.prototype.afterSaved=function(){this.callback()},EPUBJS.Unarchiver.prototype.toStorage=function(a){function b(){f--,0==f&&e.afterSaved()}var c=0,d=20,e=this,f=a.length;a.forEach(function(a){setTimeout(function(a){e.saveEntryFileToStorage(a,b)},c,a),c+=d}),console.log("time",c)},EPUBJS.Unarchiver.prototype.saveEntryFileToStorage=function(a,b){a.getData(new zip.BlobWriter,function(c){EPUBJS.storage.save(a.filename,c,b)})};