UNPKG

vue-book-reader

Version:

vue-book-reader is a vue wrapper for [foliate-js](https://github.com/johnfactotum/foliate-js) - library for rendering e-books in the browser. Supports EPUB, MOBI, KF8 (AZW3), FB2, CBZ, PDF (experimental; requires PDF.js), or add support for other formats

45 lines (44 loc) 203 kB
(function(){"use strict";try{if(typeof document<"u"){var o=document.createElement("style");o.appendChild(document.createTextNode('.reader[data-v-7b9f0714]{position:absolute;top:50px;right:50px;bottom:20px;left:50px}.viewHolder[data-v-7b9f0714]{height:100%;width:100%;position:relative}#viewer[data-v-7b9f0714]{height:100%}.container{overflow:hidden;position:relative;height:100%}.containerExpanded{transform:translate(256px)}.readerArea{position:relative;z-index:1;height:100%;width:100%;transition:all .3s ease}.container .titleArea{position:absolute;top:20px;left:50px;right:50px;text-align:center;color:#999;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.tocBackground{position:absolute;left:256px;top:0;bottom:0;right:0;z-index:1}.tocArea{position:absolute;left:0;top:0;bottom:0;z-index:0;width:256px;overflow-y:auto;-webkit-overflow-scrolling:touch;background:#f2f2f2;padding:10px 0}.tocArea::-webkit-scrollbar{width:5px;height:5px}.tocArea::-webkit-scrollbar-thumb:vertical{height:5px;background-color:#0000001a;border-radius:.5rem}.tocArea .tocAreaButton{-webkit-user-select:none;user-select:none;-webkit-appearance:none;-moz-appearance:none;appearance:none;background:none;border:none;display:block;font-family:sans-serif;width:100%;font-size:.9em;text-align:left;padding:.9em 1em;border-bottom:1px solid #ddd;color:#aaa;box-sizing:border-box;outline:none;cursor:pointer;position:relative}.tocArea .tocAreaButton:hover{background:#0000000d}.tocArea .tocAreaButton:active{background:#0000001a}.tocArea .active{color:#1565c0;border-bottom:2px solid #1565c0}.tocArea .tocAreaButton .expansion{cursor:pointer;transform:translateY(-50%);top:50%;right:12px;position:absolute;width:10px;background-color:#a2a5b4;transition:transform .3s ease-in-out,top .3s ease-in-out}.tocArea .tocAreaButton .expansion:after,.tocArea .tocAreaButton .expansion:before{content:"";position:absolute;width:6px;height:2px;background-color:currentcolor;border-radius:2px;transition:transform .3s ease-in-out,top .3s ease-in-out}.tocArea .tocAreaButton .expansion:before{transform:rotate(-45deg) translate(2.5px)}.tocArea .tocAreaButton .expansion:after{transform:rotate(45deg) translate(-2.5px)}.tocArea .tocAreaButton .open:before{transform:rotate(45deg) translate(2.5px)}.tocArea .tocAreaButton .open:after{transform:rotate(-45deg) translate(-2.5px)}.tocButton{background:none;border:none;width:32px;height:32px;position:absolute;top:10px;left:10px;border-radius:2px;outline:none;cursor:pointer}.tocButtonBar{position:absolute;width:60%;background:#ccc;height:2px;left:50%;margin:-1px -30%;top:50%;transition:all .5s ease}.tocButtonExpanded{background:#f2f2f2}.arrow{outline:none;border:none;background:none;position:absolute;top:50%;margin-top:-32px;font-size:64px;padding:0 10px;color:#e2e2e2;font-family:arial,sans-serif;cursor:pointer;-webkit-user-select:none;user-select:none;-webkit-appearance:none;-moz-appearance:none;appearance:none;font-weight:400}.arrow:hover{color:#777}.arrow:disabled{cursor:not-allowed;color:#e2e2e2}.prev{left:1px}.next{right:1px}.loadingView{position:absolute;top:50%;left:10%;right:10%;color:#ccc;text-align:center;margin-top:-.5em}')),document.head.appendChild(o)}}catch(e){console.error("vite-plugin-css-injected-by-js",e)}})(); (function(U,O){typeof exports=="object"&&typeof module<"u"?O(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],O):(U=typeof globalThis<"u"?globalThis:U||self,O(U["vue-book-reader"]={},U.Vue))})(this,function(U,O){"use strict";var Rd=Object.defineProperty;var zd=(U,O,G)=>O in U?Rd(U,O,{enumerable:!0,configurable:!0,writable:!0,value:G}):U[O]=G;var mt=(U,O,G)=>(zd(U,typeof O!="symbol"?O+"":O,G),G),pr=(U,O,G)=>{if(!O.has(U))throw TypeError("Cannot "+G)};var h=(U,O,G)=>(pr(U,O,"read from private field"),G?G.call(U):O.get(U)),k=(U,O,G)=>{if(O.has(U))throw TypeError("Cannot add the same private member more than once");O instanceof WeakSet?O.add(U):O.set(U,G)},R=(U,O,G,Ne)=>(pr(U,O,"write to private field"),Ne?Ne.call(U,G):O.set(U,G),G);var Pi=(U,O,G,Ne)=>({set _(Ps){R(U,O,Ps,G)},get _(){return h(U,O,Ne)}}),T=(U,O,G)=>(pr(U,O,"access private method"),G);var ps,Wa,Vt,qt,At,pt,gs,te,zt,_e,ee,Ot,pe,ms,ja,bs,Ha,ws,Va,mn,Os,ys,qa,xs,Xa,vs,Ga,Pa,He,si,ne,Se,bn,It,Mt,Bt,ke,wn,Is,Ve,$i,ri,gr,oi,mr,ai,br,yn,Ms,ci,wt,tt,li,nt,dt,hi,xn,Xt,vn,ie,di,se,qe,yt,Ae,Xe,j,Et,Nt,re,Gt,oe,_n,Ge,ui,fi,pi,Sn,Ee,Ke,kn,_s,Ka,gi,wr,mi,yr,bi,xr,wi,vr,Ze,Ui,Ss,Za,Te,$n,Le,Un,ks,Ya,As,Ja,Ye,Wi,yi,_r,xi,Sr,An,Bs,Es,Qa,Ts,tc,ae,an,vi,kr,et,En,xt,Ft,ce,Tn,Kt,_i,Ln,Ns,Ce,Wn,Re,Si,Je,Tt,gt,st,ki,Ai,Ls,ec,Cn,Fs,ze,jn,le,cn,Ei,Ar,Rn,Ds,he,ln,Ti,zn,Li,de,ue,Zt,Qe,On,Dt,ge,In,Mn,Bn,Ci,Ri,zi,Nn,Oi,Ii,Er,Cs,nc,tn,Fn,en,Oe,Mi,Bi,Yt,Dn,nn,sn,rn,Ie,Me,fe,Rs,zs,Be,Ni,Fi,Tr;const G=(i,e)=>i.map((t,n,s)=>e(t,n,s)?n:null).filter(t=>t!=null),Ne=(i,e)=>[-1,...e,i.length].reduce(({xs:t,a:n},s)=>({xs:(t==null?void 0:t.concat([i.slice(n+1,s)]))??[],a:s}),{}).xs,Ps=(i,e)=>i.slice(0,-1).concat([i[i.length-1].concat(e[0])]).concat(e.slice(1)),$s=/\d/,ji=/^epubcfi\((.*)\)$/,Lr=i=>i.replace(/[\^[\](),;=]/g,"^$&"),Cr=i=>ji.test(i)?i:`epubcfi(${i})`,ic=i=>{var e;return((e=i.match(ji))==null?void 0:e[1])??i},sc=(i=>(...e)=>`epubcfi(${i(...e.map(t=>{var n;return((n=t.match(ji))==null?void 0:n[1])??t}))})`)((...i)=>i.join("!")),rc=i=>{const e=[];let t,n,s="";const r=c=>(e.push(c),t=null,s=""),o=c=>(s+=c,n=!1);for(const c of Array.from(i.trim()).concat("")){if(c==="^"&&!n){n=!0;continue}if(t==="!")r(["!"]);else if(t===",")r([","]);else if(t==="/"||t===":")if($s.test(c)){o(c);continue}else r([t,parseInt(s)]);else if(t==="~")if($s.test(c)||c==="."){o(c);continue}else r(["~",parseFloat(s)]);else if(t==="@"){if(c===":"){r(["@",parseFloat(s)]),t="@";continue}if($s.test(c)||c==="."){o(c);continue}else r(["@",parseFloat(s)])}else if(t==="["){c===";"&&!n?(r(["[",s]),t=";"):c===","&&!n?(r(["[",s]),t="["):c==="]"&&!n?r(["[",s]):o(c);continue}else if(t!=null&&t.startsWith(";")){c==="="&&!n?(t=`;${s}`,s=""):c===";"&&!n?(r([t,s]),t=";"):c==="]"&&!n?r([t,s]):o(c);continue}(c==="/"||c===":"||c==="~"||c==="@"||c==="["||c==="!"||c===",")&&(t=c)}return e},Rr=(i,e)=>G(i,([t])=>t===e),oc=i=>{const e=[];let t;for(const[n,s]of i){if(n==="/")e.push({index:s});else{const r=e[e.length-1];if(n===":")r.offset=s;else if(n==="~")r.temporal=s;else if(n==="@")r.spatial=(r.spatial??[]).concat(s);else if(n===";s")r.side=s;else if(n==="[")if(t==="/"&&s)r.id=s;else{r.text=(r.text??[]).concat(s);continue}}t=n}return e},zr=i=>Ne(i,Rr(i,"!")).map(oc),Hn=i=>{const e=rc(ic(i)),t=Rr(e,",");if(!t.length)return zr(e);const[n,s,r]=Ne(e,t).map(zr);return{parent:n,start:s,end:r}},ac=({index:i,id:e,offset:t,temporal:n,spatial:s,text:r,side:o})=>{var a;const c=o?`;s=${o}`:"";return`/${i}`+(e?`[${Lr(e)}${c}]`:"")+(t!=null&&i%2?`:${t}`:"")+(n?`~${n}`:"")+(s?`@${s.join(":")}`:"")+(r||!e&&o?"["+(((a=r==null?void 0:r.map(Lr))==null?void 0:a.join(","))??"")+c+"]":"")},Or=i=>i.parent?[i.parent,i.start,i.end].map(Or).join(","):i.map(e=>e.map(ac).join("")).join("!"),Hi=i=>Cr(Or(i)),hn=(i,e)=>typeof i=="string"?Hi(hn(Hn(i),e)):i.parent?Ps(i.parent,i[e?"end":"start"]):i,cc=(i,e)=>{typeof i=="string"&&(i=Hn(i)),typeof e=="string"&&(e=Hn(e)),i=hn(i),e=hn(e,!0);const t=i[i.length-1],n=e[e.length-1],s=[],r=[],o=[];let c=!0;const a=Math.max(t.length,n.length);for(let d=0;d<a;d++){const f=t[d],g=n[d];c&&(c=(f==null?void 0:f.index)===(g==null?void 0:g.index)&&!(f!=null&&f.offset)&&!(g!=null&&g.offset)),c?s.push(f):(f&&r.push(f),g&&o.push(g))}const l=i.slice(0,-1).concat([s]);return Hi({parent:l,start:[r],end:[o]})},Us=({nodeType:i})=>i===3||i===4,Vi=({nodeType:i})=>i===1,Ir=(i,e)=>{const t=Array.from(i.childNodes).filter(n=>Us(n)||Vi(n));return e?t.map(n=>{const s=e(n);return s===NodeFilter.FILTER_REJECT?null:s===NodeFilter.FILTER_SKIP?Ir(n,e):n}).flat().filter(n=>n):t},Ws=(i,e)=>{const t=Ir(i,e).reduce((n,s)=>{let r=n[n.length-1];return r?Us(s)?Array.isArray(r)?r.push(s):Us(r)?n[n.length-1]=[r,s]:n.push(s):Vi(r)?n.push(null,s):n.push(s):n.push(s),n},[]);return Vi(t[0])&&t.unshift("first"),Vi(t[t.length-1])&&t.push("last"),t.unshift("before"),t.push("after"),t},js=(i,e,t)=>{const{id:n}=e[e.length-1];if(n){const o=i.ownerDocument.getElementById(n);if(o)return{node:o,offset:0}}for(const{index:o}of e){const c=i?Ws(i,t)[o]:null;if(c==="first")return{node:i.firstChild??i};if(c==="last")return{node:i.lastChild??i};if(c==="before")return{node:i,before:!0};if(c==="after")return{node:i,after:!0};i=c}const{offset:s}=e[e.length-1];if(!Array.isArray(i))return{node:i,offset:s};let r=0;for(const o of i){const{length:c}=o.nodeValue;if(r+c>=s)return{node:o,offset:s-r};r+=c}},qi=(i,e,t)=>{const{parentNode:n,id:s}=i,r=Ws(n,t),o=r.findIndex(l=>Array.isArray(l)?l.some(d=>d===i):l===i),c=r[o];if(Array.isArray(c)){let l=0;for(const d of c)if(d===i){l+=e;break}else l+=d.nodeValue.length;e=l}const a={id:s,index:o,offset:e};return(n!==i.ownerDocument.documentElement?qi(n,null,t).concat(a):[a]).filter(l=>l.index!==-1)},lc=(i,e)=>{const{startContainer:t,startOffset:n,endContainer:s,endOffset:r}=i,o=qi(t,n,e);if(i.collapsed)return Hi([o]);const c=qi(s,r,e);return cc([o],[c])},Mr=(i,e,t)=>{const n=hn(e),s=hn(e,!0),r=i.documentElement,o=js(r,n[0],t),c=js(r,s[0],t),a=i.createRange();return o.before?a.setStartBefore(o.node):o.after?a.setStartAfter(o.node):a.setStart(o.node,o.offset),c.before?a.setEndBefore(c.node):c.after?a.setEndAfter(c.node):a.setEnd(c.node,c.offset),a},hc=i=>{const e=[],{parentNode:t}=i[0],n=qi(t);for(const[s,r]of Ws(t).entries()){const o=i[e.length];r===o&&e.push(Hi([n.concat({id:o.id,index:s})]))}return e},Br=(i,e)=>js(i.documentElement,hn(e)).node,Nr={fromIndex:i=>Cr(`/6/${(i+1)*2}`),toIndex:i=>(i==null?void 0:i.at(-1).index)/2-1},dc=i=>{let e=0;const t=n=>{if(n.id=e++,n.subitems)for(const s of n.subitems)t(s)};for(const n of i)t(n);return i},Fr=i=>i.map(e=>{var t;return(t=e.subitems)!=null&&t.length?[e,Fr(e.subitems)].flat():e}).flat();class Dr{async init({toc:e,ids:t,splitHref:n,getFragment:s}){dc(e);const r=Fr(e),o=new Map;for(const[a,l]of r.entries()){const[d,f]=await n(l==null?void 0:l.href)??[],g={fragment:f,item:l};o.has(d)?o.get(d).items.push(g):o.set(d,{prev:r[a-1],items:[g]})}const c=new Map;for(const[a,l]of t.entries())o.has(l)?c.set(l,o.get(l)):c.set(l,c.get(t[a-1]));this.ids=t,this.map=c,this.getFragment=s}getProgress(e,t){var a;if(!this.ids)return;const n=this.ids[e],s=this.map.get(n);if(!s)return null;const{prev:r,items:o}=s;if(!o)return r;if(!t||o.length===1&&!o[0].fragment)return o[0].item;const c=t.startContainer.getRootNode();for(const[l,{fragment:d}]of o.entries()){const f=this.getFragment(c,d);if(f&&t.comparePoint(f,0)>0)return((a=o[l-1])==null?void 0:a.item)??r}return o[o.length-1].item}}class uc{constructor(e,t,n){k(this,ps);this.sizes=e.map(s=>s.linear!="no"&&s.size>0?s.size:0),this.sizePerLoc=t,this.sizePerTimeUnit=n,this.sizeTotal=this.sizes.reduce((s,r)=>s+r,0),this.sectionFractions=T(this,ps,Wa).call(this)}getProgress(e,t,n=0){const{sizes:s,sizePerLoc:r,sizePerTimeUnit:o,sizeTotal:c}=this,a=s[e]??0,d=s.slice(0,e).reduce((p,m)=>p+m,0)+t*a,f=d+n*a,g=c-d,w=(1-t)*a;return{fraction:f/c,section:{current:e,total:s.length},location:{current:Math.floor(d/r),next:Math.floor(f/r),total:Math.ceil(c/r)},time:{section:w/o,total:g/o}}}getSection(e){if(e<=0)return[0,0];if(e>=1)return[this.sizes.length-1,1];e=e+Number.EPSILON;const{sizeTotal:t}=this;let n=this.sectionFractions.findIndex(r=>r>e)-1;if(n<0)return[0,0];for(;!this.sizes[n];)n++;const s=(e-this.sectionFractions[n])/(this.sizes[n]/t);return[n,s]}}ps=new WeakSet,Wa=function(){const{sizeTotal:e}=this,t=[0];let n=0;for(const s of this.sizes)t.push((n+=s)/e);return t};const rt=i=>document.createElementNS("http://www.w3.org/2000/svg",i);class Pr{constructor(){k(this,Vt,rt("svg"));k(this,qt,new Map);Object.assign(h(this,Vt).style,{position:"absolute",top:"0",left:"0",width:"100%",height:"100%",pointerEvents:"none"})}get element(){return h(this,Vt)}add(e,t,n,s){h(this,qt).has(e)&&this.remove(e),typeof t=="function"&&(t=t(h(this,Vt).getRootNode()));const r=t.getClientRects(),o=n(r,s);h(this,Vt).append(o),h(this,qt).set(e,{range:t,draw:n,options:s,element:o,rects:r})}remove(e){h(this,qt).has(e)&&(h(this,Vt).removeChild(h(this,qt).get(e).element),h(this,qt).delete(e))}redraw(){for(const e of h(this,qt).values()){const{range:t,draw:n,options:s,element:r}=e;h(this,Vt).removeChild(r);const o=t.getClientRects(),c=n(o,s);h(this,Vt).append(c),e.element=c,e.rects=o}}hitTest({x:e,y:t}){const n=Array.from(h(this,qt).entries());for(let s=n.length-1;s>=0;s--){const[r,o]=n[s];for(const{left:c,top:a,right:l,bottom:d}of o.rects)if(a<=t&&c<=e&&d>t&&l>e)return[r,o.range]}return[]}static underline(e,t={}){const{color:n="red",width:s=2,writingMode:r}=t,o=rt("g");if(o.setAttribute("fill",n),r==="vertical-rl"||r==="vertical-lr")for(const{right:c,top:a,height:l}of e){const d=rt("rect");d.setAttribute("x",c-s),d.setAttribute("y",a),d.setAttribute("height",l),d.setAttribute("width",s),o.append(d)}else for(const{left:c,bottom:a,width:l}of e){const d=rt("rect");d.setAttribute("x",c),d.setAttribute("y",a-s),d.setAttribute("height",s),d.setAttribute("width",l),o.append(d)}return o}static strikethrough(e,t={}){const{color:n="red",width:s=2,writingMode:r}=t,o=rt("g");if(o.setAttribute("fill",n),r==="vertical-rl"||r==="vertical-lr")for(const{right:c,left:a,top:l,height:d}of e){const f=rt("rect");f.setAttribute("x",(c+a)/2),f.setAttribute("y",l),f.setAttribute("height",d),f.setAttribute("width",s),o.append(f)}else for(const{left:c,top:a,bottom:l,width:d}of e){const f=rt("rect");f.setAttribute("x",c),f.setAttribute("y",(a+l)/2),f.setAttribute("height",s),f.setAttribute("width",d),o.append(f)}return o}static squiggly(e,t={}){const{color:n="red",width:s=2,writingMode:r}=t,o=rt("g");o.setAttribute("fill","none"),o.setAttribute("stroke",n),o.setAttribute("stroke-width",s);const c=s*1.5;if(r==="vertical-rl"||r==="vertical-lr")for(const{right:a,top:l,height:d}of e){const f=rt("path"),g=Math.round(d/c/1.5),w=d/g,p=Array.from({length:g},(m,u)=>`l${u%2?-c:c} ${w}`).join("");f.setAttribute("d",`M${a} ${l}${p}`),o.append(f)}else for(const{left:a,bottom:l,width:d}of e){const f=rt("path"),g=Math.round(d/c/1.5),w=d/g,p=Array.from({length:g},(m,u)=>`l${w} ${u%2?c:-c}`).join("");f.setAttribute("d",`M${a} ${l}${p}`),o.append(f)}return o}static highlight(e,t={}){const{color:n="red"}=t,s=rt("g");s.setAttribute("fill",n),s.style.opacity="var(--overlayer-highlight-opacity, .3)",s.style.mixBlendMode="var(--overlayer-highlight-blend-mode, normal)";for(const{left:r,top:o,height:c,width:a}of e){const l=rt("rect");l.setAttribute("x",r),l.setAttribute("y",o),l.setAttribute("height",c),l.setAttribute("width",a),s.append(l)}return s}static outline(e,t={}){const{color:n="red",width:s=3,radius:r=3}=t,o=rt("g");o.setAttribute("fill","none"),o.setAttribute("stroke",n),o.setAttribute("stroke-width",s);for(const{left:c,top:a,height:l,width:d}of e){const f=rt("rect");f.setAttribute("x",c),f.setAttribute("y",a),f.setAttribute("height",l),f.setAttribute("width",d),f.setAttribute("rx",r),o.append(f)}return o}static copyImage([e],t={}){const{src:n}=t,s=rt("image"),{left:r,top:o,height:c,width:a}=e;return s.setAttribute("href",n),s.setAttribute("x",r),s.setAttribute("y",o),s.setAttribute("height",c),s.setAttribute("width",a),s}}Vt=new WeakMap,qt=new WeakMap;const fc=(i,e)=>{const t=[];for(let n=e.currentNode;n;n=e.nextNode()){const s=i.comparePoint(n,0);if(s===0)t.push(n);else if(s>0)break}return t},pc=(i,e)=>{const t=[];for(let n=e.nextNode();n;n=e.nextNode())t.push(n);return t},gc=NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_TEXT|NodeFilter.SHOW_CDATA_SECTION,mc=i=>{if(i.nodeType===1){const e=i.tagName.toLowerCase();return e==="script"||e==="style"?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_SKIP}return NodeFilter.FILTER_ACCEPT},$r=function*(i,e){const t=i.commonAncestorContainer??i.body??i,n=document.createTreeWalker(t,gc,{acceptNode:mc}),r=(i.commonAncestorContainer?fc:pc)(i,n),o=r.map(a=>a.nodeValue),c=(a,l,d,f)=>{const g=document.createRange();return g.setStart(r[a],l),g.setEnd(r[d],f),g};for(const a of e(o,c))yield a},Vn="foliate-search:";class bc extends EventTarget{constructor(){super(...arguments);k(this,At,[]);k(this,pt,-1)}pushState(t){const n=h(this,At)[h(this,pt)];n===t||n!=null&&n.fraction&&n.fraction===t.fraction||(h(this,At)[++Pi(this,pt)._]=t,h(this,At).length=h(this,pt)+1,this.dispatchEvent(new Event("index-change")))}replaceState(t){const n=h(this,pt);h(this,At)[n]=t}back(){const t=h(this,pt);if(t<=0)return;const n={state:h(this,At)[t-1]};R(this,pt,t-1),this.dispatchEvent(new CustomEvent("popstate",{detail:n})),this.dispatchEvent(new Event("index-change"))}forward(){const t=h(this,pt);if(t>=h(this,At).length-1)return;const n={state:h(this,At)[t+1]};R(this,pt,t+1),this.dispatchEvent(new CustomEvent("popstate",{detail:n})),this.dispatchEvent(new Event("index-change"))}get canGoBack(){return h(this,pt)>0}get canGoForward(){return h(this,pt)<h(this,At).length-1}clear(){R(this,At,[]),R(this,pt,-1)}}At=new WeakMap,pt=new WeakMap;const wc=i=>{var e,t;if(!i)return{};try{const n=Intl.getCanonicalLocales(i)[0],s=new Intl.Locale(n),r=["zh","ja","kr"].includes(s.language),o=(t=((e=s.getTextInfo)==null?void 0:e.call(s))??s.textInfo)==null?void 0:t.direction;return{canonical:n,locale:s,isCJK:r,direction:o}}catch(n){return console.warn(n),{}}};let yc=(Pa=class extends HTMLElement{constructor(){super();k(this,Ot);k(this,ms);k(this,bs);k(this,ws);k(this,mn);k(this,ys);k(this,xs);k(this,vs);k(this,gs,this.attachShadow({mode:"closed"}));k(this,te,void 0);k(this,zt,void 0);k(this,_e,void 0);k(this,ee,new Map);mt(this,"isFixedLayout",!1);mt(this,"lastLocation");mt(this,"history",new bc);this.history.addEventListener("popstate",({detail:t})=>{const n=this.resolveNavigation(t.state);this.renderer.goTo(n)})}async open(t){var n,s,r;if(this.book=t,this.language=wc((n=t.metadata)==null?void 0:n.language),t.splitTOCHref&&t.getTOCFragment){const o=t.sections.map(l=>l.id);R(this,te,new uc(t.sections,1500,1600));const c=t.splitTOCHref.bind(t),a=t.getTOCFragment.bind(t);R(this,zt,new Dr),await h(this,zt).init({toc:t.toc??[],ids:o,splitHref:c,getFragment:a}),R(this,_e,new Dr),await h(this,_e).init({toc:t.pageList??[],ids:o,splitHref:c,getFragment:a})}if(this.isFixedLayout=((s=this.book.rendition)==null?void 0:s.layout)==="pre-paginated",this.isFixedLayout?(await Promise.resolve().then(()=>Uc),this.renderer=document.createElement("foliate-fxl")):(await Promise.resolve().then(()=>tl),this.renderer=document.createElement("foliate-paginator")),this.renderer.setAttribute("exportparts","head,foot,filter"),this.renderer.addEventListener("load",o=>T(this,bs,Ha).call(this,o.detail)),this.renderer.addEventListener("relocate",o=>T(this,ms,ja).call(this,o.detail)),this.renderer.addEventListener("create-overlayer",o=>o.detail.attach(T(this,ys,qa).call(this,o.detail))),this.renderer.open(t),h(this,gs).append(this.renderer),t.sections.some(o=>o.mediaOverlay)){(r=t.media).activeClass||(r.activeClass="-epub-media-overlay-active");const o=t.media.activeClass;this.mediaOverlay=t.getMediaOverlay();let c;this.mediaOverlay.addEventListener("highlight",a=>{const l=this.resolveNavigation(a.detail.text);this.renderer.goTo(l).then(()=>{const{doc:d}=this.renderer.getContents().find(g=>g.index=l.index),f=l.anchor(d);f.classList.add(o),c=new WeakRef(f)})}),this.mediaOverlay.addEventListener("unhighlight",()=>{var a,l;(l=(a=c==null?void 0:c.deref())==null?void 0:a.classList)==null||l.remove(o)})}}close(){var t,n;(t=this.renderer)==null||t.destroy(),(n=this.renderer)==null||n.remove(),R(this,te,null),R(this,zt,null),R(this,_e,null),R(this,ee,new Map),this.lastLocation=null,this.history.clear(),this.tts=null,this.mediaOverlay=null}goToTextStart(){var t,n;return this.goTo(((n=(t=this.book.landmarks)==null?void 0:t.find(s=>s.type.includes("bodymatter")||s.type.includes("text")))==null?void 0:n.href)??this.book.sections.findIndex(s=>s.linear!=="no"))}async init({lastLocation:t,showTextStart:n}){const s=t?this.resolveNavigation(t):null;s?(await this.renderer.goTo(s),this.history.pushState(t)):n?await this.goToTextStart():(this.history.pushState(0),await this.next())}async addAnnotation(t,n){var l;const{value:s}=t;if(s.startsWith(Vn)){const d=s.replace(Vn,""),{index:f,anchor:g}=await this.resolveNavigation(d),w=T(this,mn,Os).call(this,f);if(w){const{overlayer:p,doc:m}=w;if(n){p.remove(s);return}const u=m?g(m):g;p.add(s,u,Pr.outline)}return}const{index:r,anchor:o}=await this.resolveNavigation(s),c=T(this,mn,Os).call(this,r);if(c){const{overlayer:d,doc:f}=c;if(d.remove(s),!n){const g=f?o(f):o,w=(p,m)=>d.add(s,g,p,m);T(this,Ot,pe).call(this,"draw-annotation",{draw:w,annotation:t,doc:f,range:g})}}const a=((l=h(this,zt).getProgress(r))==null?void 0:l.label)??"";return{index:r,label:a}}deleteAnnotation(t){return this.addAnnotation(t,!0)}async showAnnotation(t){const{value:n}=t,s=await this.goTo(n);if(s){const{index:r,anchor:o}=s,{doc:c}=T(this,mn,Os).call(this,r),a=o(c);T(this,Ot,pe).call(this,"show-annotation",{value:n,index:r,range:a})}}getCFI(t,n){const s=this.book.sections[t].cfi??Nr.fromIndex(t);return n?sc(s,lc(n)):s}resolveCFI(t){if(this.book.resolveCFI)return this.book.resolveCFI(t);{const n=Hn(t);return{index:Nr.toIndex((n.parent??n).shift()),anchor:o=>Mr(o,n)}}}resolveNavigation(t){try{if(typeof t=="number")return{index:t};if(typeof t.fraction=="number"){const[n,s]=h(this,te).getSection(t.fraction);return{index:n,anchor:s}}return ji.test(t)?this.resolveCFI(t):this.book.resolveHref(t)}catch(n){console.error(n),console.error(`Could not resolve target ${t}`)}}async goTo(t){const n=this.resolveNavigation(t);try{return await this.renderer.goTo(n),this.history.pushState(t),n}catch(s){console.error(s),console.error(`Could not go to ${t}`)}}async goToFraction(t){const[n,s]=h(this,te).getSection(t);await this.renderer.goTo({index:n,anchor:s}),this.history.pushState({fraction:t})}async select(t){try{const n=await this.resolveNavigation(t);await this.renderer.goTo({...n,select:!0}),this.history.pushState(t)}catch(n){console.error(n),console.error(`Could not go to ${t}`)}}deselect(){for(const{doc:t}of this.renderer.getContents())t.defaultView.getSelection().removeAllRanges()}getSectionFractions(){var t;return(((t=h(this,te))==null?void 0:t.sectionFractions)??[]).map(n=>n+Number.EPSILON)}getProgressOf(t,n){var o,c;const s=(o=h(this,zt))==null?void 0:o.getProgress(t,n),r=(c=h(this,_e))==null?void 0:c.getProgress(t,n);return{tocItem:s,pageItem:r}}async getTOCItemOf(t){try{const{index:n,anchor:s}=await this.resolveNavigation(t),r=await this.book.sections[n].createDocument(),o=s(r),c=o instanceof Range,a=c?o:r.createRange();return c||a.selectNodeContents(o),h(this,zt).getProgress(n,a)}catch(n){console.error(n),console.error(`Could not get ${t}`)}}async prev(t){await this.renderer.prev(t)}async next(t){await this.renderer.next(t)}goLeft(){return this.book.dir==="rtl"?this.next():this.prev()}goRight(){return this.book.dir==="rtl"?this.prev():this.next()}async*search(t){var l;this.clearSearch();const{searchMatcher:n}=await Promise.resolve().then(()=>il),{query:s,index:r}=t,o=n($r,{defaultLocale:this.language,...t}),c=r!=null?T(this,xs,Xa).call(this,o,s,r):T(this,vs,Ga).call(this,o,s),a=[];h(this,ee).set(r,a);for await(const d of c)if(d.subitems){const f=d.subitems.map(({cfi:g})=>({value:Vn+g}));h(this,ee).set(d.index,f);for(const g of f)this.addAnnotation(g);yield{label:((l=h(this,zt).getProgress(d.index))==null?void 0:l.label)??"",subitems:d.subitems}}else{if(d.cfi){const f={value:Vn+d.cfi};a.push(f),this.addAnnotation(f)}yield d}yield"done"}clearSearch(){for(const t of h(this,ee).values())for(const n of t)this.deleteAnnotation(n);h(this,ee).clear()}async initTTS(){const t=this.renderer.getContents()[0].doc;if(this.tts&&this.tts.doc===t)return;const{TTS:n}=await Promise.resolve().then(()=>dl);this.tts=new n(t,$r,s=>this.renderer.scrollToAnchor(s,!0))}startMediaOverlay(){const{index:t}=this.renderer.getContents()[0];return this.mediaOverlay.start(t)}},gs=new WeakMap,te=new WeakMap,zt=new WeakMap,_e=new WeakMap,ee=new WeakMap,Ot=new WeakSet,pe=function(t,n,s){return this.dispatchEvent(new CustomEvent(t,{detail:n,cancelable:s}))},ms=new WeakSet,ja=function({reason:t,range:n,index:s,fraction:r,size:o}){var f,g,w;const c=((f=h(this,te))==null?void 0:f.getProgress(s,r,o))??{},a=(g=h(this,zt))==null?void 0:g.getProgress(s,n),l=(w=h(this,_e))==null?void 0:w.getProgress(s,n),d=this.getCFI(s,n);this.lastLocation={...c,tocItem:a,pageItem:l,cfi:d,range:n},(t==="snap"||t==="page"||t==="scroll")&&this.history.replaceState(d),T(this,Ot,pe).call(this,"relocate",this.lastLocation)},bs=new WeakSet,Ha=function({doc:t,index:n}){var s,r;(s=t.documentElement).lang||(s.lang=this.language.canonical??""),this.language.isCJK||(r=t.documentElement).dir||(r.dir=this.language.direction??""),T(this,ws,Va).call(this,t,n),T(this,Ot,pe).call(this,"load",{doc:t,index:n})},ws=new WeakSet,Va=function(t,n){const{book:s}=this,r=s.sections[n];for(const o of t.querySelectorAll("a[href]"))o.addEventListener("click",c=>{var d,f;c.preventDefault();const a=o.getAttribute("href"),l=((d=r==null?void 0:r.resolveHref)==null?void 0:d.call(r,a))??a;(f=s==null?void 0:s.isExternal)!=null&&f.call(s,l)?Promise.resolve(T(this,Ot,pe).call(this,"external-link",{a:o,href:l},!0)).then(g=>g?globalThis.open(l,"_blank"):null).catch(g=>console.error(g)):Promise.resolve(T(this,Ot,pe).call(this,"link",{a:o,href:l},!0)).then(g=>g?this.goTo(l):null).catch(g=>console.error(g))})},mn=new WeakSet,Os=function(t){return this.renderer.getContents().find(n=>n.index===t&&n.overlayer)},ys=new WeakSet,qa=function({doc:t,index:n}){const s=new Pr;t.addEventListener("click",o=>{const[c,a]=s.hitTest(o);c&&!c.startsWith(Vn)&&T(this,Ot,pe).call(this,"show-annotation",{value:c,index:n,range:a})},!1);const r=h(this,ee).get(n);if(r)for(const o of r)this.addAnnotation(o);return T(this,Ot,pe).call(this,"create-overlay",{index:n}),s},xs=new WeakSet,Xa=async function*(t,n,s){const r=await this.book.sections[s].createDocument();for(const{range:o,excerpt:c}of t(r,n))yield{cfi:this.getCFI(s,o),excerpt:c}},vs=new WeakSet,Ga=async function*(t,n){const{sections:s}=this.book;for(const[r,{createDocument:o}]of s.entries()){if(!o)continue;const c=await o(),a=Array.from(t(c,n),({range:d,excerpt:f})=>({cfi:this.getCFI(r,d),excerpt:f}));yield{progress:(r+1)/s.length},a.length&&(yield{index:r,subitems:a})}},Pa);customElements.define("foliate-view",yc);const xc=async i=>{const e=new Uint8Array(await i.slice(0,4).arrayBuffer());return e[0]===80&&e[1]===75&&e[2]===3&&e[3]===4},vc=async i=>{const e=new Uint8Array(await i.slice(0,5).arrayBuffer());return e[0]===37&&e[1]===80&&e[2]===68&&e[3]===70&&e[4]===45},_c=async i=>{const{configure:e,ZipReader:t,BlobReader:n,TextWriter:s,BlobWriter:r}=await Promise.resolve().then(()=>ch);e({useWebWorkers:!1});const c=await new t(new n(i)).getEntries(),a=new Map(c.map(w=>[w.filename,w])),l=w=>(p,...m)=>a.has(p)?w(a.get(p),...m):null,d=l(w=>w.getData(new s)),f=l((w,p)=>w.getData(new r(p)));return{entries:c,loadText:d,loadBlob:f,getSize:w=>{var p;return((p=a.get(w))==null?void 0:p.uncompressedSize)??0}}},Ur=async i=>i.isFile?i:(await Promise.all(Array.from(await new Promise((e,t)=>i.createReader().readEntries(n=>e(n),n=>t(n))),Ur))).flat(),Sc=async i=>{const e=await Ur(i),t=await Promise.all(e.map(d=>new Promise((f,g)=>d.file(w=>f([w,d.fullPath]),w=>g(w))))),n=new Map(t.map(([d,f])=>[f.replace(i.fullPath+"/",""),d])),s=new TextDecoder,r=d=>d?s.decode(d):null,o=d=>{var f;return((f=n.get(d))==null?void 0:f.arrayBuffer())??null};return{loadText:async d=>r(await o(d)),loadBlob:d=>n.get(d),getSize:d=>{var f;return((f=n.get(d))==null?void 0:f.size)??0}}},kc=({name:i,type:e})=>e==="application/vnd.comicbook+zip"||i.endsWith(".cbz"),Ac=({name:i,type:e})=>e==="application/x-fictionbook+xml"||i.endsWith(".fb2"),Ec=({name:i,type:e})=>e==="application/x-zip-compressed-fb2"||i.endsWith(".fb2.zip")||i.endsWith(".fbz"),Wr=async(i,e)=>{let t;if(i.isDirectory){const s=await Sc(i),{EPUB:r}=await Promise.resolve().then(()=>ma);t=await new r(s).init()}else if(i.size)if(await xc(i)){const s=await _c(i);if(kc(i)){const{makeComicBook:r}=await Promise.resolve().then(()=>Ch);t=r(s,i)}else if(Ec(i)){const{makeFB2:r}=await Promise.resolve().then(()=>xa),{entries:o}=s,c=o.find(l=>l.filename.endsWith(".fb2")),a=await s.loadBlob((c??o[0]).filename);t=await r(a)}else{const{EPUB:r}=await Promise.resolve().then(()=>ma);t=await new r(s).init()}}else if(await vc(i)){const{makePDF:s}=await Promise.resolve().then(()=>Dh);t=await s(i)}else{const{isMOBI:s,MOBI:r}=await Promise.resolve().then(()=>bd);if(await s(i)){const o=await Promise.resolve().then(()=>Ld);t=await new r({unzlib:o.unzlibSync}).open(i)}else if(Ac(i)){const{makeFB2:o}=await Promise.resolve().then(()=>xa);t=await o(i)}}else throw new Error("File not found");if(!t)throw new Error("File type not supported");const n=document.createElement("foliate-view");return e.append(n),await n.open(t),n};function Tc(i,e){i.addEventListener("keyup",t=>{t.key==="ArrowUp"||t.key==="ArrowRight"?e("next"):(t.key==="ArrowDown"||t.key==="ArrowLeft")&&e("prev")},!1)}function Lc(i,e){let s=0,r;i.addEventListener("wheel",o=>{o.ignore||(o.ignore=!0,clearTimeout(r),s+=o.deltaY,r=setTimeout(()=>{if(Math.abs(s)>=750){let c=Math.sign(s)>0?"next":"prev";e(c),s=0}s=0},50))})}function Cc(i,e){let r,o,c;i.addEventListener("touchstart",a=>{a.ignore||(a.ignore=!0,r=a.changedTouches[0].pageX,o=a.changedTouches[0].pageY,c=Date.now())},!1),i.addEventListener("touchend",a=>{var g,w;if(a.ignore)return;a.ignore=!0;const l=a.changedTouches[0].pageX-r,d=a.changedTouches[0].pageY-o;Date.now()-c<=500&&(Math.abs(l)>=50&&Math.abs(d)<=200?e(l<0?"next":"prev"):Math.abs(d)>=50&&Math.abs(l)<=200?e(d<0?"up":"down"):((w=(g=i==null?void 0:i.defaultView)==null?void 0:g.getSelection())==null||w.removeAllRanges(),i.dispatchEvent(new MouseEvent("click",{clientX:r,clientY:o})),a.preventDefault()))},!1)}const Rc=(i,e)=>{const t=i.__vccOpts||i;for(const[n,s]of e)t[n]=s;return t},zc={class:"reader"},Oc={class:"viewHolder"},Ic={key:0},jr=Rc({__name:"BookView",props:{url:{type:[String,File]},location:{type:[String,Number]},tocChanged:Function,getRendition:Function},emits:["update:location"],setup(i,{expose:e,emit:t}){const n=i,{tocChanged:s,getRendition:r}=n,{url:o,location:c}=O.toRefs(n),a=t;let l=null;const d=O.ref(null),f=O.ref(!1),g=({spacing:_,justify:x,hyphenate:C})=>` @namespace epub "http://www.idpf.org/2007/ops"; html { color-scheme: light dark; } /* https://github.com/whatwg/html/issues/5426 */ @media (prefers-color-scheme: dark) { a:link { color: lightblue; } } p, li, blockquote, dd { line-height: ${_}; text-align: ${x?"justify":"start"}; -webkit-hyphens: ${C?"auto":"manual"}; hyphens: ${C?"auto":"manual"}; -webkit-hyphenate-limit-before: 3; -webkit-hyphenate-limit-after: 2; -webkit-hyphenate-limit-lines: 2; hanging-punctuation: allow-end last; widows: 2; } /* prevent the above from overriding the align attribute */ [align="left"] { text-align: left; } [align="right"] { text-align: right; } [align="center"] { text-align: center; } [align="justify"] { text-align: justify; } pre { white-space: pre-wrap !important; } aside[epub|type~="endnote"], aside[epub|type~="footnote"], aside[epub|type~="note"], aside[epub|type~="rearnote"] { display: none; } `,w=async()=>{o.value&&(l&&l.close(),typeof o.value=="string"?fetch(o.value).then(_=>_.blob()).then(async _=>{const x=o.value.split("/");l=await Wr(new File([_],x[x.length-1]),d.value),p()}).catch(_=>console.error(_)):(l=await Wr(o.value,d.value),p()))},p=()=>{var x,C;f.value=!0;const{book:_}=l;(C=(x=l.renderer).setStyles)==null||C.call(x,g({spacing:1.4,justify:!0,hyphenate:!0})),u(),r(l),s&&s(_.toc),c.value?l==null||l.goTo(c.value):l.renderer.next()},m=_=>{_==="next"?v():_==="prev"&&S()},u=()=>{l.addEventListener("load",b),l.addEventListener("relocate",y)},b=({detail:{doc:_}})=>{Lc(_,m),Cc(_,m),Tc(_,m)},y=({detail:_})=>{a("update:location",_)},v=()=>l==null?void 0:l.next(),S=()=>l==null?void 0:l.prev(),A=_=>l==null?void 0:l.goTo(_);return O.watch(o,()=>{w()}),O.onMounted(()=>{w()}),e({nextPage:v,prevPage:S,setLocation:A}),(_,x)=>(O.openBlock(),O.createElementBlock("div",zc,[O.createElementVNode("div",Oc,[O.withDirectives(O.createElementVNode("div",{ref_key:"viewer",ref:d,id:"viewer"},null,512),[[O.vShow,f.value]]),f.value?O.createCommentVNode("",!0):(O.openBlock(),O.createElementBlock("div",Ic,[O.renderSlot(_.$slots,"loadingView",{},void 0,!0)]))])]))}},[["__scopeId","data-v-7b9f0714"]]),Mc={class:"container"},Bc=[O.createElementVNode("span",{class:"tocButtonBar",style:{top:"35%"}},null,-1),O.createElementVNode("span",{class:"tocButtonBar",style:{top:"66%"}},null,-1)],Nc=["title"],Fc=O.createElementVNode("div",{class:"loadingView"},"Loading…",-1),Dc={key:0},Pc={class:"tocArea"},Hr={__name:"VueReader",props:{title:{type:String},showToc:{type:Boolean,default:!0},title:{type:String,default:""},getRendition:{type:Function},backgroundColor:{type:String,default:"#fff"}},setup(i){const e=O.defineComponent({name:"TocComponent",props:{toc:{type:Array,default:()=>[]},current:{type:[String,Number],default:""},setLocation:{type:Function,required:!0},isSubmenu:{type:Boolean,default:!1,required:!1}},setup(u){const b=O.getCurrentInstance(),y=O.h.bind(b),{setLocation:v,isSubmenu:S}=u,{toc:A,current:_}=O.toRefs(u);return()=>A.value.map((x,C)=>y("div",{key:C},[y("button",{class:["tocAreaButton",x.href===_.value?"active":""],onClick:()=>{x.subitems&&x.subitems.length>0?(x.expansion=!x.expansion,v(x.href,!1)):v(x.href)}},[S?" ".repeat(4)+x.label:x.label,x.subitems&&x.subitems.length>0&&y("div",{class:`${x.expansion?"open":""} expansion`})]),x.subitems&&x.subitems.length>0&&y(O.Transition,{name:"collapse-transition"},{default:()=>y("div",{style:{display:x.expansion?void 0:"none"}},[y(e,{toc:x.subitems,current:_.value,setLocation:v,isSubmenu:!0})])})]))}}),t=i,n=O.reactive({toc:[],expandedToc:!1}),{getRendition:s}=t,{toc:r,expandedToc:o}=O.toRefs(n),c=O.ref(null),a=O.ref(null),l=O.ref(""),d=u=>{var v;s&&s(u);const{book:b}=u,y=(v=b.metadata)==null?void 0:v.title;l.value=y||""},f=u=>{r.value=u},g=()=>{o.value=!o.value},w=()=>{var u;(u=c.value)==null||u.nextPage()},p=()=>{var u;(u=c.value)==null||u.prevPage()},m=(u,b=!0)=>{c.value.setLocation(u),o.value=!1,o.value=!b};return(u,b)=>(O.openBlock(),O.createElementBlock("div",Mc,[O.createElementVNode("div",{class:O.normalizeClass(["readerArea",{containerExpanded:O.unref(o)}]),style:O.normalizeStyle({backgroundColor:i.backgroundColor})},[i.showToc?(O.openBlock(),O.createElementBlock("button",{key:0,class:O.normalizeClass(["tocButton",{tocButtonExpanded:O.unref(o)}]),type:"button",onClick:g},Bc,2)):O.createCommentVNode("",!0),O.renderSlot(u.$slots,"title",{},()=>[O.createElementVNode("div",{class:"titleArea",title:i.title||l.value},O.toDisplayString(i.title||l.value),9,Nc)]),O.createVNode(jr,O.mergeProps({ref_key:"bookRef",ref:c},u.$attrs,{tocChanged:f,getRendition:d}),{loadingView:O.withCtx(()=>[O.renderSlot(u.$slots,"loadingView",{},()=>[Fc])]),_:3},16),O.createElementVNode("button",{class:"arrow pre",onClick:p},"‹"),O.createElementVNode("button",{class:"arrow next",onClick:w},"›")],6),i.showToc?(O.openBlock(),O.createElementBlock("div",Dc,[O.createElementVNode("div",Pc,[O.createVNode(O.unref(e),{toc:O.unref(r),current:a.value,setLocation:m},null,8,["toc","current"])]),O.unref(o)?(O.openBlock(),O.createElementBlock("div",{key:0,class:"tocBackground",onClick:g})):O.createCommentVNode("",!0)])):O.createCommentVNode("",!0)]))}},Vr=i=>{var e,t;return(t=(e=i==null?void 0:i.split(/[,;\s]/))==null?void 0:e.filter(n=>n))==null?void 0:t.map(n=>n.split("=").map(s=>s.trim()))},$c=(i,e)=>{var s,r;if(i.documentElement.localName==="svg"){const[,,o,c]=((s=i.documentElement.getAttribute("viewBox"))==null?void 0:s.split(/\s/))??[];return{width:o,height:c}}const t=Vr((r=i.querySelector('meta[name="viewport"]'))==null?void 0:r.getAttribute("content"));if(t)return Object.fromEntries(t);if(typeof e=="string")return Vr(e);if(e)return e;const n=i.querySelector("img");return n?{width:n.naturalWidth,height:n.naturalHeight}:(console.warn(new Error("Missing viewport properties")),{width:1e3,height:2e3})};class qr extends HTMLElement{constructor(){super();k(this,wn);k(this,Ve);k(this,ri);k(this,oi);k(this,ai);k(this,yn);k(this,He,this.attachShadow({mode:"closed"}));k(this,si,new ResizeObserver(()=>T(this,Ve,$i).call(this)));k(this,ne,void 0);k(this,Se,-1);mt(this,"defaultViewport");mt(this,"spread");k(this,bn,!1);k(this,It,void 0);k(this,Mt,void 0);k(this,Bt,void 0);k(this,ke,void 0);const t=new CSSStyleSheet;h(this,He).adoptedStyleSheets=[t],t.replaceSync(`:host { width: 100%; height: 100%; display: flex; justify-content: center; align-items: center; }`),h(this,si).observe(this)}open(t){this.book=t;const{rendition:n}=t;this.spread=n==null?void 0:n.spread,this.defaultViewport=n==null?void 0:n.viewport;const s=t.dir==="rtl",r=!s;this.rtl=s,(n==null?void 0:n.spread)==="none"?R(this,ne,t.sections.map(o=>({center:o}))):R(this,ne,t.sections.reduce((o,c)=>{const a=o[o.length-1],{linear:l,pageSpread:d}=c;if(l==="no")return o;const f=()=>{const g={};return o.push(g),g};if(d==="center"){const g=a.left||a.right?f():a;g.center=c}else if(d==="left"){const g=a.center||a.left||r?f():a;g.left=c}else if(d==="right"){const g=a.center||a.right||s?f():a;g.right=c}else r?a.center||a.right?f().left=c:a.left?a.right=c:a.left=c:a.center||a.left?f().right=c:a.right?a.left=c:a.right=c;return o},[{}]))}get index(){const t=h(this,ne)[h(this,Se)],n=(t==null?void 0:t.center)??(this.side==="left"?t.left??t.right:t.right??t.left);return this.book.sections.indexOf(n)}getSpreadOf(t){const n=h(this,ne);for(let s=0;s<n.length;s++){const{left:r,right:o,center:c}=n[s];if(r===t)return{index:s,side:"left"};if(o===t)return{index:s,side:"right"};if(c===t)return{index:s,side:"center"}}}async goToSpread(t,n,s){var o,c,a,l,d,f;if(t<0||t>h(this,ne).length-1)return;if(t===h(this,Se)){T(this,Ve,$i).call(this,n);return}R(this,Se,t);const r=h(this,ne)[t];if(r.center){const g=this.book.sections.indexOf(r.center),w=await((c=(o=r.center)==null?void 0:o.load)==null?void 0:c.call(o));await T(this,ri,gr).call(this,{center:{index:g,src:w}})}else{const g=this.book.sections.indexOf(r.left),w=this.book.sections.indexOf(r.right),p=await((l=(a=r.left)==null?void 0:a.load)==null?void 0:l.call(a)),m=await((f=(d=r.right)==null?void 0:d.load)==null?void 0:f.call(d)),u={index:g,src:p},b={index:w,src:m};await T(this,ri,gr).call(this,{left:u,right:b,side:n})}T(this,yn,Ms).call(this,s)}async select(t){await this.goTo(t)}async goTo(t){const{book:n}=this,s=await t,r=n.sections[s.index];if(!r)return;const{index:o,side:c}=this.getSpreadOf(r);await this.goToSpread(o,c)}async next(){if(this.rtl?T(this,oi,mr).call(this):T(this,ai,br).call(this))T(this,yn,Ms).call(this,"page");else return this.goToSpread(h(this,Se)+1,this.rtl?"right":"left","page")}async prev(){if(this.rtl?T(this,ai,br).call(this):T(this,oi,mr).call(this))T(this,yn,Ms).call(this,"page");else return this.goToSpread(h(this,Se)-1,this.rtl?"left":"right","page")}getContents(){return Array.from(h(this,He).querySelectorAll("iframe"),t=>({doc:t.contentDocument}))}destroy(){h(this,si).unobserve(this)}}He=new WeakMap,si=new WeakMap,ne=new WeakMap,Se=new WeakMap,bn=new WeakMap,It=new WeakMap,Mt=new WeakMap,Bt=new WeakMap,ke=new WeakMap,wn=new WeakSet,Is=async function({index:t,src:n}){const s=document.createElement("div"),r=document.createElement("iframe");return s.append(r),Object.assign(r.style,{border:"0",display:"none",overflow:"hidden"}),r.setAttribute("sandbox","allow-same-origin allow-scripts"),r.setAttribute("scrolling","no"),r.setAttribute("part","filter"),h(this,He).append(s),n?new Promise(o=>{const c=()=>{r.removeEventListener("load",c);const a=r.contentDocument;this.dispatchEvent(new CustomEvent("load",{detail:{doc:a,index:t}}));const{width:l,height:d}=$c(a,this.defaultViewport);o({element:s,iframe:r,width:parseFloat(l),height:parseFloat(d)})};r.addEventListener("load",c),r.src=n}):{blank:!0,element:s,iframe:r}},Ve=new WeakSet,$i=function(t=h(this,ke)){if(!t)return;const n=h(this,It)??{},s=h(this,Bt)??h(this,Mt),r=t==="left"?n:s,{width:o,height:c}=this.getBoundingClientRect(),a=this.spread!=="both"&&this.spread!=="portrait"&&c>o;R(this,bn,a);const l=n.width??s.width,d=n.height??s.height,f=a||h(this,Bt)?Math.min(o/(r.width??l),c/(r.height??d)):Math.min(o/((n.width??l)+(s.width??l)),c/Math.max(n.height??d,s.height??d)),g=w=>{const{element:p,iframe:m,width:u,height:b,blank:y}=w;Object.assign(m.style,{width:`${u}px`,height:`${b}px`,transform:`scale(${f})`,transformOrigin:"top left",display:y?"none":"block"}),Object.assign(p.style,{width:`${(u??l)*f}px`,height:`${(b??d)*f}px`,overflow:"hidden",display:"block"}),a&&w!==r&&(p.style.display="none")};h(this,Bt)?g(h(this,Bt)):(g(n),g(s))},ri=new WeakSet,gr=async function({left:t,right:n,center:s,side:r}){h(this,He).replaceChildren(),R(this,It,null),R(this,Mt,null),R(this,Bt,null),s?(R(this,Bt,await T(this,wn,Is).call(this,s)),R(this,ke,"center"),T(this,Ve,$i).call(this)):(R(this,It,await T(this,wn,Is).call(this,t)),R(this,Mt,await T(this,wn,Is).call(this,n)),R(this,ke,h(this,It).blank?"right":h(this,Mt).blank?"left":r),T(this,Ve,$i).call(this))},oi=new WeakSet,mr=function(){var t,n,s,r;if(!(h(this,Bt)||(t=h(this,It))!=null&&t.blank)&&h(this,bn)&&((r=(s=(n=h(this,It))==null?void 0:n.element)==null?void 0:s.style)==null?void 0:r.display)==="none")return h(this,Mt).element.style.display="none",h(this,It).element.style.display="block",R(this,ke,"left"),!0},ai=new WeakSet,br=function(){var t,n,s,r;if(!(h(this,Bt)||(t=h(this,Mt))!=null&&t.blank)&&h(this,bn)&&((r=(s=(n=h(this,Mt))==null?void 0:n.element)==null?void 0:s.style)==null?void 0:r.display)==="none")return h(this,It).element.style.display="none",h(this,Mt).element.style.display="block",R(this,ke,"right"),!0},yn=new WeakSet,Ms=function(t){this.dispatchEvent(new CustomEvent("relocate",{detail:{reason:t,range:null,index:this.index,fraction:0,size:1}}))},customElements.define("foliate-fxl",qr);const Uc=Object.freeze(Object.defineProperty({__proto__:null,FixedLayout:qr},Symbol.toStringTag,{value:"Module"})),Wc=i=>new Promise(e=>setTimeout(e,i)),jc=(i,e,t)=>{let n;return(...s)=>{const r=()=>{n=null,t||i(...s)},o=t&&!n;n&&clearTimeout(n),n=setTimeout(r,e),o&&i(...s)}},Hc=(i,e,t)=>t*(e-i)+i,Vc=i=>1-(1-i)*(1-i),qc=(i,e,t,n,s)=>new Promise(r=>{let o;const c=a=>{o??(o=a);const l=Math.min(1,(a-o)/t);s(Hc(i,e,n(l))),l<1?requestAnimationFrame(c):r()};requestAnimationFrame(c)}),Xc=i=>{if(!(i!=null&&i.collapsed))return i;const{endOffset:e,endContainer:t}=i;if(t.nodeType===1)return t;if(e+1<t.length)i.setEnd(t,e+1);else if(e>1)i.setStart(t,e-1);else return t.parentNode;return i},Xi=(i,e,t,n=t)=>{const s=i.createRange();return s.setStart(e,t),s.setEnd(e,n),s},Gi=(i,e,t,n=0,s=e.nodeValue.length)=>{if(s-n===1)return t(Xi(i,e,n),Xi(i,e,s))<0?n:s;const r=Math.floor(n+(s-n)/2),o=t(Xi(i,e,n,r),Xi(i,e,r,s));return o<0?Gi(i,e,t,n,r):o>0?Gi(i,e,t,r,s):r},{SHOW_ELEMENT:Gc,SHOW_TEXT:Kc,SHOW_CDATA_SECTION:Zc,FILTER_ACCEPT:Xr,FILTER_REJECT:Gr,FILTER_SKIP:Kr}=NodeFilter,Yc=Gc|Kc|Zc,Zr=(i,e,t,n)=>{const s=g=>{var p,m;const w=(p=g.localName)==null?void 0:p.toLowerCase();if(w==="script"||w==="style")return Gr;if(g.nodeType===1){const{left:u,right:b}=n(g.getBoundingClientRect());if(b<e||u>t)return Gr;if(u>=e&&b<=t)return Xr}else{if(!((m=g.nodeValue)!=null&&m.trim()))return Kr;const u=i.createRange();u.selectNodeContents(g);const{left:b,right:y}=n(u.getBoundingClientRect());if(y>=e&&b<=t)return Xr}return Kr},r=i.createTreeWalker(i.body,Yc,{acceptNode:s}),o=[];for(let g=r.nextNode();g;g=r.nextNode())o.push(g);const c=o[0]??i.body,a=o[o.length-1]??c,l=c.nodeType===1?0:Gi(i,c,(g,w)=>{const p=n(g.getBoundingClientRect()),m=n(w.getBoundingClientRect());return p.right<e&&m.left>e?0:m.left>e?-1:1}),d=a.nodeType===1?0:Gi(i,a,(g,w)=>{const p=n(g.getBoundingClientRect()),m=n(w.getBoundingClientRect());return p.right<t&&m.left>t?0:m.left>t?-1:1}),f=i.createRange();return f.setStart(c,l),f.setEnd(a,d),f},Jc=i=>{const{defaultView:e}=i,{writingMode:t,direction:n}=e.getComputedStyle(i.body),s=t==="vertical-rl"||t==="vertical-lr",r=i.body.dir==="rtl"||n==="rtl"||i.documentElement.dir==="rtl";return{vertical:s,rtl:r}},Hs=i=>{const e=i.defaultView.getComputedStyle(i.body);return e.backgroundColor==="rgba(0, 0, 0, 0)"&&e.backgroundImage==="none"?i.defaultView.getComputedStyle(i.documentElement).background:e.background},Yr=(i,e)=>Array.from({length:i},()=>{const t=document.createElement("div"),n=document.createElement("div");return t.append(n),n.setAttribute("part",e),t}),qn=(i,e)=>{const{style:t}=i;for(const[n,s]of Object.entries(e))t.setProperty(n,s,"important")};class Qc{constructor({container:e,onExpand:t}){k(this,ci,new ResizeObserver(()=>this.expand()));k(this,wt,document.createElement("div"));k(this,tt,document.createElement("iframe"));k(this,li,document.createRange());k(this,nt,void 0);k(this,dt,!1);k(this,hi,!1);k(this,xn,!0);k(this,Xt,void 0);k(this,vn,{});this.container=e,this.onExpand=t,h(this,tt).setAttribute("part","filter"),h(this,wt).append(h(this,tt)),Object.assign(h(this,wt).style,{boxSizing:"content-box",position:"relative",overflow:"hidden",flex:"0 0 auto",width:"100%",height:"100%",display:"flex",justifyContent:"center",alignItems:"center"}),Object.assign(h(this,tt).style,{overflow:"hidden",border:"0",display:"none",width:"100%",height:"100%"}),h(this,tt).setAttribute("sandbox","allow-same-origin allow-scripts"),h(this,tt).setAttribute("scrolling","no")}get element(){return h(this,wt)}get document(){return h(this,tt).contentDocument}async load(e,t,n){if(typeof e!="string")throw new Error(`${e} is not string`);return new Promise(s=>{h(this,tt).addEventListener("load",()=>{const r=this.document;t==null||t(r),h(this,tt).style.display="block";const{vertical:o,rtl:c}=Jc(r),a=Hs(r);h(this,tt).style.display="none",R(this,dt,o),R(this,hi,c),h(this,li).selectNodeContents(r.body);const l=n==null?void 0:n({vertical:o,rtl:c,background:a});h(this,tt).style.display="block",this.render(l),h(this,ci).observe(r.body),r.fonts.ready.then(()=>this.expand()),s()},{once:!0}),h(this,tt).src=e})}render(e){e&&(R(this,xn,e.flow!=="scrolled"),R(this,vn,e),h(this,xn)?this.columnize(e):this.scrolled(e))}scrolled({gap:e,columnWidth:t}){const n=h(this,dt),s=this.document;qn(s.documentElement,{"box-sizing":"border-box",padding:n?`${e}px 0`:`0 ${e}px`,"column-width":"auto",height:"auto",width:"auto"}),qn(s.body,{[n?"max-height":"max-width"]:`${t}px`,margin:"auto"}),this.setImageSize(),this.expand()}columnize({width:e,height:t,gap:n,columnWidth:s}){const r=h(this,dt);R(this,Xt,r?t:e);const o=this.document;qn(o.documentElement,{"box-sizing":"border-box","column-width":`${Math.trunc(s)}px`,"column-gap":`${n}px`,"column-fill":"auto",...r?{width:`${e}px`}:{height:`${t}px`},padding:r?`${n/2}px 0`:`0 ${n/2}px`,overflow:"hidden","overflow-wrap":"break-word",position:"static",border:"0",margin:"0","max-height":"none","max-width":"none","min-height":"none","min-width":"none","-webkit-line-box-contain":"block glyphs replaced"}),qn(o.body,{"max-height":"none","max-width":"none",margin:"0"}),this.setImageSize(),this.expand()}setImageSize(){const{width:e,height:t,margin:n}=h(this,vn),s=h(this,dt),r=this.document;for(const o of r.body.querySelectorAll("img, svg, video")){const{maxHeight:c,maxWidth:a}=r.defaultView.getComputedStyle(o);qn(o,{"max-height":s?c!=="none"&&c!=="0px"?c:"100%":`${t-n*2}px`,"max-width":s?`${e-n*2}px`:a!=="none"&&a!=="0px"?a:"100%","object-fit":"contain","page-break-inside":"avoid","break-inside":"avoid","box-sizing":"border-box"})}}expand(){const{documentElement:e}=this.document;if(h(this,xn)){const t=h(this,dt)?"height":"width",n=h(this,dt)?"width":"height",s=h(this,li).getBoundingClientRect(),r=e.getBoundingClientRect(),c=(h(this,dt)?0:h(this,hi)?r.right-s.right:s.left-r.left)+s[t],l=Math.ceil(c/h(this,Xt))*h(this,Xt);h(this,wt).style.padding="0",h(this,tt).style[t]=`${l}px`,h(this,wt).style[t]=`${l+h(this,Xt)*2}px`,h(this,tt).style[n]="100%",h(this,wt).style[n]="100%",e.style[t]=`${h(this,Xt)}px`,h(this,nt)&&(h(this,nt).element.style.margin="0",h(this,nt).element.style.left=h(this,dt)?"0":`${h(this,Xt)}px`,h(this,nt).element.style.top=h(this,dt)?`${h(this,Xt)}px`:"0",h(this,nt).element.style[t]=`${l}px`,h(this,nt).redraw())}else{const t=h(this,dt)?"width":"height",n=h(this,dt)?"height":"width",r=e.getBoundingClientRect()[t],{margin:o}=h(this,vn),c=h(this,dt)?`0 ${o}px`:`${o}px 0`;h(this,wt).style.padding=c,h(this,tt).style[t]=`${r}px`,h(this,wt).style[t]=`${r}px`,h(this,tt).style[n]="100%",h(this,wt).style[n]="100%",h(this,nt)&&(h(this,nt).element.style.margin=c,h(this,nt).element.style.left="0",h(this,nt).element.style.top="0",h(this,nt).element.style[t]=`${r}px`,h(this,nt).redraw())}this.onExpand()}set overlayer(e){R(this,nt,e),h(this,wt).append(e.element)}get overlayer(){return h(this,nt)}destroy(){this.document&&h(this,ci).unobserve(this.document.body)}}ci=new WeakMap,wt=new WeakMap,tt=new WeakMap,li=new WeakMap,nt=new WeakMap,dt=new WeakMap,hi=new WeakMap,xn=new WeakMap,Xt=new WeakMap,vn=new WeakMap;class Vs extends HTMLElement{constructor(){super();k(this,_s);k(this,gi);k(this,mi);k(this,bi);k(this,wi);k(this,Ze);k(this,Ss);k(this,Te);k(this,Le);k(this,ks);k(this,As);k(this,Ye);k(this,yi);k(this,xi);k(this,An);k(this,Es);k(this,Ts);k(this,ae);k(this,vi);k(this,ie,this.attachShadow({mode:"closed"}));k(this,di,new ResizeObserver(()=>this.render()));k(this,se,void 0);k(this,qe,void 0);k(this,yt,void 0);k(this,Ae,void 0);k(this,Xe,void 0);k(this,j,void 0);k(this,Et,!1);k(this,Nt,!