epubjs
Version:
Parse and Render Epubs
1 lines • 161 kB
JavaScript
(function(p,v){'object'==typeof exports&&'object'==typeof module?module.exports=v(require('xmldom'),function(){try{return require('JSZip')}catch(_){}}()):'function'==typeof define&&define.amd?define(['xmldom','JSZip'],v):'object'==typeof exports?exports.ePub=v(require('xmldom'),function(){try{return require('JSZip')}catch(_){}}()):p.ePub=v(p.xmldom,p.JSZip)})(this,function(s,p){return function(v){function k(C){if(_[C])return _[C].exports;var S=_[C]={i:C,l:!1,exports:{}};return v[C].call(S.exports,S,S.exports,k),S.l=!0,S.exports}var _={};return k.m=v,k.c=_,k.i=function(C){return C},k.d=function(C,S,E){k.o(C,S)||Object.defineProperty(C,S,{configurable:!1,enumerable:!0,get:E})},k.n=function(C){var S=C&&C.__esModule?function(){return C['default']}:function(){return C};return k.d(S,'a',S),S},k.o=function(C,S){return Object.prototype.hasOwnProperty.call(C,S)},k.p='/dist/',k(k.s=27)}([function(v,k,_){'use strict';function C(fe,me){if(!(fe instanceof me))throw new TypeError('Cannot call a class as a function')}function E(){var fe=new Date().getTime(),me='xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g,function(ye){var ve=0|(fe+16*Math.random())%16;return fe=Math.floor(fe/16),('x'==ye?ve:8|7&ve).toString(16)});return me}function L(fe){return!isNaN(parseFloat(fe))&&isFinite(fe)}function B(fe,me,ye,ve,be){var ke=ve||0,xe=be||me.length,_e=parseInt(ke+(xe-ke)/2),we;return(ye||(ye=function(Se,Ee){return Se>Ee?1:Se<Ee?-1:Se==Ee?0:void 0}),0>=xe-ke)?_e:(we=ye(me[_e],fe),1==xe-ke?0<=we?_e:_e+1:0===we?_e:-1===we?B(fe,me,ye,_e,xe):B(fe,me,ye,ke,_e))}function O(fe,me,ye,ve,be){var ke=ve||0,xe=be||me.length,_e=parseInt(ke+(xe-ke)/2),we;return(ye||(ye=function(Se,Ee){return Se>Ee?1:Se<Ee?-1:Se==Ee?0:void 0}),0>=xe-ke)?-1:(we=ye(me[_e],fe),1==xe-ke?0===we?_e:-1:0===we?_e:-1===we?O(fe,me,ye,_e,xe):O(fe,me,ye,ke,_e))}function D(fe,me){for(var ye=fe.parentNode,ve=ye.childNodes,ke=-1,xe=0,be;xe<ve.length&&(be=ve[xe],be.nodeType===me&&ke++,be!=fe);xe++);return ke}function X(fe,me){return new Blob([fe],{type:me})}function G(fe,me){return'undefined'==typeof fe.querySelector?fe.getElementsByTagName(me):fe.querySelectorAll(me)}function te(fe,me,ye){for(var ve=document.createTreeWalker(fe,ye,null,!1),be;be=ve.nextNode();)me(be)}function ne(fe,me){if(me(fe))return!0;if(fe=fe.firstChild,fe)do{var ye=ne(fe,me);if(ye)return!0;fe=fe.nextSibling}while(fe)}function le(fe){for(var me=[fe];fe;fe=fe.parentNode)me.unshift(fe);return me}Object.defineProperty(k,'__esModule',{value:!0});var oe=function(){function fe(me,ye){for(var ve=0,be;ve<ye.length;ve++)be=ye[ve],be.enumerable=be.enumerable||!1,be.configurable=!0,'value'in be&&(be.writable=!0),Object.defineProperty(me,be.key,be)}return function(me,ye,ve){return ye&&fe(me.prototype,ye),ve&&fe(me,ve),me}}();k.isElement=function(fe){return!!(fe&&1==fe.nodeType)},k.uuid=E,k.documentHeight=function(){return Math.max(document.documentElement.clientHeight,document.body.scrollHeight,document.documentElement.scrollHeight,document.body.offsetHeight,document.documentElement.offsetHeight)},k.isNumber=L,k.isFloat=function(fe){return L(fe)&&Math.floor(fe)!==fe},k.prefixed=function(fe){var me=['Webkit','webkit','Moz','O','ms'],ye=['-webkit-','-webkit-','-moz-','-o-','-ms-'],ve=fe[0].toUpperCase()+fe.slice(1),be=me.length;if('undefined'==typeof document||'undefined'!=typeof document.body.style[fe])return fe;for(var ke=0;ke<be;ke++)if('undefined'!=typeof document.body.style[me[ke]+ve])return ye[ke]+fe;return fe},k.defaults=function(fe){for(var me=1,ye=arguments.length,ve;me<ye;me++)for(var be in ve=arguments[me],ve)void 0===fe[be]&&(fe[be]=ve[be]);return fe},k.extend=function(fe){var me=[].slice.call(arguments,1);return me.forEach(function(ye){ye&&Object.getOwnPropertyNames(ye).forEach(function(ve){Object.defineProperty(fe,ve,Object.getOwnPropertyDescriptor(ye,ve))})}),fe},k.insert=function(fe,me,ye){var ve=B(fe,me,ye);return me.splice(ve,0,fe),ve},k.locationOf=B,k.indexOfSorted=O,k.bounds=function(fe){var me=window.getComputedStyle(fe),be=0,ke=0;return['width','paddingRight','paddingLeft','marginRight','marginLeft','borderRightWidth','borderLeftWidth'].forEach(function(xe){be+=parseFloat(me[xe])||0}),['height','paddingTop','paddingBottom','marginTop','marginBottom','borderTopWidth','borderBottomWidth'].forEach(function(xe){ke+=parseFloat(me[xe])||0}),{height:ke,width:be}},k.borders=function(fe){var me=window.getComputedStyle(fe),be=0,ke=0;return['paddingRight','paddingLeft','marginRight','marginLeft','borderRightWidth','borderLeftWidth'].forEach(function(xe){be+=parseFloat(me[xe])||0}),['paddingTop','paddingBottom','marginTop','marginBottom','borderTopWidth','borderBottomWidth'].forEach(function(xe){ke+=parseFloat(me[xe])||0}),{height:ke,width:be}},k.windowBounds=function(){var fe=window.innerWidth,me=window.innerHeight;return{top:0,left:0,right:fe,bottom:me,width:fe,height:me}},k.cleanStringForXpath=function(fe){var me=fe.match(/[^'"]+|['"]/g);return me=me.map(function(ye){return'\''===ye?'"\'"':'"'===ye?'\'"\'':'\''+ye+'\''}),'concat(\'\','+me.join(',')+')'},k.indexOfNode=D,k.indexOfTextNode=function(fe){return D(fe,ce)},k.indexOfElementNode=function(fe){return D(fe,ue)},k.isXml=function(fe){return-1<['xml','opf','ncx'].indexOf(fe)},k.createBlob=X,k.createBlobUrl=function(fe,me){var ye=window.URL||window.webkitURL||window.mozURL,be=X(fe,me),ve;return ve=ye.createObjectURL(be),ve},k.createBase64Url=function(fe,me){var ye,ve;if('string'==typeof fe)return ye=btoa(fe),ve='data:'+me+';base64,'+ye,ve},k.type=function(fe){return Object.prototype.toString.call(fe).slice(8,-1)},k.parse=function(fe,me,ye){var ve,be;return be='undefined'==typeof DOMParser||ye?_(16).DOMParser:DOMParser,65279===fe.charCodeAt(0)&&(fe=fe.slice(1)),ve=new be().parseFromString(fe,me),ve},k.qs=function(fe,me){var ye;if(!fe)throw new Error('No Element Provided');return'undefined'==typeof fe.querySelector?(ye=fe.getElementsByTagName(me),ye.length)?ye[0]:void 0:fe.querySelector(me)},k.qsa=G,k.qsp=function(fe,me,ye){var ve,be;if('undefined'!=typeof fe.querySelector){for(var ke in me+='[',ye)me+=ke+'=\''+ye[ke]+'\'';return me+=']',fe.querySelector(me)}return(ve=fe.getElementsByTagName(me),be=Array.prototype.slice.call(ve,0).filter(function(xe){for(var _e in ye)if(xe.getAttribute(_e)===ye[_e])return!0;return!1}),be)?be[0]:void 0},k.sprint=function(fe,me){var ye=fe.ownerDocument||fe;'undefined'==typeof ye.createTreeWalker?ne(fe,function(ve){ve&&3===ve.nodeType&&me(ve)},!0):te(fe,me,NodeFilter.SHOW_TEXT)},k.treeWalker=te,k.walk=ne,k.blob2base64=function(fe){return new Promise(function(me){var ve=new FileReader;ve.readAsDataURL(fe),ve.onloadend=function(){me(ve.result)}})},k.defer=function(){var fe=this;this.resolve=null,this.reject=null,this.id=E(),this.promise=new Promise(function(me,ye){fe.resolve=me,fe.reject=ye}),Object.freeze(this)},k.querySelectorByType=function(fe,me,ye){var ve;if('undefined'!=typeof fe.querySelector&&(ve=fe.querySelector(me+'[*|type="'+ye+'"]')),!ve||0===ve.length){ve=G(fe,me);for(var be=0;be<ve.length;be++)if(ve[be].getAttributeNS('http://www.idpf.org/2007/ops','type')===ye||ve[be].getAttribute('epub:type')===ye)return ve[be]}else return ve},k.findChildren=function(fe){for(var me=[],ye=fe.childNodes,ve=0,be;ve<ye.length;ve++)be=ye[ve],1===be.nodeType&&me.push(be);return me},k.parents=le;var de=k.requestAnimationFrame='undefined'!=typeof window&&(window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame),ue=1,ce=3,ge=k.RangeObject=function(){function fe(){C(this,fe),this.collapsed=!1,this.commonAncestorContainer=void 0,this.endContainer=void 0,this.endOffset=void 0,this.startContainer=void 0,this.startOffset=void 0}return oe(fe,[{key:'setStart',value:function(ye,ve){this.startContainer=ye,this.startOffset=ve,this.endContainer?this.commonAncestorContainer=this._commonAncestorContainer():this.collapse(!0),this._checkCollapsed()}},{key:'setEnd',value:function(ye,ve){this.endContainer=ye,this.endOffset=ve,this.startContainer?(this.collapsed=!1,this.commonAncestorContainer=this._commonAncestorContainer()):this.collapse(!1),this._checkCollapsed()}},{key:'collapse',value:function(ye){this.collapsed=!0,ye?(this.endContainer=this.startContainer,this.endOffset=this.startOffset,this.commonAncestorContainer=this.startContainer.parentNode):(this.startContainer=this.endContainer,this.startOffset=this.endOffset,this.commonAncestorContainer=this.endOffset.parentNode)}},{key:'selectNode',value:function(ye){var ve=ye.parentNode,be=Array.prototype.indexOf.call(ve.childNodes,ye);this.setStart(ve,be),this.setEnd(ve,be+1)}},{key:'selectNodeContents',value:function(ye){var ve=ye.childNodes[ye.childNodes-1],be=3===ye.nodeType?ye.textContent.length:parent.childNodes.length;this.setStart(ye,0),this.setEnd(ye,be)}},{key:'_commonAncestorContainer',value:function(ye,ve){var be=le(ye||this.startContainer),ke=le(ve||this.endContainer);if(be[0]==ke[0])for(var xe=0;xe<be.length;xe++)if(be[xe]!=ke[xe])return be[xe-1]}},{key:'_checkCollapsed',value:function(){this.collapsed=this.startContainer===this.endContainer&&this.startOffset===this.endOffset}},{key:'toString',value:function(){}}]),fe}()},function(v,k,_){'use strict';function C(N,A){if(!(N instanceof A))throw new TypeError('Cannot call a class as a function')}Object.defineProperty(k,'__esModule',{value:!0});var S='function'==typeof Symbol&&'symbol'==typeof Symbol.iterator?function(N){return typeof N}:function(N){return N&&'function'==typeof Symbol&&N.constructor===Symbol&&N!==Symbol.prototype?'symbol':typeof N},E=function(){function N(A,B){for(var O=0,I;O<B.length;O++)I=B[O],I.enumerable=I.enumerable||!1,I.configurable=!0,'value'in I&&(I.writable=!0),Object.defineProperty(A,I.key,I)}return function(A,B,O){return B&&N(A.prototype,B),O&&N(A,O),A}}(),P=_(0),L=1,R=3,z=function(){function N(A,B,O){C(this,N);var I;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(A,B,O);if('string'==typeof B?this.base=this.parseComponent(B):'object'===('undefined'==typeof B?'undefined':S(B))&&B.steps&&(this.base=B),I=this.checkType(A),'string'===I)return this.str=A,(0,P.extend)(this,this.parse(A));if('range'===I)return(0,P.extend)(this,this.fromRange(A,this.base,O));if('node'===I)return(0,P.extend)(this,this.fromNode(A,this.base,O));if('EpubCFI'===I&&A.path)return A;if(!A)return this;throw new TypeError('not a valid argument for EpubCFI')}return E(N,[{key:'checkType',value:function(B){return this.isCfiString(B)?'string':'object'===('undefined'==typeof B?'undefined':S(B))&&('Range'===(0,P.type)(B)||'undefined'!=typeof B.startContainer)?'range':'object'===('undefined'==typeof B?'undefined':S(B))&&'undefined'!=typeof B.nodeType?'node':'object'===('undefined'==typeof B?'undefined':S(B))&&B instanceof N&&'EpubCFI'}},{key:'parse',value:function(B){var O={spinePos:-1,range:!1,base:{},path:{},start:null,end:null},I,M,U;return'string'==typeof B?(0===B.indexOf('epubcfi(')&&')'===B[B.length-1]&&(B=B.slice(8,B.length-1)),I=this.getChapterComponent(B),!I)?{spinePos:-1}:(O.base=this.parseComponent(I),M=this.getPathComponent(B),O.path=this.parseComponent(M),U=this.getRange(B),U&&(O.range=!0,O.start=this.parseComponent(U[0]),O.end=this.parseComponent(U[1])),O.spinePos=O.base.steps[1].index,O):{spinePos:-1}}},{key:'parseComponent',value:function(B){var O={steps:[],terminal:{offset:null,assertion:null}},I=B.split(':'),M=I[0].split('/'),U;return 1<I.length&&(U=I[1],O.terminal=this.parseTerminal(U)),''===M[0]&&M.shift(),O.steps=M.map(function(W){return this.parseStep(W)}.bind(this)),O}},{key:'parseStep',value:function(B){var O,I,M,U,W;if(U=B.match(/\[(.*)\]/),U&&U[1]&&(W=U[1]),I=parseInt(B),!isNaN(I))return 0==I%2?(O='element',M=I/2-1):(O='text',M=(I-1)/2),{type:O,index:M,id:W||null}}},{key:'parseTerminal',value:function(B){var M=B.match(/\[(.*)\]/),O,I;return M&&M[1]?(O=parseInt(B.split('[')[0]),I=M[1]):O=parseInt(B),(0,P.isNumber)(O)||(O=null),{offset:O,assertion:I}}},{key:'getChapterComponent',value:function(B){var O=B.split('!');return O[0]}},{key:'getPathComponent',value:function(B){var O=B.split('!');if(O[1]){var I=O[1].split(',');return I[0]}}},{key:'getRange',value:function(B){var O=B.split(',');return 3===O.length&&[O[1],O[2]]}},{key:'getCharecterOffsetComponent',value:function(B){var O=B.split(':');return O[1]||''}},{key:'joinSteps',value:function(B){return B?B.map(function(O){var I='';return'element'===O.type&&(I+=2*(O.index+1)),'text'===O.type&&(I+=1+2*O.index),O.id&&(I+='['+O.id+']'),I}).join('/'):''}},{key:'segmentString',value:function(B){var A='/';return A+=this.joinSteps(B.steps),B.terminal&&null!=B.terminal.offset&&(A+=':'+B.terminal.offset),B.terminal&&null!=B.terminal.assertion&&(A+='['+B.terminal.assertion+']'),A}},{key:'toString',value:function(){var B='epubcfi(';return B+=this.segmentString(this.base),B+='!',B+=this.segmentString(this.path),this.range&&this.start&&(B+=',',B+=this.segmentString(this.start)),this.range&&this.end&&(B+=',',B+=this.segmentString(this.end)),B+=')',B}},{key:'compare',value:function(B,O){var I,M,U,W,H,H;if('string'==typeof B&&(B=new N(B)),'string'==typeof O&&(O=new N(O)),B.spinePos>O.spinePos)return 1;if(B.spinePos<O.spinePos)return-1;B.range?(I=B.path.steps.concat(B.start.steps),U=B.start.terminal):(I=B.path.steps,U=B.path.terminal),O.range?(M=O.path.steps.concat(O.start.steps),W=O.start.terminal):(M=O.path.steps,W=O.path.terminal);for(var Z=0;Z<I.length;Z++){if(!I[Z])return-1;if(!M[Z])return 1;if(I[Z].index>M[Z].index)return 1;if(I[Z].index<M[Z].index)return-1}return I.length<M.length?1:U.offset>W.offset?1:U.offset<W.offset?-1:0}},{key:'step',value:function(B){var O=B.nodeType===R?'text':'element';return{id:B.id,tagName:B.tagName,type:O,index:this.position(B)}}},{key:'filteredStep',value:function(B,O){var I=this.filter(B,O),M;if(I)return M=I.nodeType===R?'text':'element',{id:I.id,tagName:I.tagName,type:M,index:this.filteredPosition(I,O)}}},{key:'pathTo',value:function(B,O,I){for(var M={steps:[],terminal:{offset:null,assertion:null}},U=B,W;U&&U.parentNode&&U.parentNode.nodeType!=9;)W=I?this.filteredStep(U,I):this.step(U),W&&M.steps.unshift(W),U=U.parentNode;return null!=O&&0<=O&&(M.terminal.offset=O,'text'!=M.steps[M.steps.length-1].type&&M.steps.push({type:'text',index:0})),M}},{key:'equalStep',value:function(B,O){return B&&O&&B.index===O.index&&B.id===O.id&&B.type===O.type}},{key:'fromRange',value:function(B,O,I){var M={range:!1,base:{},path:{},start:null,end:null},U=B.startContainer,W=B.endContainer,D=B.startOffset,F=B.endOffset,H=!1;if(I&&(H=null!=U.ownerDocument.querySelector('.'+I)),'string'==typeof O?(M.base=this.parseComponent(O),M.spinePos=M.base.steps[1].index):'object'===('undefined'==typeof O?'undefined':S(O))&&(M.base=O),B.collapsed)H&&(D=this.patchOffset(U,D,I)),M.path=this.pathTo(U,D,I);else{M.range=!0,H&&(D=this.patchOffset(U,D,I)),M.start=this.pathTo(U,D,I),H&&(F=this.patchOffset(W,F,I)),M.end=this.pathTo(W,F,I),M.path={steps:[],terminal:null};var V=M.start.steps.length,X;for(X=0;X<V&&this.equalStep(M.start.steps[X],M.end.steps[X]);X++)X===V-1?M.start.terminal===M.end.terminal&&(M.path.steps.push(M.start.steps[X]),M.range=!1):M.path.steps.push(M.start.steps[X]);M.start.steps=M.start.steps.slice(M.path.steps.length),M.end.steps=M.end.steps.slice(M.path.steps.length)}return M}},{key:'fromNode',value:function(B,O,I){var M={range:!1,base:{},path:{},start:null,end:null};return'string'==typeof O?(M.base=this.parseComponent(O),M.spinePos=M.base.steps[1].index):'object'===('undefined'==typeof O?'undefined':S(O))&&(M.base=O),M.path=this.pathTo(B,null,I),M}},{key:'filter',value:function(B,O){var F=!1,I,M,U,W,D;return B.nodeType===R?(F=!0,U=B.parentNode,I=B.parentNode.classList.contains(O)):(F=!1,I=B.classList.contains(O)),I&&F?(W=U.previousSibling,D=U.nextSibling,W&&W.nodeType===R?M=W:D&&D.nodeType===R&&(M=D),M?M:B):I&&!F?!1:B}},{key:'patchOffset',value:function(B,O,I){if(B.nodeType!=R)throw new Error('Anchor must be a text node');var M=B,U=O;for(B.parentNode.classList.contains(I)&&(M=B.parentNode);M.previousSibling;){if(M.previousSibling.nodeType!==L)U+=M.previousSibling.textContent.length;else if(M.previousSibling.classList.contains(I))U+=M.previousSibling.textContent.length;else break;M=M.previousSibling}return U}},{key:'normalizedMap',value:function(B,O,I){var M={},U=-1,D=B.length,W,F,H;for(W=0;W<D;W++)F=B[W].nodeType,F===L&&B[W].classList.contains(I)&&(F=R),0<W&&F===R&&H===R?M[W]=U:O===F&&(++U,M[W]=U),H=F;return M}},{key:'position',value:function(B){var O,I;return B.nodeType===L?(O=B.parentNode.children,!O&&(O=(0,P.findChildren)(B.parentNode)),I=Array.prototype.indexOf.call(O,B)):(O=this.textNodes(B.parentNode),I=O.indexOf(B)),I}},{key:'filteredPosition',value:function(B,O){var I,M,U;return B.nodeType===L?(I=B.parentNode.children,U=this.normalizedMap(I,L,O)):(I=B.parentNode.childNodes,B.parentNode.classList.contains(O)&&(B=B.parentNode,I=B.parentNode.childNodes),U=this.normalizedMap(I,R,O)),M=Array.prototype.indexOf.call(I,B),U[M]}},{key:'stepsToXpath',value:function(B){var O=['.','*'];return B.forEach(function(I){var M=I.index+1;I.id?O.push('*[position()='+M+' and @id=\''+I.id+'\']'):'text'===I.type?O.push('text()['+M+']'):O.push('*['+M+']')}),O.join('/')}},{key:'stepsToQuerySelector',value:function(B){var O=['html'];return B.forEach(function(I){var M=I.index+1;I.id?O.push('#'+I.id):'text'===I.type||O.push('*:nth-child('+M+')')}),O.join('>')}},{key:'textNodes',value:function(B,O){return Array.prototype.slice.call(B.childNodes).filter(function(I){return I.nodeType===R||O&&I.classList.contains(O)})}},{key:'walkToNode',value:function(B,O,I){var M=O||document,U=M.documentElement,F=B.length,W,D,H;for(H=0;H<F&&(D=B[H],'element'===D.type?D.id?U=M.getElementById(D.id):(W=U.children||(0,P.findChildren)(U),U=W[D.index]):'text'===D.type&&(U=this.textNodes(U,I)[D.index]),!!U);H++);return U}},{key:'findNode',value:function(B,O,I){var M=O||document,U,W;return I||'undefined'==typeof M.evaluate?I?U=this.walkToNode(B,M,I):U=this.walkToNode(B,M):(W=this.stepsToXpath(B),U=M.evaluate(W,M,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue),U}},{key:'fixMiss',value:function(B,O,I,M){var U=this.findNode(B.slice(0,-1),I,M),W=U.childNodes,D=this.normalizedMap(W,R,M),V=B[B.length-1].index,F,H;for(var X in D){if(!D.hasOwnProperty(X))return;if(D[X]===V)if(F=W[X],H=F.textContent.length,O>H)O-=H;else{U=F.nodeType===L?F.childNodes[0]:F;break}}return{container:U,offset:O}}},{key:'toRange',value:function(B,O){var I=B||document,H=this,Y=!!O&&null!=I.querySelector('.'+O),M,U,W,D,F,V,X,J;if(M='undefined'==typeof I.createRange?new P.RangeObject:I.createRange(),H.range?(U=H.start,V=H.path.steps.concat(U.steps),D=this.findNode(V,I,Y?O:null),W=H.end,X=H.path.steps.concat(W.steps),F=this.findNode(X,I,Y?O:null)):(U=H.path,V=H.path.steps,D=this.findNode(H.path.steps,I,Y?O:null)),D)try{null==U.terminal.offset?M.setStart(D,0):M.setStart(D,U.terminal.offset)}catch(Z){J=this.fixMiss(V,U.terminal.offset,I,Y?O:null),M.setStart(J.container,J.offset)}else return console.log('NO START'),null;if(F)try{null==W.terminal.offset?M.setEnd(F,0):M.setEnd(F,W.terminal.offset)}catch(Z){J=this.fixMiss(X,H.end.terminal.offset,I,Y?O:null),M.setEnd(J.container,J.offset)}return M}},{key:'isCfiString',value:function(B){return'string'==typeof B&&0===B.indexOf('epubcfi(')&&')'===B[B.length-1]}},{key:'generateChapterComponent',value:function(B,O,I){var M=parseInt(O),W='/'+2*(B+1)+'/';return W+=2*(M+1),I&&(W+='['+I+']'),W}},{key:'collapse',value:function(B){this.range&&(this.range=!1,B?(this.path.steps=this.path.steps.concat(this.start.steps),this.path.terminal=this.start.terminal):(this.path.steps=this.path.steps.concat(this.end.steps),this.path.terminal=this.end.terminal))}}]),N}();k.default=z,v.exports=k['default']},function(v,k,_){'use strict';var C=_(39),S=_(48),E=Function.prototype.apply,P=Function.prototype.call,L=Object.create,R=Object.defineProperty,T=Object.defineProperties,z=Object.prototype.hasOwnProperty,N={configurable:!0,enumerable:!1,writable:!0},A,B,O,I,M,U,W;A=function(D,F){var H;return S(F),z.call(this,'__ee__')?H=this.__ee__:(H=N.value=L(null),R(this,'__ee__',N),N.value=null),H[D]?'object'==typeof H[D]?H[D].push(F):H[D]=[H[D],F]:H[D]=F,this},B=function(D,F){var H,V;return S(F),V=this,A.call(this,D,H=function(){O.call(V,D,H),E.call(F,this,arguments)}),H.__eeOnceListener__=F,this},O=function(D,F){var H,V,X,Y;if(S(F),!z.call(this,'__ee__'))return this;if(H=this.__ee__,!H[D])return this;if(V=H[D],'object'==typeof V)for(Y=0;X=V[Y];++Y)(X===F||X.__eeOnceListener__===F)&&(2===V.length?H[D]=V[Y?0:1]:V.splice(Y,1));else(V===F||V.__eeOnceListener__===F)&&delete H[D];return this},I=function(D){var F,H,V,X,Y;if(z.call(this,'__ee__')&&(X=this.__ee__[D],!!X))if('object'==typeof X){for(H=arguments.length,Y=Array(H-1),F=1;F<H;++F)Y[F-1]=arguments[F];for(X=X.slice(),F=0;V=X[F];++F)E.call(V,this,Y)}else switch(arguments.length){case 1:P.call(X,this);break;case 2:P.call(X,this,arguments[1]);break;case 3:P.call(X,this,arguments[1],arguments[2]);break;default:for(H=arguments.length,Y=Array(H-1),F=1;F<H;++F)Y[F-1]=arguments[F];E.call(X,this,Y);}},M={on:A,once:B,off:O,emit:I},U={on:C(A),once:C(B),off:C(O),emit:C(I)},W=T({},U),v.exports=k=function(D){return null==D?L(W):T(Object(D),U)},k.methods=M},function(v,k,_){'use strict';function S(T,z){if(!(T instanceof z))throw new TypeError('Cannot call a class as a function')}Object.defineProperty(k,'__esModule',{value:!0});var E=function(){function T(z,N){for(var A=0,B;A<N.length;A++)B=N[A],B.enumerable=B.enumerable||!1,B.configurable=!0,'value'in B&&(B.writable=!0),Object.defineProperty(z,B.key,B)}return function(z,N,A){return N&&T(z.prototype,N),A&&T(z,A),z}}(),P=_(6),L=function(T){return T&&T.__esModule?T:{default:T}}(P),R=function(){function T(z){S(this,T);var N,A;N=z.indexOf('://'),-1<N&&(z=new URL(z).pathname),A=this.parse(z),this.path=z,this.directory=this.isDirectory(z)?z:A.dir+'/',this.filename=A.base,this.extension=A.ext.slice(1)}return E(T,[{key:'parse',value:function(N){return L.default.parse(N)}},{key:'isAbsolute',value:function(N){return L.default.isAbsolute(N||this.path)}},{key:'isDirectory',value:function(N){return'/'===N.charAt(N.length-1)}},{key:'resolve',value:function(N){return L.default.resolve(this.directory,N)}},{key:'relative',value:function(N){return L.default.relative(this.directory,N)}},{key:'splitPath',value:function(N){return this.splitPathRe.exec(N).slice(1)}},{key:'toString',value:function(){return this.path}}]),T}();k.default=R,v.exports=k['default']},function(v,k,_){'use strict';function C(O){return O&&O.__esModule?O:{default:O}}Object.defineProperty(k,'__esModule',{value:!0}),k.replaceBase=function(O,I){var M,U;O&&(U=(0,T.qs)(O,'head'),M=(0,T.qs)(U,'base'),!M&&(M=O.createElement('base'),U.insertBefore(M,U.firstChild)),M.setAttribute('href',I.url))},k.replaceCanonical=function(O,I){var M,U,W=I.url;O&&(M=(0,T.qs)(O,'head'),U=(0,T.qs)(M,'link[rel=\'canonical\']'),U?U.setAttribute('href',W):(U=O.createElement('link'),U.setAttribute('rel','canonical'),U.setAttribute('href',W),M.appendChild(U)))},k.replaceMeta=function(O,I){var M,U,W=I.idref;O&&(M=(0,T.qs)(O,'head'),U=(0,T.qs)(M,'link[property=\'dc:identifier\']'),U?U.setAttribute('content',W):(U=O.createElement('meta'),U.setAttribute('property','dc:identifier'),U.setAttribute('content',W),M.appendChild(U)))},k.replaceLinks=function(O,I){var M=O.querySelectorAll('a[href]');if(M.length)for(var U=(0,T.qs)(O.ownerDocument,'base'),W=U?U.getAttribute('href'):void 0,D=function(H){var V=H.getAttribute('href');if(0!==V.indexOf('mailto:')){var X=-1<V.indexOf('://'),Y=new N.default(V,W);X?H.setAttribute('target','_blank'):H.onclick=function(){return Y&&Y.hash?I(Y.Path.path+Y.hash):Y?I(Y.Path.path):I(V),!1}}}.bind(this),F=0;F<M.length;F++)D(M[F])},k.substitute=function(O,I,M){return I.forEach(function(U,W){U&&M[W]&&(O=O.replace(new RegExp(U,'g'),M[W]))}),O};var T=_(0),z=_(5),N=C(z),A=_(3),B=C(A)},function(v,k,_){'use strict';function C(N){return N&&N.__esModule?N:{default:N}}function S(N,A){if(!(N instanceof A))throw new TypeError('Cannot call a class as a function')}Object.defineProperty(k,'__esModule',{value:!0});var E=function(){function N(A,B){for(var O=0,I;O<B.length;O++)I=B[O],I.enumerable=I.enumerable||!1,I.configurable=!0,'value'in I&&(I.writable=!0),Object.defineProperty(A,I.key,I)}return function(A,B,O){return B&&N(A.prototype,B),O&&N(A,O),A}}(),P=_(3),L=C(P),R=_(6),T=C(R),z=function(){function N(A,B){S(this,N);var O=-1<A.indexOf('://'),I=A,M;if(this.Url=void 0,this.href=A,this.protocol='',this.origin='',this.hash='',this.hash='',this.search='',this.base=B,!O&&!1!==B&&'string'!=typeof B&&window&&window.location&&(this.base=window.location.href),O||this.base)try{this.Url=this.base?new URL(A,this.base):new URL(A),this.href=this.Url.href,this.protocol=this.Url.protocol,this.origin=this.Url.origin,this.hash=this.Url.hash,this.search=this.Url.search,I=this.Url.pathname}catch(U){this.Url=void 0,this.base&&(M=new L.default(this.base),I=M.resolve(I))}this.Path=new L.default(I),this.directory=this.Path.directory,this.filename=this.Path.filename,this.extension=this.Path.extension}return E(N,[{key:'path',value:function(){return this.Path}},{key:'resolve',value:function(B){var O=-1<B.indexOf('://'),I;return O?B:(I=T.default.resolve(this.directory,B),this.origin+I)}},{key:'relative',value:function(B){return T.default.relative(B,this.directory)}},{key:'toString',value:function(){return this.href}}]),N}();k.default=z,v.exports=k['default']},function(v){'use strict';function C(R){if('string'!=typeof R)throw new TypeError('Path must be a string. Received '+R)}function S(R,T){for(var z='',N=-1,A=0,O=0,B;O<=R.length;++O){if(O<R.length)B=R.charCodeAt(O);else if(47===B)break;else B=47;if(47===B){if(N==O-1||1==A);else if(N!=O-1&&2==A){if(2>z.length||46!==z.charCodeAt(z.length-1)||46!==z.charCodeAt(z.length-2))if(2<z.length){for(var I=z.length-1,M=I;0<=M&&47!==z.charCodeAt(M);--M);if(M!=I){z=-1==M?'':z.slice(0,M),N=O,A=0;continue}}else if(2===z.length||1===z.length){z='',N=O,A=0;continue}T&&(0<z.length?z+='/..':z='..')}else 0<z.length?z+='/'+R.slice(N+1,O):z=R.slice(N+1,O);N=O,A=0}else 46===B&&-1!=A?++A:A=-1}return z}function E(R,T){var z=T.dir||T.root,N=T.base||(T.name||'')+(T.ext||'');return z?z===T.root?z+N:z+R+N:N}if(!P)var P={cwd:function(){return'/'}};var L={resolve:function(){for(var T='',z=!1,A=arguments.length-1,N;-1<=A&&!z;A--){var B;(0<=A?B=arguments[A]:(void 0==N&&(N=P.cwd()),B=N),C(B),0!==B.length)&&(T=B+'/'+T,z=47===B.charCodeAt(0))}return T=S(T,!z),z?0<T.length?'/'+T:'/':0<T.length?T:'.'},normalize:function(T){if(C(T),0===T.length)return'.';var z=47===T.charCodeAt(0),N=47===T.charCodeAt(T.length-1);return T=S(T,!z),0!==T.length||z||(T='.'),0<T.length&&N&&(T+='/'),z?'/'+T:T},isAbsolute:function(T){return C(T),0<T.length&&47===T.charCodeAt(0)},join:function(){if(0===arguments.length)return'.';for(var z=0,T,N;z<arguments.length;++z)N=arguments[z],C(N),0<N.length&&(void 0==T?T=N:T+='/'+N);return void 0===T?'.':L.normalize(T)},relative:function(T,z){if(C(T),C(z),T===z)return'';if(T=L.resolve(T),z=L.resolve(z),T===z)return'';for(var N=1;N<T.length&&47===T.charCodeAt(N);++N);for(var A=T.length,B=A-N,O=1;O<z.length&&47===z.charCodeAt(O);++O);for(var I=z.length,M=I-O,U=B<M?B:M,W=-1,D=0;D<=U;++D){if(D==U){if(M>U){if(47===z.charCodeAt(O+D))return z.slice(O+D+1);if(0==D)return z.slice(O+D)}else B>U&&(47===T.charCodeAt(N+D)?W=D:0==D&&(W=0));break}var F=T.charCodeAt(N+D),H=z.charCodeAt(O+D);if(F!==H)break;else 47===F&&(W=D)}var V='';for(D=N+W+1;D<=A;++D)(D===A||47===T.charCodeAt(D))&&(V+=0===V.length?'..':'/..');return 0<V.length?V+z.slice(O+W):(O+=W,47===z.charCodeAt(O)&&++O,z.slice(O))},_makeLong:function(T){return T},dirname:function(T){if(C(T),0===T.length)return'.';for(var z=T.charCodeAt(0),N=47===z,A=-1,B=!0,O=T.length-1;1<=O;--O)if(z=T.charCodeAt(O),47!==z)B=!1;else if(!B){A=O;break}return-1===A?N?'/':'.':N&&1===A?'//':T.slice(0,A)},basename:function(T,z){if(z!==void 0&&'string'!=typeof z)throw new TypeError('"ext" argument must be a string');C(T);var N=0,A=-1,B=!0,O;if(void 0!==z&&0<z.length&&z.length<=T.length){if(z.length===T.length&&z===T)return'';var I=z.length-1,M=-1;for(O=T.length-1;0<=O;--O){var U=T.charCodeAt(O);if(47!==U)-1==M&&(B=!1,M=O+1),0<=I&&(U===z.charCodeAt(I)?-1==--I&&(A=O):(I=-1,A=M));else if(!B){N=O+1;break}}return N===A?A=M:-1===A&&(A=T.length),T.slice(N,A)}for(O=T.length-1;0<=O;--O)if(47!==T.charCodeAt(O))-1==A&&(B=!1,A=O+1);else if(!B){N=O+1;break}return-1===A?'':T.slice(N,A)},extname:function(T){C(T);for(var z=-1,N=0,A=-1,B=!0,O=0,I=T.length-1,M;0<=I;--I){if(M=T.charCodeAt(I),47===M){if(!B){N=I+1;break}continue}-1==A&&(B=!1,A=I+1),46===M?-1==z?z=I:1!=O&&(O=1):-1!==z&&(O=-1)}return-1===z||-1===A||0==O||1==O&&z===A-1&&z===N+1?'':T.slice(z,A)},format:function(T){if(null===T||'object'!=typeof T)throw new TypeError('Parameter "pathObject" must be an object, not '+typeof T);return E('/',T)},parse:function(T){C(T);var z={root:'',dir:'',base:'',ext:'',name:''};if(0===T.length)return z;var N=T.charCodeAt(0),A=47===N,B;A?(z.root='/',B=1):B=0;for(var O=-1,I=0,M=-1,U=!0,W=T.length-1,D=0;W>=B;--W){if(N=T.charCodeAt(W),47===N){if(!U){I=W+1;break}continue}-1==M&&(U=!1,M=W+1),46===N?-1==O?O=W:1!=D&&(D=1):-1!=O&&(D=-1)}return-1==O||-1==M||0==D||1==D&&O==M-1&&O==I+1?-1!=M&&(0==I&&A?z.base=z.name=T.slice(1,M):z.base=z.name=T.slice(I,M)):(0==I&&A?(z.name=T.slice(1,O),z.base=T.slice(1,M)):(z.name=T.slice(I,O),z.base=T.slice(I,M)),z.ext=T.slice(O,M)),0<I?z.dir=T.slice(0,I-1):A&&(z.dir='/'),z},sep:'/',delimiter:':',posix:null};v.exports=L},function(v,k,_){'use strict';function C(U){return U&&U.__esModule?U:{default:U}}function S(U,W){if(!(U instanceof W))throw new TypeError('Cannot call a class as a function')}Object.defineProperty(k,'__esModule',{value:!0});var E=function(){function U(W,D){for(var F=0,H;F<D.length;F++)H=D[F],H.enumerable=H.enumerable||!1,H.configurable=!0,'value'in H&&(H.writable=!0),Object.defineProperty(W,H.key,H)}return function(W,D,F){return D&&U(W.prototype,D),F&&U(W,F),W}}(),P=_(2),L=C(P),R=_(0),T=_(1),z=C(T),N=_(8),A=C(N),B=_(4),O=_(22),I=['keydown','keyup','keypressed','mouseup','mousedown','click','touchend','touchstart'],M=function(){function U(W,D,F,H){S(this,U),this.epubcfi=new z.default,this.document=W,this.documentElement=this.document.documentElement,this.content=D||this.document.body,this.window=this.document.defaultView,this._size={width:0,height:0},this.sectionIndex=H||0,this.cfiBase=F||'',this.pane=void 0,this.highlights={},this.underlines={},this.marks={},this.listeners()}return E(U,[{key:'width',value:function(D){var F=this.content;return D&&(0,R.isNumber)(D)&&(D+='px'),D&&(F.style.width=D),this.window.getComputedStyle(F).width}},{key:'height',value:function(D){var F=this.content;return D&&(0,R.isNumber)(D)&&(D+='px'),D&&(F.style.height=D),this.window.getComputedStyle(F).height}},{key:'contentWidth',value:function(D){var F=this.content||this.document.body;return D&&(0,R.isNumber)(D)&&(D+='px'),D&&(F.style.width=D),this.window.getComputedStyle(F).width}},{key:'contentHeight',value:function(D){var F=this.content||this.document.body;return D&&(0,R.isNumber)(D)&&(D+='px'),D&&(F.style.height=D),this.window.getComputedStyle(F).height}},{key:'textWidth',value:function(){var F=this.document.createRange(),H=this.content||this.document.body,D;return F.selectNodeContents(H),D=F.getBoundingClientRect().width,D}},{key:'textHeight',value:function(){var F=this.document.createRange(),H=this.content||this.document.body,D;return F.selectNodeContents(H),D=F.getBoundingClientRect().height,D}},{key:'scrollWidth',value:function(){var D=this.documentElement.scrollWidth;return D}},{key:'scrollHeight',value:function(){var D=this.documentElement.scrollHeight;return D}},{key:'overflow',value:function(D){return D&&(this.documentElement.style.overflow=D),this.window.getComputedStyle(this.documentElement).overflow}},{key:'overflowX',value:function(D){return D&&(this.documentElement.style.overflowX=D),this.window.getComputedStyle(this.documentElement).overflowX}},{key:'overflowY',value:function(D){return D&&(this.documentElement.style.overflowY=D),this.window.getComputedStyle(this.documentElement).overflowY}},{key:'css',value:function(D,F,H){var V=this.content||this.document.body;return F&&V.style.setProperty(D,F,H?'important':''),this.window.getComputedStyle(V)[D]}},{key:'viewport',value:function(D){var te=this.document.querySelector('meta[name=\'viewport\']'),ne={width:void 0,height:void 0,scale:void 0,minimum:void 0,maximum:void 0,scalable:void 0},ae=[],Z,Q;if(te&&te.hasAttribute('content')){var ie=te.getAttribute('content'),se=ie.match(/width\s*=\s*([^,]*)/g),re=ie.match(/height\s*=\s*([^,]*)/g),le=ie.match(/initial-scale\s*=\s*([^,]*)/g),oe=ie.match(/minimum-scale\s*=\s*([^,]*)/g),de=ie.match(/maximum-scale\s*=\s*([^,]*)/g),ue=ie.match(/user-scalable\s*=\s*([^,]*)/g);se&&se.length&&'undefined'!=typeof se[1]&&(ne.width=se[1]),re&&re.length&&'undefined'!=typeof re[1]&&(ne.height=re[1]),le&&le.length&&'undefined'!=typeof le[1]&&(ne.scale=le[1]),oe&&oe.length&&'undefined'!=typeof oe[1]&&(ne.minimum=oe[1]),de&&de.length&&'undefined'!=typeof de[1]&&(ne.maximum=de[1]),ue&&ue.length&&'undefined'!=typeof ue[1]&&(ne.scalable=ue[1])}return D&&((D.width||ne.width)&&ae.push('width='+(D.width||ne.width)),(D.height||ne.height)&&ae.push('height='+(D.height||ne.height)),(D.scale||ne.scale)&&ae.push('initial-scale='+(D.scale||ne.scale)),(D.scalable||ne.scalable)&&(ae.push('minimum-scale='+(D.scale||ne.minimum)),ae.push('maximum-scale='+(D.scale||ne.maximum)),ae.push('user-scalable='+(D.scalable||ne.scalable))),!te&&(te=this.document.createElement('meta'),te.setAttribute('name','viewport'),this.document.querySelector('head').appendChild(te)),te.setAttribute('content',ae.join(', ')),this.window.scrollTo(0,0)),{width:parseInt(Z),height:parseInt(Q)}}},{key:'expand',value:function(){this.emit('expand')}},{key:'listeners',value:function(){this.imageLoadListeners(),this.mediaQueryListeners(),this.addEventListeners(),this.addSelectionListeners(),this.resizeListeners(),this.linksHandler()}},{key:'removeListeners',value:function(){this.removeEventListeners(),this.removeSelectionListeners(),clearTimeout(this.expanding)}},{key:'resizeListeners',value:function(){var D,F;clearTimeout(this.expanding),D=this.textWidth(),F=this.textHeight(),(D!=this._size.width||F!=this._size.height)&&(this._size={width:D,height:F},this.pane&&this.pane.render(),this.emit('resize',this._size)),this.expanding=setTimeout(this.resizeListeners.bind(this),350)}},{key:'mediaQueryListeners',value:function(){for(var D=this.document.styleSheets,F=function(J){J.matches&&!this._expanding&&setTimeout(this.expand.bind(this),1)}.bind(this),H=0;H<D.length;H+=1){var V;try{V=D[H].cssRules}catch(J){return}if(!V)return;for(var X=0;X<V.length;X+=1)if(V[X].media){var Y=this.window.matchMedia(V[X].media.mediaText);Y.addListener(F)}}}},{key:'observe',value:function(D){var F=this,H=new MutationObserver(function(){F._expanding&&F.expand()});return H.observe(D,{attributes:!0,childList:!0,characterData:!0,subtree:!0}),H}},{key:'imageLoadListeners',value:function(){for(var F=this.document.querySelectorAll('img'),V=0,H;V<F.length;V++)H=F[V],'undefined'!=typeof H.naturalWidth&&0===H.naturalWidth&&(H.onload=this.expand.bind(this))}},{key:'fontLoadListeners',value:function(){this.document&&this.document.fonts&&this.document.fonts.ready.then(function(){this.expand()}.bind(this))}},{key:'root',value:function(){return this.document?this.document.documentElement:null}},{key:'locationOf',value:function(D,F){var V={left:0,top:0},H;if(this.document){if(this.epubcfi.isCfiString(D)){var X=new z.default(D).toRange(this.document,F);X&&(X.startContainer.nodeType===Node.ELEMENT_NODE?(H=X.startContainer.getBoundingClientRect(),V.left=H.left,V.top=H.top):X.collapsed?H=X.getClientRects()[0]:H=X.getBoundingClientRect())}else if('string'==typeof D&&-1<D.indexOf('#')){var Y=D.substring(D.indexOf('#')+1),J=this.document.getElementById(Y);J&&(H=J.getBoundingClientRect())}return H&&(V.left=H.left,V.top=H.top),V}}},{key:'addStylesheet',value:function(D){return new Promise(function(F){var X=!1,V;return this.document?(V=this.document.querySelector('link[href=\''+D+'\']'),V?void F(!0):void(V=this.document.createElement('link'),V.type='text/css',V.rel='stylesheet',V.href=D,V.onload=V.onreadystatechange=function(){var Y=this;X||this.readyState&&'complete'!=this.readyState||(X=!0,setTimeout(function(){Y.pane&&Y.pane.render(),F(!0)},1))},this.document.head.appendChild(V))):void F(!1)}.bind(this))}},{key:'addStylesheetRules',value:function(D){var V='epubjs-inserted-css',F,H;if(this.document&&D&&0!==D.length){if(F=this.document.getElementById('#'+V),F||(F=this.document.createElement('style'),F.id=V),this.document.head.appendChild(F),H=F.sheet,'[object Array]'===Object.prototype.toString.call(D))for(var X=0,Y=D.length;X<Y;X++){var J=1,Z=D[X],Q=D[X][0],K='';'[object Array]'===Object.prototype.toString.call(Z[1][0])&&(Z=Z[1],J=0);for(var G=Z.length,$;J<G;J++)$=Z[J],K+=$[0]+':'+$[1]+($[2]?' !important':'')+';\n';H.insertRule(Q+'{'+K+'}',H.cssRules.length)}else{var ee=Object.keys(D);ee.forEach(function(te){var ne=D[te];if(Array.isArray(ne))ne.forEach(function(se){var re=Object.keys(se),le=re.map(function(oe){return oe+':'+se[oe]}).join(';');H.insertRule(te+'{'+le+'}',H.cssRules.length)});else{var ae=Object.keys(ne),ie=ae.map(function(se){return se+':'+ne[se]}).join(';');H.insertRule(te+'{'+ie+'}',H.cssRules.length)}})}this.pane&&this.pane.render()}}},{key:'addScript',value:function(D){return new Promise(function(F){var X=!1,V;return this.document?void(V=this.document.createElement('script'),V.type='text/javascript',V.async=!0,V.src=D,V.onload=V.onreadystatechange=function(){X||this.readyState&&'complete'!=this.readyState||(X=!0,setTimeout(function(){F(!0)},1))},this.document.head.appendChild(V)):void F(!1)}.bind(this))}},{key:'addClass',value:function(D){var F;this.document&&(F=this.content||this.document.body,F.classList.add(D))}},{key:'removeClass',value:function(D){var F;this.document&&(F=this.content||this.document.body,F.classList.remove(D))}},{key:'addEventListeners',value:function(){this.document&&I.forEach(function(D){this.document.addEventListener(D,this.triggerEvent.bind(this),!1)},this)}},{key:'removeEventListeners',value:function(){this.document&&I.forEach(function(D){this.document.removeEventListener(D,this.triggerEvent,!1)},this)}},{key:'triggerEvent',value:function(D){this.emit(D.type,D)}},{key:'addSelectionListeners',value:function(){this.document&&this.document.addEventListener('selectionchange',this.onSelectionChange.bind(this),!1)}},{key:'removeSelectionListeners',value:function(){this.document&&this.document.removeEventListener('selectionchange',this.onSelectionChange,!1)}},{key:'onSelectionChange',value:function(){this.selectionEndTimeout&&clearTimeout(this.selectionEndTimeout),this.selectionEndTimeout=setTimeout(function(){var F=this.window.getSelection();this.triggerSelectedEvent(F)}.bind(this),250)}},{key:'triggerSelectedEvent',value:function(D){var F,H;D&&0<D.rangeCount&&(F=D.getRangeAt(0),!F.collapsed&&(H=new z.default(F,this.cfiBase).toString(),this.emit('selected',H),this.emit('selectedRange',F)))}},{key:'range',value:function(D,F){var H=new z.default(D);return H.toRange(this.document,F)}},{key:'cfiFromRange',value:function(D,F){return new z.default(D,this.cfiBase,F).toString()}},{key:'cfiFromNode',value:function(D,F){return new z.default(D,this.cfiBase,F).toString()}},{key:'map',value:function(D){var W=new A.default(D);return W.section()}},{key:'size',value:function(D,F){var H={scale:1,scalable:'no'};0<=D&&(this.width(D),H.width=D),0<=F&&(this.height(F),H.height=F),this.css('margin','0'),this.css('box-sizing','border-box'),this.viewport(H)}},{key:'columns',value:function(D,F,H,V){var X=(0,R.prefixed)('column-axis'),Y=(0,R.prefixed)('column-gap'),J=(0,R.prefixed)('column-width'),Z=(0,R.prefixed)('column-fill');this.width(D),this.height(F),this.viewport({width:D,height:F,scale:1,scalable:'no'}),this.css('display','inline-block'),this.css('overflow-y','hidden'),this.css('margin','0',!0),this.css('padding','0',!0),this.css('box-sizing','border-box'),this.css('max-width','inherit'),this.css(X,'horizontal'),this.css(Z,'auto'),this.css(Y,V+'px'),this.css(J,H+'px')}},{key:'scaler',value:function(D,F,H){var X='';this.css('transform-origin','top left'),(0<=F||0<=H)&&(X=' translate('+(F||0)+'px, '+(H||0)+'px )'),this.css('transform','scale('+D+')'+X)}},{key:'fit',value:function(D,F){var H=this.viewport(),V=D/H.width,X=F/H.height,Y=V<X?V:X,J=(F-H.height*Y)/2;this.width(D),this.height(F),this.overflow('hidden'),this.viewport({width:D,height:F,scale:1}),this.scaler(Y,0,J),this.css('background-color','transparent')}},{key:'mapPage',value:function(D,F,H,V,X){var Y=new A.default(F,X);return Y.page(this,D,H,V)}},{key:'linksHandler',value:function(){var D=this;(0,B.replaceLinks)(this.content,function(F){D.emit('linkClicked',F)})}},{key:'highlight',value:function(D){var F=this,H=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},V=arguments[2],X=this.range(D),Y=function(){F.emit('markClicked',D,H)};H.epubcfi=D,this.pane||(this.pane=new O.Pane(this.content,this.document.body));var J=new O.Highlight(X,'epubjs-hl',H,{fill:'yellow',"fill-opacity":'0.3',"mix-blend-mode":'multiply'}),Z=this.pane.addMark(J);return this.highlights[D]={mark:Z,element:Z.element,listeners:[Y,V]},Z.element.addEventListener('click',Y),V&&Z.element.addEventListener('click',V),Z}},{key:'underline',value:function(D){var F=this,H=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},V=arguments[2],X=this.range(D),Y=function(){F.emit('markClicked',D,H)};H.epubcfi=D,this.pane||(this.pane=new O.Pane(this.content,this.document.body));var J=new O.Underline(X,'epubjs-ul',H,{stroke:'black',"stroke-opacity":'0.3',"mix-blend-mode":'multiply'}),Z=this.pane.addMark(J);return this.underlines[D]={mark:Z,element:Z.element,listeners:[Y,V]},Z.element.addEventListener('click',Y),V&&Z.element.addEventListener('click',V),Z}},{key:'mark',value:function(D){var F=this,H=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},V=arguments[2],X=this.range(D),Y=X.commonAncestorContainer,J=1===Y.nodeType?Y:Y.parentNode,Z=function(){F.emit('markClicked',D,H)};return J.setAttribute('ref','epubjs-mk'),J.dataset.epubcfi=D,H&&Object.keys(H).forEach(function(Q){J.dataset[Q]=H[Q]}),J.addEventListener('click',Z),V&&J.addEventListener('click',V),this.marks[D]={element:J,listeners:[Z,V]},J}},{key:'unhighlight',value:function(D){var F;D in this.highlights&&(F=this.highlights[D],this.pane.removeMark(F.mark),F.listeners.forEach(function(H){H&&F.element.removeEventListener('click',H)}),delete this.highlights[D])}},{key:'ununderline',value:function(D){var F;D in this.underlines&&(F=this.underlines[D],this.pane.removeMark(F.mark),F.listeners.forEach(function(H){H&&F.element.removeEventListener('click',H)}),delete this.underlines[D])}},{key:'unmark',value:function(D){var F;D in this.marks&&(F=this.marks[D],F.element.removeAttribute('ref'),F.listeners.forEach(function(H){H&&F.element.removeEventListener('click',H)}),delete this.marks[D])}},{key:'destroy',value:function(){this.observer&&this.observer.disconnect(),this.removeListeners()}}],[{key:'listenedEvents',get:function(){return I}}]),U}();(0,L.default)(M.prototype),k.default=M,v.exports=k['default']},function(v,k,_){'use strict';function S(T,z){if(!(T instanceof z))throw new TypeError('Cannot call a class as a function')}Object.defineProperty(k,'__esModule',{value:!0});var E=function(){function T(z,N){for(var A=0,B;A<N.length;A++)B=N[A],B.enumerable=B.enumerable||!1,B.configurable=!0,'value'in B&&(B.writable=!0),Object.defineProperty(z,B.key,B)}return function(z,N,A){return N&&T(z.prototype,N),A&&T(z,A),z}}(),P=_(1),L=function(T){return T&&T.__esModule?T:{default:T}}(P),R=function(){function T(z,N){S(this,T),this.layout=z,this.horizontal='paginated'===this.layout.flow,this._dev=N}return E(T,[{key:'section',value:function(N){var A=this.findRanges(N),B=this.rangeListToCfiList(N.section.cfiBase,A);return B}},{key:'page',value:function(N,A,B,O){var I=N&&N.document&&N.document.body,M;if(I){if(M=this.rangePairToCfiPair(A,{start:this.findStart(I,B,O),end:this.findEnd(I,B,O)}),!0===this._dev){var U=N.document,W=new L.default(M.start).toRange(U),D=new L.default(M.end).toRange(U),F=U.defaultView.getSelection(),H=U.createRange();F.removeAllRanges(),H.setStart(W.startContainer,W.startOffset),H.setEnd(D.endContainer,D.endOffset),F.addRange(H)}return M}}},{key:'walk',value:function(N,A){if(!(N&&N.nodeType===Node.TEXT_NODE)){var B={acceptNode:function(D){return 0<D.data.trim().length?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_REJECT}},O=B.acceptNode;O.acceptNode=B.acceptNode;for(var I=document.createTreeWalker(N,NodeFilter.SHOW_TEXT,O,!1),M,U;(M=I.nextNode())&&(U=A(M),!U););return U}}},{key:'findRanges',value:function(N){for(var A=[],B=N.contents.scrollWidth(),O=Math.ceil(B/this.layout.spreadWidth),I=O*this.layout.divisor,M=this.layout.columnWidth,U=this.layout.gap,F=0,W,D;F<I.pages;F++)W=(M+U)*F,D=M*(F+1)+U*F,A.push({start:this.findStart(N.document.body,W,D),end:this.findEnd(N.document.body,W,D)});return A}},{key:'findStart',value:function(N,A,B){for(var O=this,I=[N],W=N,M,U;I.length;)if(M=I.shift(),U=this.walk(M,function(D){var F,H,V,X;return(D.nodeType==Node.TEXT_NODE?(X=document.createRange(),X.selectNodeContents(D),V=X.getBoundingClientRect()):V=D.getBoundingClientRect(),F=O.horizontal?V.left:V.top,H=O.horizontal?V.right:V.bottom,F>=A&&F<=B)?D:H>A?D:void(W=D,I.push(D))}),U)return this.findTextStartRange(U,A,B);return this.findTextStartRange(W,A,B)}},{key:'findEnd',value:function(N,A,B){for(var O=this,I=[N],U=N,M,W;I.length;)if(M=I.shift(),W=this.walk(M,function(D){var F,H,V,X;return(D.nodeType==Node.TEXT_NODE?(X=document.createRange(),X.selectNodeContents(D),V=X.getBoundingClientRect()):V=D.getBoundingClientRect(),F=Math.round(O.horizontal?V.left:V.top),H=Math.round(O.horizontal?V.right:V.bottom),F>B&&U)?U:H>B?D:void(U=D,I.push(D))}),W)return this.findTextEndRange(W,A,B);return this.findTextEndRange(U,A,B)}},{key:'findTextStartRange',value:function(N,A){for(var O=this.splitTextNodeIntoRanges(N),W=0,I,M,U;W<O.length;W++)if(I=O[W],M=I.getBoundingClientRect(),U=this.horizontal?M.left:M.top,U>=A)return I;return O[0]}},{key:'findTextEndRange',value:function(N,A,B){for(var O=this.splitTextNodeIntoRanges(N),F=0,I,M,U,W,D;F<O.length;F++){if(M=O[F],U=M.getBoundingClientRect(),W=this.horizontal?U.left:U.top,D=this.horizontal?U.right:U.bottom,W>B&&I)return I;if(D>B)return M;I=M}return O[O.length-1]}},{key:'splitTextNodeIntoRanges',value:function(N,A){var B=[],O=N.textContent||'',I=O.trim(),U=N.ownerDocument,W=A||' ',D=I.indexOf(W),M;if(-1===D||N.nodeType!=Node.TEXT_NODE)return M=U.createRange(),M.selectNodeContents(N),[M];for(M=U.createRange(),M.setStart(N,0),M.setEnd(N,D),B.push(M),M=!1;-1!=D;)D=I.indexOf(W,D+1),0<D&&(M&&(M.setEnd(N,D),B.push(M)),M=U.createRange(),M.setStart(N,D+1));return M&&(M.setEnd(N,I.length),B.push(M)),B}},{key:'rangePairToCfiPair',value:function(N,A){var B=A.start,O=A.end;B.collapse(!0),O.collapse(!1);var I=new L.default(B,N).toString(),M=new L.default(O,N).toString();return{start:I,end:M}}},{key:'rangeListToCfiList',value:function(N,A){for(var B=[],I=0,O;I<A.length;I++)O=this.rangePairToCfiPair(N,A[I]),B.push(O);return B}}]),T}();k.default=R,v.exports=k['default']},function(v,k){'use strict';function C(P,L){if(!(P instanceof L))throw new TypeError('Cannot call a class as a function')}Object.defineProperty(k,'__esModule',{value:!0});var S=function(){function P(L,R){for(var T=0,z;T<R.length;T++)z=R[T],z.enumerable=z.enumerable||!1,z.configurable=!0,'value'in z&&(z.writable=!0),Object.defineProperty(L,z.key,z)}return function(L,R,T){return R&&P(L.prototype,R),T&&P(L,T),L}}(),E=function(){function P(L){C(this,P),this.context=L||this,this.hooks=[]}return S(P,[{key:'register',value:function(){for(var R=0;R<arguments.length;++R)if('function'==typeof arguments[R])this.hooks.push(arguments[R]);else for(var T=0;T<arguments[R].length;++T)this.hooks.push(arguments[R][T])}},{key:'trigger',value:function(){var R=arguments,T=this.context,z=[];return this.hooks.forEach(function(N){var A=N.apply(T,R);A&&'function'==typeof A.then&&z.push(A)}),Promise.all(z)}},{key:'list',value:function(){return this.hooks}},{key:'clear',value:function(){return this.hooks=[]}}]),P}();k.default=E,v.exports=k['default']},function(v,k,_){'use strict';function C(R,T){if(!(R instanceof T))throw new TypeError('Cannot call a class as a function')}Object.defineProperty(k,'__esModule',{value:!0}),k.Task=void 0;var S=function(){function R(T,z){for(var N=0,A;N<z.length;N++)A=z[N],A.enumerable=A.enumerable||!1,A.configurable=!0,'value'in A&&(A.writable=!0),Object.defineProperty(T,A.key,A)}return function(T,z,N){return z&&R(T.prototype,z),N&&R(T,N),T}}(),E=_(0),P=function(){function R(T){C(this,R),this._q=[],this.context=T,this.tick=E.requestAnimationFrame,this.running=!1,this.paused=!1}return S(R,[{key:'enqueue',value:function(){var B=[].shift.call(arguments),O=arguments,z,N,A;if(!B)throw new Error('No Task Provided');return'function'==typeof B?(z=new E.defer,N=z.promise,A={task:B,args:O,deferred:z,promise:N}):A={promise:B},this._q.push(A),!1!=this.paused||this.running||this.run(),A.promise}},{key:'dequeue',value:function(){var z,N,A;if(this._q.length&&!this.paused){if(z=this._q.shift(),N=z.task,N)return A=N.apply(this.context,z.args),A&&'function'==typeof A.then?A.then(function(){z.deferred.resolve.apply(this.context,arguments)}.bind(this),function(){z.deferred.reject.apply(this.context,arguments)}.bind(this)):(z.deferred.resolve.apply(this.context,A),z.promise);if(z.promise)return z.promise}else return z=new E.defer,z.deferred.resolve(),z.promise}},{key:'dump',value:function(){for(;this._q.length;)this.dequeue()}},{key:'run',value:function(){var z=this;r