openmedialibrary_reader/epub.js/epub.min.js

12 lines
96 KiB
JavaScript
Raw Normal View History

2015-11-19 17:33:10 +00:00
/*!
* @overview RSVP - a tiny implementation of Promises/A+.
* @copyright Copyright (c) 2014 Yehuda Katz, Tom Dale, Stefan Penner and contributors
* @license Licensed under MIT license
* See https://raw.githubusercontent.com/tildeio/rsvp.js/master/LICENSE
* @version 3.1.0
2015-03-07 19:41:19 +00:00
*/
2015-11-19 17:33:10 +00:00
(function(){"use strict";function a(a){return"function"==typeof a||"object"==typeof a&&null!==a}function b(a){return"function"==typeof a}function c(a){return"object"==typeof a&&null!==a}function d(){}function e(a,b){for(var c=0,d=a.length;d>c;c++)if(a[c]===b)return c;return-1}function f(a){var b=a._promiseCallbacks;return b||(b=a._promiseCallbacks={}),b}function g(a,b){return"onerror"===a?void va.on("error",b):2!==arguments.length?va[a]:void(va[a]=b)}function h(){setTimeout(function(){for(var a,b=0;b<wa.length;b++){a=wa[b];var c=a.payload;c.guid=c.key+c.id,c.childGuid=c.key+c.childId,c.error&&(c.stack=c.error.stack),va.trigger(a.name,a.payload)}wa.length=0},50)}function i(a,b,c){1===wa.push({name:a,payload:{key:b._guidKey,id:b._id,eventName:a,detail:b._result,childId:c&&c._id,label:b._label,timeStamp:sa(),error:va["instrument-with-stack"]?new Error(b._label):null}})&&h()}function j(){return new TypeError("A promises callback cannot return that same promise.")}function k(){}function l(a){try{return a.then}catch(b){return Ba.error=b,Ba}}function m(a,b,c,d){try{a.call(b,c,d)}catch(e){return e}}function n(a,b,c){va.async(function(a){var d=!1,e=m(c,b,function(c){d||(d=!0,b!==c?q(a,c):s(a,c))},function(b){d||(d=!0,t(a,b))},"Settle: "+(a._label||" unknown promise"));!d&&e&&(d=!0,t(a,e))},a)}function o(a,b){b._state===za?s(a,b._result):b._state===Aa?(b._onError=null,t(a,b._result)):u(b,void 0,function(c){b!==c?q(a,c):s(a,c)},function(b){t(a,b)})}function p(a,c){if(c.constructor===a.constructor)o(a,c);else{var d=l(c);d===Ba?t(a,Ba.error):void 0===d?s(a,c):b(d)?n(a,c,d):s(a,c)}}function q(b,c){b===c?s(b,c):a(c)?p(b,c):s(b,c)}function r(a){a._onError&&a._onError(a._result),v(a)}function s(a,b){a._state===ya&&(a._result=b,a._state=za,0===a._subscribers.length?va.instrument&&xa("fulfilled",a):va.async(v,a))}function t(a,b){a._state===ya&&(a._state=Aa,a._result=b,va.async(r,a))}function u(a,b,c,d){var e=a._subscribers,f=e.length;a._onError=null,e[f]=b,e[f+za]=c,e[f+Aa]=d,0===f&&a._state&&va.async(v,a)}function v(a){var b=a._subscribers,c=a._state;if(va.instrument&&xa(c===za?"fulfilled":"rejected",a),0!==b.length){for(var d,e,f=a._result,g=0;g<b.length;g+=3)d=b[g],e=b[g+c],d?y(c,d,e,f):e(f);a._subscribers.length=0}}function w(){this.error=null}function x(a,b){try{return a(b)}catch(c){return Ca.error=c,Ca}}function y(a,c,d,e){var f,g,h,i,k=b(d);if(k){if(f=x(d,e),f===Ca?(i=!0,g=f.error,f=null):h=!0,c===f)return void t(c,j())}else f=e,h=!0;c._state!==ya||(k&&h?q(c,f):i?t(c,g):a===za?s(c,f):a===Aa&&t(c,f))}function z(a,b){var c=!1;try{b(function(b){c||(c=!0,q(a,b))},function(b){c||(c=!0,t(a,b))})}catch(d){t(a,d)}}function A(a,b,c){return a===za?{state:"fulfilled",value:c}:{state:"rejected",reason:c}}function B(a,b,c,d){var e=this;e._instanceConstructor=a,e.promise=new a(k,d),e._abortOnReject=c,e._validateInput(b)?(e._input=b,e.length=b.length,e._remaining=b.length,e._init(),0===e.length?s(e.promise,e._result):(e.length=e.length||0,e._enumerate(),0===e._remaining&&s(e.promise,e._result))):t(e.promise,e._validationError())}function C(a,b){return new Da(this,a,!0,b).promise}function D(a,b){function c(a){q(f,a)}function d(a){t(f,a)}var e=this,f=new e(k,b);if(!ra(a))return t(f,new TypeError("You must pass an array to race.")),f;for(var g=a.length,h=0;f._state===ya&&g>h;h++)u(e.resolve(a[h]),void 0,c,d);return f}function E(a,b){var c=this;if(a&&"object"==typeof a&&a.constructor===c)return a;var d=new c(k,b);return q(d,a),d}function F(a,b){var c=this,d=new c(k,b);return t(d,a),d}function G(){throw new TypeError("You must pass a resolver function as the first argument to the promise constructor")}function H(){throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.")}function I(a,c){var d=this;d._id=Ja++,d._label=c,d._state=void 0,d._result=void 0,d._subscribers=[],va.instrument&&xa("created",d),k!==a&&(b(a)||G(),d instanceof I||H(),z(d,a))}function J(a,b,c){this._superConstructor(a,b,!1,c)}function K(a,b){return new J(Ka,a,b).promise}function L(a,b){return Ka.all(a
2015-12-01 15:40:31 +00:00
},EPUBJS.Book.prototype.parseLayoutProperties=function(a){var b=this.settings.layoutOveride&&this.settings.layoutOveride.layout||a.layout||"reflowable",c=this.settings.layoutOveride&&this.settings.layoutOveride.spread||a.spread||"auto",d=this.settings.layoutOveride&&this.settings.layoutOveride.orientation||a.orientation||"auto";return{layout:b,spread:c,orientation:d}},RSVP.EventTarget.mixin(EPUBJS.Book.prototype),RSVP.on("error",function(a){}),RSVP.configure("instrument",!1),EPUBJS.Chapter=function(a,b,c){this.href=a.href,this.absolute=a.url,this.id=a.id,this.spinePos=a.index,this.cfiBase=a.cfiBase,this.properties=a.properties,this.manifestProperties=a.manifestProperties,this.linear=a.linear,this.pages=1,this.store=b,this.credentials=c,this.epubcfi=new EPUBJS.EpubCFI,this.deferred=new RSVP.defer,this.loaded=this.deferred.promise,EPUBJS.Hooks.mixin(this),this.getHooks("beforeChapterRender"),this.caches={}},EPUBJS.Chapter.prototype.load=function(a,b){var c,d=a||this.store,e=b||this.credentials;return c=d?d.getXml(this.absolute):EPUBJS.core.request(this.absolute,!1,e),c.then(function(a){this.setDocument(a),this.deferred.resolve(this)}.bind(this)),c},EPUBJS.Chapter.prototype.render=function(a){return this.load().then(function(a){var b=a.querySelector("head"),c=a.createElement("base");return c.setAttribute("href",this.absolute),b.insertBefore(c,b.firstChild),this.contents=a,new RSVP.Promise(function(b,c){this.triggerHooks("beforeChapterRender",function(){b(a)}.bind(this),this)}.bind(this))}.bind(this)).then(function(a){var b=new XMLSerializer,c=b.serializeToString(a);return c}.bind(this))},EPUBJS.Chapter.prototype.url=function(a){var b,c=new RSVP.defer,d=a||this.store,e=this;return d?this.tempUrl?(b=this.tempUrl,c.resolve(b)):d.getUrl(this.absolute).then(function(a){e.tempUrl=a,c.resolve(a)}):(b=this.absolute,c.resolve(b)),c.promise},EPUBJS.Chapter.prototype.setPages=function(a){this.pages=a},EPUBJS.Chapter.prototype.getPages=function(a){return this.pages},EPUBJS.Chapter.prototype.getID=function(){return this.ID},EPUBJS.Chapter.prototype.unload=function(a){this.document=null,this.tempUrl&&a&&(a.revokeUrl(this.tempUrl),this.tempUrl=!1)},EPUBJS.Chapter.prototype.setDocument=function(a){var b=a.namespaceURI;a.doctype;this.document=a.implementation.createDocument(b,null,null),this.contents=this.document.importNode(a.documentElement,!0),this.document.appendChild(this.contents),!this.document.evaluate&&document.evaluate&&(this.document.evaluate=document.evaluate)},EPUBJS.Chapter.prototype.cfiFromRange=function(a){var b,c,d,e,f,g;if(this.document){if("undefined"!=typeof document.evaluate){if(c=EPUBJS.core.getElementXPath(a.startContainer),d=EPUBJS.core.getElementXPath(a.endContainer),e=this.document.evaluate(c,this.document,EPUBJS.core.nsResolver,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue,a.collapsed||(f=this.document.evaluate(d,this.document,EPUBJS.core.nsResolver,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue),b=this.document.createRange(),e)try{b.setStart(e,a.startOffset),!a.collapsed&&f&&b.setEnd(f,a.endOffset)}catch(h){console.log("missed"),e=!1}e||(console.log("not found, try fuzzy match"),cleanStartTextContent=EPUBJS.core.cleanStringForXpath(a.startContainer.textContent),c="//text()[contains(.,"+cleanStartTextContent+")]",e=this.document.evaluate(c,this.document,EPUBJS.core.nsResolver,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue,e&&(b.setStart(e,a.startOffset),a.collapsed||(g=EPUBJS.core.cleanStringForXpath(a.endContainer.textContent),d="//text()[contains(.,"+g+")]",f=this.document.evaluate(d,this.document,EPUBJS.core.nsResolver,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue,f&&b.setEnd(f,a.endOffset))))}else b=a;return this.epubcfi.generateCfiFromRange(b,this.cfiBase)}},EPUBJS.Chapter.prototype.find=function(a){var b=this,c=[],d=a.toLowerCase(),e=function(a){for(var e,f,g,h=a.textContent.toLowerCase(),i=b.document.createRange(),j=-1,k=150;-1!=f;)f=h.indexOf(d,j+1),-1!=f&&(i=b.document.createRange(),i.setStart(a,f),i.setEnd(a,f+d.length),e=b.cfiFromRange(i),a.textContent.leng
return e.forEach(function(a,d){var e=a.getAttribute("idref"),h=g.generateChapterComponent(f,d,e),i=a.getAttribute("properties")||"",j=i.length?i.split(" "):[],k=b[e].properties,l=k.length?k.split(" "):[],m={id:e,linear:a.getAttribute("linear")||"",properties:j,manifestProperties:l,href:b[e].href,url:b[e].url,index:d,cfiBase:h,cfi:"epubcfi("+h+")"};c.push(m)}),c},EPUBJS.Parser.prototype.querySelectorByType=function(a,b,c){var d=a.querySelector(b+'[*|type="'+c+'"]');if(null!==d&&0!==d.length)return d;d=a.querySelectorAll(b);for(var e=0;e<d.length;e++)if(d[e].getAttributeNS("http://www.idpf.org/2007/ops","type")===c)return d[e]},EPUBJS.Parser.prototype.nav=function(a,b,c){var d,e,f,g=this.querySelectorByType(a,"nav","toc"),h=g?g.querySelectorAll("ol li"):[],i=h.length,j={},k=[];if(!h||0===i)return k;for(d=0;i>d;++d)e=this.navItem(h[d],b,c),j[e.id]=e,e.parent?(f=j[e.parent],f.subitems.push(e)):k.push(e);return k},EPUBJS.Parser.prototype.navItem=function(a,b,c){var d,e=a.getAttribute("id")||!1,f=a.querySelector("a, span"),g=f.getAttribute("href")||"",h=f.textContent||"",i=g.split("#"),j=i[0],k=b[j],l=c[k],m=[],n=a.parentNode,o=l?l.cfi:"";return n&&"navPoint"===n.nodeName&&(d=n.getAttribute("id")),e||(k?(l=c[k],e=l.id,o=l.cfi):(e="epubjs-autogen-toc-id-"+EPUBJS.core.uuid(),a.setAttribute("id",e))),{id:e,href:g,label:h,spinePos:k,subitems:m,parent:d,cfi:o}},EPUBJS.Parser.prototype.toc=function(a,b,c){var d,e,f,g=a.querySelectorAll("navMap navPoint"),h=g.length,i={},j=[];if(!g||0===h)return j;for(d=0;h>d;++d)e=this.tocItem(g[d],b,c),i[e.id]=e,e.parent?(f=i[e.parent],f.subitems.push(e)):j.push(e);return j},EPUBJS.Parser.prototype.tocItem=function(a,b,c){var d,e=a.getAttribute("id")||!1,f=a.querySelector("content"),g=f.getAttribute("src"),h=a.querySelector("navLabel"),i=h.textContent?h.textContent:"",j=g.split("#"),k=j[0],l=b[k],m=c[l],n=[],o=a.parentNode,p=m?m.cfi:"";return o&&"navPoint"===o.nodeName&&(d=o.getAttribute("id")),e||(l?(m=c[l],e=m.id,p=m.cfi):(e="epubjs-autogen-toc-id-"+EPUBJS.core.uuid(),a.setAttribute("id",e))),{id:e,href:g,label:i,spinePos:l,subitems:n,parent:d,cfi:p}},EPUBJS.Parser.prototype.pageList=function(a,b,c){var d,e,f=this.querySelectorByType(a,"nav","page-list"),g=f?f.querySelectorAll("ol li"):[],h=g.length,i=[];if(!g||0===h)return i;for(d=0;h>d;++d)e=this.pageListItem(g[d],b,c),i.push(e);return i},EPUBJS.Parser.prototype.pageListItem=function(a,b,c){var d,e,f,g=(a.getAttribute("id")||!1,a.querySelector("a")),h=g.getAttribute("href")||"",i=g.textContent||"",j=parseInt(i),k=h.indexOf("epubcfi");return-1!=k?(d=h.split("#"),e=d[0],f=d.length>1?d[1]:!1,{cfi:f,href:h,packageUrl:e,page:j}):{href:h,page:j}},EPUBJS.Render.Iframe=function(){this.iframe=null,this.document=null,this.window=null,this.docEl=null,this.bodyEl=null,this.leftPos=0,this.pageWidth=0},EPUBJS.Render.Iframe.prototype.create=function(){return this.iframe=document.createElement("iframe"),this.iframe.id="epubjs-iframe:"+EPUBJS.core.uuid(),this.iframe.scrolling="no",this.iframe.seamless="seamless",this.iframe.style.border="none",this.iframe.addEventListener("load",this.loaded.bind(this),!1),this.isMobile=navigator.userAgent.match(/(iPad|iPhone|iPod|Mobile|Android)/g),this.transform=EPUBJS.core.prefixed("transform"),this.iframe},EPUBJS.Render.Iframe.prototype.load=function(a,b){var c=this,d=new RSVP.defer;return this.window&&this.unload(),this.iframe.onload=function(a){c.document=c.iframe.contentDocument,c.docEl=c.document.documentElement,c.headEl=c.document.head,c.bodyEl=c.document.body||c.document.querySelector("body"),c.window=c.iframe.contentWindow,c.window.addEventListener("resize",c.resized.bind(c),!1),c.leftPos=0,c.setLeft(0),c.bodyEl&&(c.bodyEl.style.margin="0"),"rtl"==c.direction&&"rtl"!=c.docEl.dir&&(c.docEl.dir="rtl",c.docEl.style.position="absolute",c.docEl.style.right="0"),d.resolve(c.docEl)},this.iframe.onerror=function(a){d.reject({message:"Error Loading Contents: "+a,stack:(new Error).stack})},this.document=this.iframe.contentDocument,this.document?(this.document.open(),this.document.write(a),this.document.close(),d.promise):(d.re
rfc822:["eml","mime","mht","mhtml","nws"]},text:{"cache-manifest":["manifest","appcache"],calendar:["ics","icz","ifb"],css:"css",csv:"csv",h323:"323",html:["html","htm","shtml","stm"],iuls:"uls",mathml:"mml",plain:["txt","text","brf","conf","def","list","log","in","bas"],richtext:"rtx","tab-separated-values":"tsv","x-bibtex":"bib","x-dsrc":"d","x-diff":["diff","patch"],"x-haskell":"hs","x-java":"java","x-literate-haskell":"lhs","x-moc":"moc","x-pascal":["p","pas"],"x-pcs-gcd":"gcd","x-perl":["pl","pm"],"x-python":"py","x-scala":"scala","x-setext":"etx","x-tcl":["tcl","tk"],"x-tex":["tex","ltx","sty","cls"],"x-vcard":"vcf",sgml:["sgml","sgm"],"x-c":["c","cc","cxx","cpp","h","hh","dic"],"x-fortran":["f","for","f77","f90"],"x-opml":"opml","x-nfo":"nfo","x-sfv":"sfv","x-uuencode":"uu",webviewhtml:"htt"},video:{mpeg:["mpeg","mpg","mpe","m1v","m2v","mp2","mpa","mpv2"],mp4:["mp4","mp4v","mpg4"],quicktime:["qt","mov"],ogg:"ogv","vnd.mpegurl":["mxu","m4u"],"x-flv":"flv","x-la-asf":["lsf","lsx"],"x-mng":"mng","x-ms-asf":["asf","asx","asr"],"x-ms-wm":"wm","x-ms-wmv":"wmv","x-ms-wmx":"wmx","x-ms-wvx":"wvx","x-msvideo":"avi","x-sgi-movie":"movie","x-matroska":["mpv","mkv","mk3d","mks"],"3gpp2":"3g2",h261:"h261",h263:"h263",h264:"h264",jpeg:"jpgv",jpm:["jpm","jpgm"],mj2:["mj2","mjp2"],"vnd.ms-playready.media.pyv":"pyv","vnd.uvvu.mp4":["uvu","uvvu"],"vnd.vivo":"viv",webm:"webm","x-f4v":"f4v","x-m4v":"m4v","x-ms-vob":"vob","x-smv":"smv"}},b=function(){var b,c,d,e,f={};for(b in a)if(a.hasOwnProperty(b))for(c in a[b])if(a[b].hasOwnProperty(c))if(d=a[b][c],"string"==typeof d)f[d]=b+"/"+c;else for(e=0;e<d.length;e++)f[d[e]]=b+"/"+c;return f}();EPUBJS.core.getMimeType=function(a){var c="text/plain";return a&&b[a.split(".").pop().toLowerCase()]||c}}();
2015-11-19 17:33:10 +00:00
//# sourceMappingURL=epub.min.map