=128&&s("not-basic"),g.push(t.charCodeAt(n));for(r=i>0?i+1:0;r=m&&s("invalid-input"),u=l(t.charCodeAt(r++)),(u>=x||u>P((w-v)/a))&&s("overflow"),v+=u*a,p=h<=b?_:h>=b+T?T:h-b,!(uP(w/f)&&s("overflow"),a*=f;e=g.length+1,b=d(v-o,e,0==o),P(v/e)>w-y&&s("overflow"),y+=P(v/e),v%=e,g.splice(v++,0,y)}return c(g)}function g(t){var e,i,n,r,o,a,h,c,l,f,g,m,v,y,b,k=[];for(t=u(t),m=t.length,e=z,i=0,o=E,a=0;a=e&&gP((w-i)/v)&&s("overflow"),i+=(h-e)*v,e=h,a=0;aw&&s("overflow"),g==e){for(c=i,l=x;f=l<=o?_:l>=o+T?T:l-o,!(c= 0x80 (not a basic code point)","invalid-input":"Invalid input"},R=x-_,P=Math.floor,j=String.fromCharCode;b={version:"1.3.2",ucs2:{decode:u,encode:c},decode:f,encode:g,toASCII:v,toUnicode:m},n=function(){return b}.call(e,i,e,t),!(void 0!==n&&(t.exports=n))}(this)}).call(e,i(8)(t),function(){return this}())},function(t,e){t.exports=function(t){return t.webpackPolyfill||(t.deprecate=function(){},t.paths=[],t.children=[],t.webpackPolyfill=1),t}},function(t,e,i){/*!
+!function(e,n){"use strict";t.exports=n(i(18),i(20),i(21))}(this,function(t,e,i,n){"use strict";function r(t,e){var i=arguments.length>=1,n=arguments.length>=2;if(!(this instanceof r))return i?n?new r(t,e):new r(t):new r;if(void 0===t){if(i)throw new TypeError("undefined is not a valid argument for URI");t="undefined"!=typeof location?location.href+"":""}return this.href(t),void 0!==e?this.absoluteTo(e):this}function o(t){return t.replace(/([.*+?^=!:${}()|[\]\/\\])/g,"\\$1")}function s(t){return void 0===t?"Undefined":String(Object.prototype.toString.call(t)).slice(8,-1)}function a(t){return"Array"===s(t)}function h(t,e){var i,n,r={};if("RegExp"===s(e))r=null;else if(a(e))for(i=0,n=e.length;i]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/gi,r.findUri={start:/\b(?:([a-z][a-z0-9.+-]*:\/\/)|www\.)/gi,end:/[\s\r\n]|$/,trim:/[`!()\[\]{};:'".,<>?«»“”„‘’]+$/},r.defaultPorts={http:"80",https:"443",ftp:"21",gopher:"70",ws:"80",wss:"443"},r.invalid_hostname_characters=/[^a-zA-Z0-9\.-]/,r.domAttributes={a:"href",blockquote:"cite",link:"href",base:"href",script:"src",form:"action",img:"src",area:"href",iframe:"src",embed:"src",source:"src",track:"src",input:"src",audio:"src",video:"src"},r.getDomAttribute=function(t){if(t&&t.nodeName){var e=t.nodeName.toLowerCase();if("input"!==e||"image"===t.type)return r.domAttributes[e]}},r.encode=d,r.decode=decodeURIComponent,r.iso8859=function(){r.encode=escape,r.decode=unescape},r.unicode=function(){r.encode=d,r.decode=decodeURIComponent},r.characters={pathname:{encode:{expression:/%(24|26|2B|2C|3B|3D|3A|40)/gi,map:{"%24":"$","%26":"&","%2B":"+","%2C":",","%3B":";","%3D":"=","%3A":":","%40":"@"}},decode:{expression:/[\/\?#]/g,map:{"/":"%2F","?":"%3F","#":"%23"}}},reserved:{encode:{expression:/%(21|23|24|26|27|28|29|2A|2B|2C|2F|3A|3B|3D|3F|40|5B|5D)/gi,map:{"%3A":":","%2F":"/","%3F":"?","%23":"#","%5B":"[","%5D":"]","%40":"@","%21":"!","%24":"$","%26":"&","%27":"'","%28":"(","%29":")","%2A":"*","%2B":"+","%2C":",","%3B":";","%3D":"="}}},urnpath:{encode:{expression:/%(21|24|27|28|29|2A|2B|2C|3B|3D|40)/gi,map:{"%21":"!","%24":"$","%27":"'","%28":"(","%29":")","%2A":"*","%2B":"+","%2C":",","%3B":";","%3D":"=","%40":"@"}},decode:{expression:/[\/\?#:]/g,map:{"/":"%2F","?":"%3F","#":"%23",":":"%3A"}}}},r.encodeQuery=function(t,e){var i=r.encode(t+"");return void 0===e&&(e=r.escapeQuerySpace),e?i.replace(/%20/g,"+"):i},r.decodeQuery=function(t,e){t+="",void 0===e&&(e=r.escapeQuerySpace);try{return r.decode(e?t.replace(/\+/g,"%20"):t)}catch(i){return t}};var b,w={encode:"encode",decode:"decode"},x=function(t,e){return function(i){try{return r[e](i+"").replace(r.characters[t][e].expression,function(i){return r.characters[t][e].map[i]})}catch(n){return i}}};for(b in w)r[b+"PathSegment"]=x("pathname",w[b]),r[b+"UrnPathSegment"]=x("urnpath",w[b]);var _=function(t,e,i){return function(n){var o;o=i?function(t){return r[e](r[i](t))}:r[e];for(var s=(n+"").split(t),a=0,h=s.length;a-1&&(e.fragment=t.substring(i+1)||null,t=t.substring(0,i)),i=t.indexOf("?"),i>-1&&(e.query=t.substring(i+1)||null,t=t.substring(0,i)),"//"===t.substring(0,2)?(e.protocol=null,t=t.substring(2),t=r.parseAuthority(t,e)):(i=t.indexOf(":"),i>-1&&(e.protocol=t.substring(0,i)||null,e.protocol&&!e.protocol.match(r.protocol_expression)?e.protocol=void 0:"//"===t.substring(i+1,i+3)?(t=t.substring(i+3),t=r.parseAuthority(t,e)):(t=t.substring(i+1),e.urn=!0))),e.path=t,e},r.parseHost=function(t,e){t=t.replace(/\\/g,"/");var i,n,r=t.indexOf("/");if(r===-1&&(r=t.length),"["===t.charAt(0))i=t.indexOf("]"),e.hostname=t.substring(1,i)||null,e.port=t.substring(i+2,r)||null,"/"===e.port&&(e.port=null);else{var o=t.indexOf(":"),s=t.indexOf("/"),a=t.indexOf(":",o+1);a!==-1&&(s===-1||a-1?n:t.length-1);return o>-1&&(n===-1||o1&&(n=i[0]+"@",t=i[1]),t=t.replace(N,".");var r=t.split("."),o=a(r,e).join(".");return n+o}function c(t){for(var e,i,n=[],r=0,o=t.length;r=55296&&e<=56319&&r65535&&(t-=65536,e+=O(t>>>10&1023|55296),t=56320|1023&t),e+=O(t)}).join("")}function p(t){return t-48<10?t-22:t-65<26?t-65:t-97<26?t-97:x}function l(t,e){return t+22+75*(t<26)-((0!=e)<<5)}function d(t,e,i){var n=0;for(t=i?P(t/E):t>>1,t+=P(t/e);t>R*k>>1;n+=x)t=P(t/R);return P(n+(R+1)*t/(t+S))}function f(t){var e,i,n,r,o,a,h,c,l,f,g=[],m=t.length,v=0,y=z,b=T;for(i=t.lastIndexOf(C),i<0&&(i=0),n=0;n=128&&s("not-basic"),g.push(t.charCodeAt(n));for(r=i>0?i+1:0;r=m&&s("invalid-input"),c=p(t.charCodeAt(r++)),(c>=x||c>P((w-v)/a))&&s("overflow"),v+=c*a,l=h<=b?_:h>=b+k?k:h-b,!(cP(w/f)&&s("overflow"),a*=f;e=g.length+1,b=d(v-o,e,0==o),P(v/e)>w-y&&s("overflow"),y+=P(v/e),v%=e,g.splice(v++,0,y)}return u(g)}function g(t){var e,i,n,r,o,a,h,u,p,f,g,m,v,y,b,S=[];for(t=c(t),m=t.length,e=z,i=0,o=T,a=0;a=e&&gP((w-i)/v)&&s("overflow"),i+=(h-e)*v,e=h,a=0;aw&&s("overflow"),g==e){for(u=i,p=x;f=p<=o?_:p>=o+k?k:p-o,!(u= 0x80 (not a basic code point)","invalid-input":"Invalid input"},R=x-_,P=Math.floor,O=String.fromCharCode;b={version:"1.3.2",ucs2:{decode:c,encode:u},decode:f,encode:g,toASCII:v,toUnicode:m},n=function(){return b}.call(e,i,e,t),!(void 0!==n&&(t.exports=n))}(this)}).call(e,i(19)(t),function(){return this}())},function(t,e){t.exports=function(t){return t.webpackPolyfill||(t.deprecate=function(){},t.paths=[],t.children=[],t.webpackPolyfill=1),t}},function(t,e,i){/*!
* URI.js - Mutating URLs
* IPv6 Support
*
@@ -30,7 +23,7 @@
* MIT License http://www.opensource.org/licenses/mit-license
*
*/
-!function(e,i){"use strict";t.exports=i()}(this,function(t){"use strict";function e(t){var e=t.toLowerCase(),i=e.split(":"),n=i.length,r=8;""===i[0]&&""===i[1]&&""===i[2]?(i.shift(),i.shift()):""===i[0]&&""===i[1]?i.shift():""===i[n-1]&&""===i[n-2]&&i.pop(),n=i.length,i[n-1].indexOf(".")!==-1&&(r=7);var o;for(o=0;o1);h++)s.splice(0,1);i[a]=s.join("")}var u=-1,c=0,l=0,p=-1,d=!1;for(a=0;ac&&(u=p,c=l)):"0"===i[a]&&(d=!0,p=a,l=1);l>c&&(u=p,c=l),c>1&&i.splice(u,c,""),n=i.length;var f="";for(""===i[0]&&(f=":"),a=0;a1);h++)s.splice(0,1);i[a]=s.join("")}var c=-1,u=0,p=0,l=-1,d=!1;for(a=0;au&&(c=l,u=p)):"0"===i[a]&&(d=!0,l=a,p=1);p>u&&(c=l,u=p),u>1&&i.splice(c,u,""),n=i.length;var f="";for(""===i[0]&&(f=":"),a=0;a=t.length-1)return!1;var n=t.lastIndexOf(".",e-1);if(n<=0||n>=e-1)return!1;var r=i.list[t.slice(e+1)];return!!r&&r.indexOf(" "+t.slice(n+1,e)+" ")>=0},is:function(t){var e=t.lastIndexOf(".");if(e<=0||e>=t.length-1)return!1;var n=t.lastIndexOf(".",e-1);if(n>=0)return!1;var r=i.list[t.slice(e+1)];return!!r&&r.indexOf(" "+t.slice(0,e)+" ")>=0},get:function(t){var e=t.lastIndexOf(".");if(e<=0||e>=t.length-1)return null;var n=t.lastIndexOf(".",e-1);if(n<=0||n>=e-1)return null;var r=i.list[t.slice(e+1)];return r?r.indexOf(" "+t.slice(n+1,e)+" ")<0?null:t.slice(n+1):null},noConflict:function(){return t.SecondLevelDomains===this&&(t.SecondLevelDomains=e),this}};return i})},function(t,e,i){function n(t){return!(!t||1!=t.nodeType)}function r(){var t=(new Date).getTime(),e="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var i=(t+16*Math.random())%16|0;return t=Math.floor(t/16),("x"==e?i:7&i|8).toString(16)});return e}function o(t){for(var e=-1,i=Object.keys(t),n=i.length,r=Array(n);++ee?1:t0?h:h+1:0===o?h:o===-1?d(t,e,i,h,a):d(t,e,i,s,h))}function f(t,e,i,n,r){var o,s=n||0,a=r||e.length,h=parseInt(s+(a-s)/2);return i||(i=function(t,e){return t>e?1:t-1}function x(t,e){var i=new Blob([t],{type:e});return i}function _(t,e){var i,n=window.URL||window.webkitURL||window.mozURL,r=this.createBlob(t,e);return i=n.createObjectURL(r)}function T(t,e){var i,n;if("string"==typeof t)return i=btoa(t),n="data:"+e+";base64,"+i}function k(t){return Object.prototype.toString.call(t).slice(8,-1)}function S(t,e){var n;return"undefined"==typeof DOMParser&&(DOMParser=i(13).DOMParser),n=(new DOMParser).parseFromString(t,e)}function E(t,e){var i;return"undefined"!=typeof t.querySelector?t.querySelector(e):(i=t.getElementsByTagName(e),i.length?i[0]:void 0)}function z(t,e){return"undefined"!=typeof t.querySelector?t.querySelectorAll(e):t.getElementsByTagName(e)}function C(t,e,i){var n,r;if("undefined"!=typeof t.querySelector){e+="[";for(var o in i)e+=o+"='"+i[o]+"'";return e+="]",t.querySelector(e)}if(n=t.getElementsByTagName(e),r=Array.prototype.slice.call(n,0).filter(function(t){for(var e in i)if(t.getAttribute(e)===i[e])return!0;return!1}))return r[0]}function A(t,e){var i=new FileReader;i.readAsDataURL(t),i.onloadend=function(){e(i.result)}}var q=(i(2),i(12),"undefined"!=typeof window&&(window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame));t.exports={isElement:n,uuid:r,values:o,resolveUrl:s,indexOfSorted:f,documentHeight:a,isNumber:h,prefixed:u,defaults:c,extend:l,insert:p,locationOf:d,indexOfSorted:f,requestAnimationFrame:q,bounds:g,borders:m,windowBounds:v,cleanStringForXpath:y,indexOfTextNode:b,isXml:w,createBlob:x,createBlobUrl:_,type:k,parse:S,qs:E,qsa:z,qsp:C,blob2base64:A,createBase64Url:T}},function(t,e){"use strict";function i(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");return"="===t[e-2]?2:"="===t[e-1]?1:0}function n(t){return 3*t.length/4-i(t)}function r(t){var e,n,r,o,s,a,h=t.length;s=i(t),a=new c(3*h/4-s),r=s>0?h-4:h;var l=0;for(e=0,n=0;e>16&255,a[l++]=o>>8&255,a[l++]=255&o;return 2===s?(o=u[t.charCodeAt(e)]<<2|u[t.charCodeAt(e+1)]>>4,a[l++]=255&o):1===s&&(o=u[t.charCodeAt(e)]<<10|u[t.charCodeAt(e+1)]<<4|u[t.charCodeAt(e+2)]>>2,a[l++]=o>>8&255,a[l++]=255&o),a}function o(t){return h[t>>18&63]+h[t>>12&63]+h[t>>6&63]+h[63&t]}function s(t,e,i){for(var n,r=[],s=e;sc?c:u+a));return 1===n?(e=t[i-1],r+=h[e>>2],r+=h[e<<4&63],r+="=="):2===n&&(e=(t[i-2]<<8)+t[i-1],r+=h[e>>10],r+=h[e>>4&63],r+=h[e<<2&63],r+="="),o.push(r),o.join("")}e.byteLength=n,e.toByteArray=r,e.fromByteArray=a;for(var h=[],u=[],c="undefined"!=typeof Uint8Array?Uint8Array:Array,l="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",p=0,d=l.length;p-1)return delete this.spineByHref[t.href],delete this.spineById[t.idref],this.spineItems.splice(e,1)},n.prototype.each=function(){return this.spineItems.forEach.apply(this.spineItems,arguments)},t.exports=n},function(t,e,i){function n(t,e,i){var o;if(this.str="",this.base={},this.spinePos=0,this.range=!1,this.path={},this.start=null,this.end=null,!(this instanceof n))return new n(t,e,i);if("string"==typeof e?this.base=this.parseComponent(e):"object"==typeof e&&e.steps&&(this.base=e),o=this.checkType(t),"string"===o)return this.str=t,r.extend(this,this.parse(t));if("range"===o)return r.extend(this,this.fromRange(t,this.base,i));if("node"===o)return r.extend(this,this.fromNode(t,this.base,i));if("EpubCFI"===o&&t.path)return t;if(t)throw new TypeError("not a valid argument for EpubCFI");return this}var r=(i(6),i(11));n.prototype.checkType=function(t){return this.isCfiString(t)?"string":"object"==typeof t&&"Range"===r.type(t)?"range":"object"==typeof t&&"undefined"!=typeof t.nodeType?"node":"object"==typeof t&&t instanceof n&&"EpubCFI"},n.prototype.parse=function(t){var e,i,n,r={spinePos:-1,range:!1,base:{},path:{},start:null,end:null};return"string"!=typeof t?{spinePos:-1}:(0===t.indexOf("epubcfi(")&&")"===t[t.length-1]&&(t=t.slice(8,t.length-1)),(e=this.getChapterComponent(t))?(r.base=this.parseComponent(e),i=this.getPathComponent(t),r.path=this.parseComponent(i),n=this.getRange(t),n&&(r.range=!0,r.start=this.parseComponent(n[0]),r.end=this.parseComponent(n[1])),r.spinePos=r.base.steps[1].index,r):{spinePos:-1})},n.prototype.parseComponent=function(t){var e,i={steps:[],terminal:{offset:null,assertion:null}},n=t.split(":"),r=n[0].split("/");return n.length>1&&(e=n[1],i.terminal=this.parseTerminal(e)),""===r[0]&&r.shift(),i.steps=r.map(function(t){return this.parseStep(t)}.bind(this)),i},n.prototype.parseStep=function(t){var e,i,n,r,o;if(r=t.match(/\[(.*)\]/),r&&r[1]&&(o=r[1]),i=parseInt(t),!isNaN(i))return i%2===0?(e="element",n=i/2-1):(e="text",n=(i-1)/2),{type:e,index:n,id:o||null}},n.prototype.parseTerminal=function(t){var e,i,n=t.match(/\[(.*)\]/);return n&&n[1]?(e=parseInt(t.split("[")[0])||null,i=n[1]):e=parseInt(t)||null,{offset:e,assertion:i}},n.prototype.getChapterComponent=function(t){var e=t.split("!");return e[0]},n.prototype.getPathComponent=function(t){var e=t.split("!");if(e[1])return ranges=e[1].split(","),ranges[0]},n.prototype.getRange=function(t){var e=t.split(",");return 3===e.length&&[e[1],e[2]]},n.prototype.getCharecterOffsetComponent=function(t){var e=t.split(":");return e[1]||""},n.prototype.joinSteps=function(t){return t?t.map(function(t){var e="";return"element"===t.type&&(e+=2*(t.index+1)),"text"===t.type&&(e+=1+2*t.index),t.id&&(e+="["+t.id+"]"),e}).join("/"):""},n.prototype.segmentString=function(t){var e="/";return e+=this.joinSteps(t.steps),t.terminal&&null!=t.terminal.offset&&(e+=":"+t.terminal.offset),t.terminal&&null!=t.terminal.assertion&&(e+="["+t.terminal.assertion+"]"),e},n.prototype.toString=function(){var t="epubcfi(";return t+=this.segmentString(this.base),t+="!",t+=this.segmentString(this.path),this.start&&(t+=",",t+=this.segmentString(this.start)),this.end&&(t+=",",t+=this.segmentString(this.end)),t+=")"},n.prototype.compare=function(t,e){if("string"==typeof t&&(t=new n(t)),"string"==typeof e&&(e=new n(e)),t.spinePos>e.spinePos)return 1;if(t.spinePose.path.steps[i].index)return 1;if(t.path.steps[i].indexe.path.terminal.offset?1:t.path.terminal.offset=0&&(r.terminal.offset=e,"text"!=r.steps[r.steps.length-1].type&&r.steps.push({type:"text",index:0})),r},n.prototype.equalStep=function(t,e){return!(!t||!e)&&(t.index===e.index&&t.id===e.id&&t.type===e.type)},n.prototype.fromRange=function(t,e,i){var n={range:!1,base:{},path:{},start:null,end:null},r=t.startContainer,o=t.endContainer,s=t.startOffset,a=t.endOffset,h=!1;if(i&&(h=null!=r.ownerDocument.querySelector("."+i)),"string"==typeof e?(n.base=this.parseComponent(e),n.spinePos=n.base.steps[1].index):"object"==typeof e&&(n.base=e),t.collapsed)h&&(s=this.patchOffset(r,s,i)),n.path=this.pathTo(r,s,i);else{n.range=!0,h&&(s=this.patchOffset(r,s,i)),n.start=this.pathTo(r,s,i),h&&(a=this.patchOffset(o,a,i)),n.end=this.pathTo(o,a,i),n.path={steps:[],terminal:null};var u,c=n.start.steps.length;for(u=0;u0&&r===Node.TEXT_NODE&&o===Node.TEXT_NODE?s[n]=a:e===r&&(a+=1,s[n]=a),o=r;return s},n.prototype.position=function(t){var e,i;return t.nodeType===Node.ELEMENT_NODE?(e=t.parentNode.children,i=Array.prototype.indexOf.call(e,t)):(e=this.textNodes(t.parentNode),i=e.indexOf(t)),i},n.prototype.filteredPosition=function(t,e){var i,n,r;return t.nodeType===Node.ELEMENT_NODE?(i=t.parentNode.children,r=this.normalizedMap(i,Node.ELEMENT_NODE,e)):(i=t.parentNode.childNodes,t.parentNode.classList.contains(e)&&(t=t.parentNode,i=t.parentNode.childNodes),r=this.normalizedMap(i,Node.TEXT_NODE,e)),n=Array.prototype.indexOf.call(i,t),r[n]},n.prototype.stepsToXpath=function(t){var e=[".","*"];return t.forEach(function(t){var i=t.index+1;t.id?e.push("*[position()="+i+" and @id='"+t.id+"']"):"text"===t.type?e.push("text()["+i+"]"):e.push("*["+i+"]")}),e.join("/")},n.prototype.stepsToQuerySelector=function(t){var e=["html"];return t.forEach(function(t){var i=t.index+1;t.id?e.push("#"+t.id):"text"===t.type||e.push("*:nth-child("+i+")")}),e.join(">")},n.prototype.textNodes=function(t,e){return Array.prototype.slice.call(t.childNodes).filter(function(t){return t.nodeType===Node.TEXT_NODE||!(!e||!t.classList.contains(e))})},n.prototype.walkToNode=function(t,e,i){var n,r,o=e||document,s=o.documentElement,a=t.length;for(r=0;ro)){a=r.nodeType===Node.ELEMENT_NODE?r.childNodes[0]:r;break}e-=o}}return{container:a,offset:e}},n.prototype.toRange=function(t,e){var i,n,r,o,s,a,h,u=t||document,c=u.createRange(),l=this,p=!!e&&null!=u.querySelector("."+e);if(l.range?(i=l.start,s=l.path.steps.concat(i.steps),r=this.findNode(s,u,p?e:null),n=l.end,a=l.path.steps.concat(n.steps),o=this.findNode(a,u,p?e:null)):(i=l.path,s=l.path.steps,r=this.findNode(l.path.steps,u,p?e:null)),!r)return null;try{null!=i.terminal.offset?c.setStart(r,i.terminal.offset):c.setStart(r,0)}catch(d){h=this.fixMiss(s,i.terminal.offset,u,p?e:null),c.setStart(h.container,h.offset)}if(o)try{null!=n.terminal.offset?c.setEnd(o,n.terminal.offset):c.setEnd(o,0)}catch(d){h=this.fixMiss(a,l.end.terminal.offset,u,p?e:null),c.setEnd(h.container,h.offset)}return c},n.prototype.isCfiString=function(t){return"string"==typeof t&&0===t.indexOf("epubcfi(")&&")"===t[t.length-1]},n.prototype.generateChapterComponent=function(t,e,i){var n=parseInt(e),r=t+1,o="/"+r+"/";return o+=2*(n+1),i&&(o+="["+i+"]"),o},t.exports=n},function(t,e,i){function n(t){this.context=t||this,this.hooks=[]}var r=i(2);n.prototype.register=function(){for(var t=0;ts&&(r+=s,a=s);a=s?r=s-(a-this["break"]):(i.setEnd(e,a),cfi=t.cfiFromRange(i),this._locations.push(cfi),r=0,a+=1,i=n.createRange(),i.setStart(e,a))}.bind(this)),i&&(i.setEnd(prev,prev.length),cfi=t.cfiFromRange(i),this._locations.push(cfi),r=0)}.bind(this))},n.prototype.sprint=function(t,e){for(var i=document.createTreeWalker(t,NodeFilter.SHOW_TEXT,null,!1);node=i.nextNode();)e(node)},n.prototype.locationFromCfi=function(t){
-return 0===this._locations.length?-1:r.locationOf(t,this._locations,this.epubcfi.compare)},n.prototype.precentageFromCfi=function(t){var e=this.locationFromCfi(t);return this.precentageFromLocation(e)},n.prototype.percentageFromLocation=function(t){return t&&this.total?t/this.total:0},n.prototype.cfiFromLocation=function(t){var e=-1;return"number"!=typeof t&&(t=parseInt(pg)),t>=0&&t1?t/100:t,i=Math.ceil(this.total*e);return this.cfiFromLocation(i)},n.prototype.load=function(t){return this._locations=JSON.parse(t),this.total=this._locations.length-1,this._locations},n.prototype.save=function(t){return JSON.stringify(this._locations)},n.prototype.getCurrent=function(t){return this._current},n.prototype.setCurrent=function(t){var e;if("string"==typeof t)this._currentCfi=t;else{if("number"!=typeof t)return;this._current=t}0!==this._locations.length&&("string"==typeof t?(e=this.locationFromCfi(t),this._current=e):e=t,this.trigger("changed",{percentage:this.precentageFromLocation(e)}))},Object.defineProperty(n.prototype,"currentLocation",{get:function(){return this._current},set:function(t){this.setCurrent(t)}}),a.EventTarget.mixin(n.prototype),t.exports=n},function(t,e,i){function n(t){this._q=[],this.context=t,this.tick=o.requestAnimationFrame,this.running=!1,this.paused=!1}var r=i(2),o=i(11);n.prototype.enqueue=function(){var t,e,i,n=[].shift.call(arguments),o=arguments;return n?("function"==typeof n?(t=new r.defer,e=t.promise,i={task:n,args:o,deferred:t,promise:e}):i={promise:n},this._q.push(i),0!=this.paused||this.running||this.run(),i.promise):console.error("No Task Provided")},n.prototype.dequeue=function(){var t,e,i;return this._q.length?(t=this._q.shift(),(e=t.task)?(i=e.apply(this.context,t.args),i&&"function"==typeof i.then?i.then(function(){t.deferred.resolve.apply(this.context,arguments)}.bind(this)):(t.deferred.resolve.apply(this.context,i),t.promise)):t.promise?t.promise:void 0):(t=new r.defer,t.deferred.resolve(),t.promise)},n.prototype.dump=function(){for(;this._q.length;)this.dequeue()},n.prototype.run=function(){return this.running||(this.running=!0,this.defered=new r.defer),this.tick.call(window,function(){this._q.length?this.dequeue().then(function(){this.run()}.bind(this)):(this.defered.resolve(),this.running=void 0)}.bind(this)),1==this.paused&&(this.paused=!1),this.defered.promise},n.prototype.flush=function(){return this.running?this.running:this._q.length?(this.running=this.dequeue().then(function(){return this.running=void 0,this.flush()}.bind(this)),this.running):void 0},n.prototype.clear=function(){this._q=[],this.running=!1},n.prototype.length=function(){return this._q.length},n.prototype.pause=function(){this.paused=!0},t.exports=n},function(t,e,i){function n(){}var r=i(6),o=i(11),s=i(15);n.prototype.container=function(t){var e,i,n,s;return t?(e=o.qs(t,"rootfile"))?(i=e.getAttribute("full-path"),n=r(i).directory(),s=t.xmlEncoding,{packagePath:i,basePath:n,encoding:s}):void console.error("No RootFile Found"):void console.error("Container File Not Found")},n.prototype.identifier=function(t){var e;return t?(e=o.qs(t,"metadata"),e?this.getElementText(e,"identifier"):void console.error("No Metadata Found")):void console.error("Package File Not Found")},n.prototype.packageContents=function(t){var e,i,n,r,s,a,h,u,c,l,p=this;return t?(e=o.qs(t,"metadata"))?(i=o.qs(t,"manifest"))?(n=o.qs(t,"spine"))?(r=p.manifest(i),s=p.findNavPath(i),a=p.findNcxPath(i,n),h=p.findCoverPath(t),u=Array.prototype.indexOf.call(n.parentNode.childNodes,n),c=p.spine(n,r),l=p.metadata(e),l.direction=n.getAttribute("page-progression-direction"),{metadata:l,spine:c,manifest:r,navPath:s,ncxPath:a,coverPath:h,spineNodeIndex:u}):void console.error("No Spine Found"):void console.error("No Manifest Found"):void console.error("No Metadata Found"):void console.error("Package File Not Found")},n.prototype.findNavPath=function(t){var e=o.qsp(t,"item",{properties:"nav"});return!!e&&e.getAttribute("href")},n.prototype.findNcxPath=function(t,e){var i,n=o.qsp(t,"item",{"media-type":"application/x-dtbncx+xml"});return n||(i=e.getAttribute("toc"),i&&(n=t.getElementById(i))),!!n&&n.getAttribute("href")},n.prototype.metadata=function(t){var e={},i=this;return e.title=i.getElementText(t,"title"),e.creator=i.getElementText(t,"creator"),e.description=i.getElementText(t,"description"),e.pubdate=i.getElementText(t,"date"),e.publisher=i.getElementText(t,"publisher"),e.identifier=i.getElementText(t,"identifier"),e.language=i.getElementText(t,"language"),e.rights=i.getElementText(t,"rights"),e.modified_date=i.getPropertyText(t,"dcterms:modified"),e.layout=i.getPropertyText(t,"rendition:layout"),e.orientation=i.getPropertyText(t,"rendition:orientation"),e.flow=i.getPropertyText(t,"rendition:flow"),e.viewport=i.getPropertyText(t,"rendition:viewport"),e},n.prototype.findCoverPath=function(t){var e=o.qs(t,"package"),i=e.getAttribute("version");if("2.0"===i){var n=o.qsp(t,"meta",{name:"cover"});if(n){var r=n.getAttribute("content"),s=t.getElementById(r);return!!s&&s.getAttribute("href")}return!1}var a=o.qsp(t,"item",{properties:"cover-image"});return!!a&&a.getAttribute("href")},n.prototype.getElementText=function(t,e){var i,n=t.getElementsByTagNameNS("http://purl.org/dc/elements/1.1/",e);return n&&0!==n.length?(i=n[0],i.childNodes.length?i.childNodes[0].nodeValue:""):""},n.prototype.getPropertyText=function(t,e){var i=o.qsp(t,"meta",{property:e});return i&&i.childNodes.length?i.childNodes[0].nodeValue:""},n.prototype.querySelectorText=function(t,e){var i=t.querySelector(e);return i&&i.childNodes.length?i.childNodes[0].nodeValue:""},n.prototype.manifest=function(t){var e={},i=o.qsa(t,"item"),n=Array.prototype.slice.call(i);return n.forEach(function(t){var i=t.getAttribute("id"),n=t.getAttribute("href")||"",r=t.getAttribute("media-type")||"",o=t.getAttribute("properties")||"";e[i]={href:n,type:r,properties:o.length?o.split(" "):[]}}),e},n.prototype.spine=function(t,e){var i=[],n=t.getElementsByTagName("itemref"),r=Array.prototype.slice.call(n);new s;return r.forEach(function(t,e){var n=t.getAttribute("idref"),r=t.getAttribute("properties")||"",o=r.length?r.split(" "):[],s={idref:n,linear:t.getAttribute("linear")||"",properties:o,index:e};i.push(s)}),i},n.prototype.querySelectorByType=function(t,e,i){var n;if("undefined"!=typeof t.querySelector&&(n=t.querySelector(e+'[*|type="'+i+'"]')),n&&0!==n.length)return n;n=o.qsa(t,e);for(var r=0;r1&&n[1],{cfi:s,href:h,packageUrl:r,page:c}):{href:h,page:c}},t.exports=n},function(t,e,i){function n(t,e){var n=this,a=new r,h=e||i(18);this["package"]=t,this.toc=[],this.tocByHref={},this.tocById={},t.navPath&&(this.navUrl=s(t.navPath).absoluteTo(t.baseUrl).toString(),this.nav={},this.nav.load=function(t){var e=new o.defer,i=e.promise;return h(n.navUrl,"xml").then(function(t){n.toc=a.nav(t),n.loaded(n.toc),e.resolve(n.toc)}),i}),t.ncxPath&&(this.ncxUrl=s(t.ncxPath).absoluteTo(t.baseUrl).toString(),this.ncx={},this.ncx.load=function(t){var e=new o.defer,i=e.promise;return h(n.ncxUrl,"xml").then(function(t){n.toc=a.toc(t),n.loaded(n.toc),e.resolve(n.toc)}),i})}var r=(i(11),i(22)),o=i(2),s=i(6);n.prototype.load=function(t){var e,n;t||i(18);return this.nav?e=this.nav.load():this.ncx?e=this.ncx.load():(n=new o.defer,n.resolve([]),e=n.promise),e},n.prototype.loaded=function(t){for(var e,i=0;i-1&&(i=t.substring(t.indexOf("#")+1)),n&&(i=t),this.manager.display(e,i).then(function(){this.trigger("displayed",e)}.bind(this))):(o.reject(new Error("No Section Found")),s)},n.prototype.afterDisplayed=function(t){this.hooks.content.trigger(t,this),this.trigger("rendered",t.section),this.reportLocation()},n.prototype.onResized=function(t){this.location&&this.display(this.location.start),this.trigger("resized",{width:t.width,height:t.height})},n.prototype.moveTo=function(t){this.manager.moveTo(t)},n.prototype.next=function(){return this.q.enqueue(this.manager.next.bind(this.manager)).then(this.reportLocation.bind(this))},n.prototype.prev=function(){return this.q.enqueue(this.manager.prev.bind(this.manager)).then(this.reportLocation.bind(this))},n.prototype.determineLayoutProperties=function(t){var e,i=this.settings.layout||t.layout||"reflowable",n=this.settings.spread||t.spread||"auto",r=this.settings.orientation||t.orientation||"auto",o=this.settings.flow||t.flow||"auto",s=t.viewport||"",a=this.settings.minSpreadWidth||t.minSpreadWidth||800;return this.settings.width>=0&&this.settings.height>=0&&(s="width="+this.settings.width+", height="+this.settings.height),e={layout:i,spread:n,orientation:r,flow:o,viewport:s,minSpreadWidth:a}},n.prototype.flow=function(t){var e;"scrolled-doc"!==t&&"scrolled-continuous"!==t||(e="scrolled"),"auto"!==t&&"paginated"!==t||(e="paginated"),this._layout&&this._layout.flow(e),this.manager&&this.manager.updateFlow(e)},n.prototype.layout=function(t){return t&&(this._layout=new l(t),this._layout.spread(t.spread,this.settings.minSpreadWidth),this.mapping=new p(this._layout)),this.manager&&this._layout&&this.manager.applyLayout(this._layout),this._layout},n.prototype.spread=function(t,e){this._layout.spread(t,e),this.manager.isRendered()&&this.manager.updateLayout()},n.prototype.reportLocation=function(){return this.q.enqueue(function(){var t=this.manager.currentLocation();t&&t.then&&"function"==typeof t.then?t.then(function(t){this.location=t,this.trigger("locationChanged",this.location)}.bind(this)):t&&(this.location=t,this.trigger("locationChanged",this.location))}.bind(this))},n.prototype.destroy=function(){this.q.clear(),this.manager.destroy()},n.prototype.passViewEvents=function(t){t.contents.listenedEvents.forEach(function(e){t.on(e,this.triggerViewEvent.bind(this))}.bind(this)),t.on("selected",this.triggerSelectedEvent.bind(this))},n.prototype.triggerViewEvent=function(t){this.trigger(t.type,t)},n.prototype.triggerSelectedEvent=function(t){this.trigger("selected",t)},n.prototype.replacements=function(){var t,e=this.book["package"].manifest,i=Object.keys(e).map(function(t){return e[t]}),n=i.filter(function(t){if("application/xhtml+xml"!=t.type&&"text/html"!=t.type)return!0}),s=n.filter(function(t){if("text/css"===t.type)return!0}),a=s.map(function(t){return t.href}),h=n.map(function(t){return t.href}.bind(this)),u=h.map(function(t){var e=o(t).absoluteTo(this.book.baseUrl).toString();return this.book.unarchived.createUrl(e,{base64:this.settings.useBase64})}.bind(this));return r.all(u).then(function(e){var i=[];return t=e,a.forEach(function(e){i.push(this.replaceCss(e,h,t))}.bind(this)),r.all(i)}.bind(this)).then(function(){this.book.spine.hooks.serialize.register(function(e,i){this.replaceAssets(i,h,t)}.bind(this))}.bind(this))["catch"](function(t){console.error(t)})},n.prototype.replaceCss=function(t,e,i){var n,h,u=o(t),c=u.absoluteTo(this.book.baseUrl).toString(),l=this.book.unarchived.getText(c),p=e.map(function(t){var e=o(t).absoluteTo(this.book.baseUrl),i=e.relativeTo(c).toString();return i}.bind(this));return l.then(function(o){return o=a.substitute(o,p,i),n=this.settings.useBase64?s.createBase64Url(o,"text/css"):s.createBlobUrl(o,"text/css"),h=e.indexOf(t),h>-1&&(i[h]=n),new r.Promise(function(t,n){t(e,i)})}.bind(this))},n.prototype.replaceAssets=function(t,e,i){var n=o(t.url),r=e.map(function(t){var e=o(t).absoluteTo(this.book.baseUrl),i=e.relativeTo(n).toString();return i}.bind(this));t.output=a.substitute(t.output,r,i)},n.prototype.range=function(t,e){var i=new u(t),n=this.visible().filter(function(t){if(i.spinePos===t.index)return!0});if(n.length)return n[0].range(i,e)},n.prototype.adjustImages=function(t){return t.addStylesheetRules([["img",["max-width",t.layout.spreadWidth+"px"],["max-height",t.layout.height+"px"]]]),new r.Promise(function(t,e){setTimeout(function(){t()},1)})},r.EventTarget.mixin(n.prototype),t.exports=n},function(t,e,i){function n(t){this.name=t.layout||"reflowable",this._spread="none"!==t.spread,this._minSpreadWidth=t.spread||800,this._evenSpreads=t.evenSpreads||!1,"scrolled-continuous"===t.flow||"scrolled-doc"===t.flow?this._flow="scrolled":this._flow="paginated",this.width=0,this.height=0,this.spreadWidth=0,this.delta=0,this.columnWidth=0,this.gap=0,this.divisor=1}i(11),i(2);n.prototype.flow=function(t){this._flow="paginated"===t?"paginated":"scrolled"},n.prototype.spread=function(t,e){this._spread="none"!==t,e>=0&&(this._minSpreadWidth=e)},n.prototype.calculate=function(t,e,i){var n,r,o,s=1,a=i||0,h=(Math.floor(t),t),u=Math.floor(h/8);s=this._spread&&h>=this._minSpreadWidth?2:1,"reflowable"!==this.name||"paginated"!==this._flow||i>=0||(a=u%2===0?u:u-1),"pre-paginated"===this.name&&(a=0),n=s>1?Math.floor((h-a)/s):h,"pre-paginated"===this.name&&s>1&&(h=n),r=n*s,o=(n+a)*s,this.width=h,this.height=e,this.spreadWidth=r,this.delta=o,this.columnWidth=n,this.gap=a,this.divisor=s},n.prototype.format=function(t){var e;return e="pre-paginated"===this.name?t.fit(this.columnWidth,this.height):"paginated"===this._flow?t.columns(this.width,this.height,this.columnWidth,this.gap):t.size(this.width,null)},n.prototype.count=function(t){var e=Math.ceil(t/this.spreadWidth);return{spreads:e,pages:e*this.divisor}},t.exports=n},function(t,e,i){function n(t){this.layout=t}var r=i(15);n.prototype.section=function(t){var e=this.findRanges(t),i=this.rangeListToCfiList(t.section.cfiBase,e);return i},n.prototype.page=function(t,e,i,n){var r=!(!t||!t.document)&&t.document.body;if(r)return this.rangePairToCfiPair(e,{start:this.findStart(r,i,n),end:this.findEnd(r,i,n)})},n.prototype.walk=function(t,e){for(var i,n,r=document.createTreeWalker(t,NodeFilter.SHOW_TEXT,{acceptNode:function(t){return t.data.trim().length>0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_REJECT}},!1);(i=r.nextNode())&&!(n=e(i)););return n},n.prototype.findRanges=function(t){for(var e,i,n=[],r=t.contents.scrollWidth(),o=this.layout.count(r),s=this.layout.column,a=this.layout.gap,h=0;h=e&&n<=i?t:r>e?t:(s=t,void o.push(t))}))return this.findTextStartRange(r,e,i);return this.findTextStartRange(s,e,i)},n.prototype.findEnd=function(t,e,i){for(var n,r,o=[t],s=t;o.length;)if(n=o.shift(),r=this.walk(n,function(t){var e,n,r,a;return t.nodeType==Node.TEXT_NODE?(a=document.createRange(),a.selectNodeContents(t),r=a.getBoundingClientRect()):r=t.getBoundingClientRect(),e=r.left,n=r.right,e>i&&s?s:n>i?t:(s=t,void o.push(t))}))return this.findTextEndRange(r,e,i);return this.findTextEndRange(s,e,i)},n.prototype.findTextStartRange=function(t,e,i){for(var n,r,o,s=this.splitTextNodeIntoRanges(t),a=0;a=e)return r;n=r}return s[0]},n.prototype.findTextEndRange=function(t,e,i){for(var n,r,o,s=this.splitTextNodeIntoRanges(t),a=0;ai&&n)return n;if(o.right>i)return r;n=r}return s[s.length-1]},n.prototype.splitTextNodeIntoRanges=function(t,e){var i,n=[],r=t.textContent||"",o=r.trim(),s=t.ownerDocument,a=e||" ";if(pos=o.indexOf(a),pos===-1||t.nodeType!=Node.TEXT_NODE)return i=s.createRange(),i.selectNodeContents(t),[i];for(i=s.createRange(),i.setStart(t,0),i.setEnd(t,pos),n.push(i),i=!1;pos!=-1;)pos=o.indexOf(a,pos+1),pos>0&&(i&&(i.setEnd(t,pos),n.push(i)),i=s.createRange(),i.setStart(t,pos+1));return i&&(i.setEnd(t,o.length),n.push(i)),n},n.prototype.rangePairToCfiPair=function(t,e){var i=e.start,n=e.end;return i.collapse(!0),n.collapse(!0),startCfi=new r(i,t).toString(),endCfi=new r(n,t).toString(),{start:startCfi,end:endCfi}},n.prototype.rangeListToCfiList=function(t,e){for(var i,n=[],r=0;r-1&&(id=t.substring(t.indexOf("#")+1),el=this.document.getElementById(id),el&&(i=el.getBoundingClientRect(),n.left=i.left,n.top=i.top)),n},n.prototype.addStylesheet=function(t){return new r.Promise(function(e,i){var n,r=!1;return this.document?(n=this.document.createElement("link"),n.type="text/css",n.rel="stylesheet",n.href=t,n.onload=n.onreadystatechange=function(){r||this.readyState&&"complete"!=this.readyState||(r=!0,setTimeout(function(){e(!0)},1))},void this.document.head.appendChild(n)):void e(!1)}.bind(this))},n.prototype.addStylesheetRules=function(t){var e,i;if(this.document){e=this.document.createElement("style"),this.document.head.appendChild(e),i=e.sheet;for(var n=0,r=t.length;n0&&(e=t.getRangeAt(0),e.collapsed||(i=new s(e,this.cfiBase).toString(),this.trigger("selected",i),this.trigger("selectedRange",e)))},n.prototype.range=function(t,e){var i=new s(t);return i.toRange(this.document,e)},n.prototype.map=function(t){var e=new a(t);return e.section()},n.prototype.size=function(t,e){t>=0&&this.width(t),e>=0&&this.height(e),this.css("margin","0"),this.css("boxSizing","border-box")},n.prototype.columns=function(t,e,i,n){var r=o.prefixed("columnAxis"),s=o.prefixed("columnGap"),a=o.prefixed("columnWidth"),h=o.prefixed("columnFill");this.width(t),this.height(e),this.viewport({width:t,height:e,scale:1}),this.css("overflowY","hidden"),this.css("margin","0"),this.css("boxSizing","border-box"),this.css("maxWidth","inherit"),this.css(r,"horizontal"),this.css(h,"auto"),this.css(s,n+"px"),this.css(a,i+"px")},n.prototype.scale=function(t,e,i){var t="scale("+t+")",n="";this.css("transformOrigin","top left"),(e>=0||i>=0)&&(n=" translate("+(e||0)+"px, "+(i||0)+"px )"),this.css("transform",t+n)},n.prototype.fit=function(t,e){var i=this.viewport(),n=t/i.width,r=e/i.height,o=n1&&"reflowable"===this.settings.layout.name&&e%2>0&&(r+=this.settings.layout.gap+this.settings.layout.columnWidth),this._textWidth=i,this._contentWidth=r):r=this._contentWidth):"vertical"===this.settings.axis&&(n=this.contents.textHeight(),n!=this._textHeight?(o=this.contentHeight(n),this._textHeight=n,this._contentHeight=o):o=this._contentHeight),(this._needsReframe||r!=this._width||o!=this._height)&&this.resize(r,o),this._expanding=!1)},n.prototype.contentWidth=function(t){var e,i;return e=this.iframe.style.width,this.iframe.style.width=(t||0)+"px",i=this.contents.scrollWidth(),this.iframe.style.width=e,i},n.prototype.contentHeight=function(t){var e,i;return e=this.iframe.style.height,this.iframe.style.height=(t||0)+"px",i=this.contents.scrollHeight(),this.iframe.style.height=e,i},n.prototype.resize=function(t,e){this.iframe&&(o.isNumber(t)&&(this.iframe.style.width=t+"px",this._width=t),o.isNumber(e)&&(this.iframe.style.height=e+"px",this._height=e),this.iframeBounds=o.bounds(this.iframe),this.reframe(this.iframeBounds.width,this.iframeBounds.height))},n.prototype.reframe=function(t,e){var i;o.isNumber(t)&&(this.element.style.width=t+"px"),o.isNumber(e)&&(this.element.style.height=e+"px"),this.prevBounds=this.elementBounds,this.elementBounds=o.bounds(this.element),i={width:this.elementBounds.width,height:this.elementBounds.height,widthDelta:this.elementBounds.width-this.prevBounds.width,heightDelta:this.elementBounds.height-this.prevBounds.height},this.onResize(this,i),this.trigger("resized",i)},n.prototype.load=function(t){var e=new r.defer,i=e.promise;if(!this.iframe)return e.reject(new Error("No Iframe Available")),i;if(this.iframe.onload=function(t){this.onLoad(t,e)}.bind(this),this.supportsSrcdoc)this.iframe.srcdoc=t;else{if(this.document=this.iframe.contentDocument,!this.document)return e.reject(new Error("No Document Available")),i;this.iframe.contentDocument.open(),this.iframe.contentDocument.write(t),this.iframe.contentDocument.close()}return i},n.prototype.onLoad=function(t,e){this.window=this.iframe.contentWindow,this.document=this.iframe.contentDocument,this.contents=new a(this.document,this.document.body,this.section.cfiBase),this.rendering=!1;var i=this.document.querySelector("link[rel='canonical']");i?i.setAttribute("href",this.section.url):(i=this.document.createElement("link"),i.setAttribute("rel","canonical"),i.setAttribute("href",this.section.url),this.document.querySelector("head").appendChild(i)),this.contents.on("expand",function(){this.displayed&&this.iframe&&this.expand()}),e.resolve(this.contents)},n.prototype.setLayout=function(t){this.layout=t},n.prototype.setAxis=function(t){this.settings.axis=t},n.prototype.resizeListenters=function(){clearTimeout(this.expanding),this.expanding=setTimeout(this.expand.bind(this),350)},n.prototype.addListeners=function(){},n.prototype.removeListeners=function(t){},n.prototype.display=function(t){var e=new r.defer;return this.displayed?e.resolve(this):this.render(t).then(function(){this.trigger("displayed",this),this.onDisplayed(this),this.displayed=!0,e.resolve(this)}.bind(this)),e.promise},n.prototype.show=function(){this.element.style.visibility="visible",this.iframe&&(this.iframe.style.visibility="visible"),this.trigger("shown",this)},n.prototype.hide=function(){this.element.style.visibility="hidden",this.iframe.style.visibility="hidden",this.stopExpanding=!0,this.trigger("hidden",this)},n.prototype.position=function(){return this.element.getBoundingClientRect()},n.prototype.locationOf=function(t){var e=this.iframe.getBoundingClientRect(),i=this.contents.locationOf(t,this.settings.ignoreClass);return{left:window.scrollX+e.left+i.left,top:window.scrollY+e.top+i.top}},n.prototype.onDisplayed=function(t){},n.prototype.onResize=function(t,e){},n.prototype.bounds=function(){return this.elementBounds||(this.elementBounds=o.bounds(this.element)),this.elementBounds},n.prototype.destroy=function(){this.displayed&&(this.displayed=!1,this.removeListeners(),this.stopExpanding=!0,this.element.removeChild(this.iframe),this.displayed=!1,this.iframe=null,this._textWidth=null,this._textHeight=null,this._width=null,this._height=null)},r.EventTarget.mixin(n.prototype),t.exports=n},function(t,e,i){function n(t){this.name="default",this.View=t.view,this.request=t.request,this.renditionQueue=t.queue,this.q=new a(this),this.settings=o.extend(this.settings||{},{infinite:!0,hidden:!1,width:void 0,height:void 0,axis:"vertical",ignoreClass:""}),o.extend(this.settings,t.settings||{}),this.viewSettings={ignoreClass:this.settings.ignoreClass,axis:this.settings.axis,layout:this.layout,width:0,height:0}}var r=i(2),o=i(11),s=(i(15),i(26)),a=i(21),h=i(33),u=i(34);n.prototype.render=function(t,e){this.stage=new h({width:e.width,height:e.height,overflow:this.settings.overflow,hidden:this.settings.hidden,axis:this.settings.axis}),this.stage.attachTo(t),this.container=this.stage.getContainer(),this.views=new u(this.container),this._bounds=this.bounds(),this._stageSize=this.stage.size(),this.viewSettings.width=this._stageSize.width,this.viewSettings.height=this._stageSize.height,this.stage.onResize(this.onResized.bind(this)),this.addEventListeners(),this.layout&&this.updateLayout()},n.prototype.addEventListeners=function(){window.addEventListener("unload",function(t){this.destroy()}.bind(this))},n.prototype.destroy=function(){},n.prototype.onResized=function(t){clearTimeout(this.resizeTimeout),this.resizeTimeout=setTimeout(function(){this.resize()}.bind(this),150)},n.prototype.resize=function(t,e){this.q.clear(),this._stageSize=this.stage.size(t,e),this._bounds=this.bounds(),this.viewSettings.width=this._stageSize.width,this.viewSettings.height=this._stageSize.height,this.views.each(function(t){t.size(this._stageSize.width,this._stageSize.height)}.bind(this)),this.updateLayout(),this.trigger("resized",{width:this.stage.width,height:this.stage.height})},n.prototype.createView=function(t){return new this.View(t,this.viewSettings)},n.prototype.display=function(t,e){var i=new r.defer,n=i.promise,o=this.views.find(t);return o&&e?(offset=o.locationOf(e),this.moveTo(offset),i.resolve(),n):(this.views.hide(),this.views.clear(),this.add(t).then(function(){var e;if("pre-paginated"===this.layout.name&&this.layout.divisor>1&&(e=t.next()))return this.add(e)}.bind(this)).then(function(t){e&&(offset=t.locationOf(e),this.moveTo(offset)),this.views.show(),i.resolve()}.bind(this)),n)},n.prototype.afterDisplayed=function(t){this.trigger("added",t)},n.prototype.afterResized=function(t){this.trigger("resize",t.section)},n.prototype.moveTo=function(t){var e=0,i=0;"vertical"===this.settings.axis?i=t.top:(e=Math.floor(t.left/this.layout.delta)*this.layout.delta,e+this.layout.delta>this.container.scrollWidth&&(e=this.container.scrollWidth-this.layout.delta)),this.scrollTo(e,i)},n.prototype.add=function(t){var e=this.createView(t);return this.views.append(e),e.onDisplayed=this.afterDisplayed.bind(this),e.onResize=this.afterResized.bind(this),e.display(this.request)},n.prototype.append=function(t){var e=this.createView(t);return this.views.append(e),e.display(this.request)},n.prototype.prepend=function(t){var e=this.createView(t);return this.views.prepend(e),e.display(this.request)},n.prototype.next=function(){var t,e;if(this.views.length)return"horizontal"===this.settings.axis?(this.scrollLeft=this.container.scrollLeft,e=this.container.scrollLeft+this.container.offsetWidth+this.layout.delta,e1&&(e=t.next()))return this.append(e)}.bind(this)).then(function(){this.views.show()}.bind(this))):void 0},n.prototype.prev=function(){var t,e;if(this.views.length)return"horizontal"===this.settings.axis?(this.scrollLeft=this.container.scrollLeft,e=this.container.scrollLeft,e>0?this.scrollBy(-this.layout.delta,0):t=this.views.first().section.prev()):t=this.views.first().section.prev(),t?(this.views.clear(),this.prepend(t).then(function(){var e;if(this.layout.name&&this.layout.divisor>1&&(e=t.prev()))return this.prepend(e)}.bind(this)).then(function(){"horizontal"===this.settings.axis&&this.scrollTo(this.container.scrollWidth-this.layout.delta,0),this.views.show()}.bind(this))):void 0},n.prototype.current=function(){var t=this.visible();return t.length?t[t.length-1]:null},n.prototype.currentLocation=function(){var t,e,i;if(this.views.length)return t=this.views.first(),e=container.left-t.position().left,i=e+this.layout.spread,this.mapping.page(t,t.section.cfiBase)},n.prototype.isVisible=function(t,e,i,n){var r=t.position(),o=n||this.bounds();return"horizontal"===this.settings.axis&&r.right>o.left-e&&r.lefto.top-e&&r.top-1&&this._views.splice(e,1),this.destroy(t),this.length--},i.prototype.destroy=function(t){t.off("resized"),t.displayed&&t.destroy(),this.container&&this.container.removeChild(t.element),t=null},i.prototype.each=function(){return this._views.forEach.apply(this._views,arguments)},i.prototype.clear=function(){var t,e=this.length;if(this.length){for(var i=0;i=f&&(i=this.views.last(),o=i&&i.section.next(),o&&h.push(this.append(o))),p-c<0&&(n=this.views.first(),s=n&&n.section.prev(),s&&h.push(this.prepend(s))),h.length?this.q.enqueue(function(){return this.update(c)}.bind(this)):(a.resolve(!1),a.promise)},n.prototype.trim=function(){for(var t=new r.defer,e=this.views.displayed(),i=e[0],n=e[e.length-1],o=this.views.indexOf(i),s=this.views.indexOf(n),a=this.views.slice(0,o),h=this.views.slice(s+1),u=0;uthis.settings.offsetDelta||this.scrollDeltaHorz>this.settings.offsetDelta)&&(this.q.enqueue(function(){this.check()}.bind(this)),this.scrollDeltaVert=0,this.scrollDeltaHorz=0,this.trigger("scroll",{top:scrollTop,left:scrollLeft}),clearTimeout(this.afterScrolled),this.afterScrolled=setTimeout(function(){this.trigger("scrolled",{top:this.scrollTop,left:this.scrollLeft})}.bind(this))),this.scrollDeltaVert+=Math.abs(scrollTop-this.prevScrollTop),this.scrollDeltaHorz+=Math.abs(scrollLeft-this.prevScrollLeft),this.prevScrollTop=scrollTop,this.prevScrollLeft=scrollLeft,clearTimeout(this.scrollTimeout),this.scrollTimeout=setTimeout(function(){this.scrollDeltaVert=0,this.scrollDeltaHorz=0}.bind(this),150),this.scrolled=!1},n.prototype.currentLocation=function(){return"vertical"===this.settings.axis?this.location=this.scrolledLocation():this.location=this.paginatedLocation(),this.location},n.prototype.scrolledLocation=function(){var t,e,i=this.visible();this.container.getBoundingClientRect();return 1===i.length?this.mapping.page(i[0].contents,i[0].section.cfiBase):i.length>1?(t=this.mapping.page(i[0].contents,i[0].section.cfiBase),e=this.mapping.page(i[i.length-1].contents,i[i.length-1].section.cfiBase),{start:t.start,end:e.end}):void 0},n.prototype.paginatedLocation=function(){var t,e,i,n,r,o,s=this.visible(),a=this.container.getBoundingClientRect();return 1===s.length?(t=a.left-s[0].position().left,i=t+this.layout.spreadWidth,this.mapping.page(s[0].contents,s[0].section.cfiBase,t,i)):s.length>1?(t=a.left-s[0].position().left,i=t+this.layout.columnWidth,e=a.left+this.layout.spreadWidth-s[s.length-1].position().left,n=e+this.layout.columnWidth,r=this.mapping.page(s[0].contents,s[0].section.cfiBase,t,i),o=this.mapping.page(s[s.length-1].contents,s[s.length-1].section.cfiBase,e,n),{start:r.start,end:o.end}):void 0},n.prototype.updateLayout=function(){this.stage&&("vertical"===this.settings.axis?this.layout.calculate(this._stageSize.width,this._stageSize.height):(this.layout.calculate(this._stageSize.width,this._stageSize.height,this.settings.gap),this.settings.offset=this.layout.delta,this.stage.addStyleRules("iframe",[{"margin-right":this.layout.gap+"px"}])),this.viewSettings.width=this.layout.width,this.viewSettings.height=this.layout.height,this.setLayout(this.layout))},n.prototype.next=function(){"horizontal"===this.settings.axis?(this.scrollLeft=this.container.scrollLeft,this.container.scrollLeft+this.container.offsetWidth+this.layout.delta=t.length-1)return!1;var n=t.lastIndexOf(".",e-1);if(n<=0||n>=e-1)return!1;var r=i.list[t.slice(e+1)];return!!r&&r.indexOf(" "+t.slice(n+1,e)+" ")>=0},is:function(t){var e=t.lastIndexOf(".");if(e<=0||e>=t.length-1)return!1;var n=t.lastIndexOf(".",e-1);if(n>=0)return!1;var r=i.list[t.slice(e+1)];return!!r&&r.indexOf(" "+t.slice(0,e)+" ")>=0},get:function(t){var e=t.lastIndexOf(".");if(e<=0||e>=t.length-1)return null;var n=t.lastIndexOf(".",e-1);if(n<=0||n>=e-1)return null;var r=i.list[t.slice(e+1)];return r?r.indexOf(" "+t.slice(n+1,e)+" ")<0?null:t.slice(n+1):null},noConflict:function(){return t.SecondLevelDomains===this&&(t.SecondLevelDomains=e),this}};return i})},function(t,e,i){function n(t){return!(!t||1!=t.nodeType)}function r(){var t=(new Date).getTime(),e="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var i=(t+16*Math.random())%16|0;return t=Math.floor(t/16),("x"==e?i:7&i|8).toString(16)});return e}function o(t){for(var e=-1,i=Object.keys(t),n=i.length,r=Array(n);++ee?1:t0?h:h+1:0===o?h:o===-1?d(t,e,i,h,a):d(t,e,i,s,h))}function f(t,e,i,n,r){var o,s=n||0,a=r||e.length,h=parseInt(s+(a-s)/2);return i||(i=function(t,e){return t>e?1:t-1}function x(t,e){var i=new Blob([t],{type:e});return i}function _(t,e){var i,n=window.URL||window.webkitURL||window.mozURL,r=this.createBlob(t,e);return i=n.createObjectURL(r)}function k(t,e){var i,n;if("string"==typeof t)return i=btoa(t),n="data:"+e+";base64,"+i}function S(t){return Object.prototype.toString.call(t).slice(8,-1)}function E(t,e){var n;return"undefined"==typeof DOMParser&&(DOMParser=i(24).DOMParser),n=(new DOMParser).parseFromString(t,e)}function T(t,e){var i;return"undefined"!=typeof t.querySelector?t.querySelector(e):(i=t.getElementsByTagName(e),i.length?i[0]:void 0)}function z(t,e){return"undefined"!=typeof t.querySelector?t.querySelectorAll(e):t.getElementsByTagName(e)}function C(t,e,i){var n,r;if("undefined"!=typeof t.querySelector){e+="[";for(var o in i)e+=o+"='"+i[o]+"'";return e+="]",t.querySelector(e)}if(n=t.getElementsByTagName(e),r=Array.prototype.slice.call(n,0).filter(function(t){for(var e in i)if(t.getAttribute(e)===i[e])return!0;return!1}))return r[0]}function q(t,e){var i=new FileReader;i.readAsDataURL(t),i.onloadend=function(){e(i.result)}}function L(){this.resolve=null,this.reject=null,this.promise=new Promise(function(t,e){this.resolve=t,this.reject=e}.bind(this)),Object.freeze(this)}var N=(i(23),"undefined"!=typeof window&&(window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame));t.exports={isElement:n,uuid:r,values:o,resolveUrl:s,indexOfSorted:f,documentHeight:a,isNumber:h,prefixed:c,defaults:u,extend:p,insert:l,locationOf:d,indexOfSorted:f,requestAnimationFrame:N,bounds:g,borders:m,windowBounds:v,cleanStringForXpath:y,indexOfTextNode:b,isXml:w,createBlob:x,createBlobUrl:_,type:S,parse:E,qs:T,qsa:z,qsp:C,blob2base64:q,createBase64Url:k,defer:L}},function(t,e){"use strict";function i(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");return"="===t[e-2]?2:"="===t[e-1]?1:0}function n(t){return 3*t.length/4-i(t)}function r(t){var e,n,r,o,s,a,h=t.length;s=i(t),a=new u(3*h/4-s),r=s>0?h-4:h;var p=0;for(e=0,n=0;e>16&255,a[p++]=o>>8&255,a[p++]=255&o;return 2===s?(o=c[t.charCodeAt(e)]<<2|c[t.charCodeAt(e+1)]>>4,a[p++]=255&o):1===s&&(o=c[t.charCodeAt(e)]<<10|c[t.charCodeAt(e+1)]<<4|c[t.charCodeAt(e+2)]>>2,a[p++]=o>>8&255,a[p++]=255&o),a}function o(t){return h[t>>18&63]+h[t>>12&63]+h[t>>6&63]+h[63&t]}function s(t,e,i){for(var n,r=[],s=e;su?u:c+a));return 1===n?(e=t[i-1],r+=h[e>>2],r+=h[e<<4&63],r+="=="):2===n&&(e=(t[i-2]<<8)+t[i-1],r+=h[e>>10],r+=h[e>>4&63],r+=h[e<<2&63],r+="="),o.push(r),o.join("")}e.byteLength=n,e.toByteArray=r,e.fromByteArray=a;for(var h=[],c=[],u="undefined"!=typeof Uint8Array?Uint8Array:Array,p="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",l=0,d=p.length;l-1)return delete this.spineByHref[t.href],delete this.spineById[t.idref],this.spineItems.splice(e,1)},n.prototype.each=function(){return this.spineItems.forEach.apply(this.spineItems,arguments)},t.exports=n},function(t,e,i){function n(t,e,i){var o;if(this.str="",this.base={},this.spinePos=0,this.range=!1,this.path={},this.start=null,this.end=null,!(this instanceof n))return new n(t,e,i);if("string"==typeof e?this.base=this.parseComponent(e):"object"==typeof e&&e.steps&&(this.base=e),o=this.checkType(t),"string"===o)return this.str=t,r.extend(this,this.parse(t));if("range"===o)return r.extend(this,this.fromRange(t,this.base,i));if("node"===o)return r.extend(this,this.fromNode(t,this.base,i));if("EpubCFI"===o&&t.path)return t;if(t)throw new TypeError("not a valid argument for EpubCFI");return this}var r=(i(17),i(22));n.prototype.checkType=function(t){return this.isCfiString(t)?"string":"object"==typeof t&&"Range"===r.type(t)?"range":"object"==typeof t&&"undefined"!=typeof t.nodeType?"node":"object"==typeof t&&t instanceof n&&"EpubCFI"},n.prototype.parse=function(t){var e,i,n,r={spinePos:-1,range:!1,base:{},path:{},start:null,end:null};return"string"!=typeof t?{spinePos:-1}:(0===t.indexOf("epubcfi(")&&")"===t[t.length-1]&&(t=t.slice(8,t.length-1)),(e=this.getChapterComponent(t))?(r.base=this.parseComponent(e),i=this.getPathComponent(t),r.path=this.parseComponent(i),n=this.getRange(t),n&&(r.range=!0,r.start=this.parseComponent(n[0]),r.end=this.parseComponent(n[1])),r.spinePos=r.base.steps[1].index,r):{spinePos:-1})},n.prototype.parseComponent=function(t){var e,i={steps:[],terminal:{offset:null,assertion:null}},n=t.split(":"),r=n[0].split("/");return n.length>1&&(e=n[1],i.terminal=this.parseTerminal(e)),""===r[0]&&r.shift(),i.steps=r.map(function(t){return this.parseStep(t)}.bind(this)),i},n.prototype.parseStep=function(t){var e,i,n,r,o;if(r=t.match(/\[(.*)\]/),r&&r[1]&&(o=r[1]),i=parseInt(t),!isNaN(i))return i%2===0?(e="element",n=i/2-1):(e="text",n=(i-1)/2),{type:e,index:n,id:o||null}},n.prototype.parseTerminal=function(t){var e,i,n=t.match(/\[(.*)\]/);return n&&n[1]?(e=parseInt(t.split("[")[0])||null,i=n[1]):e=parseInt(t)||null,{offset:e,assertion:i}},n.prototype.getChapterComponent=function(t){var e=t.split("!");return e[0]},n.prototype.getPathComponent=function(t){var e=t.split("!");if(e[1])return ranges=e[1].split(","),ranges[0]},n.prototype.getRange=function(t){var e=t.split(",");return 3===e.length&&[e[1],e[2]]},n.prototype.getCharecterOffsetComponent=function(t){var e=t.split(":");return e[1]||""},n.prototype.joinSteps=function(t){return t?t.map(function(t){var e="";return"element"===t.type&&(e+=2*(t.index+1)),"text"===t.type&&(e+=1+2*t.index),t.id&&(e+="["+t.id+"]"),e}).join("/"):""},n.prototype.segmentString=function(t){var e="/";return e+=this.joinSteps(t.steps),t.terminal&&null!=t.terminal.offset&&(e+=":"+t.terminal.offset),t.terminal&&null!=t.terminal.assertion&&(e+="["+t.terminal.assertion+"]"),e},n.prototype.toString=function(){var t="epubcfi(";return t+=this.segmentString(this.base),t+="!",t+=this.segmentString(this.path),this.start&&(t+=",",t+=this.segmentString(this.start)),this.end&&(t+=",",t+=this.segmentString(this.end)),t+=")"},n.prototype.compare=function(t,e){if("string"==typeof t&&(t=new n(t)),"string"==typeof e&&(e=new n(e)),t.spinePos>e.spinePos)return 1;if(t.spinePose.path.steps[i].index)return 1;if(t.path.steps[i].indexe.path.terminal.offset?1:t.path.terminal.offset=0&&(r.terminal.offset=e,"text"!=r.steps[r.steps.length-1].type&&r.steps.push({type:"text",index:0})),r},n.prototype.equalStep=function(t,e){return!(!t||!e)&&(t.index===e.index&&t.id===e.id&&t.type===e.type)},n.prototype.fromRange=function(t,e,i){var n={range:!1,base:{},path:{},start:null,end:null},r=t.startContainer,o=t.endContainer,s=t.startOffset,a=t.endOffset,h=!1;if(i&&(h=null!=r.ownerDocument.querySelector("."+i)),"string"==typeof e?(n.base=this.parseComponent(e),n.spinePos=n.base.steps[1].index):"object"==typeof e&&(n.base=e),t.collapsed)h&&(s=this.patchOffset(r,s,i)),n.path=this.pathTo(r,s,i);else{n.range=!0,h&&(s=this.patchOffset(r,s,i)),n.start=this.pathTo(r,s,i),h&&(a=this.patchOffset(o,a,i)),n.end=this.pathTo(o,a,i),n.path={steps:[],terminal:null};var c,u=n.start.steps.length;for(c=0;c0&&r===Node.TEXT_NODE&&o===Node.TEXT_NODE?s[n]=a:e===r&&(a+=1,s[n]=a),o=r;return s},n.prototype.position=function(t){var e,i;return t.nodeType===Node.ELEMENT_NODE?(e=t.parentNode.children,i=Array.prototype.indexOf.call(e,t)):(e=this.textNodes(t.parentNode),i=e.indexOf(t)),i},n.prototype.filteredPosition=function(t,e){var i,n,r;return t.nodeType===Node.ELEMENT_NODE?(i=t.parentNode.children,r=this.normalizedMap(i,Node.ELEMENT_NODE,e)):(i=t.parentNode.childNodes,t.parentNode.classList.contains(e)&&(t=t.parentNode,i=t.parentNode.childNodes),r=this.normalizedMap(i,Node.TEXT_NODE,e)),n=Array.prototype.indexOf.call(i,t),r[n]},n.prototype.stepsToXpath=function(t){var e=[".","*"];return t.forEach(function(t){var i=t.index+1;t.id?e.push("*[position()="+i+" and @id='"+t.id+"']"):"text"===t.type?e.push("text()["+i+"]"):e.push("*["+i+"]")}),e.join("/")},n.prototype.stepsToQuerySelector=function(t){var e=["html"];return t.forEach(function(t){var i=t.index+1;t.id?e.push("#"+t.id):"text"===t.type||e.push("*:nth-child("+i+")")}),e.join(">")},n.prototype.textNodes=function(t,e){return Array.prototype.slice.call(t.childNodes).filter(function(t){return t.nodeType===Node.TEXT_NODE||!(!e||!t.classList.contains(e))})},n.prototype.walkToNode=function(t,e,i){var n,r,o=e||document,s=o.documentElement,a=t.length;for(r=0;ro)){a=r.nodeType===Node.ELEMENT_NODE?r.childNodes[0]:r;break}e-=o}}return{container:a,offset:e}},n.prototype.toRange=function(t,e){var i,n,r,o,s,a,h,c=t||document,u=c.createRange(),p=this,l=!!e&&null!=c.querySelector("."+e);if(p.range?(i=p.start,s=p.path.steps.concat(i.steps),r=this.findNode(s,c,l?e:null),n=p.end,a=p.path.steps.concat(n.steps),o=this.findNode(a,c,l?e:null)):(i=p.path,s=p.path.steps,r=this.findNode(p.path.steps,c,l?e:null)),!r)return null;try{null!=i.terminal.offset?u.setStart(r,i.terminal.offset):u.setStart(r,0)}catch(d){h=this.fixMiss(s,i.terminal.offset,c,l?e:null),u.setStart(h.container,h.offset)}if(o)try{null!=n.terminal.offset?u.setEnd(o,n.terminal.offset):u.setEnd(o,0)}catch(d){h=this.fixMiss(a,p.end.terminal.offset,c,l?e:null),u.setEnd(h.container,h.offset)}return u},n.prototype.isCfiString=function(t){return"string"==typeof t&&0===t.indexOf("epubcfi(")&&")"===t[t.length-1]},n.prototype.generateChapterComponent=function(t,e,i){var n=parseInt(e),r=t+1,o="/"+r+"/";return o+=2*(n+1),i&&(o+="["+i+"]"),o},t.exports=n},function(t,e){function i(t){this.context=t||this,this.hooks=[]}i.prototype.register=function(){for(var t=0;ts&&(r+=s,a=s);a=s?r=s-(a-this["break"]):(i.setEnd(e,a),cfi=t.cfiFromRange(i),this._locations.push(cfi),r=0,a+=1,i=n.createRange(),i.setStart(e,a))}.bind(this)),i&&(i.setEnd(prev,prev.length),cfi=t.cfiFromRange(i),this._locations.push(cfi),r=0)}.bind(this))},n.prototype.sprint=function(t,e){
+for(var i=document.createTreeWalker(t,NodeFilter.SHOW_TEXT,null,!1);node=i.nextNode();)e(node)},n.prototype.locationFromCfi=function(t){return 0===this._locations.length?-1:r.locationOf(t,this._locations,this.epubcfi.compare)},n.prototype.precentageFromCfi=function(t){var e=this.locationFromCfi(t);return this.precentageFromLocation(e)},n.prototype.percentageFromLocation=function(t){return t&&this.total?t/this.total:0},n.prototype.cfiFromLocation=function(t){var e=-1;return"number"!=typeof t&&(t=parseInt(pg)),t>=0&&t1?t/100:t,i=Math.ceil(this.total*e);return this.cfiFromLocation(i)},n.prototype.load=function(t){return this._locations=JSON.parse(t),this.total=this._locations.length-1,this._locations},n.prototype.save=function(t){return JSON.stringify(this._locations)},n.prototype.getCurrent=function(t){return this._current},n.prototype.setCurrent=function(t){var e;if("string"==typeof t)this._currentCfi=t;else{if("number"!=typeof t)return;this._current=t}0!==this._locations.length&&("string"==typeof t?(e=this.locationFromCfi(t),this._current=e):e=t,this.emit("changed",{percentage:this.precentageFromLocation(e)}))},Object.defineProperty(n.prototype,"currentLocation",{get:function(){return this._current},set:function(t){this.setCurrent(t)}}),a(n.prototype),t.exports=n},function(t,e,i){function n(t){this._q=[],this.context=t,this.tick=r.requestAnimationFrame,this.running=!1,this.paused=!1}var r=i(22);n.prototype.enqueue=function(){var t,e,i,n=[].shift.call(arguments),o=arguments;return n?("function"==typeof n?(t=new r.defer,e=t.promise,i={task:n,args:o,deferred:t,promise:e}):i={promise:n},this._q.push(i),0!=this.paused||this.running||this.run(),i.promise):console.error("No Task Provided")},n.prototype.dequeue=function(){var t,e,i;return this._q.length?(t=this._q.shift(),(e=t.task)?(i=e.apply(this.context,t.args),i&&"function"==typeof i.then?i.then(function(){t.deferred.resolve.apply(this.context,arguments)}.bind(this)):(t.deferred.resolve.apply(this.context,i),t.promise)):t.promise?t.promise:void 0):(t=new r.defer,t.deferred.resolve(),t.promise)},n.prototype.dump=function(){for(;this._q.length;)this.dequeue()},n.prototype.run=function(){return this.running||(this.running=!0,this.defered=new r.defer),this.tick.call(window,function(){this._q.length?this.dequeue().then(function(){this.run()}.bind(this)):(this.defered.resolve(),this.running=void 0)}.bind(this)),1==this.paused&&(this.paused=!1),this.defered.promise},n.prototype.flush=function(){return this.running?this.running:this._q.length?(this.running=this.dequeue().then(function(){return this.running=void 0,this.flush()}.bind(this)),this.running):void 0},n.prototype.clear=function(){this._q=[],this.running=!1},n.prototype.length=function(){return this._q.length},n.prototype.pause=function(){this.paused=!0},t.exports=n},function(t,e,i){function n(){}var r=i(17),o=i(22),s=i(26);n.prototype.container=function(t){var e,i,n,s;return t?(e=o.qs(t,"rootfile"))?(i=e.getAttribute("full-path"),n=r(i).directory(),s=t.xmlEncoding,{packagePath:i,basePath:n,encoding:s}):void console.error("No RootFile Found"):void console.error("Container File Not Found")},n.prototype.identifier=function(t){var e;return t?(e=o.qs(t,"metadata"),e?this.getElementText(e,"identifier"):void console.error("No Metadata Found")):void console.error("Package File Not Found")},n.prototype.packageContents=function(t){var e,i,n,r,s,a,h,c,u,p,l=this;return t?(e=o.qs(t,"metadata"))?(i=o.qs(t,"manifest"))?(n=o.qs(t,"spine"))?(r=l.manifest(i),s=l.findNavPath(i),a=l.findNcxPath(i,n),h=l.findCoverPath(t),c=Array.prototype.indexOf.call(n.parentNode.childNodes,n),u=l.spine(n,r),p=l.metadata(e),p.direction=n.getAttribute("page-progression-direction"),{metadata:p,spine:u,manifest:r,navPath:s,ncxPath:a,coverPath:h,spineNodeIndex:c}):void console.error("No Spine Found"):void console.error("No Manifest Found"):void console.error("No Metadata Found"):void console.error("Package File Not Found")},n.prototype.findNavPath=function(t){var e=o.qsp(t,"item",{properties:"nav"});return!!e&&e.getAttribute("href")},n.prototype.findNcxPath=function(t,e){var i,n=o.qsp(t,"item",{"media-type":"application/x-dtbncx+xml"});return n||(i=e.getAttribute("toc"),i&&(n=t.getElementById(i))),!!n&&n.getAttribute("href")},n.prototype.metadata=function(t){var e={},i=this;return e.title=i.getElementText(t,"title"),e.creator=i.getElementText(t,"creator"),e.description=i.getElementText(t,"description"),e.pubdate=i.getElementText(t,"date"),e.publisher=i.getElementText(t,"publisher"),e.identifier=i.getElementText(t,"identifier"),e.language=i.getElementText(t,"language"),e.rights=i.getElementText(t,"rights"),e.modified_date=i.getPropertyText(t,"dcterms:modified"),e.layout=i.getPropertyText(t,"rendition:layout"),e.orientation=i.getPropertyText(t,"rendition:orientation"),e.flow=i.getPropertyText(t,"rendition:flow"),e.viewport=i.getPropertyText(t,"rendition:viewport"),e},n.prototype.findCoverPath=function(t){var e=o.qs(t,"package"),i=e.getAttribute("version");if("2.0"===i){var n=o.qsp(t,"meta",{name:"cover"});if(n){var r=n.getAttribute("content"),s=t.getElementById(r);return!!s&&s.getAttribute("href")}return!1}var a=o.qsp(t,"item",{properties:"cover-image"});return!!a&&a.getAttribute("href")},n.prototype.getElementText=function(t,e){var i,n=t.getElementsByTagNameNS("http://purl.org/dc/elements/1.1/",e);return n&&0!==n.length?(i=n[0],i.childNodes.length?i.childNodes[0].nodeValue:""):""},n.prototype.getPropertyText=function(t,e){var i=o.qsp(t,"meta",{property:e});return i&&i.childNodes.length?i.childNodes[0].nodeValue:""},n.prototype.querySelectorText=function(t,e){var i=t.querySelector(e);return i&&i.childNodes.length?i.childNodes[0].nodeValue:""},n.prototype.manifest=function(t){var e={},i=o.qsa(t,"item"),n=Array.prototype.slice.call(i);return n.forEach(function(t){var i=t.getAttribute("id"),n=t.getAttribute("href")||"",r=t.getAttribute("media-type")||"",o=t.getAttribute("properties")||"";e[i]={href:n,type:r,properties:o.length?o.split(" "):[]}}),e},n.prototype.spine=function(t,e){var i=[],n=t.getElementsByTagName("itemref"),r=Array.prototype.slice.call(n);new s;return r.forEach(function(t,e){var n=t.getAttribute("idref"),r=t.getAttribute("properties")||"",o=r.length?r.split(" "):[],s={idref:n,linear:t.getAttribute("linear")||"",properties:o,index:e};i.push(s)}),i},n.prototype.querySelectorByType=function(t,e,i){var n;if("undefined"!=typeof t.querySelector&&(n=t.querySelector(e+'[*|type="'+i+'"]')),n&&0!==n.length)return n;n=o.qsa(t,e);for(var r=0;r1&&n[1],{cfi:s,href:h,packageUrl:r,page:u}):{href:h,page:u}},t.exports=n},function(t,e,i){function n(t,e){var n=this,a=new o,h=e||i(29);this["package"]=t,this.toc=[],this.tocByHref={},this.tocById={},t.navPath&&(this.navUrl=s(t.navPath).absoluteTo(t.baseUrl).toString(),this.nav={},this.nav.load=function(t){var e=new r.defer,i=e.promise;return h(n.navUrl,"xml").then(function(t){n.toc=a.nav(t),n.loaded(n.toc),e.resolve(n.toc)}),i}),t.ncxPath&&(this.ncxUrl=s(t.ncxPath).absoluteTo(t.baseUrl).toString(),this.ncx={},this.ncx.load=function(t){var e=new r.defer,i=e.promise;return h(n.ncxUrl,"xml").then(function(t){n.toc=a.toc(t),n.loaded(n.toc),e.resolve(n.toc)}),i})}var r=i(22),o=i(33),s=i(17);n.prototype.load=function(t){var e,n;t||i(29);return this.nav?e=this.nav.load():this.ncx?e=this.ncx.load():(n=new r.defer,n.resolve([]),e=n.promise),e},n.prototype.loaded=function(t){for(var e,i=0;i-1&&(i=t.substring(t.indexOf("#")+1)),n&&(i=t),this.manager.display(e,i).then(function(){this.emit("displayed",e)}.bind(this))):(r.reject(new Error("No Section Found")),o)},n.prototype.afterDisplayed=function(t){this.hooks.content.trigger(t,this),this.emit("rendered",t.section),this.reportLocation()},n.prototype.onResized=function(t){this.location&&this.display(this.location.start),this.emit("resized",{width:t.width,height:t.height})},n.prototype.moveTo=function(t){this.manager.moveTo(t)},n.prototype.next=function(){return this.q.enqueue(this.manager.next.bind(this.manager)).then(this.reportLocation.bind(this))},n.prototype.prev=function(){return this.q.enqueue(this.manager.prev.bind(this.manager)).then(this.reportLocation.bind(this))},n.prototype.determineLayoutProperties=function(t){var e,i=this.settings.layout||t.layout||"reflowable",n=this.settings.spread||t.spread||"auto",r=this.settings.orientation||t.orientation||"auto",o=this.settings.flow||t.flow||"auto",s=t.viewport||"",a=this.settings.minSpreadWidth||t.minSpreadWidth||800;return this.settings.width>=0&&this.settings.height>=0&&(s="width="+this.settings.width+", height="+this.settings.height),e={layout:i,spread:n,orientation:r,flow:o,viewport:s,minSpreadWidth:a}},n.prototype.flow=function(t){var e;"scrolled-doc"!==t&&"scrolled-continuous"!==t||(e="scrolled"),"auto"!==t&&"paginated"!==t||(e="paginated"),this._layout&&this._layout.flow(e),this.manager&&this.manager.updateFlow(e)},n.prototype.layout=function(t){return t&&(this._layout=new p(t),this._layout.spread(t.spread,this.settings.minSpreadWidth),this.mapping=new l(this._layout)),this.manager&&this._layout&&this.manager.applyLayout(this._layout),this._layout},n.prototype.spread=function(t,e){this._layout.spread(t,e),this.manager.isRendered()&&this.manager.updateLayout()},n.prototype.reportLocation=function(){return this.q.enqueue(function(){var t=this.manager.currentLocation();t&&t.then&&"function"==typeof t.then?t.then(function(t){this.location=t,this.emit("locationChanged",this.location)}.bind(this)):t&&(this.location=t,this.emit("locationChanged",this.location))}.bind(this))},n.prototype.destroy=function(){this.q.clear(),this.manager.destroy()},n.prototype.passViewEvents=function(t){t.contents.listenedEvents.forEach(function(e){t.on(e,this.triggerViewEvent.bind(this))}.bind(this)),t.on("selected",this.triggerSelectedEvent.bind(this))},n.prototype.triggerViewEvent=function(t){this.emit(t.type,t)},n.prototype.triggerSelectedEvent=function(t){this.emit("selected",t)},n.prototype.replacements=function(){var t,e=this.book["package"].manifest,i=Object.keys(e).map(function(t){return e[t]}),n=i.filter(function(t){if("application/xhtml+xml"!=t.type&&"text/html"!=t.type)return!0}),r=n.filter(function(t){if("text/css"===t.type)return!0}),s=r.map(function(t){return t.href}),a=n.map(function(t){return t.href}.bind(this)),h=a.map(function(t){var e=o(t).absoluteTo(this.book.baseUrl).toString();return this.book.unarchived.createUrl(e,{base64:this.settings.useBase64})}.bind(this));return Promise.all(h).then(function(e){var i=[];return t=e,s.forEach(function(e){i.push(this.replaceCss(e,a,t))}.bind(this)),Promise.all(i)}.bind(this)).then(function(){this.book.spine.hooks.serialize.register(function(e,i){this.replaceAssets(i,a,t)}.bind(this))}.bind(this))["catch"](function(t){console.error(t)})},n.prototype.replaceCss=function(t,e,i){var n,r,h=o(t),c=h.absoluteTo(this.book.baseUrl).toString(),u=this.book.unarchived.getText(c),p=e.map(function(t){var e=o(t).absoluteTo(this.book.baseUrl),i=e.relativeTo(c).toString();return i}.bind(this));return u.then(function(o){return o=a.substitute(o,p,i),n=this.settings.useBase64?s.createBase64Url(o,"text/css"):s.createBlobUrl(o,"text/css"),r=e.indexOf(t),r>-1&&(i[r]=n),new Promise(function(t,n){t(e,i)})}.bind(this))},n.prototype.replaceAssets=function(t,e,i){var n=o(t.url),r=e.map(function(t){var e=o(t).absoluteTo(this.book.baseUrl),i=e.relativeTo(n).toString();return i}.bind(this));t.output=a.substitute(t.output,r,i)},n.prototype.range=function(t,e){var i=new c(t),n=this.visible().filter(function(t){if(i.spinePos===t.index)return!0});if(n.length)return n[0].range(i,e)},n.prototype.adjustImages=function(t){return t.addStylesheetRules([["img",["max-width",t.layout.spreadWidth+"px"],["max-height",t.layout.height+"px"]]]),new Promise(function(t,e){setTimeout(function(){t()},1)})},r(n.prototype),t.exports=n},function(t,e,i){function n(t){this.name=t.layout||"reflowable",this._spread="none"!==t.spread,this._minSpreadWidth=t.spread||800,this._evenSpreads=t.evenSpreads||!1,"scrolled-continuous"===t.flow||"scrolled-doc"===t.flow?this._flow="scrolled":this._flow="paginated",this.width=0,this.height=0,this.spreadWidth=0,this.delta=0,this.columnWidth=0,this.gap=0,this.divisor=1}i(22);n.prototype.flow=function(t){this._flow="paginated"===t?"paginated":"scrolled"},n.prototype.spread=function(t,e){this._spread="none"!==t,e>=0&&(this._minSpreadWidth=e)},n.prototype.calculate=function(t,e,i){var n,r,o,s=1,a=i||0,h=(Math.floor(t),t),c=Math.floor(h/8);s=this._spread&&h>=this._minSpreadWidth?2:1,"reflowable"!==this.name||"paginated"!==this._flow||i>=0||(a=c%2===0?c:c-1),"pre-paginated"===this.name&&(a=0),n=s>1?Math.floor((h-a)/s):h,"pre-paginated"===this.name&&s>1&&(h=n),r=n*s,o=(n+a)*s,this.width=h,this.height=e,this.spreadWidth=r,this.delta=o,this.columnWidth=n,this.gap=a,this.divisor=s},n.prototype.format=function(t){var e;return e="pre-paginated"===this.name?t.fit(this.columnWidth,this.height):"paginated"===this._flow?t.columns(this.width,this.height,this.columnWidth,this.gap):t.size(this.width,null)},n.prototype.count=function(t){var e=Math.ceil(t/this.spreadWidth);return{spreads:e,pages:e*this.divisor}},t.exports=n},function(t,e,i){function n(t){this.layout=t}var r=i(26);n.prototype.section=function(t){var e=this.findRanges(t),i=this.rangeListToCfiList(t.section.cfiBase,e);return i},n.prototype.page=function(t,e,i,n){var r=!(!t||!t.document)&&t.document.body;if(r)return this.rangePairToCfiPair(e,{start:this.findStart(r,i,n),end:this.findEnd(r,i,n)})},n.prototype.walk=function(t,e){for(var i,n,r=document.createTreeWalker(t,NodeFilter.SHOW_TEXT,{acceptNode:function(t){return t.data.trim().length>0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_REJECT}},!1);(i=r.nextNode())&&!(n=e(i)););return n},n.prototype.findRanges=function(t){for(var e,i,n=[],r=t.contents.scrollWidth(),o=this.layout.count(r),s=this.layout.column,a=this.layout.gap,h=0;h=e&&n<=i?t:r>e?t:(s=t,void o.push(t))}))return this.findTextStartRange(r,e,i);return this.findTextStartRange(s,e,i)},n.prototype.findEnd=function(t,e,i){for(var n,r,o=[t],s=t;o.length;)if(n=o.shift(),r=this.walk(n,function(t){var e,n,r,a;return t.nodeType==Node.TEXT_NODE?(a=document.createRange(),a.selectNodeContents(t),r=a.getBoundingClientRect()):r=t.getBoundingClientRect(),e=r.left,n=r.right,e>i&&s?s:n>i?t:(s=t,void o.push(t))}))return this.findTextEndRange(r,e,i);return this.findTextEndRange(s,e,i)},n.prototype.findTextStartRange=function(t,e,i){for(var n,r,o,s=this.splitTextNodeIntoRanges(t),a=0;a=e)return r;n=r}return s[0]},n.prototype.findTextEndRange=function(t,e,i){for(var n,r,o,s=this.splitTextNodeIntoRanges(t),a=0;ai&&n)return n;if(o.right>i)return r;n=r}return s[s.length-1]},n.prototype.splitTextNodeIntoRanges=function(t,e){var i,n=[],r=t.textContent||"",o=r.trim(),s=t.ownerDocument,a=e||" ";if(pos=o.indexOf(a),pos===-1||t.nodeType!=Node.TEXT_NODE)return i=s.createRange(),i.selectNodeContents(t),[i];for(i=s.createRange(),i.setStart(t,0),i.setEnd(t,pos),n.push(i),i=!1;pos!=-1;)pos=o.indexOf(a,pos+1),pos>0&&(i&&(i.setEnd(t,pos),n.push(i)),i=s.createRange(),i.setStart(t,pos+1));return i&&(i.setEnd(t,o.length),n.push(i)),n},n.prototype.rangePairToCfiPair=function(t,e){var i=e.start,n=e.end;return i.collapse(!0),n.collapse(!0),startCfi=new r(i,t).toString(),endCfi=new r(n,t).toString(),{start:startCfi,end:endCfi}},n.prototype.rangeListToCfiList=function(t,e){for(var i,n=[],r=0;r-1&&(id=t.substring(t.indexOf("#")+1),el=this.document.getElementById(id),el&&(i=el.getBoundingClientRect(),n.left=i.left,n.top=i.top)),n},n.prototype.addStylesheet=function(t){return new Promise(function(e,i){var n,r=!1;return this.document?(n=this.document.createElement("link"),n.type="text/css",n.rel="stylesheet",n.href=t,n.onload=n.onreadystatechange=function(){r||this.readyState&&"complete"!=this.readyState||(r=!0,setTimeout(function(){e(!0)},1))},void this.document.head.appendChild(n)):void e(!1)}.bind(this))},n.prototype.addStylesheetRules=function(t){var e,i;if(this.document){e=this.document.createElement("style"),this.document.head.appendChild(e),i=e.sheet;for(var n=0,r=t.length;n0&&(e=t.getRangeAt(0),e.collapsed||(i=new s(e,this.cfiBase).toString(),this.emit("selected",i),this.emit("selectedRange",e)))},n.prototype.range=function(t,e){var i=new s(t);return i.toRange(this.document,e)},n.prototype.map=function(t){var e=new a(t);return e.section()},n.prototype.size=function(t,e){t>=0&&this.width(t),e>=0&&this.height(e),this.css("margin","0"),this.css("boxSizing","border-box")},n.prototype.columns=function(t,e,i,n){var r=o.prefixed("columnAxis"),s=o.prefixed("columnGap"),a=o.prefixed("columnWidth"),h=o.prefixed("columnFill");this.width(t),this.height(e),this.viewport({width:t,height:e,scale:1}),this.css("overflowY","hidden"),this.css("margin","0"),this.css("boxSizing","border-box"),this.css("maxWidth","inherit"),this.css(r,"horizontal"),this.css(h,"auto"),this.css(s,n+"px"),this.css(a,i+"px")},n.prototype.scale=function(t,e,i){var t="scale("+t+")",n="";this.css("transformOrigin","top left"),(e>=0||i>=0)&&(n=" translate("+(e||0)+"px, "+(i||0)+"px )"),this.css("transform",t+n)},n.prototype.fit=function(t,e){var i=this.viewport(),n=t/i.width,r=e/i.height,o=n1&&"reflowable"===this.settings.layout.name&&e%2>0&&(r+=this.settings.layout.gap+this.settings.layout.columnWidth),this._textWidth=i,this._contentWidth=r):r=this._contentWidth):"vertical"===this.settings.axis&&(n=this.contents.textHeight(),n!=this._textHeight?(o=this.contentHeight(n),this._textHeight=n,this._contentHeight=o):o=this._contentHeight),(this._needsReframe||r!=this._width||o!=this._height)&&this.resize(r,o),this._expanding=!1)},n.prototype.contentWidth=function(t){var e,i;return e=this.iframe.style.width,this.iframe.style.width=(t||0)+"px",i=this.contents.scrollWidth(),this.iframe.style.width=e,i},n.prototype.contentHeight=function(t){var e,i;return e=this.iframe.style.height,this.iframe.style.height=(t||0)+"px",i=this.contents.scrollHeight(),this.iframe.style.height=e,i},n.prototype.resize=function(t,e){this.iframe&&(o.isNumber(t)&&(this.iframe.style.width=t+"px",this._width=t),o.isNumber(e)&&(this.iframe.style.height=e+"px",this._height=e),this.iframeBounds=o.bounds(this.iframe),this.reframe(this.iframeBounds.width,this.iframeBounds.height))},n.prototype.reframe=function(t,e){var i;o.isNumber(t)&&(this.element.style.width=t+"px"),o.isNumber(e)&&(this.element.style.height=e+"px"),this.prevBounds=this.elementBounds,this.elementBounds=o.bounds(this.element),i={width:this.elementBounds.width,height:this.elementBounds.height,widthDelta:this.elementBounds.width-this.prevBounds.width,heightDelta:this.elementBounds.height-this.prevBounds.height},this.onResize(this,i),this.emit("resized",i)},n.prototype.load=function(t){var e=new o.defer,i=e.promise;if(!this.iframe)return e.reject(new Error("No Iframe Available")),i;if(this.iframe.onload=function(t){this.onLoad(t,e)}.bind(this),this.supportsSrcdoc)this.iframe.srcdoc=t;else{if(this.document=this.iframe.contentDocument,!this.document)return e.reject(new Error("No Document Available")),i;this.iframe.contentDocument.open(),this.iframe.contentDocument.write(t),this.iframe.contentDocument.close()}return i},n.prototype.onLoad=function(t,e){this.window=this.iframe.contentWindow,this.document=this.iframe.contentDocument,this.contents=new a(this.document,this.document.body,this.section.cfiBase),this.rendering=!1;var i=this.document.querySelector("link[rel='canonical']");i?i.setAttribute("href",this.section.url):(i=this.document.createElement("link"),i.setAttribute("rel","canonical"),i.setAttribute("href",this.section.url),this.document.querySelector("head").appendChild(i)),this.contents.on("expand",function(){this.displayed&&this.iframe&&this.expand()}),e.resolve(this.contents)},n.prototype.setLayout=function(t){this.layout=t},n.prototype.setAxis=function(t){this.settings.axis=t},n.prototype.resizeListenters=function(){clearTimeout(this.expanding),this.expanding=setTimeout(this.expand.bind(this),350)},n.prototype.addListeners=function(){},n.prototype.removeListeners=function(t){},n.prototype.display=function(t){var e=new o.defer;return this.displayed?e.resolve(this):this.render(t).then(function(){this.emit("displayed",this),this.onDisplayed(this),this.displayed=!0,e.resolve(this)}.bind(this)),e.promise},n.prototype.show=function(){this.element.style.visibility="visible",this.iframe&&(this.iframe.style.visibility="visible"),this.emit("shown",this)},n.prototype.hide=function(){this.element.style.visibility="hidden",this.iframe.style.visibility="hidden",this.stopExpanding=!0,this.emit("hidden",this)},n.prototype.position=function(){return this.element.getBoundingClientRect()},n.prototype.locationOf=function(t){var e=this.iframe.getBoundingClientRect(),i=this.contents.locationOf(t,this.settings.ignoreClass);return{left:window.scrollX+e.left+i.left,top:window.scrollY+e.top+i.top}},n.prototype.onDisplayed=function(t){},n.prototype.onResize=function(t,e){},n.prototype.bounds=function(){return this.elementBounds||(this.elementBounds=o.bounds(this.element)),this.elementBounds},n.prototype.destroy=function(){this.displayed&&(this.displayed=!1,this.removeListeners(),this.stopExpanding=!0,this.element.removeChild(this.iframe),this.displayed=!1,this.iframe=null,this._textWidth=null,this._textHeight=null,this._width=null,this._height=null)},r(n.prototype),t.exports=n},function(t,e,i){function n(t){this.name="default",this.View=t.view,this.request=t.request,this.renditionQueue=t.queue,this.q=new a(this),this.settings=o.extend(this.settings||{},{infinite:!0,hidden:!1,width:void 0,height:void 0,axis:"vertical",ignoreClass:""}),o.extend(this.settings,t.settings||{}),this.viewSettings={ignoreClass:this.settings.ignoreClass,axis:this.settings.axis,layout:this.layout,width:0,height:0}}var r=i(2),o=i(22),s=(i(26),i(37)),a=i(32),h=i(44),c=i(45);n.prototype.render=function(t,e){this.stage=new h({width:e.width,height:e.height,overflow:this.settings.overflow,hidden:this.settings.hidden,axis:this.settings.axis}),this.stage.attachTo(t),this.container=this.stage.getContainer(),this.views=new c(this.container),this._bounds=this.bounds(),this._stageSize=this.stage.size(),this.viewSettings.width=this._stageSize.width,this.viewSettings.height=this._stageSize.height,this.stage.onResize(this.onResized.bind(this)),this.addEventListeners(),this.layout&&this.updateLayout()},n.prototype.addEventListeners=function(){window.addEventListener("unload",function(t){this.destroy()}.bind(this))},n.prototype.destroy=function(){},n.prototype.onResized=function(t){clearTimeout(this.resizeTimeout),this.resizeTimeout=setTimeout(function(){this.resize()}.bind(this),150)},n.prototype.resize=function(t,e){this.q.clear(),this._stageSize=this.stage.size(t,e),this._bounds=this.bounds(),this.viewSettings.width=this._stageSize.width,this.viewSettings.height=this._stageSize.height,this.views.each(function(t){t.size(this._stageSize.width,this._stageSize.height)}.bind(this)),this.updateLayout(),this.emit("resized",{width:this.stage.width,height:this.stage.height})},n.prototype.createView=function(t){return new this.View(t,this.viewSettings)},n.prototype.display=function(t,e){var i=new o.defer,n=i.promise,r=this.views.find(t);return r&&e?(offset=r.locationOf(e),this.moveTo(offset),i.resolve(),n):(this.views.hide(),this.views.clear(),this.add(t).then(function(){var e;if("pre-paginated"===this.layout.name&&this.layout.divisor>1&&(e=t.next()))return this.add(e)}.bind(this)).then(function(t){e&&(offset=t.locationOf(e),this.moveTo(offset)),this.views.show(),i.resolve()}.bind(this)),n)},n.prototype.afterDisplayed=function(t){this.emit("added",t)},n.prototype.afterResized=function(t){this.emit("resize",t.section)},n.prototype.moveTo=function(t){var e=0,i=0;"vertical"===this.settings.axis?i=t.top:(e=Math.floor(t.left/this.layout.delta)*this.layout.delta,e+this.layout.delta>this.container.scrollWidth&&(e=this.container.scrollWidth-this.layout.delta)),this.scrollTo(e,i)},n.prototype.add=function(t){var e=this.createView(t);return this.views.append(e),e.onDisplayed=this.afterDisplayed.bind(this),e.onResize=this.afterResized.bind(this),e.display(this.request)},n.prototype.append=function(t){var e=this.createView(t);return this.views.append(e),e.display(this.request)},n.prototype.prepend=function(t){var e=this.createView(t);return this.views.prepend(e),e.display(this.request)},n.prototype.next=function(){var t,e;if(this.views.length)return"horizontal"===this.settings.axis?(this.scrollLeft=this.container.scrollLeft,e=this.container.scrollLeft+this.container.offsetWidth+this.layout.delta,e1&&(e=t.next()))return this.append(e)}.bind(this)).then(function(){this.views.show()}.bind(this))):void 0},n.prototype.prev=function(){var t,e;if(this.views.length)return"horizontal"===this.settings.axis?(this.scrollLeft=this.container.scrollLeft,e=this.container.scrollLeft,e>0?this.scrollBy(-this.layout.delta,0):t=this.views.first().section.prev()):t=this.views.first().section.prev(),t?(this.views.clear(),this.prepend(t).then(function(){var e;if(this.layout.name&&this.layout.divisor>1&&(e=t.prev()))return this.prepend(e)}.bind(this)).then(function(){"horizontal"===this.settings.axis&&this.scrollTo(this.container.scrollWidth-this.layout.delta,0),this.views.show()}.bind(this))):void 0},n.prototype.current=function(){var t=this.visible();return t.length?t[t.length-1]:null},n.prototype.currentLocation=function(){var t,e,i;if(this.views.length)return t=this.views.first(),e=container.left-t.position().left,i=e+this.layout.spread,this.mapping.page(t,t.section.cfiBase)},n.prototype.isVisible=function(t,e,i,n){var r=t.position(),o=n||this.bounds();return"horizontal"===this.settings.axis&&r.right>o.left-e&&r.lefto.top-e&&r.top-1&&this._views.splice(e,1),this.destroy(t),this.length--},i.prototype.destroy=function(t){t.displayed&&t.destroy(),this.container&&this.container.removeChild(t.element),t=null},i.prototype.each=function(){return this._views.forEach.apply(this._views,arguments)},i.prototype.clear=function(){var t,e=this.length;if(this.length){for(var i=0;i=f&&(i=this.views.last(),o=i&&i.section.next(),o&&h.push(this.append(o))),l-u<0&&(n=this.views.first(),s=n&&n.section.prev(),s&&h.push(this.prepend(s))),h.length?this.q.enqueue(function(){return this.update(u)}.bind(this)):(a.resolve(!1),a.promise)},n.prototype.trim=function(){for(var t=new r.defer,e=this.views.displayed(),i=e[0],n=e[e.length-1],o=this.views.indexOf(i),s=this.views.indexOf(n),a=this.views.slice(0,o),h=this.views.slice(s+1),c=0;cthis.settings.offsetDelta||this.scrollDeltaHorz>this.settings.offsetDelta)&&(this.q.enqueue(function(){this.check()}.bind(this)),this.scrollDeltaVert=0,this.scrollDeltaHorz=0,this.emit("scroll",{top:scrollTop,left:scrollLeft}),clearTimeout(this.afterScrolled),this.afterScrolled=setTimeout(function(){this.emit("scrolled",{top:this.scrollTop,left:this.scrollLeft})}.bind(this))),this.scrollDeltaVert+=Math.abs(scrollTop-this.prevScrollTop),this.scrollDeltaHorz+=Math.abs(scrollLeft-this.prevScrollLeft),this.prevScrollTop=scrollTop,this.prevScrollLeft=scrollLeft,clearTimeout(this.scrollTimeout),this.scrollTimeout=setTimeout(function(){this.scrollDeltaVert=0,this.scrollDeltaHorz=0}.bind(this),150),this.scrolled=!1},n.prototype.currentLocation=function(){return"vertical"===this.settings.axis?this.location=this.scrolledLocation():this.location=this.paginatedLocation(),this.location},n.prototype.scrolledLocation=function(){var t,e,i=this.visible();this.container.getBoundingClientRect();return 1===i.length?this.mapping.page(i[0].contents,i[0].section.cfiBase):i.length>1?(t=this.mapping.page(i[0].contents,i[0].section.cfiBase),e=this.mapping.page(i[i.length-1].contents,i[i.length-1].section.cfiBase),{start:t.start,end:e.end}):void 0},n.prototype.paginatedLocation=function(){var t,e,i,n,r,o,s=this.visible(),a=this.container.getBoundingClientRect();return 1===s.length?(t=a.left-s[0].position().left,i=t+this.layout.spreadWidth,this.mapping.page(s[0].contents,s[0].section.cfiBase,t,i)):s.length>1?(t=a.left-s[0].position().left,i=t+this.layout.columnWidth,e=a.left+this.layout.spreadWidth-s[s.length-1].position().left,n=e+this.layout.columnWidth,r=this.mapping.page(s[0].contents,s[0].section.cfiBase,t,i),o=this.mapping.page(s[s.length-1].contents,s[s.length-1].section.cfiBase,e,n),{start:r.start,end:o.end}):void 0},n.prototype.updateLayout=function(){this.stage&&("vertical"===this.settings.axis?this.layout.calculate(this._stageSize.width,this._stageSize.height):(this.layout.calculate(this._stageSize.width,this._stageSize.height,this.settings.gap),this.settings.offset=this.layout.delta,this.stage.addStyleRules("iframe",[{"margin-right":this.layout.gap+"px"}])),this.viewSettings.width=this.layout.width,this.viewSettings.height=this.layout.height,this.setLayout(this.layout))},n.prototype.next=function(){"horizontal"===this.settings.axis?(this.scrollLeft=this.container.scrollLeft,this.container.scrollLeft+this.container.offsetWidth+this.layout.delta