(function(){vara=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){returnainstanceofx?a:thisinstanceofx?void(this._wrapped=a):newx(a)};"undefined"!=typeofexports?("undefined"!=typeofmodule&&module.exports&&(exports=module.exports=x),exports._=x):a._=x,x.VERSION="1.4.4";vary=x.each=x.forEach=function(a,b,d){if(null!=a)if(l&&a.forEach===l)a.forEach(b,d);elseif(a.length===+a.length){for(vare=0,f=a.length;f>e;e++)if(b.call(d,a[e],e,a)===c)return}elsefor(vargina)if(x.has(a,g)&&b.call(d,a[g],g,a)===c)return};x.map=x.collect=function(a,b,c){vard=[];returnnull==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)};varz="Reduce of empty array with no initial value";x.reduce=x.foldl=x.inject=function(a,b,c,d){vare=arguments.length>2;if(null==a&&(a=[]),n&&a.reduce===n)returnd&&(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)thrownewTypeError(z);returnc},x.reduceRight=x.foldr=function(a,b,c,d){vare=arguments.length>2;if(null==a&&(a=[]),o&&a.reduceRight===o)returnd&&(b=x.bind(b,d)),e?a.reduceRight(b,c):a.reduceRight(b);varf=a.length;if(f!==+f){varg=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)thrownewTypeError(z);returnc},x.find=x.detect=function(a,b,c){vard;returnA(a,function(a,e,f){returnb.call(c,a,e,f)?(d=a,!0):void0}),d},x.filter=x.select=function(a,b,c){vard=[];returnnull==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){returnx.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);vare=!0;returnnull==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))?void0:c}),!!e)};varA=x.some=x.any=function(a,b,d){b||(b=x.identity);vare=!1;returnnull==a?e:r&&a.some===r?a.some(b,d):(y(a,function(a,f,g){returne||(e=b.call(d,a,f,g))?c:void0}),!!e)};x.contains=x.include=function(a,b){returnnull==a?!1:s&&a.indexOf===s?-1!=a.indexOf(b):A(a,function(a){returna===b})},x.invoke=function(a,b){varc=h.call(arguments,2),d=x.isFunction(b);returnx.map(a,function(a){return(d?b:a[b]).apply(a,c)})},x.pluck=function(a,b){returnx.map(a,function(a){returna[b]})},x.where=function(a,b,c){returnx.isEmpty(b)?c?null:[]:x[c?"find":"filter"](a,function(a){for(varcinb)if(b[c]!==a[c])return!1;return!0})},x.findWhere=function(a,b){returnx.where(a,b,!0)},x.max=function(a,b,c){if(!b&&x.isArray(a)&&a[0]===+a[0]&&65535>a.length)returnMath.max.apply(Math,a);if(!b&&x.isEmpty(a))return-1/0;vard={computed:-1/0,value:-1/0};returny(a,function(a,e,f){varg=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)returnMath.min.apply(Math,a);if(!b&&x.isEmpty(a))return1/0;vard={computed:1/0,value:1/0};returny(a,function(a,e,f){varg=b?b.call(c,a,e,f):a;d.computed>g&&(d={value:a,computed:g})}),d.value},x.shuffle=function(a){varb,c=0,d=[];returny(a,function(a){b=x.random(c++),d[c-1]=d[b],d[b]=a}),d};varB=function(a){returnx.isFunction(a)?a:function(b){returnb[a]}};x.sortBy=function(a,b,c){vard=B(b);returnx.pluck(x.map(a,function(a,b,e){return{value:a,index:b,criteria:d.call(c,a,b,e)}}).sort(function(a,b){varc=a.criteria,d=b.criteria;if(c!==d){if(c>d||void0===c)return1;if(d>c||void0===d)return-1}returna.index<b.index?-1:1}),"value")};varC=function(a,b,c,d){vare={},f=B(b||x.identity);returny(a,function(b,g){varh=f.call(c,b,g,a);d(e,h,b)}),e};x.groupBy=function(a,b,c){returnC(a,b,c,function(a,b,c){(x.has(a,b)?a[b]:a[b]=[]).push(c)})},x.countBy=function(a,b,c){returnC(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(vare=c.call(d,b),f=0,g=a.length;g>f;){varh=f+g>>>1;e>c.call(d,a[h])?f=h+1:g=h}returnf},x.toArray=function(a){returna?x.isArray(a)?h.call(a):a.length===+a.length?x.map(a,x.identity):x.values(a):[]},x.size=function(a){returnnull==a?0:a.length===+a.length?a.length:x.keys(a).length},x.first=x.head=x.take=function(a,b,c){returnnull==a?void0:null==b||c?a[0]:h.call(a,0,b)},x.initial=function(a,b,c){returnh.call(a,0,a.length-(null==b||c?1:b))},x.last=function(a,b,c){returnnull==a?void0: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){returnh.call(a,null==b||c?1:b)},x.compact=function(a){returnx.filter(a,x.identity)};varD=function(a,b,c){returny(a,function(a){x.isArray(a)?b?g.apply(c,a):D(a,b,c):c.push(a)}),c};x.flatten=function(a,b){returnD(a,b,[])},x.without=function(a){returnx.difference(a,h.call(arguments,1))},x.uniq=x.unique=function(a,b,c,d){x.isFunction(b)&&(d=c,c=b,b=!1);vare=c?x.map(a,c,d):a,f=[],g=[];returny(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(){returnx.uniq(i.apply(d,arguments))},x.intersection=function(a){varb=h.call(arguments,1);returnx.filter(x.uniq(a),function(a){returnx.every(b,function(b){returnx.indexOf(b,a)>=0})})},x.difference=function(a){varb=i.apply(d,h.call(arguments,1));returnx.filter(a,function(a){return!x.contains(b,a)})},x.zip=function(){for(vara=h.call(arguments),b=x.max(x.pluck(a,"length")),c=Array(b),d=0;b>d;d++)c[d]=x.pluck(a,""+d);returnc},x.object=function(a,b){if(null==a)return{};for(varc={},d=0,e=a.length;e>d;d++)b?c[a[d]]=b[d]:c[a[d][0]]=a[d][1];returnc},x.indexOf=function(a,b,c){if(null==a)return-1;vard=0,e=a.length;if(c){if("number"!=typeofc)returnd=x.sortedIndex(a,b),a[d]===b?d:-1;d=0>c?Math.max(0,e+c):c}if(s&&a.indexOf===s)returna.indexOf(b,c);for(;e>d;d++)if(a[d]===b)returnd;return-1},x.lastIndexOf=function(a,b,c){if(null==a)return-1;vard=null!=c;if(t&&a.lastIndexOf===t)returnd?a.lastIndexOf(b,c):a.lastIndexOf(b);for(vare=d?c:a.length;e--;)if(a[e]===b)returne;return-1},x.range=function(a,b,c){1>=arguments.length&&(b=a||0,a=0),c=arguments[2]||1;for(vard=Math.max(Math.ceil((b-a)/c),0),e=0,f=Array(d);d>e;)f[e++]=a,a+=c;returnf},x.bind=function(a,b){if(a.bind===w&&w)returnw.apply(a,h.call(arguments,1));varc=h.call(arguments,2);returnfunction(){returna.apply(b,c.concat(h.call(arguments)))}},x.partial=function(a){varb=h.call(arguments,1);returnfunction(){returna.apply(this,b.concat(h.call(arguments)))}},x.bindAll=function(a){varb=h.call(arguments,1);return0===b.length&&(b=x.functions(a)),y(b,function(b){a[b]=x.bind(a[b],a)}),a},x.memoize=function(a,b){varc={};returnb||(b=x.identity),function(){vard=b.apply(this,arguments);returnx.has(c,d)?c[d]:c[d]=a.apply(this,arguments)}},x.delay=function(a,b){varc=h.call(arguments,2);returnsetTimeout(function(){returna.apply(null,c)},b)},x.defer=function(a){returnx.delay.apply(x,[a,1].concat(h.call(arguments,1)))},x.throttle=function(a,b){varc,d,e,f,g=0,h=function(){g=newDate,e=null,f=a.apply(c,d)};returnfunction(){vari=newDate,j=b-(i-g);returnc=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){vard,e;returnfunction(){varf=this,g=arguments,h=function(){d=null,c||(e=a.apply(f,g))},i=c&&!d;returnclearTimeout(d),d=setTimeout(h,b),i&&(e=a.apply(f,g)),e}},x.once=function(a){varb,c=!1;returnfunction(){returnc?b:(c=!0,b=a.apply(this,arguments),a=null,b)}},x.wrap=function(a,b){returnfunction(){varc=[a];returng.apply(c,arguments),b.apply(this,c)}},x.compose=function(){vara=arguments;returnfunction(){for(varb=arguments,c=a.length-1;c>=0;c--)b=[a[c].apply(this,b)];returnb[0]}},x.after=function(a,b){return0>=a?b():function(){return1>--a?b.apply(this,arguments):void0}},x.keys=v||function(a){if(a!==Object(a))thrownewTypeError("Invalid object");varb=[];for(varcina)x.has(a,c)&&(b[b.length]=c);returnb},x.values=function(a){varb=[];for(varcina)x.has(a,c)&&b.push(a[c]);returnb},x.pairs=function(a){varb=[];for(varcina)x.has(a,c)&&b.push([c,a[c]]);returnb},x.invert=function(a){varb={};for(varcina)x.has(a,c)&&(b[a[c]]=c);returnb},x.functions=x.methods=function(a){varb=[];for(varcina)x.isFunction(a[c])&&b.push(c);returnb.sort()},x.extend=function(a){returny(h.call(arguments,1),function(b){if(b)for(varcinb)a[c]=b[c]}),a},x.pick=function(a){varb={},c=i.apply(d,h.call(arguments,1));returny(c,function(c){cina&&(b[c]=a[c])}),b},x.omit=function(a){varb={},c=i.apply(d,h.call(arguments,1));for(vareina)x.contains(c,e)||(b[e]=a[e]);returnb},x.defaults=function(a){returny(h.call(arguments,1),function(b){if(b)for(varcinb)null==a[c]&&(a[c]=b[c])}),a},x.clone=function(a){returnx.isObject(a)?x.isArray(a)?a.slice():x.extend({},a):a},x.tap=function(a,b){returnb(a),a};varE=function(a,b,c,d){if(a===b)return0!==a||1/a==1/b;if(null==a||null==b)returna===b;ainstanceofx&&(a=a._wrapped),binstanceofx&&(b=b._wrapped);vare=j.call(a);if(e!=j.call(b))return!1;switch(e){case"[object String]":returna==b+"";case"[object Number]":returna!=+a?b!=+b:0==a?1/a==1/b:a==+b;case"[object Date]":case"[object Boolean]":return+a==+b;case"[object RegExp]":returna.source==b.source&&a.global==b.global&&a.multiline==b.multiline&&a.ignoreCase==b.ignoreCase}if("object"!=typeofa||"object"!=typeofb)return!1;for(varf=c.length;f--;)if(c[f]==a)returnd[f]==b;c.push(a),d.push(b);varg=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{vari=a.constructor,k=b.constructor;if(i!==k&&!(x.isFunction(i)&&iinstanceofi&&x.isFunction(k)&&kinstanceofk))return!1;for(varlina)if(x.has(a,l)&&(g++,!(h=x.has(b,l)&&E(a[l],b[l],c,d))))break;if(h){for(linb)if(x.has(b,l)&&!g--)break;h=!g}}returnc.pop(),d.pop(),h};x.isEqual=function(a,b){returnE(a,b,[],[])},x.isEmpty=function(a){if(null==a)return!0;if(x.isArray(a)||x.isString(a))return0===a.length;for(varbina)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){returna===Object(a)},y(["Arguments","Function","String","Number","Date","RegExp"],function(a){x["is"+a]=function(b){returnj.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"==typeofa}),x.isFinite=function(a){returnisFinite(a)&&!isNaN(parseFloat(a))},x.isNaN=function(a){returnx.isNumber(a)&&a!=+a},x.isBoolean=function(a){returna===!0||a===!1||"[object Boolean]"==j.call(a)},x.isNull=function(a){returnnull===a},x.isUndefined=function(a){returnvoid0===a},x.has=function(a,b){returnk.call(a,b)},x.noConflict=function(){returna._=b,this},x.identity=function(a){returna},x.times=function(a,b,c){for(vard=Array(a),e=0;a>e;e++)d[e]=b.call(c,e);returnd},x.random=function(a,b){returnnull==b&&(b=a,a=0),a+Math.floor(Math.random()*(b-a+1))};varF={escape:{"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"}};F.unescape=x.invert(F.escape);varG={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){returnnull==b?"":(""+b).replace(G[a],function(b){returnF[a][b]})}}),x.result=function(a,b){if(null==a)returnnull;varc=a[b];returnx.isFunction(c)?c.call(a):c},x.mixin=function(a){y(x.functions(a),function(b){varc=x[b]=a[b];x.prototype[b]=function(){vara=[this._wrapped];returng.apply(a,arguments),L.call(this,c.apply(x,a))}})};varH=0;x.uniqueId=function(a){varb=++H+"";returna?a+b:b},x.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};varI=/(.)^/,J={"'":"'","\\":"\\","\r":"r","\n":"n","":"t","\u2028":"u2028","\u2029":"u2029"},K=/\\|'|\r|\n|\t|\u2028|\u2029/g;x.template=function(a,b,c){vard;c=x.defaults({},c,x.templateSettings);vare=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){returng+=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){throwh.source=g,h}if(b)returnd(b,x);vari=function(a){returnd.call(this,a,x)};returni.source="function("+(c.variable||"obj")+"){\n"+g+"}",i},x.chain=function(a){returnx(a).chain()};varL=function(a){returnthis._chain?x(a).chain():a};x.mixin(x),y(["pop","push","reverse","shift","sort","splice","unshift"],function(a){varb=d[a];x.prototype[a]=function(){varc=this._wrapped;returnb.apply(c,arguments),"shift"!=a&&"splice"!=a||0!==c.length||deletec[0],L.call(this,c)}}),y(["concat","join","slice"],function(a){varb=d[a];x.prototype[a]=function(){returnL.call(this,b.apply(this._wrapped,arguments))}}),x.extend(x.prototype,{chain:function(){returnthis._chain=!0,this},value:function(){returnthis._wrapped}})}).call(this),function(a){varb,c,d,e;!function(){vara={},f={};b=function(b,c,d){a[b]={deps:c,callback:d}},e=d=c=function(b){functiond(a){if("."!==a.charAt(0))returna;for(varc=a.split("/"),d=b.split("/").slice(0,-1),e=0,f=c.length;f>e;e++){varg=c[e];if(".."===g)d.pop();else{if("."===g)continue;d.push(g)}}returnd.join("/")}if(e._eak_seen=a,f[b])returnf[b];if(f[b]={},!a[b])thrownewError("Could not find module "+b);for(varg,h=a[b],i=h.deps,j=h.callback,k=[],l=0,m=i.length;m>l;l++)k.push("exports"===i[l]?g={}:c(d(i[l])));varn=j.apply(this,k);returnf[b]=g||n}}(),b("rsvp/all",["./promise","exports"],function(a,b){"use strict";varc=a["default"];b["default"]=function(a,b){returnc.all(a,b)}}),b("rsvp/all_settled",["./promise","./utils","exports"],function(a,b,c){"use strict";functiond(a){return{state:"fulfilled",value:a}}functione(a){return{state:"rejected",reason:a}}varf=a["default"],g=b.isArray,h=b.isNonThenable;c["default"]=function(a,b){returnnewf(function(b){functionc(a){returnfunction(b){j(a,d(b))}}functioni(a){returnfunction(b){j(a,e(b))}}functionj(a,c){m[a]=c,0===--l&&b(m)}if(!g(a))thrownewTypeError("You must pass an array to allSettled.");vark,l=a.length;if(0===l)returnvoidb([]);for(varm=newArray(l),n=0;n<a.length;n++)k=a[n],h(k)?j(n,d(k)):f.cast(k).then(c(n),i(n))},b)}}),b("rsvp/asap",["exports"],function(a){"use strict";functionb(){returnfunction(){process.nextTick(e)}}functionc(){vara=0,b=newh(e),c=document.createTextNode("");returnb.observe(c,{characterData:!0}),function(){c.data=a=++a%2}}functiond(){returnfunction(){setTimeout(e,1)}}functione(){for(vara=0;a<i.length;a++){varb=i[a],c=b[0],d=b[1];c(d)}i=[]}a["default"]=function(a,b){varc=i.push([a,b]);1===c&&f()};varf,g="undefined"!=typeofwindow?window:{},h=g.MutationObserver||g.WebKitMutationObserver,i=[];f="undefined"!=typeofprocess&&"[object process]"==={}.toString.call(process)?b():h?c():d()}),b("rsvp/config",["./events","exports"],function(a,b){"use strict";functionc(a,b){return"onerror"===a?voide.on("error",b):2!==arguments.length?e[a]:void(e[a]=b)}vard=a["default"],e={instrument:!1};d.mixin(e),b.config=e,b.configure=c}),b("rsvp/defer",["./promise","exports"],function(a,b){"use strict";varc=a["default"];b["default"]=function(a){varb={};returnb.promise=newc(function(a,c){b.resolve=a,b.reject=c},a),b}}),b("rsvp/events",["exports"],function(a){"use strict";varb=function(a,b){for(varc=0,d=a.length;d>c;c++)if(a[c]===b)returnc;return-1},c=function(a){varb=a._promiseCallbacks;returnb||(b=a._promiseCallbacks={}),b};a["default"]={mixin:function(a){returna.on=this.on,a.off=this.off,a.trigger=this.trigger,a._promiseCallbacks=void0,a},on:function(a,d){vare,f=c(this);e=f[a],e||(e=f[a]=[]),-1===b(e,d)&&e.push(d)},off:function(a,d){vare,f,g=c(this);returnd?(e=g[a],f=b(e,d),void(-1!==f&&e.splice(f,1))):void(g[a]=[])},trigger:function(a,b){vard,e,f=c(this);if(d=f[a])for(varg=0;g<d.length;g++)(e=d[g])(b)}}}),b("rsvp/filter",["./all","./map","./utils","exports"],function(a,b,c,d){"use strict";functione(a,b,c){if(!i(a))thrownewTypeError("You must pass an array to filter.");if(!h(b))thrownewTypeError("You must pass a function to filter's second argument.");returnf(a,c).then(function(d){returng(a,b,c).then(function(a){varb,c=d.length,e=[];for(b=0;c>b;b++)a[b]&&e.push(d[b]);returne})})}varf=a["default"],g=b["default"],h=c.isFunction,i=c.isArray;d["default"]=e}),b("rsvp/hash",["./promise","./utils","exports"],function(a,b,c){"use strict";vard=a["default"],e=b.isNonThenable,f=b.keysOf;c["default"]=function(a){returnnewd(function(b,c){functiong(a){returnfunction(c){k[a]=c,0===--m&&b(k)}}functionh(a){m=0,c(a)}vari,j,k={},l=f(a),m=l.length;if(0===m)returnvoidb(k);for(varn=0;n<l.length;n++)j=l[n],i=a[j],e(i)?(k[j]=i,0===--m&&b(k)):d.cast(i).then(g(j),h)})}}),b("rsvp/instrument",["./config","./utils","exports"],function(a,b,c){"use strict";vard=a.config,e=b.now;c["default"]=function(a,b,c){try{d.trigger(a,{guid:b._guidKey+b._id,eventName:a,detail:b._detail,childGuid:c&&b._guidKey+c._id,label:b._label,timeStamp:e(),stack:newError(b._label).stack})}catch(f){setTimeout(function(){throwf},0)}}}),b("rsvp/map",["./promise","./all","./utils","exports"],function(a,b,c,d){"use strict";vare=(a["default"],b["default"]),f=c.isArray,g=c.isFunction;d["default"]=function(a,b,c){if(!f(a))thrownewTypeError("You must pass an array to map.");if(!g(b))thrownewTypeError("You must pass a function to map's second argument.");returne(a,c).then(function(a){vard,f=a.length,g=[];for(d=0;f>d;d++)g.push(b(a[d]));returne(g,c)})}}),b("rsvp/node",["./promise","exports"],function(a,b){"use strict";functionc(a,b){returnfunction(c,d){c?b(c):a(arguments.length>2?e.call(arguments,1):d)}}vard=a["default"],e=Array.prototype.slice;b["default"]=function(a,b){returnfunction(){varf=e.call(arguments),g=this||b;returnnewd(function(b,e){d.all(f).then(function(d){try{d.push(c(b,e)),a.apply(g,d)}catch(f){e(f)}})})}}}),b("rsvp/promise",["./config","./events","./instrument","./utils","./promise/cast","./promise/all","./promise/race","./promise/resolve","./promise/reject","exports"],function(a,b,c,d,e,f,g,h,i,j){"use strict";functionk(){}functionl(a,b){if(!z(a))thrownewTypeError("You must pass a resolver function as the first argument to the promise constructor");if(!(thisinstanceofl))thrownewTypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.");this._id=H++,this._label=b,this._subscribers=[],w.instrument&&x("created",this),k!==a&&m(a,this)}functionm(a,b){functionc(a){r(b,a)}functiond(a){t(b,a)}try{a(c,d)}catch(e){d(e)}}functionn(a,b,c,d){vare=a._subscribers,f=e.length;e[f]=b,e[f+K]=c,e[f+L]=d}functiono(a,b){varc,d,e=a._subscribers,f=a._detail;w.instrument&&x(b===K?"fulfilled":"rejected",a);for(varg=0;g<e.length;g+=3)c=e[g],d=e[g+b],p(b,c,d,f);a._subscribers=null}functionp(a,b,c,d){vare,f,g,h,i=z(c);if(i)try{e=c(d),g=!0}catch(j){h=!0,f=j}elsee=d,g=!0;q(b,e)||(i&&g?r(b,e):h?t(b,f):a===K?r(b,e):a===L&&t(b,e))}functionq(a,b){varc,d=null;try{if(a===b)thrownewTypeError("A promises callback cannot return that same promise.");if(y(b)&&(d=b.then,z(d)))returnd.call(b,function(d){returnc?!0:(c=!0,void(b!==d?r(a,d):s(a,d)))},function(b){returnc?!0:(c=!0,voidt(a,b))},"derived from: "+(a._label||" unknown promise")),!0}catch(e){returnc?!0:(t(a,e),!0)}return!1}functionr(a,b){a===b?s(a,b):q(a,b)||s(a,b)}functions(a,b){a._state===I&&(a._state=J,a._detail=b,w.async(u,a))}functiont(a,b){a._state===I&&(a._state=J,a._detail=b,w.async(v,a))}functionu(a){o(a,a._state=K)}functionv(a){a._onerror&&a._onerror(a._detail),o(a,a._state=L)}varw=a.config,x=(b["default"],c["default"]),y=d.objectOrFunction,z=d.isFunction,A=d.now,B=e["default"],C=f["default"],D=g["default"],E=h["default"],F=i["default"],G="rsvp_"+A()+"-",H=0;j["default"]=l,l.cast=B,l.all=C,l.race=D,l.resolve=E,l.reject=F;varI=void0,J=0,K=1,L=2;l.prototype={constructor:l,_id:void0,_guidKey:G,_label:void0,_state:void0,_detail:void0,_subscribers:void0,_onerror:function(a){w.trigger("error",a)},then:function(a,b,c){vard=this;this._onerror=null;vare=newthis.constructor(k,c);if(this._state){varf=arguments;w.async(function(){p(d._state,e,f[d._state-1],d._detail)})}elsen(this,e,a,b);returnw.instrument&&x("chained",d,e),e},"catch":function(a,b){returnthis.then(null,a,b)},"finally":function(a,b){varc=this.constructor;returnthis.then(function(b){returnc.cast(a()).then(function(){returnb})},function(b){returnc.cast(a()).then(function(){throwb})},b)}}}),b("rsvp/promise/all",["../utils","exports"],function(a,b){"use strict";varc=a.isArray,d=a.isNonThenable;b["default"]=function(a,b){vare=this;returnnewe(function(b,f){functiong(a){returnfunction(c){k[a]=c,0===--j&&b(k)}}functionh(a){j=0,f(a)}if(!c(a))thrownewTypeError("You must pass an array to all.");vari,j=a.length,k=newArray(j);if(0===j)returnvoidb(k);for(varl=0;l<a.length;l++)i=a[l],d(i)?(k[l]=i,0===--j&&b(k)):e.cast(i).then(g(l),h)},b)}}),b("rsvp/promise/cast",["exports"],function(a){"use strict";a["default"]=function(a,b){varc=this;returna&&"object"==typeofa&&a.constructor===c?a:newc(function(b){b(a)},b)}}),b("rsvp/promise/race",["../utils","exports"],function(a,b){"use strict";varc=a.isArray,d=(a.isFunction,a.isNonThenable);b["default"]=function(a,b){vare,f=this;returnnewf(function(b,g){functionh(a){j&&(j=!1,b(a))}functioni(a){j&&(j=!1,g(a))}if(!c(a))thrownewTypeError("You must pass an array to race.");for(varj=!0,k=0;k<a.length;k++){if(e=a[k],d(e))returnj=!1,voidb(e);f.cast(e).then(h,i)}},b)}}),b("rsvp/promise/reject",["exports"],function(a){"use strict";a["default"]=function(a,b){varc=this;returnnewc(function(b,c){c(a)},b)}}),b("rsvp/promise/resolve",["exports"],function(a){"use strict";a["default"]=function(a,b){varc=this;returnnewc(function(b){b(a)},b)}}),b("rsvp/race",["./promise","exports"],function(a,b){"use strict";varc=a["default"];b["default"]=function(a,b){returnc.race(a,b)}}),b("rsvp/reject",["./promise","exports"],function(a,b){"use strict";varc=a["default"];b["default"]=function(a,b){returnc.reject(a,b)}}),b("rsvp/resolve",["./promise","exports"],function(a,b){"use strict";varc=a["default"];b["default"]=function(a,b){returnc.resolve(a,b)}}),b("rsvp/rethrow",["exports"],function(a){"use strict";a["default"]=function(a){throwsetTimeout(function(){throwa}),a}}),b("rsvp/utils",["exports"],function(a){"use strict";functionb(a){return"function"==typeofa||"object"==typeofa&&null!==a}functionc(a){return"function"==typeofa}functiond(a){return!b(a)}functione(a){return"[object Array]"===Object.prototype.toString.call(a)}a.objectOrFunction=b,a.isFunction=c,a.isNonThenable=d,a.isArray=e;varf=Date.now||function(){return(newDate).getTime()};a.now=f;varg=Object.keys||function(a){varb=[];for(varcina)b.push(c);returnb};a.keysOf=g}),b("rsvp",["./rsvp/promise","./rsvp/events","./rsvp/node","./rsvp/all","./rsvp/all_settled","./rsvp/race","./rsvp/hash","./rsvp/rethrow","./rsvp/defer","./rsvp/config","./rsvp/map","./rsvp/resolve","./rsvp/reject","./rsvp/asap","./rsvp/filter","exports"],function(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p){"use strict";functionq(a,b){C.async(a,b)}functionr(){C.on.apply(C,arguments)}functions(){C.off.apply(C,arguments)}vart=a["default"],u=b["default"],v=c["default"],w=d["default"],x=e["default"],y=f["default"],z=g["default"],A=h["default"],B=i["default"],C=j.config,D=j.configure,E=k["default"],F=l["default"],G=m["default"],H=n["default"],I=o["default"];if(C.async=H,"undefined"!=typeofwindow&&"object"==typeofwindow.__PROMISE_INSTRUMENTATION__){varJ=window.__PROMISE_INSTRUMENTATION__;D("instrument",!0);for(varKinJ)J.hasOwnProperty(K)&&r(K,J[K])}p.Promise=t,p.EventTarget=u,p.all=w,p.allSettled=x,p.race=y,p.hash=z,p.rethrow=A,p.defer=B,p.denodeify=v,p.configure=D,p.on=r,p.off=s,p.resolve=F,p.reject=G,p.async=q,p.map=E,p.filter=I}),a.RSVP=c("rsvp")}(window);varEPUBJS=EPUBJS||{};EPUBJS.VERSION="0.2.2",EPUBJS.plugins=EPUBJS.plugins||{},EPUBJS.filePath=EPUBJS.filePath||"/epubjs/",EPUBJS.Render={},function(a){varb=a.ePub||{},c=a.ePub=function(){vara,b;return"undefined"!=typeofarguments[0]&&"string"==typeofarguments[0]&&(a=arguments[0],arguments[1]&&"object"==typeofarguments[1]?(b=arguments[1],b.bookPath=a):b={bookPath:a}),arguments[0]&&"object"==typeofarguments[0]&&(b=arguments[0]),newEPUBJS.Book(b)};_.extend(c,{noConflict:function(){returna.ePub=b,this}}),"function"==typeofdefine&&define.amd?define(function(){returnc}):"undefined"!=typeofmodule&&module.exports&&(module.exports=c)}(window),EPUBJS.Book=function(a){this.settings=_.defaults(a||{},{bookPath:null,bookKey:null,packageUrl:null,storage:!1,fromStorage:!1,saved:!1,online:!0,contained:!1,width:null,height:null,layoutOveride:null,orientation:null,minSpreadWidth:800,gap:"auto",version:1,restore:!1,reload:!1,"goto":!1,styles:{},headTags:{},withCredentials:!1,render_method:"Iframe"}),this.settings.EPUBJSVERSION=EPUBJS.VERSION,this.spinePos=0,this.stored=!1,this.online=this.settings.online||navigator.onLine,this.networkListeners(),this.store=!1,this.settings.storage!==!1&&(this.storage=newfileStorage.storage(this.settings.storage)),this.ready={manifest:newRSVP.defer,spine:newRSVP.defer,metadata:newRSVP.defer,cover:newRSVP.defer,toc:newRSVP.defer,pageList:newRSVP.defer},this.readyPromises=[this.ready.manifest.promise,this.ready.spine.promise,this.ready.metadata.promise,this.ready.cover.promise,this.ready.toc.promise],this.pageList=[],this.pagination=newEPUBJS.Pagination,this.pageListReady=this.ready.pageList.promise,this.ready.all=RSVP.all(this.readyPromises),this.ready.all.then(this._ready.bind(this)),this.isRendered=!1,this._q=EPUBJS.core.queue(this),this._rendering=!1,this._displayQ=EPUBJS.core.queue(this),this._moving=!1,this._gotoQ=EPUBJS.core.queue(this),this.renderer=newEPUBJS.Renderer(this.settings.render_method),this.renderer.setMinSpreadWidth(this.settings.minSpreadWidth),this.renderer.setGap(this.settings.gap),this.listenToRenderer(this.renderer),this.defer_opened=newRSVP.defer,this.opened=this.defer_opened.promise,"string"==typeofthis.settings.bookPath&&this.open(this.settings.bookPath,this.settings.reload),window.addEventListener("beforeunload",this.unload.bind(this),!1)},EPUBJS.Book.prototype.open=function(a,b){varc,d=this,e=newRSVP.defer;returnthis.settings.bookPath=a,this.bookUrl=this.urlFrom(a),this.settings.contained||this.isContained(a)?(this.settings.contained=this.contained=!0,this.bookUrl="",c=this.unarchive(a).then(function(){returnd.loadPackage()})):c=this.loadPackage(),c.then(this.settings.restore&&!b&&localStorage?function(a){varb=d.packageIdentifier(a),c=d.restore(b);c||d.unpack(a),e.resolve(),d.defer_opened.resolve()}:function(a){d.unpack(a),e.resolve(),d.defer_opened.resolve()}),this.online&&this.settings.storage&&!this.settings.contained&&(this.settings.stored||e.then(d.storeOffline())),this._registerReplacements(this.renderer),e.promise},EPUBJS.Book.prototype.loadPackage=function(a){varb,c=this,d=newEPUBJS.Parser,e=a||"META-INF/container.xml";returnb=this.settings.packageUrl?c.loadXml(c.settings.packageUrl):c.loadXml(c.bookUrl+e).then(function(a){returnd.container(a)}).then(function(a){returnc.settings.contentsPath=c.bookUrl+a.basePath,c.settings.packageUrl=c.bookUrl+a.packagePath,c.settings.encoding=a.encoding,c.loadXml(c.settings.packageUrl)}),b.catch(function(){console.error("Could not load book at: "+e),c.trigger("book:loadFailed",e)}),b},EPUBJS.Book.prototype.packageIdentifier=function(a){varb=newEPUBJS.Parser;returnb.identifier(a)},EPUBJS.Book.prototype.unpack=function(a){varb=this,c=newEPUBJS.Parser;b.contents=c.packageContents(a,b.settings.contentsPath),b.manifest=b.contents.manifest,b.spine=b.contents.spine,b.spineIndexByURL=b.contents.spineIndexByURL,b.metadata=b.contents.metadata,b.settings.bookKey||(b.settings.bookKey=b.generateBookKey(b.metadata.identifier)),b.globalLayoutProperties=b.parseLayoutProperties(b.metadata),b.cover=b.contents.cover=b.settings.contentsPath+b.contents.coverPath,b.spineNodeIndex=b.contents.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.contents.navPath?(b.settings.navUrl=b.settings.contentsPath+b.contents.navPath,b.loadXml(b.settings.navUrl).then(function(a){returnc.nav(a,b.spineIndexByURL,b.spine)}).then(function(a){b.toc=b.contents.toc=a,b.ready.toc.resolve(b.contents.toc)},function(){b.ready.toc.resolve(!1)}),b.loadXml(b.settings.navUrl).then(function(a){returnc.pageList(a,b.spineIndexByURL,b.spine)}).then(function(a){varc=newEPUBJS.EpubCFI,d=0;0!==a.length&&(b.pageList=b.contents.pageList=a,b.pageList.forEach(function(a){a.cfi||(d+=1,c.generateCfiFromHref(a.href,b).then(function(c){a.cfi=c,a.packageUrl=b.settings.packageUrl,d-=1,0===d&&(b.pagination.process(b.pageList),b.ready.pageList.resolve(b.pageList))}))}),d||(b.pagination.process(b.pageList),b.ready.pageList.resolve(b.pageList)))},function(){b.ready.pageList.resolve([])})):b.contents.tocPath?(b.settings.tocUrl=b.settings.contentsPath+b.contents.tocPath,b.loadXml(b.settings.tocUrl).then(function(a){returnc.toc(a,b.spineIndexByURL,b.spine)}).then(function(a){b.toc=b.contents.toc=a,b.ready.toc.resolve(b.contents.toc)},function(){b.ready.toc.resolve(!1)})):b.ready.toc.resolve(!1)},EPUBJS.Book.prototype.createHiddenRender=function(a,b,c){vard,e,f=this.element.getBoundingClientRect(),g=b||this.settings.width||f.width,h=c||this.settings.height||f.height;returna.setMinSpreadWidth(this.settings.minSpreadWidth),a.setGap(this.settings.gap),this._registerReplacements(a),this.settings.forceSingle&&a.forceSingle(!0),d=document.createElement("div"),d.style.visibility="hidden",d.style.overflow="hidden",d.style.width="0",d.style.height="0",this.element.appendChild(d),e=document.createElement("div"),e.style.visibility="hidden",e.style.overflow="hidden",e.style.width=g+"px",e.style.height=h+"px",d.appendChild(e),a.initialize(e),d},EPUBJS.Book.prototype.generatePageList=function(a,b){{varc=[],d=newEPUBJS.Renderer(this.settings.render_method,!1),e=this.createHiddenRender(d,a,b),f=newRSVP.defer,g=-1,h=this.spine.length,i=0,j=function(a){varb,e=g+1,f=a||newRSVP.defer;returne>=h?f.resolve():(g=e,b=newEPUBJS.Chapter(this.spine[g],this.store),d.displayChapter(b,this.globalLayoutProperties).then(function(){d.pageMap.forEach(function(a){i+=1,c.push({cfi:a.start,page:i})}),d.pageMap.length%2>0&&d.spreads&&(i+=1,c.push({cfi:d.pageMap[d.pageMap.length-1].end,page:i})),setTimeout(function(){j(f)},1)})),f.promise}.bind(this);j().then(function(){d.remove(),this.element.removeChild(e),f.resolve(c)}.bind(this))}returnf.promise},EPUBJS.Book.prototype.generatePagination=function(a,b){varc=this,d=newRSVP.defer;returnthis.ready.spine.promise.then(function(){c.generatePageList(a,b).then(function(a){c.pageList=c.contents.pageList=a,c.pagination.process(a),c.ready.pageList.resolve(c.pageList),d.resolve(c.pageList)})}),d.promise},EPUBJS.Book.prototype.loadPagination=function(a){varb=JSON.parse(a);returnb&&b.length&&(this.pageList=b,this.pagination.process(this.pageList),this.ready.pageList.resolve(this.pageList)),this.pageList},EPUBJS.Book.prototype.getPageList=function(){returnthis.ready.pageList.promise},EPUBJS.Book.prototype.getMetadata=function(){returnthis.ready.metadata.promise},EPUBJS.Book.prototype.getToc=function(){returnthis.ready.toc.promise
},EPUBJS.Book.prototype.networkListeners=function(){vara=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)},EPUBJS.Book.prototype.listenToRenderer=function(a){varb=this;a.Events.forEach(function(c){a.on(c,function(a){b.trigger(c,a)})}),a.on("renderer:visibleRangeChanged",function(a){varb,c,d,e=[];this.pageList.length>0&&(b=this.pagination.pageFromCfi(a.start),d=this.pagination.percentageFromPage(b),e.push(b),a.end&&(c=this.pagination.pageFromCfi(a.end),e.push(c)),this.trigger("book:pageChanged",{anchorPage:b,percentage:d,pageRange:e}))}.bind(this)),a.on("render:loaded",this.loadChange.bind(this))},EPUBJS.Book.prototype.loadChange=function(a){varb,c=EPUBJS.core.uri(a);this.currentChapter&&(b=EPUBJS.core.uri(this.currentChapter.absolute)),!this._rendering&&this.currentChapter&&c.path!=b.path&&(console.warn("Miss Match",c.path,this.currentChapter.absolute),this.goto(c.filename))},EPUBJS.Book.prototype.unlistenToRenderer=function(a){a.Events.forEach(function(b){a.off(b)})},EPUBJS.Book.prototype.loadXml=function(a){returnthis.settings.fromStorage?this.storage.getXml(a,this.settings.encoding):this.settings.contained?this.zip.getXml(a,this.settings.encoding):EPUBJS.core.request(a,"xml",this.settings.withCredentials)},EPUBJS.Book.prototype.urlFrom=function(a){varb,c=EPUBJS.core.uri(a),d=c.protocol,e="/"==c.path[0],f=window.location,g=f.origin||f.protocol+"//"+f.host,h=document.getElementsByTagName("base");returnh.length&&(b=h[0].href),c.protocol?c.origin+c.path:!d&&e?(b||g)+c.path:d||e?void0:EPUBJS.core.resolveUrl(b||f.pathname,c.path)},EPUBJS.Book.prototype.unarchive=function(a){returnthis.zip=newEPUBJS.Unarchiver,this.store=this.zip,this.zip.openZip(a)},EPUBJS.Book.prototype.isContained=function(a){varb=EPUBJS.core.uri(a);return!b.extension||"epub"!=b.extension&&"zip"!=b.extension?!1:!0},EPUBJS.Book.prototype.isSaved=function(a){varb;returnlocalStorage?(b=localStorage.getItem(a),localStorage&&null!==b?!0:!1):!1},EPUBJS.Book.prototype.generateBookKey=function(a){return"epubjs:"+EPUBJS.VERSION+":"+window.location.host+":"+a},EPUBJS.Book.prototype.saveContents=function(){returnlocalStorage?voidlocalStorage.setItem(this.settings.bookKey,JSON.stringify(this.contents)):!1},EPUBJS.Book.prototype.removeSavedContents=function(){returnlocalStorage?voidlocalStorage.removeItem(this.settings.bookKey):!1},EPUBJS.Book.prototype.renderTo=function(a){varb,c=this;if(_.isElement(a))this.element=a;else{if("string"!=typeofa)returnvoidconsole.error("Not an Element");this.element=EPUBJS.core.getEl(a)}returnb=this.opened.then(function(){returnc.renderer.initialize(c.element,c.settings.width,c.settings.height),c._rendered(),c.startDisplay()})},EPUBJS.Book.prototype.startDisplay=function(){vara;returna=this.settings.goto?this.goto(this.settings.goto):this.settings.previousLocationCfi?this.gotoCfi(this.settings.previousLocationCfi):this.displayChapter(this.spinePos)},EPUBJS.Book.prototype.restore=function(a){varb,c=this,d=["manifest","spine","metadata","cover","toc","spineNodeIndex","spineIndexByURL","globalLayoutProperties"],e=!1,f=this.generateBookKey(a),g=localStorage.getItem(f),h=d.length;if(this.settings.clearSaved&&(e=!0),!e&&"undefined"!=g&&null!==g)for(c.contents=JSON.parse(g),b=0;h>b;b++){vari=d[b];if(!c.contents[i]){e=!0;break}c[i]=c.contents[i]}return!e&&g&&this.contents&&this.settings.contentsPath?(this.settings.bookKey=f,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),!0):!1},EPUBJS.Book.prototype.displayChapter=function(a,b,c){vard,e,f,g,h=this,i=c||newRSVP.defer;returnthis.isRendered?this._rendering||this._rendering?(this._displayQ.enqueue("displayChapter",[a,b,i]),i.promise):(_.isNumber(a)?f=a:(e=newEPUBJS.EpubCFI(a),f=e.spinePos),(0>f||f>=this.spine.length)&&(console.warn("Not A Valid Location"),f=0,b=!1,e=!1),g=newEPUBJS.Chapter(this.spine[f],this.store),this._rendering=!0,d=h.renderer.displayChapter(g,this.globalLayoutProperties),e?h.renderer.gotoCfi(e):b&&h.renderer.lastPage(),d.then(function(){h.spinePos=f,i.resolve(h.renderer),h.settings.fromStorage||h.settings.contained||h.preloadNextChapter(),h.currentChapter=g,h._rendering=!1,h._displayQ.dequeue(),0===h._displayQ.length()&&h._gotoQ.dequeue()},function(a){console.error("Could not load Chapter: "+g.absolute),h.trigger("book:chapterLoadFailed",g.absolute),h._rendering=!1,i.reject(a)}),i.promise):(this._q.enqueue("displayChapter",arguments),i.reject({message:"Rendering",stack:(newError).stack}),i.promise)},EPUBJS.Book.prototype.nextPage=function(){vara;returnthis.isRendered?(a=this.renderer.nextPage(),a?void0:this.nextChapter()):this._q.enqueue("nextPage",arguments)},EPUBJS.Book.prototype.prevPage=function(){vara;returnthis.isRendered?(a=this.renderer.prevPage(),a?void0:this.prevChapter()):this._q.enqueue("prevPage",arguments)},EPUBJS.Book.prototype.nextChapter=function(){vara;if(this.spinePos<this.spine.length-1){for(a=this.spinePos+1;this.spine[a]&&this.spine[a].linear&&"no"==this.spine[a].linear;)a++;if(a<this.spine.length)returnthis.displayChapter(a);this.trigger("book:atEnd")}elsethis.trigger("book:atEnd")},EPUBJS.Book.prototype.prevChapter=function(){vara;if(this.spinePos>0){for(a=this.spinePos-1;this.spine[a]&&this.spine[a].linear&&"no"==this.spine[a].linear;)a--;if(a>=0)returnthis.displayChapter(a,!0);this.trigger("book:atStart")}elsethis.trigger("book:atStart")},EPUBJS.Book.prototype.getCurrentLocationCfi=function(){returnthis.isRendered?this.renderer.currentLocationCfi:!1},EPUBJS.Book.prototype.goto=function(a){return0===a.indexOf("epubcfi(")?this.gotoCfi(a):a.indexOf("%")===a.length-1?this.gotoPercentage(parseInt(a.substring(0,a.length-1))/100):"number"==typeofa||isNaN(a)===!1?this.gotoPage(a):this.gotoHref(a)},EPUBJS.Book.prototype.gotoCfi=function(a,b){varc,d,e,f=b||newRSVP.defer;returnthis.isRendered?this._moving||this._rendering?(console.warn("Renderer is moving"),this._gotoQ.enqueue("gotoCfi",[a,f]),!1):(c=newEPUBJS.EpubCFI(a),d=c.spinePos,-1==d?!1:(e=this.spine[d],promise=f.promise,this._moving=!0,this.currentChapter&&this.spinePos===d?(this.renderer.gotoCfi(c),this._moving=!1,f.resolve(this.renderer.currentLocationCfi)):(e&&-1!=d||(d=0,e=this.spine[d]),this.currentChapter=newEPUBJS.Chapter(e,this.store),this.currentChapter&&(this.spinePos=d,render=this.renderer.displayChapter(this.currentChapter,this.globalLayoutProperties),this.renderer.gotoCfi(c),render.then(function(a){this._moving=!1,f.resolve(a.currentLocationCfi)}.bind(this)))),promise.then(function(){this._gotoQ.dequeue()}.bind(this)),promise)):(console.warn("Not yet Rendered"),this.settings.previousLocationCfi=a,!1)},EPUBJS.Book.prototype.gotoHref=function(a,b){varc,d,e,f,g,h=b||newRSVP.defer;returnthis.isRendered?this._moving||this._rendering?(this._gotoQ.enqueue("gotoHref",[a,h]),!1):(c=a.split("#"),d=c[0],e=c[1]||!1,f=d.replace(this.settings.contentsPath,""),g=this.spineIndexByURL[f],d||(g=this.currentChapter?this.currentChapter.spinePos:0),"number"!=typeofg?!1:this.currentChapter&&g==this.currentChapter.spinePos?(e?this.renderer.section(e):this.renderer.firstPage(),h.resolve(this.renderer.currentLocationCfi),h.promise.then(function(){this._gotoQ.dequeue()}.bind(this)),h.promise):this.displayChapter(g).then(function(){e&&this.renderer.section(e),h.resolve(this.renderer.currentLocationCfi)}.bind(this))):(this.settings.goto=a,!1)},EPUBJS.Book.prototype.gotoPage=function(a){varb=this.pagination.cfiFromPage(a);returnthis.gotoCfi(b)},EPUBJS.Book.prototype.gotoPercentage=function(a){varb=this.pagination.pageFromPercentage(a);returnthis.gotoPage(b)},EPUBJS.Book.prototype.preloadNextChapter=function(){vara,b=this.spinePos+1;returnb>=this.spine.length?!1:(a=newEPUBJS.Chapter(this.spine[b]),void(a&&EPUBJS.core.request(a.absolute)))},EPUBJS.Book.prototype.storeOffline=function(){vara=this,b=_.values(this.manifest);returnEPUBJS.storage.batch(b).then(function(){a.settings.stored=!0,a.trigger("book:stored")})},EPUBJS.Book.prototype.availableOffline=function(){returnthis.settings.stored>0?!0:!1},EPUBJS.Book.prototype.setStyle=function(a,b,c){vard=["color","background","background-color"];returnthis.isRendered?(this.settings.styles[a]=b,this.renderer.setStyle(a,b,c),void(-1===d.indexOf(a)&&this.renderer.reformat())):this._q.enqueue("setStyle",arguments)},EPUBJS.Book.prototype.removeStyle=function(a){returnthis.isRendered?(this.renderer.removeStyle(a),this.renderer.reformat(),voiddeletethis.settings.styles[a]):this._q.enqueue("removeStyle",arguments)},EPUBJS.Book.prototype.addHeadTag=function(a,b){returnthis.isRendered?void(this.settings.headTags[a]=b):this._q.enqueue("addHeadTag",arguments)},EPUBJS.Book.prototype.useSpreads=function(a){console.warn("useSpreads is deprecated, use forceSingle or set a layoutOveride instead"),this.forceSingle(a===!1?!0:!1)},EPUBJS.Book.prototype.forceSingle=function(a){varb="undefined"==typeofa?!0:a;this.renderer.forceSingle(b),this.settings.forceSingle=b,this.isRendered&&this.renderer.reformat()},EPUBJS.Book.prototype.setMinSpreadWidth=function(a){this.settings.minSpreadWidth=a,this.isRendered&&(this.renderer.setMinSpreadWidth(this.settings.minSpreadWidth),this.renderer.reformat())},EPUBJS.Book.prototype.setGap=function(a){this.settings.gap=a,this.isRendered&&(this.renderer.setGap(this.settings.gap),this.renderer.reformat())},EPUBJS.Book.prototype.chapter=function(a){varb,c,d=this.spineIndexByURL[a];returnd&&(b=this.spine[d],c=newEPUBJS.Chapter(b,this.store),c.load()),c},EPUBJS.Book.prototype.unload=function(){this.settings.restore&&localStorage&&this.saveContents(),this.unlistenToRenderer(this.renderer),this.trigger("book:unload")},EPUBJS.Book.prototype.destroy=function(){window.removeEventListener("beforeunload",this.unload),this.currentChapter&&this.currentChapter.unload(),this.unload(),this.render&&this.render.remove()},EPUBJS.Book.prototype._ready=function(){this.trigger("book:ready")},EPUBJS.Book.prototype._rendered=function(){this.isRendered=!0,this.trigger("book:rendered"),this._q.flush()},EPUBJS.Book.prototype.applyStyles=function(a,b){a.applyStyles(this.settings.styles),b()},EPUBJS.Book.prototype.applyHeadTags=function(a,b){a.applyHeadTags(this.settings.headTags),b()},EPUBJS.Book.prototype._registerReplacements=function(a){a.registerHook("beforeChapterDisplay",this.applyStyles.bind(this,a),!0),a.registerHook("beforeChapterDisplay",this.applyHeadTags.bind(this,a),!0),a.registerHook("beforeChapterDisplay",EPUBJS.replace.hrefs.bind(this),!0),this._needsAssetReplacement()&&a.registerHook("beforeChapterDisplay",[EPUBJS.replace.head,EPUBJS.replace.resources,EPUBJS.replace.svg],!0)},EPUBJS.Book.prototype._needsAssetReplacement=function(){returnthis.settings.fromStorage?"filesystem"==this.storage.getStorageType()?!1:!0:this.settings.contained?!0:!1},EPUBJS.Book.prototype.parseLayoutProperties=function(a){varb=this.layoutOveride&&this.layoutOveride.layout||a.layout||"reflowable",c=this.layoutOveride&&this.layoutOveride.spread||a.spread||"auto",d=this.layoutOveride&&this.layoutOveride.orientation||a.orientation||"auto";return{layout:b,spread:c,orientation:d}},RSVP.EventTarget.mixin(EPUBJS.Book.prototype),RSVP.on("error",function(){}),RSVP.configure("instrument",!0),RSVP.on("rejected",function(a){console.error(a.detail.message,a.detail.stack)}),EPUBJS.Chapter=function(a,b){this.href=a.href,this.absolute=a.url,this.id=a.id,this.spinePos=a.index,this.cfiBase=a.cfiBase,this.properties=a.properties,this.manifestProperties=a.manifestProperties,this.linear=a.linear,this.pages=1,this.store=b,this.epubcfi=newEPUBJS.EpubCFI,this.deferred=newRSVP.defer,this.loaded=this.deferred.promise},EPUBJS.Chapter.prototype.load=function(a){varb,c=a||this.store;returnb=c?c.get(this.href):EPUBJS.core.request(this.absolute,"xml"),b.then(function(a){this.setDocument(a),this.deferred.resolve(this)}.bind(this)),b},EPUBJS.Chapter.prototype.render=function(){returnthis.load().then(function(a){varb,c=newXMLSerializer,d=a.head,e=a.createElement("base");returne.setAttribute("href",window.location.origin+this.absolute),d.insertBefore(e,d.firstChild),b=c.serializeToString(a)}.bind(this))},EPUBJS.Chapter.prototype.url=function(a){varb,c=newRSVP.defer,d=a||this.store,e=this;returnd?this.tempUrl?(b=this.tempUrl,c.resolve(b)):d.getUrl(this.absolute).then(function(a){e.tempUrl=a,c.resolve(a)}):(b=this.absolute,c.resolve(b)),c.promise},EPUBJS.Chapter.prototype.setPages=function(a){this.pages=a},EPUBJS.Chapter.prototype.getPages=function(){returnthis.pages},EPUBJS.Chapter.prototype.getID=function(){returnthis.ID},EPUBJS.Chapter.prototype.unload=function(a){this.document=null,this.tempUrl&&a&&(a.revokeUrl(this.tempUrl),this.tempUrl=!1)},EPUBJS.Chapter.prototype.setDocument=function(a){{varb=a.namespaceURI;a.doctype}this.document=a.implementation.createDocument(b,null,null),this.contents=this.document.importNode(a.documentElement,!0),this.document.appendChild(this.contents),!this.document.evaluate&&document.evaluate&&(this.document.evaluate=document.evaluate)},EPUBJS.Chapter.prototype.cfiFromRange=function(a){varb,c,d,e,f,g;if(this.document){if(c=EPUBJS.core.getElementXPath(a.startContainer),d=EPUBJS.core.getElementXPath(a.endContainer),e=this.document.evaluate(c,this.document,EPUBJS.core.nsResolver,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue,a.collapsed||(f=this.document.evaluate(d,this.document,EPUBJS.core.nsResolver,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue),b=this.document.createRange(),e)try{b.setStart(e,a.startOffset),!a.collapsed&&f&&b.setEnd(f,a.endOffset)}catch(h){console.log("missed"),e=!1}returne||(console.log("not found, try fuzzy match"),cleanStartTextContent=EPUBJS.core.cleanStringForXpath(a.startContainer.textContent),c="//text()[contains(.,"+cleanStartTextContent+")]",e=this.document.evaluate(c,this.document,EPUBJS.core.nsResolver,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue,e&&(b.setStart(e,a.startOffset),a.collapsed||(g=EPUBJS.core.cleanStringForXpath(a.endContainer.textContent),d="//text()[contains(.,"+g+")]",f=this.document.evaluate(d,this.document,EPUBJS.core.nsResolver,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue,f&&b.setEnd(f,a.endOffset)))),this.epubcfi.generateCfiFromRange(b,this.cfiBase)}},EPUBJS.Chapter.prototype.find=function(a){varb=this,c=[],d=a.toLowerCase(),e=function(a){for(vare,f,g,h=a.textContent.toLowerCase(),i=b.document.createRange(),j=-1,k=150;-1!=f;)f=h.indexOf(d,j+1),-1!=f&&(i=b.document.createRange(),i.setStart(a,f),i.setEnd(a,f+d.length),e=b.cfiFromRange(i),a.textContent.length<k?g=a.textContent:(g=a.textContent.substring(f-k/2,f+k/2),g="..."+g+"..."),c.push({cfi:e,excerpt:g})),j=f};returnthis.textSprint(this.document,function(a){e(a)}),c},EPUBJS.Chapter.prototype.textSprint=function(a,b){for(varc,d=document.createTreeWalker(a,NodeFilter.SHOW_TEXT,{acceptNode:function(a){returna.data&&!/^\s*$/.test(a.data)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_REJECT}},!1);c=d.nextNode();)b(c)};varEPUBJS=EPUBJS||{};EPUBJS.core={},EPUBJS.core.getEl=function(a){returndocument.getElementById(a)},EPUBJS.core.getEls=function(a){returndocument.getElementsByClassName(a)},EPUBJS.core.request=function(a,b,c){functiond(){if(this.readyState===this.DONE)if(200===this.status||this.responseXML){vara;a="xml"==b?this.responseXML:"json"==b?JSON.parse(this.response):"blob"==b?e?this.response:newBlob([this.response]):this.response,g.resolve(a)}elseg.reject({message:this.response,stack:(newError).stack})}vare=window.URL,f=e?"blob":"arraybuffer",g=newRSVP.defer,h=newXMLHttpRequest,i=XMLHttpRequest.prototype;return"overrideMimeType"ini||Object.defineProperty(i,"overrideMimeType",{value:function(){}}),c&&(h.withCredentials=!0),h.open("GET",a,!0),h.onreadystatechange=d,"blob"==b&&(h.responseType=f),"json"==b&&h.setRequestHeader("Accept","application/json"),"xml"==b&&h.overrideMimeType("text/xml"),h.send(),g.promise},EPUBJS.core.toArray=function(a){varb=[];for(varcina){vard;a.hasOwnProperty(c)&&(d=a[c],d.ident=c,b.push(d))}returnb},EPUBJS.core.uri=function(a){varb,c,d,e={protocol:"",host:"",path:"",origin:"",directory:"",base:"",filename:"",extension:"",fragment:"",href:a},f=a.indexOf("://"),g=a.indexOf("?"),h=a.indexOf("#");return-1!=h&&(e.fragment=a.slice(h+1),a=a.slice(0,h)),-1!=g&&(e.search=a.slice(g+1),a=a.slice(0,g),href=a),-1!=f?(e.protocol=a.slice(0,f),b=a.slice(f+3),d=b.indexOf("/"),-1===d?(e.host=e.path,e.path=""):(e.host=b.slice(0,d),e.path=b.slice(d)),e.origin=e.protocol+"://"+e.host,e.directory=EPUBJS.core.folder(e.path),e.base=e.origin+e.directory):(e.path=a,e.directory=EPUBJS.core.folder(a),e.base=e.directory),e.filename=a.replace(e.base,""),c=e.filename.lastIndexOf("."),-1!=c&&(e.extension=e.filename.slice(c+1)),e},EPUBJS.core.folder=function(a){varb=a.lastIndexOf("/");if(-1==b)varc="";returnc=a.slice(0,b+1)},EPUBJS.core.dataURLToBlob=function(a){varb,c,d,e,f,g=";base64,";if(-1==a.indexOf(g))returnb=a.split(","),c=b[0].split(":")[1],d=b[1],newBlob([d],{type:c});b=a.split(g),c=b[0].split(":")[1],d=window.atob(b[1]),e=d.length,f=newUint8Array(e);for(varh=0;e>h;++h)f[h]=d.charCodeAt(h);returnnewBlob([f],{type:c})},EPUBJS.core.addScript=function(a,b,c){vard,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){vard=a.length,e=0,f=function(){e++,d==e?b&&b():EPUBJS.core.addScript(a[e],f,c)};EPUBJS.core.addScript(a[e],f,c)},EPUBJS.core.addCss=function(a,b,c){vard,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){varb=["Webkit","Moz","O","ms"],c=a[0].toUpperCase()+a.slice(1),d=b.length;if("undefined"!=typeofdocument.body.style[a])returna;for(vare=0;d>e;e++)if("undefined"!=typeofdocument.body.style[b[e]+c])returnb[e]+c;returna},EPUBJS.core.resolveUrl=function(a,b){varc,d,e=[],f=EPUBJS.core.uri(b),g=a.split("/");returnf.host?b:(g.pop(),d=b.split("/"),d.forEach(function(a){".."===a?g.pop():e.push(a)}),c=g.concat(e),c.join("/"))},EPUBJS.core.uuid=function(){vara=(newDate).getTime(),b="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(b){varc=(a+16*Math.random())%16|0;returna=Math.floor(a/16),("x"==b?c:7&c|8).toString(16)});returnb},EPUBJS.core.insert=function(a,b,c){vard=EPUBJS.core.locationOf(a,b,c);returnb.splice(d,0,a),d},EPUBJS.core.locationOf=function(a,b,c,d,e){varf,g=d||0,h=e||b.length,i=parseInt(g+(h-g)/2);returnc||(c=function(a,b){returna>b?1:b>a?-1:(a=b)?0:void0}),0>=h-g?i:(f=c(b[i],a),h-g===1?f>0?i:i+1:0===f?i:-1===f?EPUBJS.core.locationOf(a,b,c,i,h):EPUBJS.core.locationOf(a,b,c,g,i))},EPUBJS.core.indexOfSorted=function(a,b,c,d,e){varf,g=d||0,h=e||b.length,i=parseInt(g+(h-g)/2);returnc||(c=function(a,b){returna>b?1:b>a?-1:(a=b)?0:void0}),0>=h-g?-1:(f=c(b[i],a),h-g===1?0===f?i:-1:0===f?i:-1===f?EPUBJS.core.indexOfSorted(a,b,c,i,h):EPUBJS.core.indexOfSorted(a,b,c,g,i))},EPUBJS.core.queue=function(a){varb=[],c=a,d=function(a,c,d){returnb.push({funcName:a,args:c,context:d}),b},e=function(){vara;b.length&&(a=b.shift(),c[a.funcName].apply(a.context||c,a.args))},f=function(){for(;b.length;)e()},g=function(){b=[]},h=function(){returnb.length};return{enqueue:d,dequeue:e,flush:f,clear:g,length:h}},EPUBJS.core.getElementXPath=function(a){returna&&a.id?'//*[@id="'+a.id+'"]':EPUBJS.core.getElementTreeXPath(a)},EPUBJS.core.getElementTreeXPath=function(a){varb,c,d,e,f=[],g="http://www.w3.org/1999/xhtml"===a.ownerDocument.documentElement.getAttribute("xmlns");for(a.nodeType===Node.TEXT_NODE&&(b=EPUBJS.core.indexOfTextNode(a)+1,f.push("text()["+b+"]"),a=a.parentNode);a&&1==a.nodeType;a=a.parentNode){b=0;for(varh=a.previousSibling;h;h=h.previousSibling)h.nodeType!=Node.DOCUMENT_TYPE_NODE&&h.nodeName==a.nodeName&&++b;c=a.nodeName.toLowerCase(),d=g?"xhtml:"+c:c,e=b?"["+(b+1)+"]":"",f.splice(0,0,d+e)}returnf.length?"./"+f.join("/"):null},EPUBJS.core.nsResolver=function(a){varb={xhtml:"http://www.w3.org/1999/xhtml",epub:"http://www.idpf.org/2007/ops"};returnb[a]||null},EPUBJS.core.cleanStringForXpath=function(a){varb=a.match(/[^'"]+|['"]/g);returnb=b.map(function(a){return"'"===a?'"\'"':'"'===a?"'\"'":"'"+a+"'"}),"concat('',"+b.join(",")+")"},EPUBJS.core.indexOfTextNode=function(a){for(varb,c=a.parentNode,d=c.childNodes,e=-1,f=0;f<d.length&&(b=d[f],b.nodeType===Node.TEXT_NODE&&e++,b!=a);f++);returne},EPUBJS.EpubCFI=function(a){returna?this.parse(a):void0},EPUBJS.EpubCFI.prototype.generateChapterComponent=function(a,b,c){vard=parseInt(b),e=a+1,f="/"+e+"/";returnf+=2*(d+1),c&&(f+="["+c+"]"),f},EPUBJS.EpubCFI.prototype.generatePathComponent=function(a){varb=[];returna.forEach(function(a){varc="";c+=2*(a.index+1),a.id&&(c+="["+a.id+"]"),b.push(c)}),b.join("/")},EPUBJS.EpubCFI.prototype.generateCfiFromElement=function(a,b){varc=this.pathTo(a),d=this.generatePathComponent(c);returnd.length?"epubcfi("+b+"!"+d+"/1:0)":"epubcfi("+b+"!/4/)"},EPUBJS.EpubCFI.prototype.pathTo=function(a){for(varb,c=[];a&&null!==a.parentNode&&9!=a.parentNode.nodeType;)b=a.parentNode.children,c.unshift({id:a.id,tagName:a.tagName,index:b?Array.prototype.indexOf.call(b,a):0}),a=a.parentNode;returnc},EPUBJS.EpubCFI.prototype.getChapterComponent=function(a){varb=a.split("!");returnb[0]},EPUBJS.EpubCFI.prototype.getPathComponent=function(a){varb=a.split("!"),c=b[1]?b[1].split(":"):"";returnc[0]},EPUBJS.EpubCFI.prototype.getCharecterOffsetComponent=function(a){varb=a.split(":");returnb[1]||""},EPUBJS.EpubCFI.prototype.parse=function(a){varb,c,d,e,f,g,h,i,j,k={},l=function(a){varb,c,d,e;returnb="element",c=parseInt(a)/2-1,d=a.match(/\[(.*)\]/),d&&d[1]&&(e=d[1]),{type:b,index:c,id:e||!1}};return"string"!=typeofa?{spinePos:-1}:(k.str=a,0===a.indexOf("epubcfi(")&&")"===a[a.length-1]&&(a=a.slice(8,a.length-1)),c=this.getChapterComponent(a),d=this.getPathComponent(a)||"",e=this.getCharecterOffsetComponent(a),c&&(b=c.split("/")[2]||"")?(k.spinePos=parseInt(b)/2-1||0,g=b.match(/\[(.*)\]/),k.spineId=g?g[1]:!1,-1!=d.indexOf(",")&&console.warn("CFI Ranges are not supported"),h=d.split("/"),i=h.pop(),k.steps=[],h.forEach(function(a){varb;a&&(b=l(a),k.steps.push(b))}),j=parseInt(i),isNaN(j)||k.steps.push(j%2===0?l(i):{type:"text",index:(j-1)/2}),f=e.match(/\[(.*)\]/),f&&f[1]?(k.characterOffset=parseInt(e.split("[")[0]),k.textLocationAssertion=f[1]):k.characterOffset=parseInt(e),k):{spinePos:-1})},EPUBJS.EpubCFI.prototype.addMarker=function(a,b,c){vard,e,f,g,h=b||document,i=c||this.createMarker(h);return"string"==typeofa&&(a=this.parse(a)),e=a.steps[a.steps.length-1],-1===a.spinePos?!1:(d=this.findParent(a,h))?(e&&"text"===e.type?(f=d.childNodes[e.index],a.characterOffset?(g=f.splitText(a.characterOffset),i.classList.add("EPUBJS-CFI-SPLIT"),d.insertBefore(i,g)):d.insertBefore(i,f)):d.insertBefore(i,d.firstChild),i):!1},EPUBJS.EpubCFI.prototype.createMarker=function(a){varb=a||document,c=b.createElement("span");returnc.id="EPUBJS-CFI-MARKER:"+EPUBJS.core.uuid(),c.classList.add("EPUBJS-CFI-MARKER"),c},EPUBJS.EpubCFI.prototype.removeMarker=function(a,b){a.classList.contains("EPUBJS-CFI-SPLIT")?(nextSib=a.nextSibling,prevSib=a.previousSibling,nextSib&&prevSib&&3===nextSib.nodeType&&3===prevSib.nodeType&&(prevSib.textContent+=nextSib.textContent,a.parentNode.removeChild(nextSib)),a.parentNode.removeChild(a)):a.classList.contains("EPUBJS-CFI-MARKER")&&a.parentNode.removeChild(a)},EPUBJS.EpubCFI.prototype.findParent=function(a,b){varc,d,e,f=b||document,g=f.getElementsByTagName("html")[0],h=Array.prototype.slice.call(g.children);if("string"==typeofa&&(a=this.parse(a)),d=a.steps.slice(0),!d.length)returnf.getElementsByTagName("body")[0];for(;d&&d.length>0;){if(c=d.shift(),"text"===c.type?(e=g.childNodes[c.index],g=e.parentNode||g):g=c.id?f.getElementById(c.id):h[c.index],"undefined"==typeofg)returnconsole.error("No Element For",c,a.str),!1;h=Array.prototype.slice.call(g.children)}returng},EPUBJS.EpubCFI.prototype.compare=function(a,b){if("string"==typeofa&&(a=newEPUBJS.EpubCFI(a)),"string"==typeofb&&(b=newEPUBJS.EpubCFI(b)),a.spinePos>b.spinePos)return1;if(a.spinePos<b.spinePos)return-1;for(varc=0;c<a.steps.length;c++){if(!b.steps[c])return1;if(a.steps[c].index>b.steps[c].index)return1;if(a.steps[c].index<b.steps[c].index)return-1}returna.steps.length<b.steps.length?-1:a.characterOffset>b.characterOffset?1:a.characterOffset<b.characterOffset?-1:0},EPUBJS.EpubCFI.prototype.generateCfiFromHref=function(a,b){varc,d,e=EPUBJS.core.uri(a),f=e.path,g=e.fragment,h=b.spineIndexByURL[f],i=newRSVP.defer,j=newEPUBJS.EpubCFI;return"undefined"!=typeofh&&(d=b.spine[h],c=b.loadXml(d.url),c.then(function(a){varb,c=a.getElementById(g);b=j.generateCfiFromElement(c,d.cfiBase),i.resolve(b)})),i.promise},EPUBJS.EpubCFI.prototype.generateCfiFromTextNode=function(a,b,c){vard=a.parentNode,e=this.pathTo(d),f=this.generatePathComponent(e),g=1+2*Array.prototype.indexOf.call(d.childNodes,a);return"epubcfi("+c+"!"+f+"/"+g+":"+(b||0)+")"},EPUBJS.EpubCFI.prototype.generateCfiFromRangeAnchor=function(a,b){varc=a.anchorNode,d=a.anchorOffset;returnthis.generateCfiFromTextNode(c,d,b)},EPUBJS.EpubCFI.prototype.generateCfiFromRange=function(a,b){varc,d,e,f,g,h,i,j,k,l,m,n;if(c=a.startContainer,3===c.nodeType)d=c.parentNode,h=1+2*EPUBJS.core.indexOfTextNode(c),e=this.pathTo(d);else{if(a.collapsed)returnthis.generateCfiFromElement(c,b);e=this.pathTo(c)}returnf=this.generatePathComponent(e),g=a.startOffset,a.collapsed?"epubcfi("+b+"!"+f+"/"+h+":"+g+")":(i=a.endContainer,3===i.nodeType?(j=i.parentNode,n=1+2*EPUBJS.core.indexOfTextNode(i),k=this.pathTo(j)):k=this.pathTo(i),l=this.generatePathComponent(k),m=a.endOffset,"epubcfi("+b+"!"+f+"/"+h+":"+g+","+l+"/"+n+":"+m+")")},EPUBJS.EpubCFI.prototype.generateXpathFromSteps=function(a){varb=[".","*"];returna.forEach(function(a){varc=a.index+1;b.push(a.id?"*[position()="+c+" and @id='"+a.id+"']":"text"===a.type?"text()["+c+"]":"*["+c+"]")}),b.join("/")},EPUBJS.EpubCFI.prototype.generateRangeFromCfi=function(a,b){varc,d,e,f,g=b||document,h=g.createRange();return"string"==typeofa&&(a=this.parse(a)),-1===a.spinePos?!1:(d=this.generateXpathFromSteps(a.steps),c=a.steps[a.steps.length-1],(e=g.evaluate(d,g,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue)?(e&&a.characterOffset>=0?(f=e.length,a.characterOffset<f?(h.setStart(e,a.characterOffset),h.setEnd(e,f)):(console.debug("offset greater than length:",a.characterOffset,f),h.setStart(e,f-1),h.setEnd(e,f))):e&&h.selectNode(e),h):null)},EPUBJS.Events=function(a,b){returnthis.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){varb=newCustomEvent(a);returnthis.events[a]=b,b},EPUBJS.Events.prototype.tell=function(a,b){varc;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){returnthis.events[a]?void(c?this.el.addEventListener(a,b.bind(c),!1):this.el.addEventListener(a,b,!1)):(console.warn("No event:",a,"defined yet, creating."),voidthis.createEvent(a))},EPUBJS.Events.prototype.deafen=function(a,b){this.el.removeEventListener(a,b,!1)},EPUBJS.Events.prototype.listenUntil=function(a,b,c,d){functione(){this.deafen(a,c),this.deafen(b,e)}this.listen(a,c,d),this.listen(b,e,this)},EPUBJS.hooks={},EPUBJS.Hooks=function(){functiona(){}returna.prototype.getHooks=function(){vara;this.hooks={},Array.prototype.slice.call(arguments).forEach(function(a){this.hooks[a]=[]},this);for(varbinthis.hooks)a=_.values(EPUBJS.hooks[b]),a.forEach(function(a){this.registerHook(b,a)},this)},a.prototype.registerHook=function(a,b,c){"undefined"!=typeofthis.hooks[a]?"function"==typeofb?c?this.hooks[a].unshift(b):this.hooks[a].push(b):Array.isArray(b)&&b.forEach(function(b){c?this.hooks[a].unshift(b):this.hooks[a].push(b)},this):this.hooks[a]=[func]},a.prototype.triggerHooks=function(a,b,c){functiond(){f--,0>=f&&b&&b()}vare,f;return"undefined"==typeofthis.hooks[a]?!1:(e=this.hooks[a],f=e.length,0===f&&b&&b(),voide.forEach(function(a){a(d,c)}))},{register:function(a){if(void0===EPUBJS.hooks[a]&&(EPUBJS.hooks[a]={}),"object"!=typeofEPUBJS.hooks[a])throw"Already registered: "+a;returnEPUBJS.hooks[a]},mixin:function(b){for(varcina.prototype)b[c]=a.prototype[c]}}}(),EPUBJS.Layout=EPUBJS.Layout||{},EPUBJS.Layout.Reflowable=function(){this.documentElement=null,this.spreadWidth=null},EPUBJS.Layout.Reflowable.prototype.format=function(a,b,c,d){vare=EPUBJS.core.prefixed("columnAxis"),f=EPUBJS.core.prefixed("columnGap"),g=EPUBJS.core.prefixed("columnWidth"),h=EPUBJS.core.prefixed("columnFill"),i=Math.floor(b),j=Math.floor(i/8),k=d>=0?d:j%2===0?j:j-1;returnthis.documentElement=a,this.spreadWidth=i+k,a.style.overflow="hidden",a.style.width=i+"px",a.style.height=c+"px",a.style[e]="horizontal",a.style[h]="auto",a.style[g]=i+"px",a.style[f]=k+"px",this.colWidth=i,this.gap=k,{pageWidth:this.spreadWidth,pageHeight:c}},EPUBJS.Layout.Reflowable.prototype.calculatePages=function(){vara,b;returnthis.documentElement.style.width="auto",a=this.documentElement.scrollWidth,b=Math.ceil(a/this.spreadWidth),{displayedPages:b,pageCount:b}},EPUBJS.Layout.ReflowableSpreads=function(){this.documentElement=null,this.spreadWidth=null},EPUBJS.Layout.ReflowableSpreads.prototype.format=function(a,b,c,d){vare=EPUBJS.core.prefixed("columnAxis"),f=EPUBJS.core.prefixed("columnGap"),g=EPUBJS.core.prefixed("columnWidth"),h=EPUBJS.core.prefixed("columnFill"),i=2,j=Math.floor(b),k=j%2===0?j:j-1,l=Math.floor(k/8),m=d>=0?d:l%2===0?l:l-1,n=Math.floor((k-m)/i);returnthis.documentElement=a,this.spreadWidth=(n+m)*i,a.style.overflow="hidden",a.style.width=k+"px",a.style.height=c+"px",a.style[e]="horizontal",a.style[h]="auto",a.style[f]=m+"px",a.style[g]=n+"px",this.colWidth=n,this.gap=m,{pageWidth:this.spreadWidth,pageHeight:c}},EPUBJS.Layout.ReflowableSpreads.prototype.calculatePages=function(){vara=this.documentElement.scrollWidth,b=Math.ceil(a/this.spreadWidth);returnthis.documentElement.style.width=b*this.spreadWidth-this.gap+"px",{displayedPages:b,pageCount:2*b}},EPUBJS.Layout.Fixed=function(){this.documentElement=null},EPUBJS.Layout.Fixed=function(a){varb,c,d,e,f=EPUBJS.core.prefixed("columnWidth"),g=a.querySelector("[name=viewport");returnthis.documentElement=a,g&&g.hasAttribute("content")&&(b=g.getAttribute("content"),c=b.split(","),c[0]&&(d=c[0].replace("width=","")),c[1]&&(e=c[1].replace("height=",""))),a.style.width=d+"px"||"auto",a.style.height=e+"px"||"auto",a.style[f]="auto",a.style.overflow="auto",this.colWidth=d,this.gap=0,{pageWidth:d,pageHeight:e}},EPUBJS.Layout.Fixed.prototype.calculatePages=function(){return{displayedPages:1,pageCount:1}},EPUBJS.Pagination=function(a){this.pages=[],this.locations=[],this.epubcfi=newEPUBJS.EpubCFI,a&&a.length&&this.process(a)},EPUBJS.Pagination.prototype.process=function(a){a.forEach(function(a){this.pages.push(a.page),this.locations.push(a.cfi)},this),this.pageList=a,this.firstPage=parseInt(this.pages[0]),this.lastPage=parseInt(this.pages[this.pages.length-1]),this.totalPages=this.lastPage-this.firstPage},EPUBJS.Pagination.prototype.pageFromCfi=function(a){varb=-1;if(0===this.locations.length)return-1;varc=EPUBJS.core.indexOfSorted(a,this.locations,this.epubcfi.compare);return-1!=c&&c<this.pages.length-1?b=this.pages[c]:(c=EPUBJS.core.locationOf(a,this.locations,this.epubcfi.compare),b=c-1>=0?this.pages[c-1]:this.pages[0],void0!==b||(b=-1)),b
},EPUBJS.Pagination.prototype.cfiFromPage=function(a){varb=-1;"number"!=typeofa&&(a=parseInt(a));varc=this.pages.indexOf(a);return-1!=c&&(b=this.locations[c]),b},EPUBJS.Pagination.prototype.pageFromPercentage=function(a){varb=Math.round(this.totalPages*a);returnb},EPUBJS.Pagination.prototype.percentageFromPage=function(a){varb=(a-this.firstPage)/this.totalPages;returnMath.round(1e3*b)/1e3},EPUBJS.Pagination.prototype.percentageFromCfi=function(a){varb=this.pageFromCfi(a),c=this.percentageFromPage(b);returnc},EPUBJS.Parser=function(a){this.baseUrl=a||""},EPUBJS.Parser.prototype.container=function(a){varb,c,d,e;returna?(b=a.querySelector("rootfile"))?(c=b.getAttribute("full-path"),d=EPUBJS.core.uri(c).directory,e=a.xmlEncoding,{packagePath:c,basePath:d,encoding:e}):voidconsole.error("No RootFile Found"):voidconsole.error("Container File Not Found")},EPUBJS.Parser.prototype.identifier=function(a){varb;returna?(b=a.querySelector("metadata"),b?this.getElementText(b,"identifier"):voidconsole.error("No Metadata Found")):voidconsole.error("Package File Not Found")},EPUBJS.Parser.prototype.packageContents=function(a,b){varc,d,e,f,g,h,i,j,k,l,m=this;returnb&&(this.baseUrl=b),a?(c=a.querySelector("metadata"))?(d=a.querySelector("manifest"))?(e=a.querySelector("spine"))?(f=m.manifest(d),g=m.findNavPath(d),h=m.findTocPath(d),i=m.findCoverPath(d),j=Array.prototype.indexOf.call(e.parentNode.childNodes,e),k=m.spine(e,f),l={},k.forEach(function(a){l[a.href]=a.index}),{metadata:m.metadata(c),spine:k,manifest:f,navPath:g,tocPath:h,coverPath:i,spineNodeIndex:j,spineIndexByURL:l}):voidconsole.error("No Spine Found"):voidconsole.error("No Manifest Found"):voidconsole.error("No Metadata Found"):voidconsole.error("Package File Not Found")},EPUBJS.Parser.prototype.findNavPath=function(a){varb=a.querySelector("item[properties^='nav']");returnb?b.getAttribute("href"):!1},EPUBJS.Parser.prototype.findTocPath=function(a){varb=a.querySelector("item[media-type='application/x-dtbncx+xml']");returnb?b.getAttribute("href"):!1},EPUBJS.Parser.prototype.findCoverPath=function(a){varb=a.querySelector("item[properties='cover-image']");returnb?b.getAttribute("href"):!1},EPUBJS.Parser.prototype.metadata=function(a){varb={},c=this;returnb.bookTitle=c.getElementText(a,"title"),b.creator=c.getElementText(a,"creator"),b.description=c.getElementText(a,"description"),b.pubdate=c.getElementText(a,"date"),b.publisher=c.getElementText(a,"publisher"),b.identifier=c.getElementText(a,"identifier"),b.language=c.getElementText(a,"language"),b.rights=c.getElementText(a,"rights"),b.modified_date=c.querySelectorText(a,"meta[property='dcterms:modified']"),b.layout=c.querySelectorText(a,"meta[property='rendition:layout']"),b.orientation=c.querySelectorText(a,"meta[property='rendition:orientation']"),b.spread=c.querySelectorText(a,"meta[property='rendition:spread']"),b},EPUBJS.Parser.prototype.getElementText=function(a,b){varc,d=a.getElementsByTagNameNS("http://purl.org/dc/elements/1.1/",b);returnd&&0!==d.length?(c=d[0],c.childNodes.length?c.childNodes[0].nodeValue:""):""},EPUBJS.Parser.prototype.querySelectorText=function(a,b){varc=a.querySelector(b);returnc&&c.childNodes.length?c.childNodes[0].nodeValue:""},EPUBJS.Parser.prototype.manifest=function(a){varb=this.baseUrl,c={},d=a.querySelectorAll("item"),e=Array.prototype.slice.call(d);returne.forEach(function(a){vard=a.getAttribute("id"),e=a.getAttribute("href")||"",f=a.getAttribute("media-type")||"",g=a.getAttribute("properties")||"";c[d]={href:e,url:b+e,type:f,properties:g}}),c},EPUBJS.Parser.prototype.spine=function(a,b){varc=[],d=a.getElementsByTagName("itemref"),e=Array.prototype.slice.call(d),f=Array.prototype.indexOf.call(a.parentNode.childNodes,a),g=newEPUBJS.EpubCFI;returne.forEach(function(a,d){vare=a.getAttribute("idref"),h=g.generateChapterComponent(f,d,e),i=a.getAttribute("properties")||"",j=i.length?i.split(""):[],k=b[e].properties,l=k.length?k.split(""):[],m={id:e,linear:a.getAttribute("linear")||"",properties:j,manifestProperties:l,href:b[e].href,url:b[e].url,index:d,cfiBase:h,cfi:"epub("+h+")"};c.push(m)}),c},EPUBJS.Parser.prototype.nav=function(a,b,c){functiond(a){varb=[];returnArray.prototype.slice.call(a.childNodes).forEach(function(a){"ol"==a.tagName&&Array.prototype.slice.call(a.childNodes).forEach(function(a){"li"==a.tagName&&b.push(a)})}),b}functione(a){varb=null;returnArray.prototype.slice.call(a.childNodes).forEach(function(a){("a"==a.tagName||"span"==a.tagName)&&(b=a)}),b}functionf(a){varg=[],i=d(a),j=Array.prototype.slice.call(i),k=j.length;return0===k?!1:(j.forEach(function(d){vari=d.getAttribute("id")||!1,j=e(d),k=j.getAttribute("href")||"",l=j.textContent||"",m=k.split("#"),n=m[0],o=f(d),p=b[n],q=c[p],r=q?q.cfi:"";i||(p?(q=c[p],i=q.id,r=q.cfi):i="epubjs-autogen-toc-id-"+h++),d.setAttribute("id",i),g.push({id:i,href:k,label:l,subitems:o,parent:a?a.getAttribute("id"):null,cfi:r})}),g)}varg=a.querySelector('nav[*|type="toc"]'),h=0;returng?f(g):[]},EPUBJS.Parser.prototype.toc=function(a,b,c){functiond(e){varf=[],g=a.evaluate("*[local-name()='navPoint']",e,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null),h=g.snapshotLength;if(0===h)return[];for(vari=h-1;i>=0;i--){varj=g.snapshotItem(i),k=j.getAttribute("id")||!1,l=j.querySelector("content"),m=l.getAttribute("src"),n=j.querySelector("navLabel"),o=n.textContent?n.textContent:"",p=m.split("#"),q=p[0],r=b[q],s=c[r],t=d(j),u=s?s.cfi:"";k||(r?(s=c[r],k=s.id,u=s.cfi):k="epubjs-autogen-toc-id-"+idCounter++),f.unshift({id:k,href:m,label:o,spinePos:r,subitems:t,parent:e?e.getAttribute("id"):null,cfi:u})}returnf}vare=a.querySelector("navMap");returne?d(e):[]},EPUBJS.Parser.prototype.pageList=function(a){functionb(a){varb=[];returnArray.prototype.slice.call(a.childNodes).forEach(function(a){"ol"==a.tagName&&Array.prototype.slice.call(a.childNodes).forEach(function(a){"li"==a.tagName&&b.push(a)})}),b}functionc(a){varb=null;returnArray.prototype.slice.call(a.childNodes).forEach(function(a){("a"==a.tagName||"span"==a.tagName)&&(b=a)}),b}functiond(a){vard=[],e=b(a),f=Array.prototype.slice.call(e),g=f.length;return0===g?!1:(f.forEach(function(a){varb,e,f,g=(a.getAttribute("id")||!1,c(a)),h=g.getAttribute("href")||"",i=g.textContent||"",j=parseInt(i),k=h.indexOf("epubcfi");-1!=k?(b=h.split("#"),e=b[0],f=b.length>1?b[1]:!1,d.push({cfi:f,href:h,packageUrl:e,page:j})):d.push({href:h,page:j})}),d)}vare=a.querySelector('nav[*|type="page-list"]');returne?d(e):[]},EPUBJS.Render.Iframe=function(){this.iframe=null,this.document=null,this.window=null,this.docEl=null,this.bodyEl=null,this.leftPos=0,this.pageWidth=0},EPUBJS.Render.Iframe.prototype.create=function(){returnthis.iframe=document.createElement("iframe"),this.iframe.id="epubjs-iframe:"+EPUBJS.core.uuid(),this.iframe.scrolling="no",this.iframe.seamless="seamless",this.iframe.style.border="none",this.iframe.addEventListener("load",this.loaded.bind(this),!1),this.iframe},EPUBJS.Render.Iframe.prototype.load=function(a){varb=this,c=newRSVP.defer;returna.url().then(function(a){b.leftPos=0,this.window&&this.unload(),this.iframe.onload=function(){b.document=b.iframe.contentDocument,b.docEl=b.document.documentElement,b.headEl=b.document.head,b.bodyEl=b.document.body,b.window=b.iframe.contentWindow,b.window.addEventListener("resize",b.resized.bind(b),!1),b.bodyEl&&(b.bodyEl.style.margin="0"),c.resolve(b.docEl)},this.iframe.onerror=function(a){c.reject({message:"Error Loading Contents: "+a,stack:(newError).stack})},this.iframe.contentWindow.location.replace(a)}.bind(this)),c.promise},EPUBJS.Render.Iframe.prototype.loaded=function(){vara=this.iframe.contentWindow.location.href;"about:blank"!=a&&this.trigger("render:loaded",a)},EPUBJS.Render.Iframe.prototype.resize=function(a,b){this.iframe&&(this.iframe.height=b,isNaN(a)||a%2===0||(a+=1),this.iframe.width=a,this.width=this.iframe.getBoundingClientRect().width||a,this.height=this.iframe.getBoundingClientRect().height||b)},EPUBJS.Render.Iframe.prototype.resized=function(){this.width=this.iframe.getBoundingClientRect().width,this.height=this.iframe.getBoundingClientRect().height},EPUBJS.Render.Iframe.prototype.totalWidth=function(){returnthis.docEl.scrollWidth},EPUBJS.Render.Iframe.prototype.totalHeight=function(){returnthis.docEl.scrollHeight},EPUBJS.Render.Iframe.prototype.setPageDimensions=function(a,b){this.pageWidth=a,this.pageHeight=b},EPUBJS.Render.Iframe.prototype.setLeft=function(a){this.document.defaultView.scrollTo(a,0)},EPUBJS.Render.Iframe.prototype.setStyle=function(a,b,c){c&&(a=EPUBJS.core.prefixed(a)),this.bodyEl&&(this.bodyEl.style[a]=b)},EPUBJS.Render.Iframe.prototype.removeStyle=function(a){this.bodyEl&&(this.bodyEl.style[a]="")},EPUBJS.Render.Iframe.prototype.addHeadTag=function(a,b,c){vard=c||this.document,e=d.createElement(a),f=d.head;for(varginb)e.setAttribute(g,b[g]);f&&f.insertBefore(e,f.firstChild)},EPUBJS.Render.Iframe.prototype.page=function(a){this.leftPos=this.pageWidth*(a-1),this.setLeft(this.leftPos)},EPUBJS.Render.Iframe.prototype.getPageNumberByElement=function(a){varb,c;if(a)returnb=this.leftPos+a.getBoundingClientRect().left,c=Math.floor(b/this.pageWidth)+1},EPUBJS.Render.Iframe.prototype.getPageNumberByRect=function(a){varb,c;returnb=this.leftPos+a.left,c=Math.floor(b/this.pageWidth)+1},EPUBJS.Render.Iframe.prototype.getBaseElement=function(){returnthis.bodyEl},EPUBJS.Render.Iframe.prototype.isElementVisible=function(a){varb,c;returna&&"function"==typeofa.getBoundingClientRect&&(b=a.getBoundingClientRect(),c=b.left,0!==b.width&&0!==b.height&&c>=0&&c<this.pageWidth)?!0:!1},EPUBJS.Render.Iframe.prototype.scroll=function(a){this.iframe.scrolling=a?"yes":"no"},EPUBJS.Render.Iframe.prototype.unload=function(){this.window.removeEventListener("resize",this.resized)},RSVP.EventTarget.mixin(EPUBJS.Render.Iframe.prototype),EPUBJS.Renderer=function(a,b){this.listenedEvents=["keydown","keyup","keypressed","mouseup","mousedown","click"],this.upEvent="mouseup",this.downEvent="mousedown","ontouchstart"indocument.documentElement&&(this.listenedEvents.push("touchstart","touchend"),this.upEvent="touchend",this.downEvent="touchstart"),a&&"undefined"!=typeofEPUBJS.Render[a]?this.render=newEPUBJS.Render[a]:console.error("Not a Valid Rendering Method"),this.render.on("render:loaded",this.loaded.bind(this)),this.caches={},this.epubcfi=newEPUBJS.EpubCFI,this.spreads=!0,this.isForcedSingle=!1,this.resized=_.debounce(this.onResized.bind(this),100),this.layoutSettings={},this.hidden=b||!1,EPUBJS.Hooks.mixin(this),this.getHooks("beforeChapterDisplay"),this._q=EPUBJS.core.queue(this),this._moving=!1},EPUBJS.Renderer.prototype.Events=["renderer:keydown","renderer:keyup","renderer:keypressed","renderer:mouseup","renderer:mousedown","renderer:click","renderer:touchstart","renderer:touchend","renderer:selected","renderer:chapterUnloaded","renderer:chapterDisplayed","renderer:locationChanged","renderer:visibleLocationChanged","renderer:resized","renderer:spreads"],EPUBJS.Renderer.prototype.initialize=function(a,b,c){this.container=a,this.element=this.render.create(),this.initWidth=b,this.initHeight=c,this.width=b||this.container.clientWidth,this.height=c||this.container.clientHeight,this.container.appendChild(this.element),b&&c?this.render.resize(this.width,this.height):this.render.resize("100%","100%"),document.addEventListener("orientationchange",this.onResized)},EPUBJS.Renderer.prototype.displayChapter=function(a,b){returnthis._moving?voidconsole.error("Rendering In Progress"):(this._moving=!0,a.url().then(function(){returnthis.currentChapter&&(this.currentChapter.unload(),this.render.window&&this.render.window.removeEventListener("resize",this.resized),this.removeEventListeners(),this.removeSelectionListeners(),this.trigger("renderer:chapterUnloaded"),this.contents=null,this.doc=null,this.pageMap=null),this.currentChapter=a,this.chapterPos=1,this.currentChapterCfiBase=a.cfiBase,this.layoutSettings=this.reconcileLayoutSettings(b,a.properties),this.load(a)}.bind(this)))},EPUBJS.Renderer.prototype.load=function(a){varb=newRSVP.defer;returnthis.layoutMethod=this.determineLayout(this.layoutSettings),this.layout=newEPUBJS.Layout[this.layoutMethod],this.visible(!1),render=this.render.load(a),render.then(function(a){this.currentChapter.setDocument(this.render.document),this.contents=a,this.doc=this.render.document,this.formated=this.layout.format(a,this.render.width,this.render.height,this.gap),this.render.setPageDimensions(this.formated.pageWidth,this.formated.pageHeight),this.initWidth||this.initHeight||this.render.window.addEventListener("resize",this.resized,!1),this.addEventListeners(),this.addSelectionListeners(),this.beforeDisplay(function(){vara=this.layout.calculatePages(),c=this.currentChapter,d=this._q.length();this._moving=!1,this.updatePages(a),this.visibleRangeCfi=this.getVisibleRangeCfi(),this.currentLocationCfi=this.visibleRangeCfi.start,0===d&&(this.trigger("renderer:locationChanged",this.currentLocationCfi),this.trigger("renderer:visibleRangeChanged",this.visibleRangeCfi)),c.cfi=this.currentLocationCfi,this.trigger("renderer:chapterDisplayed",c),this.visible(!0),b.resolve(this)}.bind(this))}.bind(this)),b.promise},EPUBJS.Renderer.prototype.loaded=function(a){this.trigger("render:loaded",a)},EPUBJS.Renderer.prototype.reconcileLayoutSettings=function(a,b){varc={};for(vardina)a.hasOwnProperty(d)&&(c[d]=a[d]);returnb.forEach(function(a){varb,d,e=a.replace("rendition:",""),f=e.indexOf("-");-1!=f&&(b=e.slice(0,f),d=e.slice(f+1),c[b]=d)}),c},EPUBJS.Renderer.prototype.determineLayout=function(a){varb=this.determineSpreads(this.minSpreadWidth),c=b?"ReflowableSpreads":"Reflowable",d=!1;return"pre-paginated"===a.layout&&(c="Fixed",d=!0,b=!1),"reflowable"===a.layout&&"none"===a.spread&&(c="Reflowable",d=!1,b=!1),"reflowable"===a.layout&&"both"===a.spread&&(c="ReflowableSpreads",d=!1,b=!0),this.spreads=b,this.render.scroll(d),this.trigger("renderer:spreads",b),c},EPUBJS.Renderer.prototype.beforeDisplay=function(a){this.triggerHooks("beforeChapterDisplay",a,this)},EPUBJS.Renderer.prototype.updatePages=function(){this.pageMap=this.mapPage(),this.displayedPages=this.spreads?Math.ceil(this.pageMap.length/2):this.pageMap.length,this.currentChapter.pages=this.pageMap.length,this._q.flush()},EPUBJS.Renderer.prototype.reformat=function(){vara,b=this;this.contents&&(spreads=this.determineSpreads(this.minSpreadWidth),spreads!=this.spreads&&(this.spreads=spreads,this.layoutMethod=this.determineLayout(this.layoutSettings),this.layout=newEPUBJS.Layout[this.layoutMethod]),this.chapterPos=1,this.render.page(1),b.formated=b.layout.format(b.contents,b.render.width,b.render.height,b.gap),b.render.setPageDimensions(b.formated.pageWidth,b.formated.pageHeight),a=b.layout.calculatePages(),b.updatePages(a),b.currentLocationCfi&&b.gotoCfi(b.currentLocationCfi))},EPUBJS.Renderer.prototype.visible=function(a){return"undefined"==typeofa?this.element.style.visibility:void(a!==!0||this.hidden?a===!1&&(this.element.style.visibility="hidden"):this.element.style.visibility="visible")},EPUBJS.Renderer.prototype.remove=function(){this.render.window&&(this.render.unload(),this.render.window.removeEventListener("resize",this.resized),this.removeEventListeners(),this.removeSelectionListeners()),this.container.removeChild(this.element)},EPUBJS.Renderer.prototype.applyStyles=function(a){for(varbina)this.render.setStyle(b,a[b])},EPUBJS.Renderer.prototype.setStyle=function(a,b,c){this.render.setStyle(a,b,c)},EPUBJS.Renderer.prototype.removeStyle=function(a){this.render.removeStyle(a)},EPUBJS.Renderer.prototype.applyHeadTags=function(a){for(varbina)this.render.addHeadTag(b,a[b])},EPUBJS.Renderer.prototype.page=function(a){returnthis.pageMap?a>=1&&a<=this.displayedPages?(this.chapterPos=a,this.render.page(a),this.visibleRangeCfi=this.getVisibleRangeCfi(),this.currentLocationCfi=this.visibleRangeCfi.start,this.trigger("renderer:locationChanged",this.currentLocationCfi),this.trigger("renderer:visibleRangeChanged",this.visibleRangeCfi),!0):!1:(console.warn("pageMap not set, queuing"),this._q.enqueue("page",arguments),!0)},EPUBJS.Renderer.prototype.nextPage=function(){returnthis.page(this.chapterPos+1)},EPUBJS.Renderer.prototype.prevPage=function(){returnthis.page(this.chapterPos-1)},EPUBJS.Renderer.prototype.pageByElement=function(a){varb;a&&(b=this.render.getPageNumberByElement(a),this.page(b))},EPUBJS.Renderer.prototype.lastPage=function(){returnthis._moving?this._q.enqueue("lastPage",arguments):voidthis.page(this.displayedPages)},EPUBJS.Renderer.prototype.firstPage=function(){this.page(1)},EPUBJS.Renderer.prototype.section=function(a){varb=this.doc.getElementById(a);b&&this.pageByElement(b)},EPUBJS.Renderer.prototype.firstElementisTextNode=function(a){varb=a.childNodes,c=b.length;returnc&&b[0]&&3===b[0].nodeType&&b[0].textContent.trim().length?!0:!1},EPUBJS.Renderer.prototype.walk=function(a,b,c){for(vard,e,f,g,h=a,i=[h],j=1e4,k=0;!d&&i.length;){if(a=i.shift(),this.containsPoint(a,b,c)&&this.firstElementisTextNode(a)&&(d=a),!d&&a&&a.childElementCount>0){if(e=a.children,!e||!e.length)returnd;f=e.length?e.length:0;for(varl=f-1;l>=0;l--)e[l]!=g&&i.unshift(e[l])}if(!d&&0===i.length&&h&&null!==h.parentNode&&(i.push(h.parentNode),g=h,h=h.parentNode),k++,k>j){console.error("ENDLESS LOOP");break}}returnd},EPUBJS.Renderer.prototype.containsPoint=function(a,b){varc;returna&&"function"==typeofa.getBoundingClientRect&&(c=a.getBoundingClientRect(),0!==c.width&&0!==c.height&&c.left>=b&&b<=c.left+c.width)?!0:!1},EPUBJS.Renderer.prototype.textSprint=function(a,b){for(varc,d=document.createTreeWalker(a,NodeFilter.SHOW_TEXT,{acceptNode:function(a){return/^\s*$/.test(a.data)?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}},!1);c=d.nextNode();)b(c)},EPUBJS.Renderer.prototype.sprint=function(a,b){for(varc,d=document.createTreeWalker(a,NodeFilter.SHOW_ELEMENT,null,!1);c=d.nextNode();)b(c)},EPUBJS.Renderer.prototype.mapPage=function(){vara,b,c=this,d=[],e=this.render.getBaseElement(),f=1,g=this.layout.colWidth+this.layout.gap,h=this.formated.pageWidth*(this.chapterPos-1),i=g*f-h,j=0,k=function(a){varb,c,d=Array.prototype.slice.call(a.childNodes);if(a.nodeType==Node.ELEMENT_NODE){if(c=document.createRange(),c.selectNodeContents(a),b=c.getBoundingClientRect(),!b||0===b.width&&0===b.height)return;b.left>j&&d.forEach(function(a){a.nodeType==Node.TEXT_NODE&&a.textContent.trim().length&&l(a)}),b.right>j&&d.forEach(function(a){a.nodeType==Node.TEXT_NODE&&a.textContent.trim().length&&l(a)})}},l=function(e){vark=c.splitTextNodeIntoWordsRanges(e);k.forEach(function(e){vark=e.getBoundingClientRect();!k||0===k.width&&0===k.height||(k.left+k.width<i?d[f-1]||(e.collapse(!0),b=c.currentChapter.cfiFromRange(e),d.push({start:b,end:null})):(a&&(a.collapse(!0),b=c.currentChapter.cfiFromRange(a),d[d.length-1].end=b),e.collapse(!0),b=c.currentChapter.cfiFromRange(e),d.push({start:b,end:null}),f+=1,i=g*f-h,j=i),a=e)})};returnthis.sprint(e,k),a&&(a.collapse(!0),b=c.currentChapter.cfiFromRange(a),d[d.length-1].end=b),d.length||(range=this.doc.createRange(),range.selectNodeContents(e),range.collapse(!0),b=c.currentChapter.cfiFromRange(range),d.push({start:b,end:b})),a=null,ranges=null,range=null,e=null,d},EPUBJS.Renderer.prototype.splitTextNodeIntoWordsRanges=function(a){varb,c=[],d=a.textContent.trim();if(pos=d.indexOf(""),-1===pos)returnb=this.doc.createRange(),b.selectNodeContents(a),[b];for(b=this.doc.createRange(),b.setStart(a,0),b.setEnd(a,pos),c.push(b),b=!1;-1!=pos;)pos=d.indexOf("",pos+1),pos>0&&(b&&(b.setEnd(a,pos),c.push(b)),b=this.doc.createRange(),b.setStart(a,pos+1));returnb&&(b.setEnd(a,d.length),c.push(b)),c},EPUBJS.Renderer.prototype.rangePosition=function(a){varb,c;returnc=a.getClientRects(),c.length?b=c[0]:null},EPUBJS.Renderer.prototype.getPageCfi=function(){vara;returnthis.spreads?(a=2*this.chapterPos,startRange=this.pageMap[a-2]):(a=this.chapterPos,startRange=this.pageMap[a-1]),this.pageMap[2*this.chapterPos-1].start},EPUBJS.Renderer.prototype.getRange=function(a,b,c){vard,e=this.doc.createRange();returnc=!0,"undefined"==typeofdocument.caretPositionFromPoint||c?"undefined"==typeofdocument.caretRangeFromPoint||c?(this.visibileEl=this.findElementAfter(a,b),e.setStart(this.visibileEl,1)):e=this.doc.caretRangeFromPoint(a,b):(d=this.doc.caretPositionFromPoint(a,b),e.setStart(d.offsetNode,d.offset)),e},EPUBJS.Renderer.prototype.pagesInCurrentChapter=function(){vara,b;returnthis.pageMap?(b=this.pageMap.length,a=this.spreads?Math.ceil(b/2):b):(console.warn("page map not loaded"),!1)},EPUBJS.Renderer.prototype.currentRenderedPage=function(){vara;returnthis.pageMap?a=this.spreads&&this.layout.pageCount>1?2*this.chapterPos:this.chapterPos:(console.warn("page map not loaded"),!1)},EPUBJS.Renderer.prototype.getRenderedPagesLeft=function(){vara,b,c;returnthis.pageMap?(b=this.pageMap.length,a=this.spreads?2*this.chapterPos:this.chapterPos,c=b-a):(console.warn("page map not loaded"),!1)},EPUBJS.Renderer.prototype.getVisibleRangeCfi=function(){vara,b,c;returnthis.pageMap?(this.spreads?(a=2*this.chapterPos,b=this.pageMap[a-2],c=b,this.layout.pageCount>1&&(c=this.pageMap[a-1])):(a=this.chapterPos,b=this.pageMap[a-1],c=b),b||(console.warn("page range miss:",a,this.pageMap),b=this.pageMap[this.pageMap.length-1],c=b),{start:b.start,end:c.end}):(console.warn("page map not loaded"),!1)},EPUBJS.Renderer.prototype.gotoCfi=function(a){varb,c,d;returnthis._moving?this._q.enqueue("gotoCfi",arguments):(_.isString(a)&&(a=this.epubcfi.parse(a)),void("undefined"==typeofdocument.evaluate?(c=this.epubcfi.addMarker(a,this.doc),c&&(b=this.render.getPageNumberByElement(c),this.epubcfi.removeMarker(c,this.doc),this.page(b))):(d=this.epubcfi.generateRangeFromCfi(a,this.doc),d&&(b=this.render.getPageNumberByRect(d.getBoundingClientRect()),this.page(b),this.currentLocationCfi=a.str))))},EPUBJS.Renderer.prototype.findFirstVisible=function(a){varb,c=a||this.render.getBaseElement();returnb=this.walk(c),b?b:a},EPUBJS.Renderer.prototype.findElementAfter=function(a,b,c){vard,e=c||this.render.getBaseElement();returnd=this.walk(e,a,b),d?d:e},EPUBJS.Renderer.prototype.resize=function(a,b,c){this.width=a,this.height=b,c!==!1&&this.render.resize(this.width,this.height),this.contents&&this.reformat(),this.trigger("renderer:resized",{width:this.width,height:this.height})},EPUBJS.Renderer.prototype.onResized=function(){vara=this.container.clientWidth,b=this.container.clientHeight;this.resize(a,b,!1)},EPUBJS.Renderer.prototype.addEventListeners=function(){this.render.document&&this.listenedEvents.forEach(function(a){this.render.document.addEventListener(a,this.triggerEvent.bind(this),!1)},this)},EPUBJS.Renderer.prototype.removeEventListeners=function(){this.render.document&&this.listenedEvents.forEach(function(a){this.render.document.removeEventListener(a,this.triggerEvent,!1)},this)},EPUBJS.Renderer.prototype.triggerEvent=function(a){this.trigger("renderer:"+a.type,a)},EPUBJS.Renderer.prototype.addSelectionListeners=function(){this.render.document.addEventListener("selectionchange",this.onSelectionChange.bind(this),!1)},EPUBJS.Renderer.prototype.removeSelectionListeners=function(){this.render.document&&this.doc.removeEventListener("selectionchange",this.onSelectionChange,!1)},EPUBJS.Renderer.prototype.onSelectionChange=function(){this.selectionEndTimeout&&clearTimeout(this.selectionEndTimeout),this.selectionEndTimeout=setTimeout(function(){this.selectedRange=this.render.window.getSelection(),this.trigger("renderer:selected",this.selectedRange)}.bind(this),500)},EPUBJS.Renderer.prototype.setMinSpreadWidth=function(a){this.minSpreadWidth=a,this.spreads=this.determineSpreads(a)},EPUBJS.Renderer.prototype.determineSpreads=function(a){returnthis.isForcedSingle||!a||this.width<a?!1:!0},EPUBJS.Renderer.prototype.forceSingle=function(a){this.isForcedSingle=a?!0:!1},EPUBJS.Renderer.prototype.setGap=function(a){this.gap=a},EPUBJS.Renderer.prototype.replace=function(a,b,c,d){vare=this.contents.querySelectorAll(a),f=Array.prototype.slice.call(e),g=f.length;return0===g?voidc(!1):voidf.forEach(function(a){vare=!1,f=function(a,b){e===!1&&(g--,d&&d(a,b,g),0>=g&&c&&c(!0),e=!0)};b(a,f)}.bind(this))},EPUBJS.Renderer.prototype.replaceWithStored=function(a,b,c,d){vare,f={},g=this.currentChapter.store,h=this.caches[a],i=EPUBJS.core.uri(this.currentChapter.absolute),j=i.base,k=b,l=2e3,m=function(a,b){f[b]=a},n=function(){d&&d(),_.each(e,function(a){g.revokeUrl(a)}),h=f};g&&(h||(h={}),e=_.clone(h),this.replace(a,function(b,d){varh=b.getAttribute(k),i=EPUBJS.core.resolveUrl(j,h),m=function(c){vare;b.onload=function(){clearTimeout(e),d(c,i)},b.onerror=function(a){clearTimeout(e),d(c,i),console.error(a)},"image"==a&&b.setAttribute("externalResourcesRequired","true"),"link[href]"==a&&"stylesheet"!==b.getAttribute("rel")&&d(c,i),b.setAttribute(k,c),e=setTimeout(function(){d(c,i)},l)};iine?(m(e[i]),f[i]=e[i],deletee[i]):c(g,i,m,b)},n,m))},RSVP.EventTarget.mixin(EPUBJS.Renderer.prototype);varEPUBJS=EPUBJS||{};EPUBJS.replace={},EPUBJS.replace.hrefs=function(a,b){varc=this,d=function(a,d){vare,f,g=a.getAttribute("href"),h=g.search("://");-1!=h?a.setAttribute("target","_blank"):(e=EPUBJS.core.uri(b.render.window.location.href).directory,f=EPUBJS.core.resolveUrl(e,g),a.onclick=function(){returnc.goto(f),!1}),d()};b.replace("a[href]",d,a)},EPUBJS.replace.head=function(a,b){b.replaceWithStored("link[href]","href",EPUBJS.replace.links,a)},EPUBJS.replace.resources=function(a,b){b.replaceWithStored("[src]","src",EPUBJS.replace.srcs,a)},EPUBJS.replace.svg=function(a,b){b.replaceWithStored("image","xlink:href",function(a,b,c){a.getUrl(b).then(c)},a)},EPUBJS.replace.srcs=function(a,b,c){a.getUrl(b).then(c)},EPUBJS.replace.links=function(a,b,c,d){"stylesheet"===d.getAttribute("rel")?EPUBJS.replace.stylesheets(a,b).then(function(a,b){setTimeout(function(){c(a,b)},5)}):a.getUrl(b).then(c)},EPUBJS.replace.stylesheets=function(a,b){varc=newRSVP.defer;if(a)returna.getText(b).then(function(d){EPUBJS.replace.cssUrls(a,b,d).then(function(a){varb=window.URL||window.webkitURL||window.mozURL,d=newBlob([a],{type:"text/css"}),e=b.createObjectURL(d);c.resolve(e)},function(a){console.error(a)})}),c.promise},EPUBJS.replace.cssUrls=function(a,b,c){vard=newRSVP.defer,e=[],f=c.match(/url\(\'?\"?([^\'|^\"^\)]*)\'?\"?\)/g);if(a)returnf?(f.forEach(function(d){varf=EPUBJS.core.resolveUrl(b,d.replace(/url\(|[|\)|\'|\"]/g,"")),g=a.getUrl(f).then(function(a){c=c.replace(d,'url("'+a+'")')});e.push(g)}),RSVP.all(e).then(function(){d.resolve(c)}),d.promise):(d.resolve(c),d.promise)},EPUBJS.Unarchiver=function(a){returnthis.libPath=EPUBJS.filePath,this.zipUrl=a,this.loadLib(),this.urlCache={},this.zipFs=newzip.fs.FS,this.promise},EPUBJS.Unarchiver.prototype.loadLib=function(){"undefined"==typeofzip&&console.error("Zip lib not loaded"),zip.workerScriptsPath=this.libPath},EPUBJS.Unarchiver.prototype.openZip=function(a){varb=newRSVP.defer,c=this.zipFs;returnc.importHttpContent(a,!1,function(){b.resolve(c)},this.failed),b.promise},EPUBJS.Unarchiver.prototype.getXml=function(a,b){returnthis.getText(a,b).then(function(a){varb=newDOMParser;returnb.parseFromString(a,"application/xml")})},EPUBJS.Unarchiver.prototype.getUrl=function(a,b){varc=this,d=newRSVP.defer,e=window.decodeURIComponent(a),f=this.zipFs.find(e),g=window.URL||window.webkitURL||window.mozURL;returnf?ainthis.urlCache?(d.resolve(this.urlCache[a]),d.promise):(f.getBlob(b||zip.getMimeType(f.name),function(b){vare=g.createObjectURL(b);d.resolve(e),c.urlCache[a]=e}),d.promise):(d.reject({message:"File not found in the epub: "+a,stack:(newError).stack}),d.promise)},EPUBJS.Unarchiver.prototype.getText=function(a,b){{varc=newRSVP.defer,d=window.decodeURIComponent(a),e=this.zipFs.find(d);window.URL||window.webkitURL||window.mozURL}returne?(e.getText(function(a){c.resolve(a)},null,null,b||"UTF-8"),c.promise):(console.warn("File not found in the contained epub:",a),c.promise)},EPUBJS.Unarchiver.prototype.revokeUrl=function(a){varb=window.URL||window.webkitURL||window.mozURL,c=unarchiver.urlCache[a];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){functionb(){f--,0===f&&e.afterSaved()}varc=0,d=20,e=this,f=