From c1e97e74763ce40d3ccfd0f3f0405ac5c93f1d56 Mon Sep 17 00:00:00 2001 From: troyeguo <13820674+troyeguo@users.noreply.github.com> Date: Tue, 21 Jan 2025 18:41:08 +0800 Subject: [PATCH] fix bug --- .eslintrc.js | 1 + main.js | 10 ++- src/assets/lib/kookit.min.js | 2 +- .../dialogs/feedbackDialog/component.tsx | 71 +++++++++---------- .../dialogs/feedbackDialog/feedbackDialog.css | 18 +---- src/components/popups/popupDict/component.tsx | 2 +- .../popups/popupTrans/component.tsx | 2 +- src/utils/common.tsx | 6 +- 8 files changed, 50 insertions(+), 62 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index adccfd67..581b8dc7 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -2,5 +2,6 @@ module.exports = { // 其他配置 rules: { 'no-unused-expressions': 'off', + '@typescript-eslint/ban-types': 'off', }, }; diff --git a/main.js b/main.js index a84c0fbe..94774bc6 100644 --- a/main.js +++ b/main.js @@ -17,6 +17,7 @@ const configDir = app.getPath("userData"); const dirPath = path.join(configDir, "uploads"); let mainWin; let readerWindow; +let urlWindow; let mainView; let dbConnection = {}; const singleInstance = app.requestSingleInstanceLock(); @@ -269,7 +270,8 @@ const createMainWin = () => { event.returnValue = dirPath; }); ipcMain.handle("hide-reader", (event, arg) => { - if (readerWindow && readerWindow.isFocused()) { + console.log(readerWindow) + if (!readerWindow.isDestroyed() && readerWindow && readerWindow.isFocused()) { readerWindow.minimize(); event.returnvalue = true; } else if (mainWin && mainWin.isFocused()) { @@ -353,6 +355,12 @@ const createMainWin = () => { console.log("exit full"); } }); + ipcMain.handle("open-url", (event, config) => { + if (!urlWindow || urlWindow.isDestroyed()) { + urlWindow = new BrowserWindow(options); + } + urlWindow.loadURL(config.url); + }); ipcMain.handle("switch-moyu", (event, arg) => { let id; if (store.get("isPreventSleep") === "yes") { diff --git a/src/assets/lib/kookit.min.js b/src/assets/lib/kookit.min.js index aa305bec..9cf12bf6 100644 --- a/src/assets/lib/kookit.min.js +++ b/src/assets/lib/kookit.min.js @@ -1 +1 @@ -import e from"chinese-s2t";import t from"underscore";import n from"rangy/lib/rangy-core.js";import"rangy/lib/rangy-textrange";import{ZipReader as r,BlobReader as i,TextWriter as o,BlobWriter as s}from"@zip.js/zip.js";import a from"jszip";import{unzlibSync as l}from"fflate";import c from"js-untar";import h from"mammoth";import{marked as d}from"marked";import u from"mhtml2html";function f(e,t,n,r){return new(n||(n=Promise))((function(i,o){function s(e){try{l(r.next(e))}catch(e){o(e)}}function a(e){try{l(r.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}l((r=r.apply(e,t||[])).next())}))}const p=e=>e?parseFloat(e+""):0,g=(e,t)=>f(void 0,void 0,void 0,(function*(){let n="";if(e.load){let t=yield fetch(yield e.load()).then((e=>e.blob()));n=yield t.text()}return t||(e.loadAsset&&(n=yield y(n,e.loadAsset)),n=b(n)),n})),m=e=>Array.from(e.querySelectorAll("img, image")),y=(e,t)=>f(void 0,void 0,void 0,(function*(){let n=(new DOMParser).parseFromString(e,"text/html"),r=m(n);for(let e=0;e{let t=(new DOMParser).parseFromString(e,"text/html"),n=m(t);if(0===n.length)return e;for(let e=0;e{var n=document.createElement("iframe");n.style.width="100%",n.style.border="0",n.style.margin="0",n.style.padding="0",n.style.minHeight="calc(100% - 2px)",n.style.fontSize="100%",n.style.font="inherit",n.scrolling="no",n.tabIndex=0,n.style.verticalAlign="baseline",e.innerHTML="",e.appendChild(n)},v=(e,t)=>({totalPage:"scroll"===e?1:parseInt(t.body.scrollWidth/t.body.clientWidth+"")+1,currentPage:parseInt(p(t.body.scrollLeft)/t.body.clientWidth+"")+1}),x=e=>{let t=e.querySelectorAll("a, article, cite, div, li, p, span, pre, table, bold, body");for(let e=0;ef(void 0,void 0,void 0,(function*(){const t=new Image;t.src=e;try{yield t.decode()}catch(e){console.log(e)}return t})),S=(e,t,n,r)=>f(void 0,void 0,void 0,(function*(){let i=Math.floor(e.clientWidth/12),o=i%2==0?i:i-1,s=r.querySelectorAll("img, image");for(let i of s){let s=i.parentElement,a=0,l=0,c=i.naturalWidth,h=i.naturalHeight;if("image"===i.tagName){let e=yield C(i.getAttribute("xlink:href"));c=e.naturalWidth,h=e.naturalHeight}if(n.startsWith("CB")&&"scroll"===t)l=s.offsetWidth;else if(n.startsWith("CB")&&"single"===t)a=e.clientHeight,l=e.clientWidth;else if(c&&h){h/c>s.clientHeight/s.clientWidth?(a=s.clientHeight,l=parseInt(a*c/h+"")):(l=s.clientWidth,a=parseInt(l*h/c+"")),a>r.body.clientHeight&&(l=parseInt(l*(r.body.clientHeight/a)+""),a=r.body.clientHeight)}else s&&s.clientWidth&&s.clientWidth>0?(l=s.clientWidth,a=s.clientHeight):(l=e.clientWidth,a=e.clientHeight);l=l?Math.min("scroll"===t||"single"===t?e.clientWidth:(e.clientWidth-o)/2,l):"scroll"===t||"single"===t?e.clientWidth:(e.clientWidth-o)/2,c&&h&&(c>h||a/l>h/c?a=l*(h/c):l=a*(c/h)),(l||a)&&i.setAttribute("style",i.getAttribute("style")+";"+`max-width: ${l>0?l+"px":""};max-height:${a>0?a+"px":""}; margin: 0 auto; ${n.startsWith("CB")?"display: block; margin-left: auto; margin-right: auto;":""}`)}})),T=(e,t,n)=>{let r=n.createElement("style");if(r.id="default-style",r.textContent="p,empty-line{display: inherit;margin-block-start: inherit;margin-block-end: inherit;margin-inline-start: inherit;margin-inline-end: inherit;}body{margin: 0px}",n.head.appendChild(r),"scroll"===t)return;let i="double"===t?2:1,o=Math.floor(e.clientWidth/12),s=o%2==0?o:o-1;n.body.setAttribute("style",`width: auto;height: 100%;overflow-y: hidden;overflow-X: hidden;padding-left: 0px;padding-right: 0px;margin: 0px;box-sizing: border-box;max-width: inherit;column-fill: auto;column-gap: ${s}px; column-width: ${(e.clientWidth-s)/i}px;`)};class L{constructor(e){this.book=e,this.chapterList=[],this.flattenChapters=[],this.chapterDocList=[]}getChapter(e){return f(this,void 0,void 0,(function*(){return this.chapterList=e?yield Promise.all(e.map((e=>f(this,void 0,void 0,(function*(){let t=-1;try{t=e.href&&(yield this.book.resolveHref(e.href))?(yield this.book.resolveHref(e.href)).index:-1}catch(e){console.log(e)}return{label:e.label?e.label:t,href:e.href?e.href:"title"+t,index:t,subitems:e.subitems?yield this.getChapter(e.subitems):[]}}))))):yield Promise.all(this.book.sections.map(((e,t)=>f(this,void 0,void 0,(function*(){return{label:e.label?e.label:t,href:e.href?e.href:"title"+t,index:t,subitems:e.subitems?yield this.getChapter(e.subitems):[]}}))))),this.flattenChapters=this.flatChapter(this.chapterList),this.chapterList}))}getChapterDoc(){return f(this,void 0,void 0,(function*(){const e=this.flattenChapters.map((e=>e.index));return this.book.sections.map(((t,n)=>e.indexOf(n)>-1?{label:this.flattenChapters[e.indexOf(n)].label,href:this.flattenChapters[e.indexOf(n)].href,text:t}:{label:"",href:"",text:t}))}))}flatChapter(e){let t=[];for(let n=0;n0?(t.push(e[n]),t=t.concat(this.flatChapter(e[n].subitems))):t.push(e[n]);return t}getMetadata(){return new Promise(((e,t)=>f(this,void 0,void 0,(function*(){const n=this.book.metadata;try{const t=yield this.book.getCover();var r=new FileReader;r.readAsDataURL(t),r.onloadend=()=>{e({name:n.title,author:n.author?n.author[0].name:"",description:n.description,publisher:n.publisher,cover:r.result})}}catch(r){try{let t=n.author&&n.author[0]&&n.author[0].name?n.author[0].name:n.author&&n.author[0]?n.author[0]:n.author?n.author:"";e({name:n.title,author:t,description:n.description,publisher:n.publisher,cover:""})}catch(e){console.log(e),t(e)}}}))))}}const k=(e,t)=>[-1,...t,e.length].reduce((({xs:t,a:n},r)=>({xs:t?.concat([e.slice(n+1,r)])??[],a:r})),{}).xs,A=/\d/,I=/^epubcfi\((.*)\)$/,E=e=>e.replace(/[\^[\](),;=]/g,"^$&"),M=(e,t)=>{return n=([e])=>e===t,e.map(((e,t,r)=>n(e,t,r)?t:null)).filter((e=>null!=e));var n},B=e=>{const t=[];let n;for(const[r,i]of e){if("/"===r)t.push({index:i});else{const e=t[t.length-1];if(":"===r)e.offset=i;else if("~"===r)e.temporal=i;else if("@"===r)e.spatial=(e.spatial??[]).concat(i);else if(";s"===r)e.side=i;else if("["===r){if("/"!==n||!i){e.text=(e.text??[]).concat(i);continue}e.id=i}}n=r}return t},O=e=>k(e,M(e,"!")).map(B),D=e=>{const t=(e=>{const t=[];let n,r,i="";const o=e=>(t.push(e),n=null,i=""),s=e=>(i+=e,r=!1);for(const t of Array.from(e.trim()).concat(""))if("^"!==t||r){if("!"===n)o(["!"]);else if(","===n)o([","]);else if("/"===n||":"===n){if(A.test(t)){s(t);continue}o([n,parseInt(i)])}else if("~"===n){if(A.test(t)||"."===t){s(t);continue}o(["~",parseFloat(i)])}else if("@"===n){if(":"===t){o(["@",parseFloat(i)]),n="@";continue}if(A.test(t)||"."===t){s(t);continue}o(["@",parseFloat(i)])}else{if("["===n){";"!==t||r?","!==t||r?"]"!==t||r?s(t):o(["[",i]):(o(["[",i]),n="["):(o(["[",i]),n=";");continue}if(n?.startsWith(";")){"="!==t||r?";"!==t||r?"]"!==t||r?s(t):o([n,i]):(o([n,i]),n=";"):(n=`;${i}`,i="");continue}}"/"!==t&&":"!==t&&"~"!==t&&"@"!==t&&"["!==t&&"!"!==t&&","!==t||(n=t)}else r=!0;return t})((n=e,n.match(I)?.[1]??n));var n;const r=M(t,",");if(!r.length)return O(t);const[i,o,s]=k(t,r).map(O);return{parent:i,start:o,end:s}},N=({index:e,id:t,offset:n,temporal:r,spatial:i,text:o,side:s})=>{const a=s?`;s=${s}`:"";return`/${e}`+(t?`[${E(t)}${a}]`:"")+(null!=n&&e%2?`:${n}`:"")+(r?`~${r}`:"")+(i?`@${i.join(":")}`:"")+(o||!t&&s?"["+(o?.map(E)?.join(",")??"")+a+"]":"")},R=e=>e.parent?[e.parent,e.start,e.end].map(R).join(","):e.map((e=>e.map(N).join(""))).join("!"),P=e=>{return t=R(e),I.test(t)?t:`epubcfi(${t})`;var t},F=(e,t)=>{return"string"==typeof e?P(F(D(e),t)):e.parent?(n=e.parent,r=e[t?"end":"start"],n.slice(0,-1).concat([n[n.length-1].concat(r[0])]).concat(r.slice(1))):e;var n,r},_=({nodeType:e})=>3===e||4===e,H=({nodeType:e})=>1===e,U=e=>{const t=Array.from(e.childNodes).filter((e=>_(e)||H(e))).reduce(((e,t)=>{let n=e[e.length-1];return n?_(t)?Array.isArray(n)?n.push(t):_(n)?e[e.length-1]=[n,t]:e.push(t):H(n)?e.push(null,t):e.push(t):e.push(t),e}),[]);return H(t[0])&&t.unshift("first"),H(t[t.length-1])&&t.push("last"),t.unshift("before"),t.push("after"),t},j=(e,t)=>e?U(e)[t]:null,$=(e,t)=>{const{id:n}=t[t.length-1];if(n){const t=e.ownerDocument.getElementById(n);if(t)return{node:t,offset:0}}for(const{index:n}of t){const t=j(e,n);if("first"===t)return{node:e.firstChild??e};if("last"===t)return{node:e.lastChild??e};if("before"===t)return{node:e,before:!0};if("after"===t)return{node:e,after:!0};e=t}const{offset:r}=t[t.length-1];if(!Array.isArray(e))return{node:e,offset:r};let i=0;for(const t of e){const{length:e}=t.nodeValue;if(i+e>=r)return{node:t,offset:r-i};i+=e}},z=(e,t)=>{const{parentNode:n,id:r}=e,i=U(n),o=i.findIndex((t=>Array.isArray(t)?t.some((t=>t===e)):t===e)),s=i[o];if(Array.isArray(s)){let n=0;for(const r of s){if(r===e){n+=t;break}n+=r.nodeValue.length}t=n}const a={id:r,index:o,offset:t};return n!==e.ownerDocument.documentElement?z(n).concat(a):[a]},q=(e,t)=>$(e.documentElement,F(t)).node,W="urn:oasis:names:tc:opendocument:xmlns:container",X="http://www.w3.org/1999/xhtml",V="http://www.idpf.org/2007/opf",G="http://www.idpf.org/2007/ops",J="http://purl.org/dc/elements/1.1/",K="http://www.w3.org/2001/04/xmlenc#",Z="http://www.daisy.org/z3986/2005/ncx/",Y="http://www.w3.org/1999/xlink",Q="http://www.w3.org/ns/SMIL",ee={XML:"application/xml",NCX:"application/x-dtbncx+xml",XHTML:"application/xhtml+xml",HTML:"text/html",CSS:"text/css",SVG:"image/svg+xml",JS:/\/(x-)?(javascript|ecmascript)/},te=e=>e.toLowerCase().replace(/[-:](.)/g,((e,t)=>t.toUpperCase())),ne=(e,t,n)=>n?n=>n.getAttribute(e)?.split(/\s/)?.includes(t):"function"==typeof t?n=>t(n.getAttribute(e)):n=>n.getAttribute(e)===t,re=(...e)=>t=>t?Object.fromEntries(e.map((e=>[te(e),t.getAttribute(e)]))):null,ie=e=>{return t=e?.textContent,t?t.trim().replace(/\s{2,}/g," "):"";var t},oe=(e,t)=>{const n=e.lookupNamespaceURI(null)===t||e.lookupPrefix(t),r=n?(e,n)=>e=>e.namespaceURI===t&&e.localName===n:(e,t)=>e=>e.localName===t;return{$:(e,t)=>[...e.children].find(r(e,t)),$$:(e,t)=>[...e.children].filter(r(e,t)),$$$:n?(e,n)=>[...e.getElementsByTagNameNS(t,n)]:(e,n)=>[...e.getElementsByTagName(t,n)]}},se=(e,t)=>{try{if(t.includes(":"))return new URL(e,t);const n="whatever://whatever/";return decodeURI(new URL(e,n+t).href.replace(n,""))}catch(t){return console.warn(t),e}},ae=e=>/^(?!blob)\w+:/i.test(e),le=async(e,t,n)=>{const r=[];e.replace(t,((...e)=>(r.push(e),null)));const i=[];for(const e of r)i.push(await n(...e));return e.replace(t,(()=>i.shift()))},ce=e=>e.replace(/[-/\\^$*+?.()|[\]{}]/g,"\\$&"),he={attrs:["dir","xml:lang"]},de={name:"alternate-script",many:!0,...he,props:["file-as"]},ue={many:!0,...he,props:[{name:"role",many:!0,attrs:["scheme"]},"file-as",de]},fe=[{name:"title",many:!0,...he,props:["title-type","display-seq","file-as",de]},{name:"identifier",many:!0,props:[{name:"identifier-type",attrs:["scheme"]}]},{name:"language",many:!0},{name:"creator",...ue},{name:"contributor",...ue},{name:"publisher",...he,props:["file-as",de]},{name:"description",...he,props:[de]},{name:"rights",...he,props:[de]},{name:"date"},{name:"dcterms:modified",type:"meta"},{name:"subject",many:!0,...he,props:["term","authority",de]},{name:"belongs-to-collection",type:"meta",many:!0,...he,props:["collection-type","group-position","dcterms:identifier","file-as",de,{name:"belongs-to-collection",recursive:!0}]}],pe=(e,t=e=>e)=>{const{$:n,$$:r,$$$:i}=oe(e,X),o=e=>r=>{const i=n(r,"a")??n(r,"span"),o=n(r,"ol"),a=(e=>e?decodeURI(t(e)):null)(i?.getAttribute("href")),l={label:ie(i)||i?.getAttribute("title"),href:a,subitems:s(o)};return e&&(l.type=i?.getAttributeNS(G,"type")?.split(/\s/)),l},s=(e,t)=>e?r(e,"li").map(o(t)):null,a=(e,t)=>s(n(e,"ol"),t),l=i(e,"nav");let c=null,h=null,d=null,u=[];for(const e of l){const t=e.getAttributeNS(G,"type")?.split(/\s/)??[];t.includes("toc")?c??=a(e):t.includes("page-list")?h??=a(e):t.includes("landmarks")?d??=a(e,!0):u.push({label:ie(e.firstElementChild),type:t,list:a(e)})}return{toc:c,pageList:h,landmarks:d,others:u}},ge=(e,t=e=>e)=>{const{$:n,$$:r}=oe(e,Z),i=e=>{const o=n(e,"navLabel"),s=n(e,"content"),a=ie(o),l=(e=>e?decodeURI(t(e)):null)(s.getAttribute("src"));if("navPoint"===e.localName){const t=r(e,"navPoint");return{label:a,href:l,subitems:t.length?t.map(i):null}}return{label:a,href:l}},o=(e,t)=>r(e,t).map(i),s=(t,r)=>{const i=n(e.documentElement,t);return i?o(i,r):null};return{toc:s("navMap","navPoint"),pageList:s("pageList","pageTarget"),others:r(e.documentElement,"navList").map((e=>({label:ie(n(e,"navLabel")),list:o(e,"navTarget")})))}},me=e=>{if(!e)return;const t=e.split(":").map((e=>parseFloat(e)));if(3===t.length){const[e,n,r]=t;return 60*e*60+60*n+r}if(2===t.length){const[e,n]=t;return 60*e+n}const[n,r]=e.split(/(?=[^\d.])/);return parseFloat(n)*("h"===r?3600:"min"===r?60:"ms"===r?.001:1)},ye=/([0-9a-f]{8})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{12})/,be=e=>ie(e.getElementById(e.documentElement.getAttribute("unique-identifier"))??e.getElementsByTagNameNS(J,"identifier")[0]),we=async(e,t,n)=>{const r=new Uint8Array(await n.slice(0,t).arrayBuffer());t=Math.min(t,r.length);for(var i=0;i{const t=(new TextEncoder).encode(e),n=await globalThis.crypto.subtle.digest("SHA-1",t);return new Uint8Array(n)},xe=(e=ve)=>({"http://www.idpf.org/2008/embedding":{key:t=>e(be(t).replaceAll(/[\u0020\u0009\u000d\u000a]/g,"")),decode:(e,t)=>we(e,1040,t)},"http://ns.adobe.com/pdf/enc#RC":{key:e=>{const t=(e=>{for(const t of e.getElementsByTagNameNS(J,"identifier")){const[e]=ie(t).split(":").slice(-1);if(ye.test(e))return e}return""})(e).replaceAll("-","");return Uint8Array.from({length:16},((e,n)=>parseInt(t.slice(2*n,2*n+2),16)))},decode:(e,t)=>we(e,1024,t)}});class Ce{#e=new Map;#t=new Map;#n;constructor(e){this.#n=e}async init(e,t){if(!e)return;const n=Array.from(e.getElementsByTagNameNS(K,"EncryptedData"),(e=>({algorithm:e.getElementsByTagNameNS(K,"EncryptionMethod")[0]?.getAttribute("Algorithm"),uri:e.getElementsByTagNameNS(K,"CipherReference")[0]?.getAttribute("URI")})));for(const{algorithm:e,uri:r}of n){if(!this.#t.has(e)){const n=this.#n[e];if(!n){console.warn("Unknown encryption algorithm");continue}const r=await n.key(t);this.#t.set(e,(e=>n.decode(r,e)))}this.#e.set(r,e)}}getDecoder(e){return this.#t.get(this.#e.get(e))??(e=>e)}}class Se{constructor({opf:e,resolveHref:t}){this.opf=e;const{$:n,$$:r,$$$:i}=oe(e,V),o=n(e.documentElement,"manifest"),s=n(e.documentElement,"spine"),a=r(s,"itemref");this.manifest=r(o,"item").map(re("href","id","media-type","properties","media-overlay")).map((e=>(e.href=t(e.href),e.properties=e.properties?.split(/\s/),e))),this.spine=a.map(re("idref","id","linear","properties")).map((e=>(e.properties=e.properties?.split(/\s/),e))),this.pageProgressionDirection=s.getAttribute("page-progression-direction"),this.navPath=this.getItemByProperty("nav")?.href,this.ncxPath=(this.getItemByID(s.getAttribute("toc"))??this.manifest.find((e=>e.mediaType===ee.NCX)))?.href;const l=n(e.documentElement,"guide");l&&(this.guide=r(l,"reference").map(re("type","title","href")).map((({type:e,title:n,href:r})=>({label:n,type:e.split(/\s/),href:t(r)})))),this.cover=this.getItemByProperty("cover-image")??this.getItemByID(i(e,"meta").find(ne("name","cover"))?.getAttribute("content"))??this.getItemByHref(this.guide?.find((e=>e.type.includes("cover")))?.href),this.cfis=(e=>{const t=[],{parentNode:n}=e[0],r=z(n);for(const[i,o]of U(n).entries()){const n=e[t.length];o===n&&t.push(P([r.concat({id:n.id,index:i})]))}return t})(a)}getItemByID(e){return this.manifest.find((t=>t.id===e))}getItemByHref(e){return this.manifest.find((t=>t.href===e))}getItemByProperty(e){return this.manifest.find((t=>t.properties?.includes(e)))}resolveCFI(e){const t=D(e),n=(t.parent??t).shift();let r=q(this.opf,n);r&&"idref"!==r.nodeName&&(n.at(-1).id=null,r=q(this.opf,n));const i=r?.getAttribute("idref");return{index:this.spine.findIndex((e=>e.idref===i)),anchor:e=>((e,t)=>{const n=F(t),r=F(t,!0),i=e.documentElement,o=$(i,n[0]),s=$(i,r[0]),a=e.createRange();return o.before?a.setStartBefore(o.node):o.after?a.setStartAfter(o.node):a.setStart(o.node,o.offset),s.before?a.setEndBefore(s.node):s.after?a.setEndAfter(s.node):a.setEnd(s.node,s.offset),a})(e,t)}}}class Te{#r=new Map;#i=new Map;#o=new Map;allowScript=!1;constructor({loadText:e,loadBlob:t,resources:n}){this.loadText=e,this.loadBlob=t,this.manifest=n.manifest,this.assets=n.manifest}createURL(e,t,n,r){if(!t)return"";const i=URL.createObjectURL(new Blob([t],{type:n}));if(this.#r.set(e,i),this.#o.set(e,1),r){const t=this.#i.get(r);t?t.push(e):this.#i.set(r,[e])}return i}ref(e,t){const n=this.#i.get(t);return n?.includes(e)||(this.#o.set(e,this.#o.get(e)+1),n?n.push(e):this.#i.set(t,[e])),this.#r.get(e)}unref(e){if(!this.#o.has(e))return;const t=this.#o.get(e)-1;if(t<1){URL.revokeObjectURL(this.#r.get(e)),this.#r.delete(e),this.#o.delete(e);const t=this.#i.get(e);if(t)for(;t.length;)this.unref(t.pop());this.#i.delete(e)}else this.#o.set(e,t)}async loadItem(e,t=[]){if(!e)return null;const{href:n,mediaType:r}=e,i=ee.JS.test(e.mediaType);if(i&&!this.allowScript)return null;const o=t.at(-1);if(this.#r.has(n))return this.ref(n,o);return(i||[ee.XHTML,ee.HTML,ee.CSS,ee.SVG].includes(r))&&t.every((e=>e!==n))?this.loadReplaced(e,t):this.createURL(n,await this.loadBlob(n),r,o)}async loadHref(e,t,n=[]){if(ae(e))return e;const r=se(e,t);let i=this.manifest.find((e=>e.href===r));return i||(i={href:r,mediaType:""}),this.loadItem(i,n.concat(t))}async loadReplaced(e,t=[]){const{href:n,mediaType:r}=e,i=t.at(-1),o=await this.loadText(n);if(!o)return null;if([ee.XHTML,ee.HTML,ee.SVG].includes(r)){let s=(new DOMParser).parseFromString(o,r);if(r===ee.XHTML&&s.querySelector("parsererror")&&(console.warn(s.querySelector("parsererror").innerText),e.mediaType=ee.HTML,s=(new DOMParser).parseFromString(o,e.mediaType)),[ee.XHTML,ee.SVG].includes(e.mediaType)){let e=s.firstChild;for(;e instanceof ProcessingInstruction;){if(e.data){const r=await le(e.data,/(?:^|\s*)(href\s*=\s*['"])([^'"]*)(['"])/i,((e,r,i,o)=>this.loadHref(i,n,t).then((e=>`${r}${e}${o}`))));e.replaceWith(s.createProcessingInstruction(e.target,r))}e=e.nextSibling}}const a=async(e,r)=>e.setAttribute(r,await this.loadHref(e.getAttribute(r),n,t));for(const e of s.querySelectorAll("link[href]"))await a(e,"href");for(const e of s.querySelectorAll("[src]"))await a(e,"src");for(const e of s.querySelectorAll("[poster]"))await a(e,"poster");for(const e of s.querySelectorAll("object[data]"))await a(e,"data");for(const e of s.querySelectorAll("[*|href]:not([href]"))e.setAttributeNS(Y,"href",await this.loadHref(e.getAttributeNS(Y,"href"),n,t));for(const e of s.querySelectorAll("style"))e.textContent&&(e.textContent=await this.replaceCSS(e.textContent,n,t));for(const e of s.querySelectorAll("[style]"))e.setAttribute("style",await this.replaceCSS(e.getAttribute("style"),n,t));const l=(new XMLSerializer).serializeToString(s);return this.createURL(n,l,e.mediaType,i)}const s=r===ee.CSS?await this.replaceCSS(o,n,t):await this.replaceString(o,n,t);return this.createURL(n,s,r,i)}async replaceCSS(e,t,n=[]){const r=await le(e,/url\(\s*["']?([^'"\n]*?)\s*["']?\s*\)/gi,((e,r)=>this.loadHref(r,t,n).then((e=>`url("${e}")`)))),i=await le(r,/@import\s*["']([^"'\n]*?)["']/gi,((e,r)=>this.loadHref(r,t,n).then((e=>`@import "${e}"`)))),o=window?.innerWidth??800,s=window?.innerHeight??600;return i.replace(/-epub-/gi,"").replace(/(\d*\.?\d+)vw/gi,((e,t)=>parseFloat(t)*o/100+"px")).replace(/(\d*\.?\d+)vh/gi,((e,t)=>parseFloat(t)*s/100+"px")).replace(/page-break-(after|before|inside)/gi,((e,t)=>`-webkit-column-break-${t}`))}replaceString(e,t,n=[]){const r=new Map,i=this.assets.map((e=>{if(e.href===t)return;const n=((e,t)=>{if(!e)return t;const n=e.replace(/\/$/,"").split("/"),r=t.replace(/\/$/,"").split("/"),i=(n.length>r.length?n:r).findIndex(((e,t)=>n[t]!==r[t]));return i<0?"":Array(n.length-i).fill("..").concat(r.slice(i)).join("/")})((e=>e.slice(0,e.lastIndexOf("/")+1))(t),e.href),i=encodeURI(n),o="/"+e.href,s=encodeURI(o),a=new Set([n,i,o,s]);for(const t of a)r.set(t,e);return Array.from(a)})).flat().filter((e=>e));if(!i.length)return e;const o=new RegExp(i.map(ce).join("|"),"g");return le(e,o,(async e=>this.loadItem(r.get(e.replace(/^\//,"")),n.concat(t))))}unloadItem(e){this.unref(e?.href)}}const Le=e=>{for(const t of e){if("page-spread-left"===t||"rendition:page-spread-left"===t)return"left";if("page-spread-right"===t||"rendition:page-spread-right"===t)return"right";if("rendition:page-spread-center"===t)return"center"}};class ke{parser=new DOMParser;#s;constructor({loadText:e,loadBlob:t,getSize:n,sha1:r}){this.loadText=e,this.loadBlob=t,this.getSize=n,this.#s=new Ce(xe(r))}#a(e){return e?this.parser.parseFromString(e,ee.XML):null}async#l(e){return this.#a(await this.loadText(e))}async init(){const e=await this.#l("META-INF/container.xml");if(!e)throw new Error("Failed to load container file");const t=Array.from(e.getElementsByTagNameNS(W,"rootfile"),re("full-path","media-type")).filter((e=>"application/oebps-package+xml"===e.mediaType));if(!t.length)throw new Error("No package document defined in container");const n=t[0].fullPath,r=await this.#l(n);if(!r)throw new Error("Failed to load package document");const i=await this.#l("META-INF/encryption.xml");await this.#s.init(i,r),this.resources=new Se({opf:r,resolveHref:e=>se(e,n)});const o=new Te({loadText:this.loadText,loadBlob:e=>Promise.resolve(this.loadBlob(e)).then(this.#s.getDecoder(e)),resources:this.resources});this.sections=this.resources.spine.map(((e,t)=>{const{idref:n,linear:r,properties:i=[]}=e,s=this.resources.getItemByID(n);return s?{id:this.resources.getItemByID(n)?.href,load:()=>o.loadItem(s),unload:()=>o.unloadItem(s),createDocument:()=>this.loadDocument(s),size:this.getSize(s.href),cfi:this.resources.cfis[t],linear:r,pageSpread:Le(i),resolveHref:e=>se(e,s.href),loadMediaOverlay:()=>this.loadMediaOverlay(s)}:(console.warn(`Could not find item with ID "${n}" in manifest`),null)})).filter((e=>e));const{navPath:s,ncxPath:a}=this.resources;if(s)try{const e=e=>se(e,s),t=pe(await this.#l(s),e);this.toc=t.toc,this.pageList=t.pageList,this.landmarks=t.landmarks}catch(e){console.warn(e)}if(!this.toc&&a)try{const e=e=>se(e,a),t=ge(await this.#l(a),e);this.toc=t.toc,this.pageList=t.pageList}catch(e){console.warn(e)}this.landmarks??=this.resources.guide;const{metadata:l,rendition:c,media:h}=(e=>{const{$:t,$$:n}=oe(e,V),r=t(e.documentElement,"metadata"),i=Array.from(r.children),o=(e,t)=>{if(!t)return null;const{props:n=[],attrs:r=[]}=e,s=ie(t);if(!n.length&&!r.length)return s;const a=t.getAttribute("id"),l=a?i.filter(ne("refines","#"+a)):[];return Object.fromEntries([["value",s]].concat(n.map((t=>{const{many:n,recursive:r}=t,i="string"==typeof t?t:t.name,s=ne("property",i),a=r?e:t;return[te(i),n?l.filter(s).map((e=>o(a,e))):o(a,l.find(s))]}))).concat(r.map((e=>[te(e),t.getAttribute(e)]))))},s=i.filter(ne("refines",null)),a=e=>Object.fromEntries(n(r,"meta").filter(ne("property",(t=>t?.startsWith(e)))).map((t=>[t.getAttribute("property").replace(e,""),ie(t)])));return{metadata:Object.fromEntries(fe.map((e=>{const{type:t,name:n,many:r}=e,i="meta"===t?e=>e.namespaceURI===V&&e.getAttribute("property")===n:e=>e.namespaceURI===J&&e.localName===n;return[te(n),r?s.filter(i).map((t=>o(e,t))):o(e,s.find(i))]}))),rendition:a("rendition:"),media:a("media:")}})(r);this.rendition=c,this.media=h,h.duration=me(h.duration),this.dir=this.resources.pageProgressionDirection,this.rawMetadata=l;const d=l?.title?.[0];this.metadata={title:d?.value,sortAs:d?.fileAs,language:l?.language,identifier:be(r),description:l?.description?.value,publisher:l?.publisher?.value,published:l?.date,modified:l?.dctermsModified,subject:l?.subject?.filter((({value:e,code:t})=>e||t))?.map((({value:e,code:t,scheme:n})=>({name:e,code:t,scheme:n}))),rights:l?.rights?.value};const u={art:"artist",aut:"author",bkp:"producer",clr:"colorist",edt:"editor",ill:"illustrator",trl:"translator",pbl:"publisher"},f=e=>t=>{const n=[...new Set(t.role?.map((({value:t,scheme:n})=>(n&&"marc:relators"!==n?null:u[t])??e)))],r={name:t.value,sortAs:t.fileAs};return[n?.length?n:[e],r]};return l?.creator?.map(f("author"))?.concat(l?.contributor?.map?.(f("contributor")))?.forEach((([e,t])=>e.forEach((e=>{this.metadata[e]?this.metadata[e].push(t):this.metadata[e]=[t]})))),this}async loadDocument(e){const t=await this.loadText(e.href);return this.parser.parseFromString(t,e.mediaType)}async loadMediaOverlay(e){const t=e.mediaOverlay;if(!t)return null;const n=this.resources.getItemByID(t),r=((e,t=e=>e)=>{const{$:n,$$$:r}=oe(e,Q);return r(e,"par").map((e=>{const r=n(e,"text")?.getAttribute("src")?.split("#")?.[1],i=n(e,"audio");return i?{id:r,audio:{src:(o=i.getAttribute("src"),o?decodeURI(t(o)):null),clipBegin:me(i.getAttribute("clipBegin")),clipEnd:me(i.getAttribute("clipEnd"))}}:{id:r};var o}))})(await this.#l(n.href),(e=>se(e,n.href)));return r}resolveCFI(e){return this.resources.resolveCFI(e)}resolveHref(e){const[t,n]=e.split("#"),r=this.resources.getItemByHref(decodeURI(t));if(!r)return null;return{index:this.resources.spine.findIndex((({idref:e})=>e===r.id)),anchor:n?e=>((e,t)=>e.getElementById(t)??e.querySelector(`[name="${CSS.escape(t)}"]`))(e,n):()=>0}}splitTOCHref(e){return e?.split("#")??[]}getTOCFragment(e,t){return e.getElementById(t)??e.querySelector(`[name="${CSS.escape(t)}"]`)}isExternal(e){return ae(e)}async getCover(){const e=this.resources?.cover;return e?.href?new Blob([await this.loadBlob(e.href)],{type:e.mediaType}):null}async getCalibreBookmarks(){const e=await this.loadText("META-INF/calibre_bookmarks.txt"),t="encoding=json+base64:";if(e?.startsWith(t)){const t=atob(e.slice(21));return JSON.parse(t)}}}const Ae=(e,t=!1)=>{const n=(new DOMParser).parseFromString(t?je(e):e,"text/html");let r=Oe(n);0===r.length&&(r=qe(n));for(let e=0;e""};return a.sections=s.map((e=>({id:e.index,load:()=>{return t=e.index,f(void 0,void 0,void 0,(function*(){return URL.createObjectURL(new Blob([s[t].text],{type:"text/html"}))}));var t},unload:()=>{e.index}}))),a.toc=s.map((e=>({label:e.label,href:"title"+e.index}))).filter((e=>""!==e.label)),a.rendition={layout:"pre-paginated"},a.resolveHref=e=>({index:parseInt(e.substring(5,e.length))}),a.splitTOCHref=e=>[e,null],a.getTOCFragment=e=>e.documentElement,a};let Ie=["章","节","回","節","卷","部","輯","辑","話","集","话","篇"," "," "],Ee=[],Me=["CHAPTER","Chapter","序章","前言","声明","写在前面的话","后记","楔子","后序","尾声"],Be=[" "," ","、","·",".",":",":"];const Oe=e=>Array.from(e.querySelectorAll("h1,h2,h3,h4,h5,h6,title")),De=e=>e.trim().replace(/(\r\n|\n|\r|\t)/gm,"").substring(0,100).split("").filter((e=>"="!==e&&"-"!==e&&"_"!==e&&"+"!==e)).join(""),Ne=e=>e&&e.length<40&&!Re(e)&&(Pe(e)||e.startsWith("第")&&_e(e)||e.startsWith("卷")&&He(e)||e.indexOf("第")>-1&&e.lastIndexOf("第")<4&&_e(e.substr(e.indexOf("第")))||Fe(e)),Re=e=>Ee.filter((t=>e.indexOf(t)>-1)).length>0,Pe=t=>Me.filter((n=>t.startsWith(n)||t.startsWith(e.s2t(n))||t.startsWith(e.t2s(n)))).length>0,Fe=e=>Be.filter((t=>e.indexOf(t)>-1&&(/^[\u4e00\u4e8c\u4e09\u56db\u4e94\u516d\u4e03\u516b\u4e5d\u5341\u767e\u5343\u4e07\u842c\u96f6]+$/.test(e.substring(0,e.indexOf(t)))||/^\d+$/.test(e.substring(0,e.indexOf(t)))))).length>0,_e=e=>{let t=!1;for(let n=0;n!(!/^[\u4e00\u4e8c\u4e09\u56db\u4e94\u516d\u4e03\u516b\u4e5d\u5341\u767e\u5343\u4e07\u842c\u96f6]+$/.test(e.substring(1,e.indexOf(" ")))&&!/^\d+$/.test(e.substring(1,e.indexOf(" "))))||(!(!/^[\u4e00\u4e8c\u4e09\u56db\u4e94\u516d\u4e03\u516b\u4e5d\u5341\u767e\u5343\u4e07\u842c\u96f6]+$/.test(e.substring(1,e.indexOf(" ")))&&!/^\d+$/.test(e.substring(1,e.indexOf(" "))))||!(!/^[\u4e00\u4e8c\u4e09\u56db\u4e94\u516d\u4e03\u516b\u4e5d\u5341\u767e\u5343\u4e07\u842c\u96f6]+$/.test(e.substring(1))&&!/^\d+$/.test(e.substring(1)))),Ue=e=>{let t=[],n=e.split("
").filter((e=>""!==e.trim())),r=n.map((e=>$e(e)||ze(e)));return t=n.map(((e,t)=>({index:t,label:r[t],text:e,href:"title"+t}))),t},je=e=>{let t="",n=e.split("\n");for(let e of n)De(e)&&Ne(De(e))?t+=`

${De(e)}

`:t+=`

${e}

`;return t||`

Title

${e}

`},$e=e=>{const t=/]*>(.*?)<\/h[1-6]>/.exec(e);return t?t[1].replace(/</g,"<").replace(/>/g,">"):""},ze=e=>{const t=/]*>(.*?)<\/title>/.exec(e);return t?t[1].replace(/</g,"<").replace(/>/g,">"):""},qe=e=>{let t=e.getElementsByTagName("*"),n=Array.from(t).filter((e=>1===e.childNodes.length&&e.childNodes[0].nodeType===Node.TEXT_NODE&&Ne(De(e.textContent)))),r=[];for(let e=0;eArray.from(e.querySelectorAll("h1,h2,h3,h4,h5,h6,p,div,ul,dl,ol,pre,blockquote,address")),Ve=(e,t,n,r,i,o)=>f(void 0,void 0,void 0,(function*(){let s=Math.floor(e.clientWidth/12),a=s%2==0?s:s-1;const l=e.clientWidth;if("mimical"===t){let e=document.getElementById("book");e&&(e.style.display="block",n>0?o():n<0&&i(),console.log("first"),setTimeout((()=>{if(!e)return{};e.style.display="none"}),1e3))}n>0?r.body.scrollBy({top:0,left:-l-a,behavior:"sliding"===t?"smooth":"auto"}):n<0&&r.body.scrollBy({top:0,left:l+a,behavior:"sliding"===t?"smooth":"auto"})})),Ge=(e,n,r,i)=>{let o=t.findLastIndex(r,{href:n});return n&&t.findLastIndex(r,{href:n})>-1||(o=e),"prev"===i?Object.assign(Object.assign({},r[o-1]),{index:o-1}):Object.assign(Object.assign({},r[o+1]),{index:o+1})},Je=(e,t,n,r,i,o,s,a)=>f(void 0,void 0,void 0,(function*(){let t=parseInt(o.chapterDocIndex||"0"),l=o.chapterHref||"";if(0===t)return;let c=Ge(t,l,n,"prev");c&&(o.text="prevChapter",o.page="",yield Ze(c.index,c.label,c.href,n,e,r,i,o,s,a))})),Ke=(e,t,n,r)=>f(void 0,void 0,void 0,(function*(){let{width:i,height:o}=yield n[r].text.getDimension(),s="double"===t?2:1,a=Math.floor(e.clientWidth/12),l=a%2==0?a:a-1,c=(e.clientWidth-l)/s;"single"===t&&(c=e.clientWidth);let h=e.clientHeight,d=Math.min(c/i,h/o);return"scroll"===t&&(d=c/i),d})),Ze=(e,n,r,i,o,s,a,l,c,h)=>f(void 0,void 0,void 0,(function*(){if(c.body.innerHTML="",h.height="0px",c.body.scrollTo(0,0),n&&!e||i[e]&&i[e].label&&n&&n!==i[e].label&&-1===r.indexOf("#")){let r=t.findLastIndex(i,{label:n});-1!==r&&(e=r)}if((-1===e||e>i.length-1)&&(e=0),c.body.innerHTML=yield g(i[e].text,!1),"PDF"===a){let t=yield Ke(o,s,i,e);yield i[e].text.render(c,t)}yield Ye(c),l.chapterDocIndex&&i[l.chapterDocIndex].text&&i[l.chapterDocIndex].text.unload&&i[l.chapterDocIndex].text.unload(),l.chapterTitle=n,l.chapterHref=r,l.chapterDocIndex=e+"",l.percentage=e/i.length+"",l.text="",yield((e,t,n,r,i)=>f(void 0,void 0,void 0,(function*(){if(yield Promise.all(Array.from([...i.images,...i.querySelectorAll("image")]).map((e=>e.complete?Promise.resolve(0!==e.naturalHeight):new Promise((t=>{e.addEventListener("load",(()=>t(!0))),e.addEventListener("error",(()=>t(!1)))}))))).then((e=>{e.every((e=>e))?console.log("all images loaded successfully!!"):console.log("some images failed to load, all finished loading")})),console.log(1),yield S(e,t,n,i),"PDF"!==n&&x(i),"scroll"!==t){if(r.height=e.clientHeight+"px","double"===t){let t=Math.floor(e.clientWidth/12),n=t%2==0?t:t-1,r=(e.clientWidth+n)/2;if((i.body.scrollWidth-i.body.clientWidth)/r%2==1){let e=document.createElement("div");e.setAttribute("style","height: "+i.body.clientHeight+"px; display: inline-block; width: "+(r-n)+"px"),i.body.appendChild(e)}}}else if("PDF"===n){let e=i.querySelector(".koodoPDFLayer");if(!e)return;r.height=e.getBoundingClientRect().height+100+"px"}else r.height=i.body.scrollHeight+"px",r.height=i.body.scrollHeight+300+"px";console.log(2)})))(o,s,a,h,c),Qe(o,s,"","","","",c)})),Ye=e=>f(void 0,void 0,void 0,(function*(){let t=Array.from(e.getElementsByTagName("link"));for(let e=0;e{console.log("finished")}}let n=[];for(let e=0;e{r.addEventListener("load",e)})))}try{yield Promise.race([Promise.all(n),new Promise(((e,t)=>{setTimeout((()=>{t(new Error("Timeout"))}),1e3)}))])}catch(e){console.log(e)}})),Qe=(t,n,r,i,o,s,a)=>f(void 0,void 0,void 0,(function*(){let l=0,c=0,h=a.body;if(s&&"scroll"!==n){let e=Math.floor(t.clientWidth/12),n=e%2==0?e:e-1;c=((d=getComputedStyle(t).width,parseFloat(d.substring(0,d.length-2)))+n)*(parseInt(s)-1)}else if(r){let o=Xe(a.body).filter(((t,n)=>De(t.textContent)&&(De(t.textContent)===De(r)||De(t.textContent)===e.t2s(De(r))||De(t.textContent)===e.s2t(De(r)))&&(Math.abs(n-parseInt(i))<2||"search"===i||"ignore"===i||"next"===i)));if(0===o.length)return void console.log("failed");h=et(o[0],t,n),c=h?p(h.offsetLeft)-p(h.marginLeft||parseFloat(getComputedStyle(h).marginLeft)):"prevChapter"===r?a.body.scrollWidth:0,l=h?p(h.offsetTop)-p(h.marginTop||parseFloat(getComputedStyle(h).marginTop)):0,console.log(c,"left"),console.log(l,"top")}else if(o&&o.indexOf("#")>-1){let e=CSS.escape(o.split("#").reverse()[0]);if(!a.body.querySelector("#"+e))return;h=et(a.body.querySelector("#"+e)||a.body,t,n),c=h?p(h.offsetLeft)-p(h.marginLeft||parseFloat(getComputedStyle(h).marginLeft)):0,l=h?p(h.offsetTop)-p(h.marginTop||parseFloat(getComputedStyle(h).marginTop)):0}var d;"scroll"!==n?a.body.scrollTo(c,0):h.scrollIntoView()})),et=(e,t,n)=>{let r=Math.floor(t.clientWidth/12),i=r%2==0?r:r-1,o=p(e.offsetLeft)-p(e.marginLeft||parseFloat(getComputedStyle(e).marginLeft));return"scroll"===n||"scroll"!==n&&tt(parseInt(o+""),(t.clientWidth+i)/2)?e:e.parentElement?et(e.parentElement,t,n):e},tt=(e,t)=>{for(let n=e-10;n<=e+10;n++)if(n%t==0)return!0;return!1},nt=(e,t,n,r,i,o)=>f(void 0,void 0,void 0,(function*(){var s;if(We)return;let a=Xe(i.body),l=a.filter((n=>lt(e,n,t)&&(n.textContent||"").trim()));console.log(l,"visibleNode");let c=l[0];o&&(c=o);let h=0;console.log(c,"firstVisibleNode");for(let n=0;n{We=!1}),100)})),rt=(e,t,n)=>{let r=Math.floor(t.clientWidth/12),i=r%2==0?r:r-1;return Math.abs(e.offsetLeft-et(e,t,n).offsetLeft)>(t.clientWidth+i)/2},it=(e,n,r)=>{let i=r.chapterHref||"",o=i.lastIndexOf("#"),s=i.substring(0,o),a=i.substring(o+1);for(let i=0;i-1&&(r.chapterHref=e)}}},ot=(e,t,n,r,i,o,s,a)=>f(void 0,void 0,void 0,(function*(){let t=parseInt(o.chapterDocIndex||"0"),l=o.chapterHref||"";if(t>=n.length-1)return void(o.percentage="1");let c=Ge(t,l,n,"next");c&&(o.page="",yield Ze(c.index,c.label,c.href,n,e,r,i,o,s,a))})),st=(e,t,n)=>Xe(n.body).filter((e=>!at(e))).filter((n=>lt(e,n,t)&&(n.textContent||"").trim())).filter((e=>"img"!==e.textContent)).map((e=>e.textContent)),at=e=>{var t=e.children;let n=!1;var r=/^(address|section|blockquote|body|center|dir|div|dl|fieldset|form|h[1-6]|hr|isindex|menu|noframes|noscript|ol|p|pre|table|ul|dd|dt|frameset|li|tbody|td|tfoot|th|thead|tr|html)$/i;if(Array.from(t).filter((e=>r.test(e.nodeName))).length<3)return!1;for(var i=0;i{var r=!1,i=t.getBoundingClientRect();if("scroll"!==n&&t.textContent&&t.textContent.trim()){let t=i.left;r=t>-10&&t<=e.clientWidth}else if("scroll"===n&&t.textContent&&t.textContent.trim()){let t=i.top;r=t>=e.scrollTop&&t<=e.scrollTop+e.clientHeight}else if("scroll"!==n){let t=i.left;r=t>=0&&t<=e.clientWidth}return r};class ct{constructor(){this.callbacks={},this.callbacks.base={}}on(e,t){const n=this;if(void 0===e||""===e)return console.warn("wrong names"),!1;if(void 0===t)return console.warn("wrong callback"),!1;return this.resolveNames(e).forEach((function(e){const r=n.resolveName(e);n.callbacks[r.namespace]instanceof Object||(n.callbacks[r.namespace]={}),n.callbacks[r.namespace][r.value]instanceof Array||(n.callbacks[r.namespace][r.value]=[]),n.callbacks[r.namespace][r.value].push(t)})),this}off(e){const t=this;if(void 0===e||""===e)return console.warn("wrong name"),!1;return this.resolveNames(e).forEach((function(e){const n=t.resolveName(e);if("base"!==n.namespace&&""===n.value)delete t.callbacks[n.namespace];else if("base"===n.namespace)for(const e in t.callbacks)t.callbacks[e]instanceof Object&&t.callbacks[e][n.value]instanceof Array&&(delete t.callbacks[e][n.value],0===Object.keys(t.callbacks[e]).length&&delete t.callbacks[e]);else t.callbacks[n.namespace]instanceof Object&&t.callbacks[n.namespace][n.value]instanceof Array&&(delete t.callbacks[n.namespace][n.value],0===Object.keys(t.callbacks[n.namespace]).length&&delete t.callbacks[n.namespace])})),this}trigger(e,t=[]){if(void 0===e||""===e)return console.warn("wrong name"),!1;const n=this;const r=t instanceof Array?t:[];let i=this.resolveNames(e);i=this.resolveName(i[0]),setTimeout((()=>{if("base"===i.namespace)for(const e in n.callbacks){if(n.callbacks[e]instanceof Object&&n.callbacks[e][i.value]instanceof Array&&n.callbacks[e][i.value])n.callbacks[e][i.value].forEach((function(e){e.apply(n,r)}));else if(this.callbacks[i.namespace]instanceof Object&&n.callbacks[i.namespace][i.value]){if(""===i.value)return console.warn("wrong name"),this;n.callbacks[i.namespace][i.value].forEach((function(e){e.apply(n,r)}))}return null}}),100)}resolveNames(e){let t=e;return t=t.replace(/[^a-zA-Z0-9 ,/.]/g,""),t=t.replace(/[,/]+/g," "),t=t.split(" "),t}resolveName(e){const t={},n=e.split(".");return t.original=e,t.value=n[0],t.namespace="base",n.length>1&&""!==n[1]&&(t.namespace=n[1]),t}}const ht=Node.ELEMENT_NODE,dt=Node.TEXT_NODE,ut=Node.CDATA_SECTION_NODE;function ft(e,t,n){let r,i,o,s=0,a=0,l=!0;for(i=0;ithis.compare(e,t)))}static compare(e,t){let n=e.get(),r=t.get();if(e.isRange||t.isRange){if(e.isRange&&t.isRange){const e=this.comparePath(n.from,r.from);return e||this.comparePath(n.to,r.to)}return e.isRange&&(n=n.from),t.isRange&&(r=r.from),this.comparePath(n,r)}return this.comparePath(n,r)}static compareParts(e,t){const n=Math.max(e.length,t.length);let r,i,o,s;for(r=0;r=n)return"img"===a.tagName.toLowerCase()&&r?{node:a,offset:r}:{node:a,offset:0}}else{if(l+=1,l===n)return"img"===a.tagName.toLowerCase()&&r?{node:a,offset:r}:{node:a,offset:0};if(l>n)return o?{node:o,offset:this.trueLength(e,o.textContent)}:{node:t,offset:0}}o=a;break;case dt:case ut:if(0!==l&&l%2!=0||(l+=1),l===n){const t=this.trueLength(e,a.textContent);if(!(r>=t))return{node:a,offset:r};r-=t}o=a;break;default:continue}if(n>l){const n={relativeToNode:"after",offset:0};return n.node=o||t,this.isTextNode(n.node)&&(n.offset=this.trueLength(e,n.node.textContent.length)),n}}isTextNode(e){return!!e&&(e.nodeType===dt||e.nodeType===ut)}correctOffset(e,t,n,r){let i,o=t;if("string"==typeof r?i=this.decodeEntities(e,r):(r.pre=this.decodeEntities(e,r.pre),r.post=this.decodeEntities(e,r.post),i=r.pre+"."+r.post),!this.isTextNode(t))return{node:t,offset:0};for(;this.isTextNode(o.previousSibling);)o=o.previousSibling;const s=o;let a;const l=[];let c="",h=0;for(;this.isTextNode(o)&&(a=this.decodeEntities(e,o.textContent),l[h]=a.length,c+=a,o.nextSibling);)o=o.nextSibling,h++;const d=r.pre?r.pre.length:0,u=function(e,t,n){n=n||0;const r=[];let i,o=0;do{if(i=e.match(t),!i)break;r.push(i.index+n),o+=i.index+i.length,e=e.slice(i.index+i.length)}while(o=l[h];){if(f-=l[h],f<0)return{node:t,offset:n};const e=[];if(!o.nextSibling||h+1>=e.length)return{node:t,offset:n};h++,o=o.nextSibling}return{node:o,offset:f}}resolveNode(e,t,n,r){if(r=Object.assign({},r||{}),!n)throw new Error("Missing DOM argument");let i;if(0===e&&(i=n.querySelector("package")),!i)for(const e of n.childNodes)if(e.nodeType===ht){i=e;break}if(i=n,!i)throw new Error("Document incompatible with CFIs");let o,s,a=i,l=0;for(o=t.length-1;o>=0;o--)if(s=t[o],!r.ignoreIDs&&s.nodeID&&(a=n.getElementById(s.nodeID))){l=o+1;break}a||(a=i);let c={node:a,offset:0};for(o=l;othis.parts.length-2)throw new Error("index is out of bounds");const r=this.parts[e];if(!r)throw new Error("Missing CFI part for index: "+e);let i=this.resolveNode(e,r,t,n).node;const o=i.tagName.toLowerCase();if("itemref"===o&&"spine"===i.parentNode.tagName.toLowerCase()){const e=i.getAttribute("idref");if(!e)throw new Error("Referenced node had not 'idref' attribute");if(i=t.getElementById(e),!i)throw new Error("Specified node is missing from manifest");const n=i.getAttribute("href");if(!n)throw new Error("Manifest item is missing href attribute");return n}if("iframe"===o||"embed"===o){const e=i.getAttribute("src");if(!e)throw new Error(o+" element is missing 'src' attribute");return e}if("object"===o){const e=i.getAttribute("data");if(!e)throw new Error(o+" element is missing 'data' attribute");return e}if("image"===o||"use"===o){const e=i.getAttribute("xlink:href");if(!e)throw new Error(o+" element is missing 'xlink:href' attribute");return e}throw new Error("No URI found")}deepClone(e){return JSON.parse(JSON.stringify(e))}resolveLocation(e,t){const n=t.length-1,r=t[n];if(!r)throw new Error("Missing CFI part for index: "+n);const i=this.resolveNode(n,r,e),o=this.deepClone(r[r.length-1]);return delete o.nodeIndex,o.offset||delete i.offset,Object.assign(Object.assign({},o),i)}resolveLast(e,t){if(t=Object.assign({range:!1},t||{}),!this.isRange)return this.resolveLocation(e,this.parts);if(t.range){const t=e.createRange(),n=this.getFrom();"before"===n.relativeToNode?t.setStartBefore(n.node,n.offset):"after"===n.relativeToNode?t.setStartAfter(n.node,n.offset):t.setStart(n.node,n.offset);const r=this.getTo();return"before"===r.relativeToNode?t.setEndBefore(r.node,r.offset):"after"===r.relativeToNode?t.setEndAfter(r.node,r.offset):t.setEnd(r.node,r.offset),t}return{from:this.resolveLocation(e,this.getFrom()),to:this.resolveLocation(e,this.getTo()),isRange:!0}}resolve(e,t){return this.resolveLast(e,t)}}const yt=["color-0","color-1","color-2","color-3","line-0","line-1","line-2","line-3"],bt=["#FEF3CD","#FBFACC","#CEFACD","#CDE9FA"],wt=["#fac106","#ebe702","#0be603","#0493e6"],vt=["#FF0000","#000080","#0000FF","#2EFF2E"],xt=(e,t,r,i,o,s)=>{var a,l;n.init();let c=yt[t],h=s.contentWindow||(null===(a=s.contentDocument)||void 0===a?void 0:a.defaultView),d=e;d=[d],n.getSelection(s).restoreCharacterRanges(o,d);let u=o.getSelection();if(!u)return;let f=u.getRangeAt(0);for(var p=kt(f),g=0;g{let a=yt[t],l=s.querySelector(".noteLayer");var c=i.getViewport({scale:o});e.coords.forEach((e=>{var t=c.convertToViewportRectangle(e),i=document.createElement("div");null==i||i.setAttribute("style","position: absolute;"+(a.indexOf("color")>-1?"background-color: ":"border-bottom: ")+(a.indexOf("color")>-1?wt[a.split("-")[1]]:`2px solid ${vt[a.split("-")[1]]}`)+"; left:"+Math.min(t[0],t[2])+"px; top:"+Math.min(t[1],t[3])+"px;width:"+Math.abs(t[0]-t[2])+"px; height:"+Math.abs(t[1]-t[3])+"px; z-index: 1;opacity: "+(a.indexOf("color")>-1?.3:1)+";"),null==i||i.setAttribute("data-key",n),null==i||i.setAttribute("class","kookit-note"),null==i||i.addEventListener("click",(e=>{e&&e.target&&e.target.dataset&&e.target.dataset.key&&r(e)})),l.appendChild(i)}))},St=e=>{const t=e.querySelectorAll(".kookit-note");for(let e=0;e{const o=Lt(e.getClientRects());for(let e=0;e-1?"background-color: ":"border-bottom: ")+(t.indexOf("color")>-1?bt[t.split("-")[1]]+";opacity: 1":`2px solid ${vt[t.split("-")[1]]}`)+";left:"+(Math.min(l.left,l.x)+i.body.scrollLeft)+"px; top:"+(Math.min(l.top,l.y)+i.body.scrollTop)+"px;width:"+l.width+"px; height:"+l.height+"px; z-index:-1;"),s.setAttribute("class"," kookit-note"),s.setAttribute("data-key",n),i.body.appendChild(s);var a=document.createElement("span");null==a||a.setAttribute("style","position: absolute;left:"+(Math.min(l.left,l.x)+i.body.scrollLeft)+"px; top:"+(Math.min(l.top,l.y)+i.body.scrollTop)+"px;width:"+l.width+"px; height:"+l.height+"px; z-index:1;"),a.setAttribute("class"," kookit-note"),a.setAttribute("data-key",n),a.addEventListener("click",(e=>{e&&e.target&&e.target.dataset&&e.target.dataset.key&&r(e)})),a.ontouchend=e=>{e&&e.target&&e.target.dataset&&e.target.dataset.key&&r(e),e.preventDefault(),e.stopPropagation()},i.body.appendChild(a)}},Lt=e=>{let t=[];for(let n=0;n{var t=e.commonAncestorContainer,n=new Array(0),r=new Array(0);if(e.startContainer!==t)for(let r=e.startContainer;r!==t;r=r.parentNode)n.push(r);if(n.length>0)for(let t=0;t0)for(let t=0;t0&&o.length>0))return[e];var c=document.createRange();return c.setStartAfter(n[n.length-1]),c.setEndBefore(o[o.length-1]),r.push(c),r.concat(s)};const At=e=>{!function(e){let t=document.getElementById("book");t&&t.remove();const n=document.createElement("div");n.id="book";const r=document.createElement("canvas");r.id="pageflip-canvas";const i=document.createElement("div");i.id="pages";for(let t=0;t=0?u[l-1].dragging=!0:d.x>0&&l+1{l+1{l-1>=0&&(u[l-1].target=1,l=Math.max(l-1,0))}}}}function y(e){var t=1-Math.abs(e.progress),n=.5*o*(1-e.progress),i=o*e.progress+n,l=20*t,c=.5*o*Math.max(Math.min(1-e.progress,.5),0),d=.5*o*Math.max(Math.min(t,.5),0),u=.5*o*Math.max(Math.min(t,.5),0);e.page.style.width=Math.max(i,0)+"px",h.save(),h.translate(0+r/2,a+0),h.strokeStyle="rgba(0,0,0,"+.05*t+")",h.lineWidth=30*t,h.beginPath(),h.moveTo(i-n,.5*-l),h.lineTo(i-n,s+.5*l),h.stroke();var f=h.createLinearGradient(i,0,i+d,0);f.addColorStop(0,"rgba(0,0,0,"+.2*t+")"),f.addColorStop(.8,"rgba(0,0,0,0.0)"),h.fillStyle=f,h.beginPath(),h.moveTo(i,0),h.lineTo(i+d,0),h.lineTo(i+d,s),h.lineTo(i,s),h.fill();var p=h.createLinearGradient(i-n-u,0,i-n,0);p.addColorStop(0,"rgba(0,0,0,0.0)"),p.addColorStop(1,"rgba(0,0,0,"+.15*t+")"),h.fillStyle=p,h.beginPath(),h.moveTo(i-n-u,0),h.lineTo(i-n,0),h.lineTo(i-n,s),h.lineTo(i-n-u,s),h.fill();var g=h.createLinearGradient(i-c,0,i,0);g.addColorStop(.35,"#fafafa"),g.addColorStop(.73,"#eeeeee"),g.addColorStop(.9,"#fafafa"),g.addColorStop(1,"#e2e2e2"),h.fillStyle=g,h.strokeStyle="rgba(0,0,0,0.06)",h.lineWidth=.5,h.beginPath(),h.moveTo(i,0),h.lineTo(i,s),h.quadraticCurveTo(i,s+2*l,i-n,s+l),h.lineTo(i-n,-l),h.quadraticCurveTo(i,2*-l,i,0),h.fill(),h.stroke(),h.restore()}},It=(e,t)=>{void 0!==t.nextSibling?t.parentNode.insertBefore(e,t.nextSibling):t.parentNode.appendChild(e)},Et=e=>{for(var t=0;void 0!==e.childNodes[t];t++)if("#text"===e.childNodes[t].nodeName&&0!==e.childNodes[t].textContent.trim().length){var n=e.childNodes[t],r=0;e.childNodes[t].textContent.split(/(\s+|\S+)/).forEach((e=>{if(0===e.length)return;var t=e.trim().length;if(0===t){let t=document.createTextNode(e);return It(t,n),r++,void(n=t)}var i=Math.floor(t/2);0===i&&(i=1);const o=document.createElement("b");if(o.innerHTML=e.slice(0,i),It(o,n),r++,n=o,1===e.length)return;let s=document.createTextNode(e.slice(i));It(s,n),r++,n=s})),e.removeChild(e.childNodes[t]),t+=r-1}};var Mt={B:!0,META:!0,LINK:!0,SCRIPT:!0,STYLE:!0};const Bt=e=>{if(null!==e&&void 0!==e.body)for(var t=e.body.getElementsByTagName("*"),n=0;void 0!==t[n];n++)if(!Mt[t[n].nodeName]&&1===t[n].nodeType)if("IFRAME"===t[n].nodeName)Bt(t[n].contentDocument);else{if(0===t[n].childNodes.length)continue;Et(t[n])}};class Ot extends ct{constructor(t){super(),this.tsTransform=()=>{let t=this.getDocument();t&&("Simplified To Traditional"===this.convertChinese?t.querySelectorAll("h1,h2,h3,h4,h5,h6,p,div,ul,dl,ol,pre,blockquote,address").forEach((t=>{t.innerHTML=t.innerHTML.split("").map((t=>e.s2t(t))).join("")})):"Traditional To Simplified"===this.convertChinese&&t.querySelectorAll("h1,h2,h3,h4,h5,h6,p,div,ul,dl,ol,pre,blockquote,address").forEach((t=>{t.innerHTML=t.innerHTML.split("").map((t=>e.t2s(t))).join("")})))},this.bionicReadingProcess=()=>{let e=this.getDocument();e&&"yes"===this.isBionic&&Bt(e)},this.addPageAnimation=()=>{if("mimical"===this.animation){let e=this.getProgress();if(!e)return;const t=At(e.totalPage);t&&(this.flipToNextPage=t.flipToNextPage,this.flipToPrevPage=t.flipToPrevPage)}},this.mode=t.mode,this.animation=t.animation,this.format=t.format,this.convertChinese=t.convertChinese,this.isBionic=t.isBionic,this.chapterList=[],this.chapterDocList=[],this.flattenChapters=[],this.book="",this.element="",this.tempLocation={},this.flipToNextPage=()=>{},this.flipToPrevPage=()=>{}}getPageSize(){let e="double"===this.mode?2:1,t=Math.floor(this.element.clientWidth/12),n=t%2==0?t:t-1;return{width:this.element.clientWidth,height:this.element.clientHeight,left:this.element.offsetLeft,top:this.element.offsetTop,scrollTop:this.element.scrollTop,sectionWidth:(this.element.clientWidth-n)/e,gap:n}}resolveChapter(e){let t=e,n=-1;for(let e=0;e-1)return this.flattenChapters[n];{let r=e.split("#")[0];for(let e=0;e-1)return this.flattenChapters[n];for(let e=0;e-1?{label:"",href:"",index:n}:null}}flatChapter(e){let t=[];for(let n=0;n0?(t.push(e[n]),t=t.concat(this.flatChapter(e[n].subitems))):t.push(e[n]);return this.flattenChapters=t,t}getChapter(){return this.chapterList}getChapterDoc(){return this.chapterDocList}goToPercentage(e){return f(this,void 0,void 0,(function*(){if(this.flattenChapters.length>0){let t=1===e?this.flattenChapters.length-1:Math.floor(this.flattenChapters.length*e);yield this.goToChapter(this.flattenChapters[t].index.toString(),this.flattenChapters[t].href,this.flattenChapters[t].label)}}))}goToChapterIndex(e){return f(this,void 0,void 0,(function*(){this.flattenChapters.length>0&&(yield this.goToChapter(this.flattenChapters[e].index,this.flattenChapters[e].href,this.flattenChapters[e].label))}))}goToChapter(e,t,n){return f(this,void 0,void 0,(function*(){console.log(e,t,n);let r=this.getDocument(),i=this.getIframe();r&&i&&(yield Ze(parseInt(e),n,t,this.chapterDocList,this.element,this.mode,this.format,this.tempLocation,r,i),t&&t.indexOf("#")>-1&&(yield Qe(this.element,this.mode,"","",t,"",r)),yield this.record(),this.trigger("rendered"))}))}goToPosition(e){return f(this,void 0,void 0,(function*(){let t=this.getDocument(),n=this.getIframe();if(!t||!n)return;let r=JSON.parse(e);this.tempLocation={text:r.text,chapterTitle:r.chapterTitle,chapterDocIndex:r.chapterDocIndex,chapterHref:r.chapterHref,count:r.count,page:r.page};let{text:i,chapterTitle:o,chapterDocIndex:s,chapterHref:a,count:l,page:c,cfi:h}=r;if(yield Ze(parseInt(s),o,a,this.chapterDocList,this.element,this.mode,this.format,this.tempLocation,t,n),h){const e=new mt(h,{});let t=this.getDocument();if(!t)return;const{node:n,offset:r}=e.resolve(t,{});if(console.log(n,r),n){let e=null,t=n;for(;t;){const n=t;if(n.tagName&&"h1,h2,h3,h4,h5,h6,p,div,ul,dl,ol,pre,blockquote,address".indexOf(n.tagName.toLowerCase())>-1){e=n;break}t=t.parentNode}e&&(l="ignore",i=e.textContent)}}yield Qe(this.element,this.mode,i,l,"",c,t),yield this.record(),this.trigger("rendered")}))}getDocument(){let e=document.getElementById("page-area");if(!e)return null;let t=e.getElementsByTagName("iframe")[0];if(!t)return null;let n=t.contentDocument;return n||null}getIframe(){let e=document.getElementById("page-area");if(!e)return null;let t=e.getElementsByTagName("iframe")[0];return t||null}goToNode(e){return f(this,void 0,void 0,(function*(){let t=this.getDocument();if(!t)return;let n=et(e,this.element,this.mode),r=n?p(n.offsetLeft)-p(n.marginLeft||parseFloat(getComputedStyle(n).marginLeft)):0,i=n?p(n.offsetTop)-p(n.marginTop||parseFloat(getComputedStyle(n).marginTop)):0;"scroll"!==this.mode?t.body.scrollTo(r,0):this.element.scrollTo(0,i),yield this.record(),this.trigger("rendered")}))}removeContent(){this.element.innerHTML=""}prev(){return f(this,void 0,void 0,(function*(){this.trigger("page-changed");let e=this.getDocument(),t=this.getIframe();if(e&&t){if("scroll"===this.mode&&0===p(this.element.scrollTop)||"scroll"!==this.mode&&0===p(e.body.scrollLeft)){yield Je(this.element,this.flatChapter(this.chapterList),this.chapterDocList,this.mode,this.format,this.tempLocation,e,t),parseInt(this.tempLocation.chapterDocIndex||"-1")>-1&&e.body.scrollTo(e.body.scrollWidth,0),this.trigger("rendered")}else"scroll"===this.mode?this.element.scrollBy({left:0,top:-(this.element.clientHeight-50),behavior:"smooth"}):yield Ve(this.element,this.animation,1,e,this.flipToNextPage,this.flipToPrevPage);yield this.record()}}))}next(){return f(this,void 0,void 0,(function*(){this.trigger("page-changed");let e=this.getDocument(),t=this.getIframe();e&&t&&(Math.abs(e.body.scrollWidth-p(e.body.scrollLeft)-e.body.clientWidth)<10&&"scroll"!==this.mode||Math.abs(this.element.scrollHeight-p(this.element.scrollTop)-this.element.clientHeight)<10&&"scroll"===this.mode?(yield ot(this.element,this.flatChapter(this.chapterList),this.chapterDocList,this.mode,this.format,this.tempLocation,e,t),this.trigger("rendered")):"scroll"===this.mode?this.element.scrollBy({left:0,top:this.element.clientHeight-50,behavior:"smooth"}):yield Ve(this.element,this.animation,-1,e,this.flipToNextPage,this.flipToPrevPage),yield this.record())}))}prevChapter(){return f(this,void 0,void 0,(function*(){this.trigger("page-changed");let e=this.getDocument(),t=this.getIframe();e&&t&&(yield Je(this.element,this.flatChapter(this.chapterList),this.chapterDocList,this.mode,this.format,this.tempLocation,e,t),yield this.record(),this.trigger("rendered"))}))}nextChapter(){return f(this,void 0,void 0,(function*(){this.trigger("page-changed");let e=this.getDocument(),t=this.getIframe();e&&t&&(yield ot(this.element,this.flatChapter(this.chapterList),this.chapterDocList,this.mode,this.format,this.tempLocation,e,t),yield this.record(),this.trigger("rendered"))}))}visibleText(){let e=this.getDocument();return e?st(this.element,this.mode,e):""}audioText(){let e=this.getDocument();return e?((e,t,n)=>{let r=Xe(n.body).filter((e=>!at(e))).filter((e=>(e.textContent||"").trim())).filter((e=>"img"!==e.textContent)).map((e=>e.textContent)),i=0,o=st(e,t,n);if(o&&o.length>0){let e=o[0];i=r.indexOf(e)}return r.slice(i)})(this.element,this.mode,e):""}highlightNode(e,t){let n=this.getDocument();n&&((e,t,n)=>{let r=Xe(n.body).filter((n=>(n.getAttribute("style")===t&&n.setAttribute("style",""),(n.textContent||"").trim()&&n.textContent===e)));r.length>0&&r[0].setAttribute("style",t)})(e,t,n)}doSearch(e){return f(this,void 0,void 0,(function*(){return yield((e,n)=>f(void 0,void 0,void 0,(function*(){var r;let i=[];for(let t=0;t!at(e)));for(let o=0;o-1&&i.push({excerpt:(null===(r=s[o].textContent)||void 0===r?void 0:r.substring(a-100,a+100))||"",cfi:JSON.stringify({text:s[o].textContent,chapterTitle:n[t].label,chapterDocIndex:t,chapterHref:n[t].href,count:"search",percentage:t/n.length})})}}for(let e=0;esetTimeout(e,1e3))));let e=this.getDocument();e&&(yield nt(this.element,this.mode,this.flatChapter(this.chapterList),this.tempLocation,e,null))}))}getPosition(){return this.tempLocation}getNotePosition(){return f(this,void 0,void 0,(function*(){let e=this.getDocument();if(!e)return;let t=function(e){const t=e.getSelection();if(!t)return null;if(t.rangeCount>0)return t.getRangeAt(0).startContainer.parentElement;return null}(e);return t?(yield nt(this.element,this.mode,this.flatChapter(this.chapterList),this.tempLocation,e,t),this.tempLocation):void 0}))}setStyle(e){let t=this.getDocument();t&&t.body.setAttribute("style",e)}getHightlightCoords(e){return f(this,void 0,void 0,(function*(){n.init();let e=this.getDocument(),t=this.getIframe();if(e&&t)return n.getSelection(t).saveCharacterRanges(e.body)[0]}))}renderHighlighters(e,t){return f(this,void 0,void 0,(function*(){let n=this.getDocument(),r=this.getIframe();if(n&&r){St(n);for(let i=0;if(void 0,void 0,void 0,(function*(){let n=yield a.loadAsync(e);var r=n.file("toc.json");let i=[];r&&(i=JSON.parse(yield r.async("string")));var o=n.file("sections.json");let s=[];o&&(s=JSON.parse(yield o.async("string")));const l={getCover:()=>""};return l.sections=s.map(((e,t)=>({id:e.href,load:()=>(e=>f(void 0,void 0,void 0,(function*(){var t=n.file("chapters/"+e+".html");let r="";return t&&(r=yield t.async("string")),URL.createObjectURL(new Blob([r],{type:"text/html"}))})))(t),unload:()=>{},loadAsset:e=>(e=>f(void 0,void 0,void 0,(function*(){var t=n.file(e);let r;return t&&(r=yield t.async("arraybuffer")),URL.createObjectURL(new Blob([r],{type:Dt[e.split(".").reverse()[0]]}))})))(e)}))),l.toc=i.map((e=>({label:e.label,href:e.href,subitems:e.subitems}))),l.rendition={layout:"pre-paginated"},l.resolveHref=e=>({index:t.findLastIndex(s,{href:e})}),l.splitTOCHref=e=>[e,null],l.getTOCFragment=e=>e.documentElement,l})),Pt=e=>new Promise(((t,n)=>f(void 0,void 0,void 0,(function*(){let n=new L(e),r=yield n.getChapter(e.toc),i=yield n.getChapterDoc(),o=r,s=i.map((e=>({href:e.href,label:e.label}))),l=yield Promise.all(i.map((e=>f(void 0,void 0,void 0,(function*(){let t="";if(e.text.load){let n=yield fetch(yield e.text.load()).then((e=>e.blob()));t=yield n.text()}return t}))))),c=new a;c.file("toc.json",JSON.stringify(o)),c.file("sections.json",JSON.stringify(s));let h=[];for(let e=0;ee.blob()));r.file(t+"."+Nt[o.type],o);let s="imgs/"+e+"/"+t+"."+Nt[o.type];n[t].src=s,n[t].getAttribute("xlink:href")&&n[t].setAttribute("xlink:href",s)}catch(e){console.log(e)}}let r=Array.from(t.getElementsByTagName("link"));for(let t=0;te.blob()));i.file(t+"."+Nt[r.type],r),n.href="css/"+e+"/"+t+"."+Nt[r.type]}catch(e){console.log(e)}}h.push(t.documentElement.innerHTML)}let d=c.folder("chapters");if(d){for(let e=0;ef(void 0,void 0,void 0,(function*(){t(yield new Response(e).arrayBuffer())})))).catch((e=>{t("err")}))}}))));class Ft extends Ot{constructor(e,t,n){super({mode:t,format:"EPUB",animation:n}),this.epubBuffer=e}renderTo(e){return new Promise(((t,n)=>f(this,void 0,void 0,(function*(){this.element=e,this.book||(yield this.parse());let n=new L(this.book);this.chapterList=yield n.getChapter(this.book.toc),this.chapterDocList=yield n.getChapterDoc(),w(e);let r=this.getDocument();r&&(T(e,this.mode,r),t())}))))}parse(){return f(this,void 0,void 0,(function*(){let e=new Blob([this.epubBuffer]),t=new File([e],"book",{lastModified:(new Date).getTime(),type:e.type});try{const e=yield this.makeZipLoader(t);this.book=yield new ke(e).init()}catch(e){throw console.log(e),e}}))}preCache(){return f(this,void 0,void 0,(function*(){return this.book||(yield this.parse()),yield Pt(this.book)}))}makeZipLoader(e){return f(this,void 0,void 0,(function*(){let t;try{t=new r(new i(e))}catch(e){throw e}const n=yield t.getEntries(),a=new Map(n.map((e=>[e.filename,e]))),l=e=>(t,...n)=>a.has(t)?e(a.get(t),...n):null;return{entries:n,loadText:l((e=>e.getData(new o))),loadBlob:l(((e,t)=>new Promise(((n,r)=>{e.getData(new s(t)).then((e=>{n(e)})).catch((e=>{n(new Blob)}))})))),getSize:e=>{var t,n;return null!==(n=null===(t=a.get(e))||void 0===t?void 0:t.uncompressedSize)&&void 0!==n?n:0}}}))}getMetadata(){return f(this,void 0,void 0,(function*(){try{this.book||(yield this.parse());let e=new L(this.book);return yield e.getMetadata()}catch(e){throw console.log(e),e}}))}}const _t=e=>{if(!e)return"";const t=document.createElement("textarea");return t.innerHTML=e,t.value},Ht={XML:"application/xml",XHTML:"application/xhtml+xml",HTML:"text/html",CSS:"text/css",SVG:"image/svg+xml"},Ut={name:[0,32,"string"],type:[60,4,"string"],creator:[64,4,"string"],numRecords:[76,2,"uint"]},jt={compression:[0,2,"uint"],numTextRecords:[8,2,"uint"],recordSize:[10,2,"uint"],encryption:[12,2,"uint"]},$t={magic:[16,4,"string"],length:[20,4,"uint"],type:[24,4,"uint"],encoding:[28,4,"uint"],uid:[32,4,"uint"],version:[36,4,"uint"],titleOffset:[84,4,"uint"],titleLength:[88,4,"uint"],localeRegion:[94,1,"uint"],localeLanguage:[95,1,"uint"],resourceStart:[108,4,"uint"],huffcdic:[112,4,"uint"],numHuffcdic:[116,4,"uint"],exthFlag:[128,4,"uint"],trailingFlags:[240,4,"uint"],indx:[244,4,"uint"]},zt={resourceStart:[108,4,"uint"],fdst:[192,4,"uint"],numFdst:[196,4,"uint"],frag:[248,4,"uint"],skel:[252,4,"uint"],guide:[260,4,"uint"]},qt={magic:[0,4,"string"],length:[4,4,"uint"],count:[8,4,"uint"]},Wt={magic:[0,4,"string"],length:[4,4,"uint"],type:[8,4,"uint"],idxt:[20,4,"uint"],numRecords:[24,4,"uint"],encoding:[28,4,"uint"],language:[32,4,"uint"],total:[36,4,"uint"],ordt:[40,4,"uint"],ligt:[44,4,"uint"],numLigt:[48,4,"uint"],numCncx:[52,4,"uint"]},Xt={magic:[0,4,"string"],length:[4,4,"uint"],numControlBytes:[8,4,"uint"]},Vt={magic:[0,4,"string"],offset1:[8,4,"uint"],offset2:[12,4,"uint"]},Gt={magic:[0,4,"string"],length:[4,4,"uint"],numEntries:[8,4,"uint"],codeLength:[12,4,"uint"]},Jt={magic:[0,4,"string"],numEntries:[8,4,"uint"]},Kt={flags:[8,4,"uint"],dataStart:[12,4,"uint"],keyLength:[16,4,"uint"],keyStart:[20,4,"uint"]},Zt={1252:"windows-1252",65001:"utf-8"},Yt={100:["creator","string",!0],101:["publisher"],103:["description"],104:["isbn"],105:["subject","string",!0],106:["date"],108:["contributor","string",!0],109:["rights"],110:["subjectCode","string",!0],112:["source","string",!0],113:["asin"],121:["boundary","uint"],122:["fixedLayout"],125:["numResources","uint"],126:["originalResolution"],127:["zeroGutter"],128:["zeroMargin"],129:["coverURI"],132:["regionMagnification"],201:["coverOffset","uint"],202:["thumbnailOffset","uint"],503:["title"],524:["language","string",!0],527:["pageProgressionDirection"]},Qt={1:["ar","ar-SA","ar-IQ","ar-EG","ar-LY","ar-DZ","ar-MA","ar-TN","ar-OM","ar-YE","ar-SY","ar-JO","ar-LB","ar-KW","ar-AE","ar-BH","ar-QA"],2:["bg"],3:["ca"],4:["zh","zh-TW","zh-CN","zh-HK","zh-SG"],5:["cs"],6:["da"],7:["de","de-DE","de-CH","de-AT","de-LU","de-LI"],8:["el"],9:["en","en-US","en-GB","en-AU","en-CA","en-NZ","en-IE","en-ZA","en-JM",null,"en-BZ","en-TT","en-ZW","en-PH"],10:["es","es-ES","es-MX",null,"es-GT","es-CR","es-PA","es-DO","es-VE","es-CO","es-PE","es-AR","es-EC","es-CL","es-UY","es-PY","es-BO","es-SV","es-HN","es-NI","es-PR"],11:["fi"],12:["fr","fr-FR","fr-BE","fr-CA","fr-CH","fr-LU","fr-MC"],13:["he"],14:["hu"],15:["is"],16:["it","it-IT","it-CH"],17:["ja"],18:["ko"],19:["nl","nl-NL","nl-BE"],20:["no","nb","nn"],21:["pl"],22:["pt","pt-BR","pt-PT"],23:["rm"],24:["ro"],25:["ru"],26:["hr",null,"sr"],27:["sk"],28:["sq"],29:["sv","sv-SE","sv-FI"],30:["th"],31:["tr"],32:["ur"],33:["id"],34:["uk"],35:["be"],36:["sl"],37:["et"],38:["lv"],39:["lt"],41:["fa"],42:["vi"],43:["hy"],44:["az"],45:["eu"],46:["hsb"],47:["mk"],48:["st"],49:["ts"],50:["tn"],52:["xh"],53:["zu"],54:["af"],55:["ka"],56:["fo"],57:["hi"],58:["mt"],59:["se"],62:["ms"],63:["kk"],65:["sw"],67:["uz",null,"uz-UZ"],68:["tt"],69:["bn"],70:["pa"],71:["gu"],72:["or"],73:["ta"],74:["te"],75:["kn"],76:["ml"],77:["as"],78:["mr"],79:["sa"],82:["cy","cy-GB"],83:["gl","gl-ES"],87:["kok"],97:["ne"],98:["fy"]},en=(e,t)=>{const n=new e.constructor(e.length+t.length);return n.set(e),n.set(t,e.length),n},tn=(e,t,n)=>{const r=new e.constructor(e.length+t.length+n.length);return r.set(e),r.set(t,e.length),r.set(n,e.length+t.length),r},nn=new TextDecoder,rn=e=>nn.decode(e),on=e=>{if(!e)return;const t=e.byteLength,n=4===t?"getUint32":2===t?"getUint16":"getUint8";return new DataView(e)[n](0)},sn=(e,t)=>Object.fromEntries(Array.from(Object.entries(e)).map((([e,[n,r,i]])=>[e,("string"===i?rn:on)(t.slice(n,n+r))]))),an=e=>new TextDecoder(Zt[e]),ln=(e,t=0)=>{let n=0,r=0;for(const i of e.subarray(t,t+4))if(n=n<<7|(127&i)>>>0,r++,128&i)break;return{value:n,length:r}},cn=e=>{let t=0;for(const n of e.subarray(-4))128&n&&(t=0),t=t<<7|127&n;return t},hn=e=>{let t=0;for(;e>0;e>>=1)1&~e||t++;return t},dn=e=>{let t=0;for(;!(1&e);)e>>=1,t++;return t},un=e=>{let t=[];for(let n=0;n>>3,s=3+(7&i);for(let e=0;e{const n=t+32,r=n>>3;let i=0n;for(let n=t>>3;n<=r;n++)i=i<<8n|BigInt(e[n]??0);return i>>8n-BigInt(7&n)&0xffffffffn},pn=async(e,t)=>{const n=await t(e),r=sn(Wt,n);if("INDX"!==r.magic)throw new Error("Invalid INDX record");const i=an(r.encoding),o=n.slice(r.length),s=sn(Xt,o);if("TAGX"!==s.magic)throw new Error("Invalid TAGX section");const a=(s.length-12)/4,l=Array.from({length:a},((e,t)=>new Uint8Array(o.slice(12+4*t,12+4*t+4)))),c={};let h=0;for(let n=0;n1){const{value:n,length:r}=ln(i,p);h.push([e,null,n,t]),p+=r}else h.push([e,1,null,t]);else h.push([e,a>>dn(n),null,t])}const g={};for(const[e,t,n,r]of h){const o=[];if(null!=t)for(let e=0;eon(n.slice(8*t,8*t+4)))).map(((e,t,n)=>[e,n[t+1]]))}loadRecord(e){const t=this.#h[e];if(!t)throw new RangeError("Record index out of bounds");return this.#c.slice(...t).arrayBuffer()}async loadMagic(e){const t=this.#h[e][0];return rn(await this.#c.slice(t,t+4).arrayBuffer())}}class mn extends gn{#d=0;#u;#f;#p;#g;#m;constructor({unzlib:e}){super(),this.unzlib=e}async open(e){await super.open(e),this.headers=this.#y(await super.loadRecord(0)),this.#u=this.headers.mobi.resourceStart;let t=this.headers.mobi.version>=8;if(!t){const e=this.headers.exth?.boundary;if(e<4294967295)try{this.headers=this.#y(await super.loadRecord(e)),this.#d=e,t=!0}catch(e){console.warn(e),console.warn("Failed to open KF8; falling back to MOBI")}}return await this.#b(),t?new kn(this).init():new wn(this).init()}#y(e){const t=sn(jt,e),n=sn($t,e);if("MOBI"!==n.magic)throw new Error("Missing MOBI header");const{titleOffset:r,titleLength:i,localeLanguage:o,localeRegion:s}=n;n.title=e.slice(r,r+i);const a=Qt[o];n.language=a?.[s>>2]??a?.[0];const l=64&n.exthFlag?((e,t)=>{const{magic:n,count:r}=sn(qt,e);if("EXTH"!==n)throw new Error("Invalid EXTH header");const i=an(t),o={};let s=12;for(let t=0;t=8?sn(zt,e):null}}async#b(){const{palmdoc:e,mobi:t}=this.headers;this.#f=an(t.encoding),this.#p=new TextEncoder;const{compression:n}=e;if(this.#g=1===n?e=>e:2===n?un:17480===n?await(async(e,t)=>{const n=await t(e.huffcdic),{magic:r,offset1:i,offset2:o}=sn(Vt,n);if("HUFF"!==r)throw new Error("Invalid HUFF record");const s=Array.from({length:256},((e,t)=>i+4*t)).map((e=>on(n.slice(e,e+4)))).map((e=>[128&e,31&e,e>>>8])),a=[null].concat(Array.from({length:32},((e,t)=>o+8*t)).map((e=>[on(n.slice(e,e+4)),on(n.slice(e+4,e+8))]))),l=[];for(let n=1;n{let t=new Uint8Array;const n=8*e.byteLength;for(let r=0;r>>24];if(!o){for(;i>>>32-hn)break;const u=d-(i>>>32-h);let[f,p]=l[u];p||(f=c(f),l[u]=[f,!0]),t=en(t,f)}return t};return c})(t,this.loadRecord.bind(this)):null,!this.#g)throw new Error("Unknown compression type");const{trailingFlags:r}=t,i=1&r,o=hn(r>>>1);this.#m=e=>{for(let t=0;tnew Uint8Array(e))).then(this.#m).then(this.#g)}async loadResource(e){const t=await super.loadRecord(this.#u+e),n=rn(t.slice(0,4));return"FONT"===n?(async(e,t)=>{const{flags:n,dataStart:r,keyLength:i,keyStart:o}=sn(Kt,e),s=new Uint8Array(e.slice(r));if(2&n){const t=16===i?1024:1040,n=new Uint8Array(e.slice(o,o+i)),r=Math.min(t,s.length);for(var a=0;a{const{table:n,cncx:r}=await pn(e,t),i=n.map((({tagMap:e},t)=>({index:t,offset:e[1]?.[0],size:e[2]?.[0],label:r[e[3]]??"",headingLevel:e[4]?.[0],pos:e[6],parent:e[21]?.[0],firstChild:e[22]?.[0],lastChild:e[23]?.[0]}))),o=e=>(null==e.firstChild||(e.children=i.filter((t=>t.parent===e.index)).map(o)),e);return i.filter((e=>0===e.headingLevel)).map(o)})(e,this.loadRecord.bind(this))}getMetadata(){const{mobi:e,exth:t}=this.headers;return{identifier:e.uid.toString(),title:_t(t?.title||this.decode(e.title)),author:t?.creator?.map(_t),publisher:_t(t?.publisher),language:t?.language??e.language,published:t?.date,description:_t(t?.description),subject:t?.subject?.map(_t),rights:_t(t?.rights)}}async getCover(){const{exth:e}=this.headers,t=e?.coverOffset<4294967295?e?.coverOffset:e?.thumbnailOffset<4294967295?e?.thumbnailOffset:null;if(null!=t){const e=await this.loadResource(t);return new Blob([e])}}}const yn=/<\s*(?:mbp:)?pagebreak[^>]*>/gi,bn=/<[^<>]+filepos=['"]{0,1}(\d+)[^<>]*>/gi;class wn{parser=new DOMParser;serializer=new XMLSerializer;#w=new Map;#v=new Map;#r=new Map;#x;#C=[];#S=Ht.HTML;constructor(e){this.mobi=e}async init(){let e=new Uint8Array;for(let t=0;tString.fromCharCode(e))).join("");this.#x=[0].concat(Array.from(t.matchAll(yn),(e=>e.index))).map(((e,n,r)=>t.slice(e,r[n+1]))).map((e=>Uint8Array.from(e,(e=>e.charCodeAt(0))))).map((e=>({book:this,raw:e}))).reduce(((e,t)=>{const n=e[e.length-1];return t.start=n?.end??0,t.end=t.start+t.raw.byteLength,e.concat(t)}),[]),this.sections=this.#x.map(((e,t)=>({id:t,load:()=>this.loadSection(e),createDocument:()=>this.createDocument(e),size:e.end-e.start})));try{this.landmarks=await this.getGuide();const e=this.landmarks.find((({type:e})=>e?.includes("toc")))?.href;if(e){const{index:t}=this.resolveHref(e),n=await this.sections[t].createDocument();let r,i=0,o=0;const s=new Map,a=new Map;this.toc=Array.from(n.querySelectorAll("a[filepos]")).reduce(((e,t)=>{const n=(e=>{let t=0;for(;e;){const n=e.parentElement;if(n){const e=n.tagName.toLowerCase();"p"===e?t+=1.5:"blockquote"===e&&(t+=2)}e=n}return t})(t),l={label:t.innerText?.trim(),href:`filepos:${t.getAttribute("filepos")}`},c=n>o?i+1:n===o?i:s.get(n)??Math.max(0,i-1);if(c>i)r?(r.subitems??=[],r.subitems.push(l),a.set(c,r)):e.push(l);else{const t=a.get(c);t?t.subitems.push(l):e.push(l)}return r=l,i=c,o=n,s.set(n,c),e}),[])}}catch(e){console.warn(e)}return this.#C=[...new Set(Array.from(t.matchAll(bn),(e=>e[1])))].map((e=>({filepos:e,number:Number(e)}))).sort(((e,t)=>e.number-t.number)),this.metadata=this.mobi.getMetadata(),this.getCover=this.mobi.getCover.bind(this.mobi),this}async getGuide(){const e=await this.createDocument(this.#x[0]);return Array.from(e.getElementsByTagName("reference"),(e=>({label:e.getAttribute("title"),type:e.getAttribute("type")?.split(/\s/),href:`filepos:${e.getAttribute("filepos")}`})))}async loadResource(e){if(this.#w.has(e))return this.#w.get(e);const t=await this.mobi.loadResource(e),n=URL.createObjectURL(new Blob([t]));return this.#w.set(e,n),n}async loadRecindex(e){return this.loadResource(Number(e)-1)}async replaceResources(e){for(const t of e.querySelectorAll("img[recindex]")){const e=t.getAttribute("recindex");try{t.src=await this.loadRecindex(e)}catch(t){console.warn(`Failed to load image ${e}`)}}for(const t of e.querySelectorAll("[mediarecindex]")){const e=t.getAttribute("mediarecindex"),n=t.getAttribute("recindex");try{t.src=await this.loadRecindex(e),n&&(t.poster=await this.loadRecindex(n))}catch(t){console.warn(`Failed to load media ${e}`)}}for(const t of e.querySelectorAll("[filepos]")){const e=t.getAttribute("filepos");t.href=`filepos:${e}`}}async loadText(e){if(this.#v.has(e))return this.#v.get(e);const{raw:t}=e,n=this.#C.filter((({number:t})=>t>=e.start&&t({...t,offset:t.number-e.start})));let r=t;n.length&&(r=t.subarray(0,n[0].offset),n.forEach((({filepos:e,offset:i},o)=>{const s=n[o+1],a=this.mobi.encode(``);r=tn(r,a,t.subarray(i,s?.offset))})));const i=this.mobi.decode(r).replaceAll(yn,"");return this.#v.set(e,i),i}async createDocument(e){const t=await this.loadText(e);return this.parser.parseFromString(t,this.#S)}async loadSection(e){if(this.#r.has(e))return this.#r.get(e);const t=await this.createDocument(e),n=t.createElement("style");t.head.append(n),n.append(t.createTextNode("blockquote {\n margin-block-start: 0;\n margin-block-end: 0;\n margin-inline-start: 1em;\n margin-inline-end: 0;\n }")),await this.replaceResources(t);const r=this.serializer.serializeToString(t),i=URL.createObjectURL(new Blob([r],{type:this.#S}));return this.#r.set(e,i),i}resolveHref(e){const t=e.match(/filepos:(.*)/)[1],n=Number(t);return{index:this.#x.findIndex((e=>e.end>n)),anchor:e=>e.getElementById(`filepos${t}`)}}splitTOCHref(e){const t=e.match(/filepos:(.*)/)[1],n=Number(t);return[this.#x.findIndex((e=>e.end>n)),`filepos${t}`]}getTOCFragment(e,t){return e.getElementById(t)}isExternal(e){return/^(?!blob|filepos)\w+:/i.test(e)}destroy(){for(const e of this.#w.values())URL.revokeObjectURL(e);for(const e of this.#r.values())URL.revokeObjectURL(e)}}const vn=/kindle:(flow|embed):(\w+)(?:\?mime=(\w+\/[-+.\w]+))?/,xn=/kindle:pos:fid:(\w+):off:(\w+)/,Cn=e=>{const[t,n]=e.match(xn).slice(1);return{fid:parseInt(t,32),off:parseInt(n,32)}},Sn=(e=0,t=0)=>`kindle:pos:fid:${e.toString(32).toUpperCase().padStart(4,"0")}:off:${t.toString(32).toUpperCase().padStart(10,"0")}`,Tn=e=>{const t=e.match(/\s(id|name|aid)\s*=\s*['"]([^'"]*)['"]/i);if(!t)return;const[,n,r]=t;return`[${n}="${CSS.escape(r)}"]`},Ln=e=>{for(const t of e){if("page-spread-left"===t||"rendition:page-spread-left"===t)return"left";if("page-spread-right"===t||"rendition:page-spread-right"===t)return"right";if("rendition:page-spread-center"===t)return"center"}};class kn{parser=new DOMParser;serializer=new XMLSerializer;#r=new Map;#T=new Map;#L=new Map;#k={};#x;#A;#I=new Uint8Array;#E=new Uint8Array;#M=-1;#B=-1;#S=Ht.XHTML;#O=new Map;constructor(e){this.mobi=e}async init(){const e=this.mobi.loadRecord.bind(this.mobi),{kf8:t}=this.mobi.headers;try{const n=await e(t.fdst),r=sn(Jt,n);if("FDST"!==r.magic)throw new Error("Missing FDST record");const i=Array.from({length:r.numEntries},((e,t)=>12+8*t)).map((e=>[on(n.slice(e,e+4)),on(n.slice(e+4,e+8))]));this.#k.fdstTable=i,this.#A=i[i.length-1][1]}catch{}const n=(await pn(t.skel,e)).table.map((({name:e,tagMap:t},n)=>({index:n,name:e,numFrag:t[1][0],offset:t[6][0],length:t[6][1]}))),r=await pn(t.frag,e),i=r.table.map((({name:e,tagMap:t})=>({insertOffset:parseInt(e),selector:r.cncx[t[2][0]],index:t[4][0],offset:t[6][0],length:t[6][1]})));this.#k.skelTable=n,this.#k.fragTable=i,this.#x=n.reduce(((e,t)=>{const n=e[e.length-1],r=n?.fragEnd??0,o=r+t.numFrag,s=i.slice(r,o),a=t.length+s.map((e=>e.length)).reduce(((e,t)=>e+t)),l=(n?.totalLength??0)+a;return e.concat({skel:t,frags:s,fragEnd:o,length:a,totalLength:l})}),[]);const o=await this.getResourcesByMagic(["RESC","PAGE"]),s=new Map;if(o.RESC){const e=await this.mobi.loadRecord(o.RESC),t=this.mobi.decode(e.slice(16)).replace(/\0/g,""),n=t.search(/\?>/),r=`${t.slice(n)}`,i=this.parser.parseFromString(r,Ht.XML);for(const e of i.querySelectorAll("spine > itemref")){const t=parseInt(e.getAttribute("skelid"));s.set(t,Ln(e.getAttribute("properties")?.split(" ")??[]))}}this.sections=this.#x.map(((e,t)=>e.frags.length?{id:t,load:()=>this.loadSection(e),createDocument:()=>this.createDocument(e),size:e.length,pageSpread:s.get(t)}:{linear:"no"}));try{const e=await this.mobi.getNCX(),t=({label:e,pos:n,children:r})=>{const[i,o]=n,s=Sn(i,o),a=this.#T.get(i);return a?a.push(o):this.#T.set(i,[o]),{label:_t(e),href:s,subitems:r?.map(t)}};this.toc=e?.map(t),this.landmarks=await this.getGuide()}catch(e){console.warn(e)}const{exth:a}=this.mobi.headers;return this.dir=a.pageProgressionDirection,this.rendition={layout:"true"===a.fixedLayout?"pre-paginated":"reflowable",viewport:Object.fromEntries(a.originalResolution?.split("x")?.slice(0,2)?.map(((e,t)=>[t?"height":"width",e]))??[])},this.metadata=this.mobi.getMetadata(),this.getCover=this.mobi.getCover.bind(this.mobi),this}async getResourcesByMagic(e){const t={},n=this.mobi.headers.kf8.resourceStart,r=this.mobi.pdb.numRecords;for(let i=n;ie===n));r&&(t[r]=i)}catch{}return t}async getGuide(){const e=this.mobi.headers.kf8.guide;if(e<4294967295){const t=this.mobi.loadRecord.bind(this.mobi),{table:n,cncx:r}=await pn(e,t);return n.map((({name:e,tagMap:t})=>({label:r[t[1][0]]??"",type:e?.split(/\s/),href:Sn(t[6]?.[0]??t[3]?.[0])})))}}async loadResourceBlob(e){const{resourceType:t,id:n,type:r}=(e=>{const[t,n,r]=e.match(vn).slice(1);return{resourceType:t,id:parseInt(n,32),type:r}})(e),i="flow"===t?await this.loadFlow(n):await this.mobi.loadResource(n-1),o=[Ht.XHTML,Ht.HTML,Ht.CSS,Ht.SVG].includes(r)?await this.replaceResources(this.mobi.decode(i)):i,s=r===Ht.SVG?this.parser.parseFromString(o,r):null;return[new Blob([o],{type:r}),s?.getElementsByTagNameNS("http://www.w3.org/2000/svg","image")?.length?s.documentElement:null]}async loadResource(e){if(this.#r.has(e))return this.#r.get(e);const[t,n]=await this.loadResourceBlob(e),r=n?e:URL.createObjectURL(t);return n&&this.#O.set(r,n),this.#r.set(e,r),r}replaceResources(e){return(async(e,t,n)=>{const r=[];e.replace(t,((...e)=>(r.push(e),null)));const i=[];for(const e of r)i.push(await n(...e));return e.replace(t,(()=>i.shift()))})(e,new RegExp(vn,"g"),this.loadResource.bind(this))}async loadRaw(e,t){const n=t-this.#I.length,r=null==this.#A?1/0:this.#A-this.#E.length-e;if(n<0||ne;){const e=this.mobi.headers.palmdoc.numTextRecords-1-++this.#B,t=await this.mobi.loadText(e);this.#E=en(t,this.#E)}const i=this.#A-this.#E.length;return this.#E.slice(e-i,t-i)}loadFlow(e){if(e<4294967295)return this.loadRaw(...this.#k.fdstTable[e])}async loadText(e){const{skel:t,frags:n,length:r}=e,i=await this.loadRaw(t.offset,t.offset+r);let o=i.slice(0,t.length);for(const e of n){const n=e.insertOffset-t.offset,r=t.length+e.offset,s=i.slice(r,r+e.length);o=tn(o.slice(0,n),s,o.slice(n));const a=this.#T.get(e.index);if(a)for(const t of a){const n=this.mobi.decode(s).slice(t),r=Tn(n);this.#D(e.index,t,r)}}return this.mobi.decode(o)}async createDocument(e){const t=await this.loadText(e);return this.parser.parseFromString(t,this.#S)}async loadSection(e){if(this.#r.has(e))return this.#r.get(e);const t=await this.loadText(e),n=await this.replaceResources(t);let r=this.parser.parseFromString(n,this.#S);r.querySelector("parsererror")&&(this.#S=Ht.HTML,r=this.parser.parseFromString(n,this.#S));for(const[e,t]of this.#O)for(const n of r.querySelectorAll(`img[src="${e}"]`))n.replaceWith(t);const i=URL.createObjectURL(new Blob([this.serializer.serializeToString(r)],{type:this.#S}));return this.#r.set(e,i),i}getIndexByFID(e){return this.#x.findIndex((t=>t.frags.some((t=>t.index===e))))}#D(e,t,n){const r=this.#L.get(e);if(r)r.set(t,n);else{const r=new Map;this.#L.set(e,r),r.set(t,n)}}async resolveHref(e){const{fid:t,off:n}=Cn(e),r=this.getIndexByFID(t);if(r<0)return;const i=this.#L.get(t)?.get(n);if(i)return{index:r,anchor:e=>e.querySelector(i)};const{skel:o,frags:s}=this.#x[r],a=s.find((e=>e.index===t)),l=o.offset+o.length+a.offset,c=await this.loadRaw(l,l+a.length),h=this.mobi.decode(c).slice(n),d=Tn(h);this.#D(t,n,d);return{index:r,anchor:e=>e.querySelector(d)}}splitTOCHref(e){const t=Cn(e);return[this.getIndexByFID(t.fid),t]}getTOCFragment(e,{fid:t,off:n}){const r=this.#L.get(t)?.get(n);return e.querySelector(r)}isExternal(e){return/^(?!blob|kindle)\w+:/i.test(e)}destroy(){for(const e of this.#r.values())URL.revokeObjectURL(e)}}class An extends Ot{constructor(e,t,n){super({mode:t,format:"MOBI",animation:n}),this.mobiBuffer=e}renderTo(e){return new Promise(((t,n)=>f(this,void 0,void 0,(function*(){this.element=e,this.book||(yield this.parse());let n=new L(this.book);this.chapterList=yield n.getChapter(this.book.toc),this.chapterDocList=yield n.getChapterDoc(),w(e);let r=this.getDocument();r&&(T(e,this.mode,r),t())}))))}parse(){return f(this,void 0,void 0,(function*(){try{let e=new Blob([this.mobiBuffer]),t=new File([e],"book",{lastModified:(new Date).getTime(),type:e.type});(yield(async e=>"BOOKMOBI"===rn(await e.slice(60,68).arrayBuffer()))(t))&&(this.book=yield new mn({unzlib:l}).open(t))}catch(e){throw console.log(e),e}}))}preCache(){return f(this,void 0,void 0,(function*(){return this.book||(yield this.parse()),yield Pt(this.book)}))}getMetadata(){return f(this,void 0,void 0,(function*(){try{this.book||(yield this.parse());let e=new L(this.book);return yield e.getMetadata()}catch(e){throw console.log(e),e}}))}}const In=e=>`./lib/pdfjs/${e}`,En=window.pdfjsLib,Mn=async e=>await(await fetch(e)).text(),Bn=async()=>await Mn(In("text_layer_builder.css")),On=async()=>await Mn(In("annotation_layer_builder.css")),Dn=async(e,t)=>{const n=e.getViewport({scale:1});if(t){const t=document.createElement("canvas");t.height=n.height,t.width=n.width;const r=t.getContext("2d");return await e.render({canvasContext:r,viewport:n}).promise,new Promise((e=>t.toBlob(e)))}return URL.createObjectURL(new Blob([`\n \n \n \n \n \n
\n
\n
\n
\n
\n
\n\n `],{type:"text/html"}))},Nn=e=>({label:e.title,href:e.dest?JSON.stringify(e.dest):null,subitems:e.items.length?e.items.map(Nn):null}),Rn=async e=>{const t=new En.PDFDataRangeTransport(e.size,[]);t.requestDataRange=(n,r)=>{e.slice(n,r).arrayBuffer().then((e=>{t.onDataRange(n,e)}))};const n=await En.getDocument({range:t,cMapUrl:In("cmaps/"),standardFontDataUrl:In("standard_fonts/"),isEvalSupported:!1}).promise,r={rendition:{layout:"pre-paginated"}},{metadata:i,info:o}=await n.getMetadata()??{};r.metadata={title:i?.get("dc:title")??o?.Title,author:i?.get("dc:creator")??o?.Author,contributor:i?.get("dc:contributor"),description:i?.get("dc:description")??o?.Subject,language:i?.get("dc:language"),publisher:i?.get("dc:publisher"),subject:i?.get("dc:subject"),identifier:i?.get("dc:identifier"),source:i?.get("dc:source"),rights:i?.get("dc:rights")};const s=await n.getOutline();r.toc=s?.map(Nn);const a=new Map;return r.sections=Array.from({length:n.numPages}).map(((e,t)=>({id:t,load:async()=>{const e=a.get(t);if(e)return e;const r=await Dn(await n.getPage(t+1));return console.log(r),a.set(t,r),r},unload:async()=>{let e=await n.getPage(t+1);console.log(e),e.cleanup()},render:async(e,r)=>await(async(e,t,n)=>{const r=n*devicePixelRatio;let i=t.querySelector(".koodoPDFLayer");i.style.transform=`scale(${1/devicePixelRatio})`,i.style.transformOrigin="top left",i.style.setProperty("--scale-factor",r);const o=e.getViewport({scale:r}),s=document.createElement("canvas");i.style.width=`${o.width}px`,i.style.height=`${o.height}px`,s.height=o.height,s.width=o.width;const a=s.getContext("2d");await e.render({canvasContext:a,viewport:o}).promise,t.querySelector("#canvas").replaceChildren(t.adoptNode(s)),i.style.overflow="hidden";const l=t.querySelector(".textLayer"),c=new En.TextLayer({textContentSource:await e.streamTextContent(),container:l,viewport:o});await c.render();for(const e of document.querySelectorAll(".hiddenCanvasElement"))Object.assign(e.style,{position:"absolute",top:"0",left:"0",width:"0",height:"0",display:"none"});const h=document.createElement("div");h.className="endOfContent",l.append(h),l.onpointerdown=()=>l.classList.add("selecting"),l.onpointerup=()=>l.classList.remove("selecting");const d=t.querySelector(".annotationLayer");await new En.AnnotationLayer({page:e,viewport:o,div:d}).render({annotations:await e.getAnnotations(),linkService:{goToDestination:()=>{},getDestinationHash:e=>JSON.stringify(e),addLinkAttributes:(e,t)=>e.href=t}})})(await n.getPage(t+1),e,r),size:1e3,getDimension:async()=>{let e=(await n.getPage(t+1)).getViewport({scale:1});return{width:e.width,height:e.height}},getPage:async()=>await n.getPage(t+1)}))),r.isExternal=e=>/^\w+:/i.test(e),r.resolveHref=async e=>{const t=JSON.parse(e),r="string"==typeof t?await n.getDestination(t):t;return{index:await n.getPageIndex(r[0])}},r.splitTOCHref=async e=>{const t=JSON.parse(e),r="string"==typeof t?await n.getDestination(t):t;return[await n.getPageIndex(r[0]),null]},r.getTOCFragment=e=>e.documentElement,r.getCover=async()=>Dn(await n.getPage(1),!0),r.destroy=()=>n.destroy(),r};class Pn extends Ot{constructor(e,t,n){super({mode:t,format:"PDF",animation:n}),this.pdfBuffer=e}renderTo(e){return new Promise(((t,n)=>f(this,void 0,void 0,(function*(){this.element=e,this.book||(yield this.parse());let n=new L(this.book);this.chapterList=yield n.getChapter(this.book.toc),this.chapterDocList=yield n.getChapterDoc(),w(e);let r=this.getDocument();r&&(T(e,this.mode,r),t())}))))}parse(){return f(this,void 0,void 0,(function*(){try{let e=new Blob([this.pdfBuffer]),t=new File([e],"book",{lastModified:(new Date).getTime(),type:e.type});(yield(async e=>{const t=new Uint8Array(await e.slice(0,5).arrayBuffer());return 37===t[0]&&80===t[1]&&68===t[2]&&70===t[3]&&45===t[4]})(t))&&(this.book=yield Rn(t))}catch(e){throw console.log(e),e}}))}preCache(){return f(this,void 0,void 0,(function*(){return this.book||(yield this.parse()),yield Pt(this.book)}))}getMetadata(){return f(this,void 0,void 0,(function*(){try{this.book||(yield this.parse());let e=new L(this.book);return yield e.getMetadata()}catch(e){throw console.log(e),e}}))}getHightlightCoords(e){return f(this,void 0,void 0,(function*(){let t=this.getDocument();if(!t)return;var n=t.getSelection().getRangeAt(0).getClientRects();let r=yield this.chapterDocList[e].text.getPage(),i=yield Ke(this.element,this.mode,this.chapterDocList,e);var o=r.getViewport({scale:i});let s=t.querySelector("canvas");var a=null==s?void 0:s.getClientRects()[0];let l=[];for(let e=0;en[e].left&&(l[l.length-1].left=n[e].left),l[l.length-1].right{throw new Error("File system is not available")};var jn={},$n={};Object.defineProperty($n,"__esModule",{value:!0}),$n.default=(e,t,n)=>({confidence:n,name:t.name(e),lang:t.language?t.language():void 0});var zn=Fn&&Fn.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(jn,"__esModule",{value:!0});const qn=zn($n);jn.default=class{name(){return"ASCII"}match(e){const t=e.rawInput;for(let n=0;n126)return(0,qn.default)(e,this,0)}return(0,qn.default)(e,this,100)}};var Wn={},Xn=Fn&&Fn.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(Wn,"__esModule",{value:!0});const Vn=Xn($n);Wn.default=class{name(){return"UTF-8"}match(e){let t,n=!1,r=0,i=0,o=0;const s=e.rawInput;e.rawLen>=3&&239==(255&s[0])&&187==(255&s[1])&&191==(255&s[2])&&(n=!0);for(let t=0;t5)break;o=0}for(;t++,!(t>=e.rawLen);){if(128!=(192&s[t])){i++;break}if(0==--o){r++;break}}}}if(t=0,n&&0==i)t=100;else if(n&&r>10*i)t=80;else if(r>3&&0==i)t=100;else if(r>0&&0==i)t=80;else if(0==r&&0==i)t=10;else{if(!(r>10*i))return null;t=25}return(0,Vn.default)(e,this,t)}};var Gn={},Jn=Fn&&Fn.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(Gn,"__esModule",{value:!0}),Gn.UTF_32LE=Gn.UTF_32BE=Gn.UTF_16LE=Gn.UTF_16BE=void 0;const Kn=Jn($n);Gn.UTF_16BE=class{name(){return"UTF-16BE"}match(e){const t=e.rawInput;return t.length>=2&&254==(255&t[0])&&!(255&~t[1])?(0,Kn.default)(e,this,100):null}};Gn.UTF_16LE=class{name(){return"UTF-16LE"}match(e){const t=e.rawInput;return t.length>=2&&!(255&~t[0])&&254==(255&t[1])?t.length>=4&&0==t[2]&&0==t[3]?null:(0,Kn.default)(e,this,100):null}};class Zn{name(){return"UTF-32"}getChar(e,t){return-1}match(e){let t=0,n=0,r=!1,i=0;const o=e.rawLen/4*4,s=e.rawInput;if(0==o)return null;65279==this.getChar(s,0)&&(r=!0);for(let e=0;e=1114111||r>=55296&&r<=57343?n+=1:t+=1}return r&&0==n?i=100:r&&t>10*n?i=80:t>3&&0==n?i=100:t>0&&0==n?i=80:t>10*n&&(i=25),0==i?null:(0,Kn.default)(e,this,i)}}Gn.UTF_32BE=class extends Zn{name(){return"UTF-32BE"}getChar(e,t){return(255&e[t+0])<<24|(255&e[t+1])<<16|(255&e[t+2])<<8|255&e[t+3]}};Gn.UTF_32LE=class extends Zn{name(){return"UTF-32LE"}getChar(e,t){return(255&e[t+3])<<24|(255&e[t+2])<<16|(255&e[t+1])<<8|255&e[t+0]}};var Yn={},Qn=Fn&&Fn.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(Yn,"__esModule",{value:!0}),Yn.gb_18030=Yn.euc_kr=Yn.euc_jp=Yn.big5=Yn.sjis=void 0;const er=Qn($n);function tr(e,t){const n=(e,t,r,i)=>{if(i>>1);return t>e[o]?n(e,t,o+1,i):t=e.rawLen)return this.done=!0,-1;return 255&e.rawInput[this.nextIndex++]}}class rr{constructor(){this.commonChars=[]}name(){return"mbcs"}match(e){let t=0,n=0,r=0,i=0,o=0;const s=new nr;e:{for(s.reset();this.nextChar(s,e);){if(i++,s.error)r++;else{const e=4294967295&s.charValue;e>255&&(t++,null!=this.commonChars&&tr(this.commonChars,e)>=0&&n++)}if(r>=2&&5*r>=t)break e}if(t<=10&&0==r)o=0==t&&i<10?0:10;else if(t<20*r)o=0;else if(null==this.commonChars)o=30+t-20*r,o>100&&(o=100);else{const e=90/Math.log(t/4);o=Math.floor(Math.log(n+1)*e+10),o=Math.min(o,100)}}return 0==o?null:(0,er.default)(e,this,o)}nextChar(e,t){return!0}}Yn.sjis=class extends rr{constructor(){super(...arguments),this.commonChars=[33088,33089,33090,33093,33115,33129,33130,33141,33142,33440,33442,33444,33449,33450,33451,33453,33455,33457,33459,33461,33463,33469,33470,33473,33476,33477,33478,33480,33481,33484,33485,33500,33504,33511,33512,33513,33514,33520,33521,33601,33603,33614,33615,33624,33630,33634,33639,33653,33654,33673,33674,33675,33677,33683,36502,37882,38314]}name(){return"Shift_JIS"}language(){return"ja"}nextChar(e,t){e.index=e.nextIndex,e.error=!1;const n=e.charValue=e.nextByte(t);if(n<0)return!1;if(n<=127||n>160&&n<=223)return!0;const r=e.nextByte(t);return!(r<0)&&(e.charValue=n<<8|r,r>=64&&r<=127||r>=128&&r<=255||(e.error=!0),!0)}};function ir(e,t){e.index=e.nextIndex,e.error=!1;let n=0,r=0,i=0;return n=e.charValue=e.nextByte(t),n<0?e.done=!0:n<=141||(r=e.nextByte(t),e.charValue=e.charValue<<8|r,n>=161&&n<=254?r<161&&(e.error=!0):142!=n?143==n&&(i=e.nextByte(t),e.charValue=e.charValue<<8|i,i<161&&(e.error=!0)):r<161&&(e.error=!0)),0==e.done}Yn.big5=class extends rr{constructor(){super(...arguments),this.commonChars=[41280,41281,41282,41283,41287,41289,41333,41334,42048,42054,42055,42056,42065,42068,42071,42084,42090,42092,42103,42147,42148,42151,42177,42190,42193,42207,42216,42237,42304,42312,42328,42345,42445,42471,42583,42593,42594,42600,42608,42664,42675,42681,42707,42715,42726,42738,42816,42833,42841,42970,43171,43173,43181,43217,43219,43236,43260,43456,43474,43507,43627,43706,43710,43724,43772,44103,44111,44208,44242,44377,44745,45024,45290,45423,45747,45764,45935,46156,46158,46412,46501,46525,46544,46552,46705,47085,47207,47428,47832,47940,48033,48593,49860,50105,50240,50271]}name(){return"Big5"}language(){return"zh"}nextChar(e,t){e.index=e.nextIndex,e.error=!1;const n=e.charValue=e.nextByte(t);if(n<0)return!1;if(n<=127||255==n)return!0;const r=e.nextByte(t);return!(r<0)&&(e.charValue=e.charValue<<8|r,(r<64||127==r||255==r)&&(e.error=!0),!0)}};Yn.euc_jp=class extends rr{constructor(){super(...arguments),this.commonChars=[41377,41378,41379,41382,41404,41418,41419,41430,41431,42146,42148,42150,42152,42154,42155,42156,42157,42159,42161,42163,42165,42167,42169,42171,42173,42175,42176,42177,42179,42180,42182,42183,42184,42185,42186,42187,42190,42191,42192,42206,42207,42209,42210,42212,42216,42217,42218,42219,42220,42223,42226,42227,42402,42403,42404,42406,42407,42410,42413,42415,42416,42419,42421,42423,42424,42425,42431,42435,42438,42439,42440,42441,42443,42448,42453,42454,42455,42462,42464,42465,42469,42473,42474,42475,42476,42477,42483,47273,47572,47854,48072,48880,49079,50410,50940,51133,51896,51955,52188,52689],this.nextChar=ir}name(){return"EUC-JP"}language(){return"ja"}};Yn.euc_kr=class extends rr{constructor(){super(...arguments),this.commonChars=[45217,45235,45253,45261,45268,45286,45293,45304,45306,45308,45496,45497,45511,45527,45538,45994,46011,46274,46287,46297,46315,46501,46517,46527,46535,46569,46835,47023,47042,47054,47270,47278,47286,47288,47291,47337,47531,47534,47564,47566,47613,47800,47822,47824,47857,48103,48115,48125,48301,48314,48338,48374,48570,48576,48579,48581,48838,48840,48863,48878,48888,48890,49057,49065,49088,49124,49131,49132,49144,49319,49327,49336,49338,49339,49341,49351,49356,49358,49359,49366,49370,49381,49403,49404,49572,49574,49590,49622,49631,49654,49656,50337,50637,50862,51151,51153,51154,51160,51173,51373],this.nextChar=ir}name(){return"EUC-KR"}language(){return"ko"}};Yn.gb_18030=class extends rr{constructor(){super(...arguments),this.commonChars=[41377,41378,41379,41380,41392,41393,41457,41459,41889,41900,41914,45480,45496,45502,45755,46025,46070,46323,46525,46532,46563,46767,46804,46816,47010,47016,47037,47062,47069,47284,47327,47350,47531,47561,47576,47610,47613,47821,48039,48086,48097,48122,48316,48347,48382,48588,48845,48861,49076,49094,49097,49332,49389,49611,49883,50119,50396,50410,50636,50935,51192,51371,51403,51413,51431,51663,51706,51889,51893,51911,51920,51926,51957,51965,52460,52728,52906,52932,52946,52965,53173,53186,53206,53442,53445,53456,53460,53671,53930,53938,53941,53947,53972,54211,54224,54269,54466,54490,54754,54992]}name(){return"GB18030"}language(){return"zh"}nextChar(e,t){e.index=e.nextIndex,e.error=!1;let n=0,r=0,i=0,o=0;e:if(n=e.charValue=e.nextByte(t),n<0)e.done=!0;else if(!(n<=128))if(r=e.nextByte(t),e.charValue=e.charValue<<8|r,n>=129&&n<=254){if(r>=64&&r<=126||r>=80&&r<=254)break e;if(r>=48&&r<=57&&(i=e.nextByte(t),i>=129&&i<=254&&(o=e.nextByte(t),o>=48&&o<=57))){e.charValue=e.charValue<<16|i<<8|o;break e}e.error=!0}else;return 0==e.done}};var or={},sr=Fn&&Fn.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(or,"__esModule",{value:!0}),or.KOI8_R=or.windows_1256=or.windows_1251=or.ISO_8859_9=or.ISO_8859_8=or.ISO_8859_7=or.ISO_8859_6=or.ISO_8859_5=or.ISO_8859_2=or.ISO_8859_1=void 0;const ar=sr($n);class lr{constructor(e,t){this.byteIndex=0,this.ngram=0,this.ngramCount=0,this.hitCount=0,this.spaceChar=32,this.ngramList=e,this.byteMap=t}search(e,t){let n=0;return e[n+32]<=t&&(n+=32),e[n+16]<=t&&(n+=16),e[n+8]<=t&&(n+=8),e[n+4]<=t&&(n+=4),e[n+2]<=t&&(n+=2),e[n+1]<=t&&(n+=1),e[n]>t&&(n-=1),n<0||e[n]!=t?-1:n}lookup(e){this.ngramCount+=1,this.search(this.ngramList,e)>=0&&(this.hitCount+=1)}addByte(e){this.ngram=(this.ngram<<8)+(255&e)&16777215,this.lookup(this.ngram)}nextByte(e){return this.byteIndex>=e.inputLen?-1:255&e.inputBytes[this.byteIndex++]}parse(e,t){let n,r=!1;for(this.spaceChar=t;(n=this.nextByte(e))>=0;){const e=this.byteMap[n];0!=e&&(e==this.spaceChar&&r||this.addByte(e),r=e==this.spaceChar)}this.addByte(this.spaceChar);const i=this.hitCount/this.ngramCount;return i>.33?98:Math.floor(300*i)}}class cr{constructor(e,t){this.fLang=e,this.fNGrams=t}}class hr{constructor(){this.spaceChar=32,this.nGramLang=void 0}ngrams(){return[]}byteMap(){return[]}name(e){return"sbcs"}language(){return this.nGramLang}match(e){this.nGramLang=void 0;const t=this.ngrams();if(n=t,Array.isArray(n)&&isFinite(n[0])){const n=new lr(t,this.byteMap()).parse(e,this.spaceChar);return n<=0?null:(0,ar.default)(e,this,n)}var n;let r=-1;for(let n=t.length-1;n>=0;n--){const i=t[n],o=new lr(i.fNGrams,this.byteMap()).parse(e,this.spaceChar);o>r&&(r=o,this.nGramLang=i.fLang)}return r<=0?null:(0,ar.default)(e,this,r)}}or.ISO_8859_1=class extends hr{byteMap(){return[32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,0,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,32,32,32,32,32,32,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,170,32,32,32,32,32,32,32,32,32,32,181,32,32,32,32,186,32,32,32,32,32,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,32,248,249,250,251,252,253,254,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,32,248,249,250,251,252,253,254,255]}ngrams(){return[new cr("da",[2122086,2122100,2122853,2123118,2123122,2123375,2123873,2124064,2125157,2125671,2126053,2126697,2126708,2126953,2127465,6383136,6385184,6385252,6386208,6386720,6579488,6579566,6579570,6579572,6627443,6644768,6644837,6647328,6647396,6648352,6648421,6648608,6648864,6713202,6776096,6776174,6776178,6907749,6908960,6909543,7038240,7039845,7103858,7104871,7105637,7169380,7234661,7234848,7235360,7235429,7300896,7302432,7303712,7398688,7479396,7479397,7479411,7496992,7566437,7610483,7628064,7628146,7629164,7759218]),new cr("de",[2122094,2122101,2122341,2122849,2122853,2122857,2123113,2123621,2123873,2124142,2125161,2126691,2126693,2127214,2127461,2127471,2127717,2128501,6448498,6514720,6514789,6514804,6578547,6579566,6579570,6580581,6627428,6627443,6646126,6646132,6647328,6648352,6648608,6776174,6841710,6845472,6906728,6907168,6909472,6909541,6911008,7104867,7105637,7217249,7217252,7217267,7234592,7234661,7234848,7235360,7235429,7238757,7479396,7496805,7497065,7562088,7566437,7610468,7628064,7628142,7628146,7695972,7695975,7759218]),new cr("en",[2122016,2122094,2122341,2122607,2123375,2123873,2123877,2124142,2125153,2125670,2125938,2126437,2126689,2126708,2126952,2126959,2127720,6383972,6384672,6385184,6385252,6386464,6386720,6386789,6386793,6561889,6561908,6627425,6627443,6627444,6644768,6647412,6648352,6648608,6713202,6840692,6841632,6841714,6906912,6909472,6909543,6909806,6910752,7217249,7217268,7234592,7235360,7238688,7300640,7302688,7303712,7496992,7500576,7544929,7544948,7561577,7566368,7610484,7628146,7628897,7628901,7629167,7630624,7631648]),new cr("es",[2122016,2122593,2122607,2122853,2123116,2123118,2123123,2124142,2124897,2124911,2125921,2125935,2125938,2126197,2126437,2126693,2127214,2128160,6365283,6365284,6365285,6365292,6365296,6382441,6382703,6384672,6386208,6386464,6515187,6516590,6579488,6579564,6582048,6627428,6627429,6627436,6646816,6647328,6647412,6648608,6648692,6907246,6943598,7102752,7106419,7217253,7238757,7282788,7282789,7302688,7303712,7303968,7364978,7435621,7495968,7497075,7544932,7544933,7544944,7562528,7628064,7630624,7693600,15953440]),new cr("fr",[2122101,2122607,2122849,2122853,2122869,2123118,2123124,2124897,2124901,2125921,2125935,2125938,2126197,2126693,2126703,2127214,2154528,6385268,6386793,6513952,6516590,6579488,6579571,6583584,6627425,6627427,6627428,6627429,6627436,6627440,6627443,6647328,6647412,6648352,6648608,6648864,6649202,6909806,6910752,6911008,7102752,7103776,7103859,7169390,7217252,7234848,7238432,7238688,7302688,7302772,7304562,7435621,7479404,7496992,7544929,7544932,7544933,7544940,7544944,7610468,7628064,7629167,7693600,7696928]),new cr("it",[2122092,2122600,2122607,2122853,2122857,2123040,2124140,2124142,2124897,2125925,2125938,2127214,6365283,6365284,6365296,6365299,6386799,6514789,6516590,6579564,6580512,6627425,6627427,6627428,6627433,6627436,6627440,6627443,6646816,6646892,6647412,6648352,6841632,6889569,6889571,6889572,6889587,6906144,6908960,6909472,6909806,7102752,7103776,7104800,7105633,7234848,7235872,7237408,7238757,7282785,7282788,7282793,7282803,7302688,7302757,7366002,7495968,7496992,7563552,7627040,7628064,7629088,7630624,8022383]),new cr("nl",[2122092,2122341,2122849,2122853,2122857,2123109,2123118,2123621,2123877,2124142,2125153,2125157,2125680,2126949,2127457,2127461,2127471,2127717,2128489,6381934,6381938,6385184,6385252,6386208,6386720,6514804,6579488,6579566,6579570,6627426,6627446,6645102,6645106,6647328,6648352,6648435,6648864,6776174,6841716,6907168,6909472,6909543,6910752,7217250,7217252,7217253,7217256,7217263,7217270,7234661,7235360,7302756,7303026,7303200,7303712,7562088,7566437,7610468,7628064,7628142,7628146,7758190,7759218,7761775]),new cr("no",[2122100,2122102,2122853,2123118,2123122,2123375,2123873,2124064,2125157,2125671,2126053,2126693,2126699,2126703,2126708,2126953,2127465,2155808,6385252,6386208,6386720,6579488,6579566,6579572,6627443,6644768,6647328,6647397,6648352,6648421,6648864,6648948,6713202,6776174,6908779,6908960,6909543,7038240,7039845,7103776,7105637,7169380,7169390,7217267,7234848,7235360,7235429,7237221,7300896,7302432,7303712,7398688,7479411,7496992,7565165,7566437,7610483,7628064,7628142,7628146,7629164,7631904,7631973,7759218]),new cr("pt",[2122016,2122607,2122849,2122853,2122863,2123040,2123123,2125153,2125423,2125600,2125921,2125935,2125938,2126197,2126437,2126693,2127213,6365281,6365283,6365284,6365296,6382693,6382703,6384672,6386208,6386273,6386464,6516589,6516590,6578464,6579488,6582048,6582131,6627425,6627428,6647072,6647412,6648608,6648692,6906144,6906721,7169390,7238757,7238767,7282785,7282787,7282788,7282789,7282800,7303968,7364978,7435621,7495968,7497075,7544929,7544932,7544933,7544944,7566433,7628064,7630624,7693600,14905120,15197039]),new cr("sv",[2122100,2122102,2122853,2123118,2123510,2123873,2124064,2124142,2124655,2125157,2125667,2126053,2126699,2126703,2126708,2126953,2127457,2127465,2155634,6382693,6385184,6385252,6386208,6386804,6514720,6579488,6579566,6579570,6579572,6644768,6647328,6648352,6648864,6747762,6776174,6909036,6909543,7037216,7105568,7169380,7217267,7233824,7234661,7235360,7235429,7235950,7299944,7302432,7302688,7398688,7479393,7479411,7495968,7564129,7565165,7610483,7627040,7628064,7628146,7629164,7631904,7758194,14971424,16151072])]}name(e){return e&&e.c1Bytes?"windows-1252":"ISO-8859-1"}};or.ISO_8859_2=class extends hr{byteMap(){return[32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,0,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,32,32,32,32,32,32,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,177,32,179,32,181,182,32,32,185,186,187,188,32,190,191,32,177,32,179,32,181,182,183,32,185,186,187,188,32,190,191,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,32,248,249,250,251,252,253,254,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,32,248,249,250,251,252,253,254,32]}ngrams(){return[new cr("cs",[2122016,2122361,2122863,2124389,2125409,2125413,2125600,2125668,2125935,2125938,2126072,2126447,2126693,2126703,2126708,2126959,2127392,2127481,2128481,6365296,6513952,6514720,6627440,6627443,6627446,6647072,6647533,6844192,6844260,6910836,6972704,7042149,7103776,7104800,7233824,7268640,7269408,7269664,7282800,7300206,7301737,7304052,7304480,7304801,7368548,7368554,7369327,7403621,7562528,7565173,7566433,7566441,7566446,7628146,7630573,7630624,7676016,12477728,14773997,15296623,15540336,15540339,15559968,16278884]),new cr("hu",[2122016,2122106,2122341,2123111,2123116,2123365,2123873,2123887,2124147,2124645,2124649,2124790,2124901,2125153,2125157,2125161,2125413,2126714,2126949,2156915,6365281,6365291,6365293,6365299,6384416,6385184,6388256,6447470,6448494,6645625,6646560,6646816,6646885,6647072,6647328,6648421,6648864,6648933,6648948,6781216,6844263,6909556,6910752,7020641,7075450,7169383,7170414,7217249,7233899,7234923,7234925,7238688,7300985,7544929,7567973,7567988,7568097,7596391,7610465,7631904,7659891,8021362,14773792,15299360]),new cr("pl",[2122618,2122863,2124064,2124389,2124655,2125153,2125161,2125409,2125417,2125668,2125935,2125938,2126697,2127648,2127721,2127737,2128416,2128481,6365296,6365303,6385257,6514720,6519397,6519417,6582048,6584937,6627440,6627443,6627447,6627450,6645615,6646304,6647072,6647401,6778656,6906144,6907168,6907242,7037216,7039264,7039333,7170405,7233824,7235937,7235941,7282800,7305057,7305065,7368556,7369313,7369327,7369338,7502437,7502457,7563754,7564137,7566433,7825765,7955304,7957792,8021280,8022373,8026400,15955744]),new cr("ro",[2122016,2122083,2122593,2122597,2122607,2122613,2122853,2122857,2124897,2125153,2125925,2125938,2126693,2126819,2127214,2144873,2158190,6365283,6365284,6386277,6386720,6386789,6386976,6513010,6516590,6518048,6546208,6579488,6627425,6627427,6627428,6627440,6627443,6644e3,6646048,6646885,6647412,6648692,6889569,6889571,6889572,6889584,6907168,6908192,6909472,7102752,7103776,7106418,7107945,7234848,7238770,7303712,7365998,7496992,7497057,7501088,7594784,7628064,7631477,7660320,7694624,7695392,12216608,15625760])]}name(e){return e&&e.c1Bytes?"windows-1250":"ISO-8859-2"}};or.ISO_8859_5=class extends hr{byteMap(){return[32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,0,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,32,32,32,32,32,32,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,241,242,243,244,245,246,247,248,249,250,251,252,32,254,255,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,32,241,242,243,244,245,246,247,248,249,250,251,252,32,254,255]}ngrams(){return[2150944,2151134,2151646,2152400,2152480,2153168,2153182,2153936,2153941,2154193,2154462,2154464,2154704,2154974,2154978,2155230,2156514,2158050,13688280,13689580,13884960,14015468,14015960,14016994,14017056,14164191,14210336,14211104,14216992,14407133,14407712,14413021,14536736,14538016,14538965,14538991,14540320,14540498,14557394,14557407,14557409,14602784,14602960,14603230,14604576,14605292,14605344,14606818,14671579,14672085,14672088,14672094,14733522,14734804,14803664,14803666,14803672,14806816,14865883,14868e3,14868192,14871584,15196894,15459616]}name(){return"ISO-8859-5"}language(){return"ru"}};or.ISO_8859_6=class extends hr{byteMap(){return[32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,0,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,32,32,32,32,32,32,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,32,32,32,32,32,224,225,226,227,228,229,230,231,232,233,234,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32]}ngrams(){return[2148324,2148326,2148551,2152932,2154986,2155748,2156006,2156743,13050055,13091104,13093408,13095200,13100064,13100227,13100231,13100232,13100234,13100236,13100237,13100239,13100243,13100249,13100258,13100261,13100264,13100266,13100320,13100576,13100746,13115591,13181127,13181153,13181156,13181157,13181160,13246663,13574343,13617440,13705415,13748512,13836487,14229703,14279913,14805536,14950599,14993696,15001888,15002144,15016135,15058720,15059232,15066656,15081671,15147207,15189792,15255524,15263264,15278279,15343815,15343845,15343848,15386912,15388960,15394336]}name(){return"ISO-8859-6"}language(){return"ar"}};or.ISO_8859_7=class extends hr{byteMap(){return[32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,0,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,32,32,32,32,32,32,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,161,162,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,220,32,221,222,223,32,252,32,253,254,192,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,32,243,244,245,246,247,248,249,250,251,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,32]}ngrams(){return[2154989,2154992,2155497,2155753,2156016,2156320,2157281,2157797,2158049,2158368,2158817,2158831,2158833,2159604,2159605,2159847,2159855,14672160,14754017,14754036,14805280,14806304,14807292,14807584,14936545,15067424,15069728,15147252,15199520,15200800,15278324,15327520,15330014,15331872,15393257,15393268,15525152,15540449,15540453,15540464,15589664,15725088,15725856,15790069,15790575,15793184,15868129,15868133,15868138,15868144,15868148,15983904,15984416,15987951,16048416,16048617,16050157,16050162,16050666,16052e3,16052213,16054765,16379168,16706848]}name(e){return e&&e.c1Bytes?"windows-1253":"ISO-8859-7"}language(){return"el"}};or.ISO_8859_8=class extends hr{byteMap(){return[32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,0,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,32,32,32,32,32,32,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,181,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,32,32,32,32,32]}ngrams(){return[new cr("he",[2154725,2154727,2154729,2154746,2154985,2154990,2155744,2155749,2155753,2155758,2155762,2155769,2155770,2157792,2157796,2158304,2159340,2161132,14744096,14950624,14950625,14950628,14950636,14950638,14950649,15001056,15065120,15068448,15068960,15071264,15071776,15278308,15328288,15328762,15329773,15330592,15331104,15333408,15333920,15474912,15474916,15523872,15524896,15540448,15540449,15540452,15540460,15540462,15540473,15655968,15671524,15787040,15788320,15788525,15920160,16261348,16312813,16378912,16392416,16392417,16392420,16392428,16392430,16392441]),new cr("he",[2154725,2154732,2155753,2155756,2155758,2155760,2157040,2157810,2157817,2158053,2158057,2158565,2158569,2160869,2160873,2161376,2161381,2161385,14688484,14688492,14688493,14688506,14738464,14738916,14740512,14741024,14754020,14754029,14754042,14950628,14950633,14950636,14950637,14950639,14950648,14950650,15002656,15065120,15066144,15196192,15327264,15327520,15328288,15474916,15474925,15474938,15528480,15530272,15591913,15591920,15591928,15605988,15605997,15606010,15655200,15655968,15918112,16326884,16326893,16326906,16376864,16441376,16442400,16442857])]}name(e){return e&&e.c1Bytes?"windows-1255":"ISO-8859-8"}language(){return"he"}};or.ISO_8859_9=class extends hr{byteMap(){return[32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,0,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,32,32,32,32,32,32,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,170,32,32,32,32,32,32,32,32,32,32,181,32,32,32,32,186,32,32,32,32,32,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,32,248,249,250,251,252,105,254,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,32,248,249,250,251,252,253,254,255]}ngrams(){return[2122337,2122345,2122357,2122849,2122853,2123621,2123873,2124140,2124641,2124655,2125153,2125676,2126689,2126945,2127461,2128225,6365282,6384416,6384737,6384993,6385184,6385405,6386208,6386273,6386429,6386685,6388065,6449522,6578464,6579488,6580512,6627426,6627435,6644841,6647328,6648352,6648425,6648681,6909029,6909472,6909545,6910496,7102830,7102834,7103776,7103858,7217249,7217250,7217259,7234657,7234661,7234848,7235872,7235950,7273760,7498094,7535982,7759136,7954720,7958386,16608800,16608868,16609021,16642301]}name(e){return e&&e.c1Bytes?"windows-1254":"ISO-8859-9"}language(){return"tr"}};or.windows_1251=class extends hr{byteMap(){return[32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,0,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,32,32,32,32,32,32,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,32,32,32,32,32,144,131,32,131,32,32,32,32,32,32,154,32,156,157,158,159,144,32,32,32,32,32,32,32,32,32,154,32,156,157,158,159,32,162,162,188,32,180,32,32,184,32,186,32,32,32,32,191,32,32,179,179,180,181,32,32,184,32,186,32,188,190,190,191,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255]}ngrams(){return[2155040,2155246,2155758,2156512,2156576,2157280,2157294,2158048,2158053,2158305,2158574,2158576,2158816,2159086,2159090,2159342,2160626,2162162,14740968,14742268,14937632,15068156,15068648,15069682,15069728,15212783,15263008,15263776,15269664,15459821,15460384,15465709,15589408,15590688,15591653,15591679,15592992,15593186,15605986,15605999,15606001,15655456,15655648,15655918,15657248,15657980,15658016,15659506,15724267,15724773,15724776,15724782,15786210,15787492,15856352,15856354,15856360,15859488,15918571,15920672,15920880,15924256,16249582,16512288]}name(){return"windows-1251"}language(){return"ru"}};or.windows_1256=class extends hr{byteMap(){return[32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,0,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,32,32,32,32,32,32,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,32,32,32,32,32,32,129,32,131,32,32,32,32,136,32,138,32,156,141,142,143,144,32,32,32,32,32,32,32,152,32,154,32,156,32,32,159,32,32,32,32,32,32,32,32,32,32,170,32,32,32,32,32,32,32,32,32,32,181,32,32,32,32,32,32,32,32,32,32,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,32,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,32,32,32,32,244,32,32,32,32,249,32,251,252,32,32,255]}ngrams(){return[2148321,2148324,2148551,2153185,2153965,2154977,2155492,2156231,13050055,13091104,13093408,13095200,13099296,13099459,13099463,13099464,13099466,13099468,13099469,13099471,13099475,13099482,13099486,13099491,13099494,13099501,13099808,13100064,13100234,13115591,13181127,13181149,13181153,13181155,13181158,13246663,13574343,13617440,13705415,13748512,13836487,14295239,14344684,14544160,14753991,14797088,14806048,14806304,14885063,14927648,14928160,14935072,14950599,15016135,15058720,15124449,15131680,15474887,15540423,15540451,15540454,15583520,15585568,15590432]}name(){return"windows-1256"}language(){return"ar"}};or.KOI8_R=class extends hr{byteMap(){return[32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,0,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,32,32,32,32,32,32,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,163,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,163,32,32,32,32,32,32,32,32,32,32,32,32,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223]}ngrams(){return[2147535,2148640,2149313,2149327,2150081,2150085,2150338,2150607,2150610,2151105,2151375,2151380,2151631,2152224,2152399,2153153,2153684,2154196,12701385,12702936,12963032,12963529,12964820,12964896,13094688,13181136,13223200,13224224,13226272,13419982,13420832,13424846,13549856,13550880,13552069,13552081,13553440,13553623,13574352,13574355,13574359,13617103,13617696,13618392,13618464,13620180,13621024,13621185,13684684,13685445,13685449,13685455,13812183,13813188,13881632,13882561,13882569,13882583,13944268,13946656,13946834,13948960,14272544,14603471]}name(){return"KOI8-R"}language(){return"ru"}};var dr={},ur=Fn&&Fn.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(dr,"__esModule",{value:!0}),dr.ISO_2022_CN=dr.ISO_2022_KR=dr.ISO_2022_JP=void 0;const fr=ur($n);class pr{constructor(){this.escapeSequences=[]}name(){return"ISO_2022"}match(e){let t,n,r,i,o=0,s=0,a=0;const l=e.inputBytes,c=e.inputLen;e:for(t=0;tnull!=e&&"object"==typeof e&&(isFinite(e.length)&&e.length>=0),function(e){var t=Fn&&Fn.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var i=Object.getOwnPropertyDescriptor(t,n);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,i)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),n=Fn&&Fn.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),r=Fn&&Fn.__importStar||function(e){if(e&&e.__esModule)return e;var r={};if(null!=e)for(var i in e)"default"!==i&&Object.prototype.hasOwnProperty.call(e,i)&&t(r,e,i);return n(r,e),r},i=Fn&&Fn.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(e,"__esModule",{value:!0}),e.detectFileSync=e.detectFile=e.analyse=e.detect=void 0;const o=i(Un),s=i(jn),a=i(Wn),l=r(Gn),c=r(Yn),h=r(or),d=r(dr),u=gr,f=[new a.default,new l.UTF_16BE,new l.UTF_16LE,new l.UTF_32BE,new l.UTF_32LE,new c.sjis,new c.big5,new c.euc_jp,new c.euc_kr,new c.gb_18030,new d.ISO_2022_JP,new d.ISO_2022_KR,new d.ISO_2022_CN,new h.ISO_8859_1,new h.ISO_8859_2,new h.ISO_8859_5,new h.ISO_8859_6,new h.ISO_8859_7,new h.ISO_8859_8,new h.ISO_8859_9,new h.windows_1251,new h.windows_1256,new h.KOI8_R,new s.default];e.detect=t=>{const n=(0,e.analyse)(t);return n.length>0?n[0].name:null};e.analyse=e=>{if(!(0,u.isByteArray)(e))throw new Error("Input must be a byte array, e.g. Buffer or Uint8Array");const t=[];for(let e=0;e<256;e++)t[e]=0;for(let n=e.length-1;n>=0;n--)t[255&e[n]]++;let n=!1;for(let e=128;e<=159;e+=1)if(0!==t[e]){n=!0;break}const r={byteStats:t,c1Bytes:n,rawInput:e,rawLen:e.length,inputBytes:e,inputLen:e.length},i=f.map((e=>e.match(r))).filter((e=>!!e)).sort(((e,t)=>t.confidence-e.confidence));return i};e.detectFile=(t,n={})=>new Promise(((r,i)=>{let s;const a=(0,o.default)(),l=(t,n)=>{s&&a.closeSync(s),t?i(t):r((0,e.detect)(n))};if(n&&n.sampleSize){s=a.openSync(t,"r");const e=Buffer.allocUnsafe(n.sampleSize);a.read(s,e,0,n.sampleSize,n.offset,(t=>{l(t,e)}))}else a.readFile(t,l)}));e.detectFileSync=(t,n={})=>{const r=(0,o.default)();if(n&&n.sampleSize){const i=r.openSync(t,"r"),o=Buffer.allocUnsafe(n.sampleSize);return r.readSync(i,o,0,n.sampleSize,n.offset),r.closeSync(i),(0,e.detect)(o)}return(0,e.detect)(r.readFileSync(t))},e.default={analyse:e.analyse,detect:e.detect,detectFileSync:e.detectFileSync,detectFile:e.detectFile}}(Hn);var mr=_n(Hn);class yr extends Ot{constructor(e,t,n,r){super({mode:t,format:"TXT",animation:n}),this.txtBuffer=e,this.charset=r}renderTo(e){return new Promise(((t,n)=>f(this,void 0,void 0,(function*(){this.element=e,this.book||(yield this.parse());let n=new L(this.book);this.chapterList=yield n.getChapter(this.book.toc),this.chapterDocList=yield n.getChapterDoc(),w(e);let r=this.getDocument();r&&(T(e,this.mode,r),t())}))))}parse(){return f(this,void 0,void 0,(function*(){try{const e=new TextDecoder(this.charset),t=new Uint8Array(this.txtBuffer);let n=e.decode(t);this.book=Ae(n,!0)}catch(e){throw console.log(e),e}}))}preCache(){return f(this,void 0,void 0,(function*(){return this.book||(yield this.parse()),yield Pt(this.book)}))}getMetadata(e){return f(this,void 0,void 0,(function*(){try{const t=new Uint8Array(e);let n=mr.detect(t);return this.charset=n||"utf8",{charset:n||"utf8"}}catch(e){throw console.log(e),e}}))}}const br=({entries:e,loadBlob:t,getSize:n},r)=>{const i=new Map,o=new Map,s=[".jpg",".jpeg",".png",".gif",".bmp",".webp",".svg"],a=e.map((e=>e.filename)).filter((e=>s.some((t=>e.endsWith(t))))).sort(),l={getCover:()=>t(a[0])};return l.metadata={title:r.name},l.sections=a.map((e=>({id:e,load:()=>(async e=>{if(i.has(e))return i.get(e);const n=URL.createObjectURL(await t(e)),r=URL.createObjectURL(new Blob([``],{type:"text/html"}));return o.set(e,[n,r]),i.set(e,r),r})(e),unload:()=>(e=>{o.get(e)?.forEach?.((e=>URL.revokeObjectURL(e))),o.delete(e),i.delete(e)})(e),size:n(e)}))),l.toc=a.map((e=>({label:e,href:e}))),l.rendition={layout:"pre-paginated"},l.resolveHref=e=>({index:l.sections.findIndex((t=>t.id===e))}),l.splitTOCHref=e=>[e,null],l.getTOCFragment=e=>e.documentElement,l};class wr extends Ot{constructor(e,t,n,r){super({mode:t,format:n,animation:r}),this.comicBuffer=e,this.mode=t,this.format=n,this.chapterList=[],this.chapterDocList=[],this.book="",this.element="",this.rpc}renderTo(e){return new Promise(((t,n)=>f(this,void 0,void 0,(function*(){if(this.element=e,w(e),!this.book)try{yield this.parse()}catch(e){console.log(e),n(e)}let r=new L(this.book);this.chapterList=yield r.getChapter(this.book.toc),this.chapterDocList=yield r.getChapterDoc();let i=this.getDocument();i&&(T(e,this.mode,i),t())}))))}parse(){return f(this,void 0,void 0,(function*(){try{let e=new Blob([this.comicBuffer]),t=new File([e],"book."+this.format.toLocaleLowerCase(),{lastModified:(new Date).getTime(),type:e.type});if("CBZ"===this.format){const e=yield this.makeZipLoader(t);this.book=br(e,t)}else if("CBT"===this.format){const e=yield this.makeTarLoader();this.book=br(e,t)}else if("CBR"===this.format){this.rpc=yield window.RPC.new("./lib/libunrar/worker.js",{loaded:function(){console.log("loaded")},progressShow:function(e,t,n){console.log(n)}}),yield new Promise((e=>setTimeout(e,200)));const e=yield this.makeRarLoader();this.book=br(e,t)}else if("CB7"===this.format){const e=yield this.make7zLoader();this.book=br(e,t)}}catch(e){throw console.log(e),e}}))}preCache(){return f(this,void 0,void 0,(function*(){return this.book||(yield this.parse()),yield Pt(this.book)}))}makeZipLoader(e){return f(this,void 0,void 0,(function*(){const t=new r(new i(e)),n=yield t.getEntries(),a=new Map(n.map((e=>[e.filename,e]))),l=e=>(t,...n)=>a.has(t)?e(a.get(t),...n):null;return{entries:n,loadText:l((e=>e.getData(new o))),loadBlob:l(((e,t)=>e.getData(new s(t)))),getSize:e=>{var t,n;return null!==(n=null===(t=a.get(e))||void 0===t?void 0:t.uncompressedSize)&&void 0!==n?n:0}}}))}makeTarLoader(){return f(this,void 0,void 0,(function*(){const e=yield c(this.comicBuffer),t=new Map(e.map((e=>[e.name,e]))),n=e=>(n,...r)=>t.has(n)?e(t.get(n),...r):null,r=n((e=>e.readAsString())),i=n(((e,t)=>e.blob));return{entries:e.map((e=>({filename:e.name}))),loadText:r,loadBlob:i,getSize:e=>{var n,r;return null!==(r=null===(n=t.get(e))||void 0===n?void 0:n.size)&&void 0!==r?r:0}}}))}makeRarLoader(){return f(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{var n=[this.comicBuffer],r=[{name:"book.rar",content:this.comicBuffer}];this.rpc.transferables=n,this.rpc.unrar(r,null,0).then((t=>{let n=this.getRarEntries(t.ls);const r=new Map(Object.values(n).map((e=>[e.fullFileName,e]))),i=e=>(t,...n)=>r.has(t)?e(r.get(t),...n):null,o=i((e=>e.fullFileName)),s=i(((e,t)=>new Blob([e.fileContent])));e({entries:Object.values(n).map((e=>({filename:e.fullFileName}))),loadText:o,loadBlob:s,getSize:e=>{var t,n;return null!==(n=null===(t=r.get(e))||void 0===t?void 0:t.fileSize)&&void 0!==n?n:0}})})).catch((e=>{t(e),console.log(e)}))}))}))}make7zLoader(){return f(this,void 0,void 0,(function*(){const e="./lib/7z-wasm/7zz.wasm";if(!window.wasmBinary){const t=yield fetch(e,{credentials:"same-origin"});if(!t.ok)throw"failed to load wasm binary file at '"+e+"'";window.wasmBinary=yield t.arrayBuffer()}const t=yield window.SevenZip({wasmBinary:window.wasmBinary}),n=new Uint8Array(this.comicBuffer),r="archive.cb7",i=t.FS.open(r,"w+");t.FS.write(i,n,0,n.length),t.FS.close(i),t.callMain(["x",r]);const o=t.FS,s=this.get7zEntries(o.lookupPath("/").node),a=new Map(s.map((e=>[e.name,e]))),l=e=>(t,...n)=>a.has(t)?e(a.get(t),...n):null,c=l((e=>e.name)),h=l(((e,t)=>new Blob([e.buffer])));return{entries:s.map((e=>({filename:e.name}))),loadText:c,loadBlob:h,getSize:e=>{var t,n;return null!==(n=null===(t=a.get(e))||void 0===t?void 0:t.packSize)&&void 0!==n?n:0}}}))}getRarEntries(e){const t=Object.keys(e);let n=[];for(let r=0;r"archive.cb7"!=e&&"dev"!=e&&"home"!=e&&"proc"!=e&&"tmp"!=e));let r=[];for(let e=0;ef(this,void 0,void 0,(function*(){try{this.book||(yield this.parse());const t=yield this.book.getCover();var n=new FileReader;n.readAsDataURL(t),n.onloadend=()=>{e({cover:n.result})}}catch(e){console.log(e),t(e)}}))))}))}}const vr=e=>e?.trim()?.replace(/\s{2,}/g," "),xr=e=>vr(e?.textContent),Cr={XLINK:"http://www.w3.org/1999/xlink",EPUB:"http://www.idpf.org/2007/ops"},Sr="application/xml",Tr="application/xhtml+xml",Lr={strong:["strong","self"],emphasis:["em","self"],style:["span","self"],a:"anchor",strikethrough:["s","self"],sub:["sub","self"],sup:["sup","self"],code:["code","self"],image:"image"},kr={epigraph:["blockquote"],subtitle:["h2",Lr],"text-author":["p",Lr],date:["p",Lr],stanza:"stanza"},Ar={title:["header",{p:["h1",Lr],"empty-line":["br"]}],epigraph:["blockquote","self"],image:"image",annotation:["aside"],section:["section","self"],p:["p",Lr],poem:["blockquote",kr],subtitle:["h2",Lr],cite:["blockquote","self"],"empty-line":["br"],table:["table",{tr:["tr",["align"]],th:["th",["colspan","rowspan","align","valign"]],td:["td",["colspan","rowspan","align","valign"]]}],"text-author":["p",Lr]};kr.epigraph.push(Ar);const Ir={image:"image",title:["section",{p:["h1",Lr],"empty-line":["br"]}],epigraph:["section",Ar],section:["section",Ar]},Er=e=>{const t=e.getAttributeNS(Cr.XLINK,"href"),[,n]=t.split("#"),r=e.getRootNode().getElementById(n);return r?`data:${r.getAttribute("content-type")};base64,${r.textContent}`:t};class Mr{constructor(e){this.fb2=e,this.doc=document.implementation.createDocument(Cr.XHTML,"html")}image(e){const t=this.doc.createElement("img");return t.alt=e.getAttribute("alt"),t.title=e.getAttribute("title"),t.setAttribute("src",Er(e)),t}anchor(e){const t=this.convert(e,{a:["a",Lr]});return t.setAttribute("href",e.getAttributeNS(Cr.XLINK,"href")),"note"===e.getAttribute("type")&&t.setAttributeNS(Cr.EPUB,"epub:type","noteref"),t}stanza(e){const t=this.convert(e,{stanza:["p",{title:["header",{p:["strong",Lr],"empty-line":["br"]}],subtitle:["p",Lr]}]});for(const n of e.children)"v"===n.nodeName&&(t.append(this.doc.createTextNode(n.textContent)),t.append(this.doc.createElement("br")));return t}convert(e,t){if(3===e.nodeType)return this.doc.createTextNode(e.textContent);if(4===e.nodeType)return this.doc.createCDATASection(e.textContent);if(8===e.nodeType)return this.doc.createComment(e.textContent);const n=t?.[e.nodeName];if(!n)return null;if("string"==typeof n)return this[n](e);const[r,i]=n,o=this.doc.createElement(r);if(e.id&&(o.id=e.id),o.classList.add(e.nodeName),Array.isArray(i))for(const t of i)o.setAttribute(t,e.getAttribute(t));const s="self"===i?t:Array.isArray(i)?null:i;let a=e.firstChild;for(;a;){const e=this.convert(a,s);e&&o.append(e),a=a.nextSibling}return o}}const Br=URL.createObjectURL(new Blob(['\n@namespace epub "http://www.idpf.org/2007/ops";\nbody > img, section > img {\n display: block;\n margin: auto;\n}\n.title {\n text-align: center;\n}\nbody > section > .title, body.notesBodyType > .title {\n margin: 3em 0;\n}\nbody.notesBodyType > section .title {\n text-align: left;\n margin: 1em 0;\n}\np {\n text-indent: 1em;\n margin: 0;\n}\n:not(p) + p, p:first-child {\n text-indent: 0;\n}\n.poem p {\n text-indent: 0;\n margin: 1em 0;\n}\n.text-author, .date {\n text-align: end;\n}\n.text-author:before {\n content: "—";\n}\ntable {\n border-collapse: collapse;\n}\ntd, th {\n padding: .25em;\n}\na[epub|type~="noteref"] {\n font-size: .75em;\n vertical-align: super;\n}\nbody:not(.notesBodyType) > .title, body:not(.notesBodyType) > .epigraph {\n margin: 3em 0;\n}\n'],{type:"text/css"})),Or="data-foliate-id",Dr=async e=>{const t={},n=await(async e=>{const t=await e.arrayBuffer(),n=new TextDecoder("utf-8").decode(t),r=new DOMParser,i=r.parseFromString(n,Sr),o=i.xmlEncoding||n.match(/^<\?xml\s+version\s*=\s*["']1.\d+"\s+encoding\s*=\s*["']([A-Za-z0-9._-]*)["']/)?.[1];if(o&&"utf-8"!==o.toLowerCase()){const e=new TextDecoder(o).decode(t);return r.parseFromString(e,Sr)}return i})(e),r=new Mr(n),i=e=>n.querySelector(e),o=e=>[...n.querySelectorAll(e)],s=e=>{const t=xr(e.querySelector("nickname"));if(t)return t;const n=xr(e.querySelector("first-name")),r=xr(e.querySelector("middle-name")),i=xr(e.querySelector("last-name"));return{name:[n,r,i].filter((e=>e)).join(" "),sortAs:i?[i,[n,r].filter((e=>e)).join(" ")].join(", "):null}},a=e=>e?.getAttribute("value")??xr(e),l=i("title-info annotation");t.metadata={title:xr(i("title-info book-title")),identifier:xr(i("document-info id")),language:xr(i("title-info lang")),author:o("title-info author").map(s),translator:o("title-info translator").map(s),producer:o("document-info author").map(s).concat(o("document-info program-used").map(xr)),publisher:xr(i("publish-info publisher")),published:a(i("title-info date")),modified:a(i("document-info date")),description:l?r.convert(l,{annotation:["div",Ar]}).innerHTML:null,subject:o("title-info genre").map(xr)},t.getCover=()=>fetch(Er(i("coverpage image"))).then((e=>e.blob()));const c=Array.from(n.querySelectorAll("body"),(e=>{const t=r.convert(e,{body:["body",Ir]});return[Array.from(t.children,(e=>{const t=[e,...e.querySelectorAll("[id]")].map((e=>e.id));return{el:e,ids:t}})),t]})),h=c[0][0].map((({el:e,ids:t})=>({ids:t,titles:Array.from(e.querySelectorAll(":scope > section > .title"),((e,t)=>(e.setAttribute(Or,t),{title:xr(e),index:t}))),el:e}))).concat(c.slice(1).map((([e,t])=>{const n=e.map((e=>e.ids)).flat();return t.classList.add("notesBodyType"),{ids:n,el:t,linear:"no"}}))).map((({ids:e,titles:t,el:n,linear:r})=>{const i=(o=n.outerHTML,`\n\n \n ${o}\n`);var o;const s=new Blob([i],{type:Tr}),a=URL.createObjectURL(s);return{ids:e,title:vr(n.querySelector(".title, .subtitle, p")?.textContent??(n.classList.contains("title")?n.textContent:"")),titles:t,load:()=>a,createDocument:()=>(new DOMParser).parseFromString(i,Tr),size:s.size-Array.from(n.querySelectorAll("[src]"),(e=>e.getAttribute("src")?.length??0)).reduce(((e,t)=>e+t),0),linear:r}})),d=new Map;return t.sections=h.map(((e,t)=>{const{ids:n,load:r,createDocument:i,size:o,linear:s}=e;for(const e of n)e&&d.set(e,t);return{id:t,load:r,createDocument:i,size:o,linear:s}})),t.toc=h.map((({title:e,titles:t},n)=>{const r=n.toString();return{label:e,href:r,subitems:t?.length?t.map((({title:e,index:t})=>({label:e,href:`${r}#${t}`}))):null}})).filter((e=>e)),t.resolveHref=e=>{const[t,n]=e.split("#");return t?{index:Number(t),anchor:e=>e.querySelector(`[${Or}="${n}"]`)}:{index:d.get(n),anchor:e=>e.getElementById(n)}},t.splitTOCHref=e=>e?.split("#")?.map((e=>Number(e)))??[],t.getTOCFragment=(e,t)=>e.querySelector(`[${Or}="${t}"]`),t};class Nr extends Ot{constructor(e,t,n){super({mode:t,format:"FB2",animation:n}),this.fb2Buffer=e}renderTo(e){return new Promise(((t,n)=>f(this,void 0,void 0,(function*(){this.element=e,this.book||(yield this.parse());let n=new L(this.book);this.chapterList=yield n.getChapter(this.book.toc),this.chapterDocList=yield n.getChapterDoc(),w(e);let r=this.getDocument();r&&(T(e,this.mode,r),t())}))))}parse(){return f(this,void 0,void 0,(function*(){try{let e=new Blob([this.fb2Buffer]);this.book=yield Dr(e)}catch(e){throw console.log(e),e}}))}preCache(){return f(this,void 0,void 0,(function*(){return this.book||(yield this.parse()),yield Pt(this.book)}))}getMetadata(){return f(this,void 0,void 0,(function*(){try{this.book||(yield this.parse());let e=new L(this.book);return yield e.getMetadata()}catch(e){throw console.log(e),e}}))}}class Rr extends Ot{constructor(e,t,n){super({mode:t,format:"CACHE",animation:n}),this.cacheBuffer=e}renderTo(e){return new Promise(((t,n)=>f(this,void 0,void 0,(function*(){this.element=e,this.book=yield Rt(this.cacheBuffer);let n=new L(this.book);this.chapterList=yield n.getChapter(this.book.toc),this.chapterDocList=yield n.getChapterDoc(),w(e);let r=this.getDocument();r&&(T(e,this.mode,r),t())}))))}}class Pr extends Ot{constructor(e,t,n){super({mode:t,format:"DOCX",animation:n}),this.docxBuffer=e}renderTo(e){return new Promise(((t,n)=>f(this,void 0,void 0,(function*(){this.element=e,this.book||(yield this.parse());let n=new L(this.book);this.chapterList=yield n.getChapter(this.book.toc),this.chapterDocList=yield n.getChapterDoc(),w(e);let r=this.getDocument();r&&(T(e,this.mode,r),t())}))))}parse(){return f(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{try{h.convertToHtml({arrayBuffer:this.docxBuffer}).then((t=>f(this,void 0,void 0,(function*(){this.book=Ae(t.value,!1),e()}))))}catch(e){console.log(e),t(e)}}))}))}preCache(){return f(this,void 0,void 0,(function*(){return this.book||(yield this.parse()),yield Pt(this.book)}))}}class Fr extends Ot{constructor(e,t,n){super({mode:t,format:"MD",animation:n}),this.mdBuffer=e}renderTo(e){return new Promise(((t,n)=>f(this,void 0,void 0,(function*(){this.element=e,this.book||(yield this.parse());let n=new L(this.book);this.chapterList=yield n.getChapter(this.book.toc),this.chapterDocList=yield n.getChapterDoc(),w(e);let r=this.getDocument();r&&(T(e,this.mode,r),t())}))))}parse(){return f(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{try{var n=new Blob([this.mdBuffer],{type:"text/plain"}),r=new FileReader;r.onload=t=>f(this,void 0,void 0,(function*(){var n;let r=yield d(null===(n=t.target)||void 0===n?void 0:n.result);this.book=Ae(r,!1),e()})),r.readAsText(n,"UTF-8")}catch(e){console.log(e),t(e)}}))}))}preCache(){return f(this,void 0,void 0,(function*(){return this.book||(yield this.parse()),yield Pt(this.book)}))}}class _r extends Ot{constructor(e,t,n,r){super({mode:t,format:n,animation:r}),this.htmlBuffer=e}renderTo(e){return new Promise(((t,n)=>f(this,void 0,void 0,(function*(){this.element=e,this.book||(yield this.parse());let n=new L(this.book);this.chapterList=yield n.getChapter(this.book.toc),this.chapterDocList=yield n.getChapterDoc(),w(e);let r=this.getDocument();r&&(T(e,this.mode,r),t())}))))}parse(){return f(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{try{var n=new Blob([this.htmlBuffer],{type:Dt[this.format.toLocaleLowerCase()]}),r=new FileReader;r.onload=t=>f(this,void 0,void 0,(function*(){var n;let r=null===(n=t.target)||void 0===n?void 0:n.result;"MHTML"===this.format&&(r=u.convert(r).window.document.documentElement.innerHTML),this.book=Ae(r,!1),e()})),r.readAsText(n,"UTF-8")}catch(e){console.log(e),t(e)}}))}))}preCache(){return f(this,void 0,void 0,(function*(){return this.book||(yield this.parse()),yield Pt(this.book)}))}}export{Rr as CacheRender,wr as ComicRender,Pr as DocxRender,Ft as EpubRender,Nr as Fb2Render,_r as HtmlRender,Fr as MdRender,An as MobiRender,Pn as PdfRender,yr as TxtRender}; +import e from"chinese-s2t";import t from"underscore";import n from"rangy/lib/rangy-core.js";import"rangy/lib/rangy-textrange";import{ZipReader as r,BlobReader as i,TextWriter as o,BlobWriter as s}from"@zip.js/zip.js";import a from"jszip";import{unzlibSync as l}from"fflate";import c from"js-untar";import h from"mammoth";import{marked as d}from"marked";import u from"mhtml2html";function f(e,t,n,r){return new(n||(n=Promise))((function(i,o){function s(e){try{l(r.next(e))}catch(e){o(e)}}function a(e){try{l(r.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}l((r=r.apply(e,t||[])).next())}))}const p=e=>e?parseFloat(e+""):0,g=(e,t)=>f(void 0,void 0,void 0,(function*(){let n="";if(e.load){let t=yield fetch(yield e.load()).then((e=>e.blob()));n=yield t.text()}return t||(e.loadAsset&&(n=yield y(n,e.loadAsset)),n=b(n)),n})),m=e=>Array.from(e.querySelectorAll("img, image")),y=(e,t)=>f(void 0,void 0,void 0,(function*(){let n=(new DOMParser).parseFromString(e,"text/html"),r=m(n);for(let e=0;e{let t=(new DOMParser).parseFromString(e,"text/html"),n=m(t);if(0===n.length)return e;for(let e=0;e{var n=document.createElement("iframe");n.style.width="100%",n.style.border="0",n.style.margin="0",n.style.padding="0",n.style.minHeight="calc(100% - 2px)",n.style.fontSize="100%",n.style.font="inherit",n.scrolling="no",n.tabIndex=0,n.style.verticalAlign="baseline",e.innerHTML="",e.appendChild(n)},v=(e,t)=>({totalPage:"scroll"===e?1:parseInt(t.body.scrollWidth/t.body.clientWidth+"")+1,currentPage:parseInt(p(t.body.scrollLeft)/t.body.clientWidth+"")+1}),x=e=>{let t=e.querySelectorAll("a, article, cite, div, li, p, span, pre, table, bold, body");for(let e=0;ef(void 0,void 0,void 0,(function*(){const t=new Image;t.src=e;try{yield t.decode()}catch(e){console.log(e)}return t})),S=(e,t,n,r)=>f(void 0,void 0,void 0,(function*(){let i=Math.floor(e.clientWidth/12),o=i%2==0?i:i-1,s=r.querySelectorAll("img, image");for(let i of s){let s=i.parentElement,a=0,l=0,c=i.naturalWidth,h=i.naturalHeight;if("image"===i.tagName){let e=yield C(i.getAttribute("xlink:href"));console.log(e,"img"),c=e.naturalWidth,h=e.naturalHeight}if(n.startsWith("CB")&&"scroll"===t)l=s.offsetWidth;else if(n.startsWith("CB")&&"single"===t)a=e.clientHeight,l=e.clientWidth;else if(c&&h){h/c>s.clientHeight/s.clientWidth?(a=s.clientHeight,l=parseInt(a*c/h+"")):(l=s.clientWidth,a=parseInt(l*h/c+"")),a>r.body.clientHeight&&(l=parseInt(l*(r.body.clientHeight/a)+""),a=r.body.clientHeight)}else s&&s.clientWidth&&s.clientWidth>0?(l=s.clientWidth,a=s.clientHeight):(l=e.clientWidth,a=e.clientHeight);l=l?Math.min("scroll"===t||"single"===t?e.clientWidth:(e.clientWidth-o)/2,l):"scroll"===t||"single"===t?e.clientWidth:(e.clientWidth-o)/2,c&&h&&(c>h||a/l>h/c?a=l*(h/c):l=a*(c/h)),(l||a)&&i.setAttribute("style",i.getAttribute("style")+";"+`max-width: ${l>0?l+"px":""};max-height:${a>0?a+"px":""}; margin: 0 auto; ${n.startsWith("CB")?"display: block; margin-left: auto; margin-right: auto;":""}`)}})),T=(e,t,n)=>{let r=n.createElement("style");if(r.id="default-style",r.textContent="p,empty-line{display: inherit;margin-block-start: inherit;margin-block-end: inherit;margin-inline-start: inherit;margin-inline-end: inherit;}body{margin: 0px}",n.head.appendChild(r),"scroll"===t)return;let i="double"===t?2:1,o=Math.floor(e.clientWidth/12),s=o%2==0?o:o-1;n.body.setAttribute("style",`width: auto;height: 100%;overflow-y: hidden;overflow-X: hidden;padding-left: 0px;padding-right: 0px;margin: 0px;box-sizing: border-box;max-width: inherit;column-fill: auto;column-gap: ${s}px; column-width: ${(e.clientWidth-s)/i}px;`)};class L{constructor(e){this.book=e,this.chapterList=[],this.flattenChapters=[],this.chapterDocList=[]}getChapter(e){return f(this,void 0,void 0,(function*(){return this.chapterList=e?yield Promise.all(e.map((e=>f(this,void 0,void 0,(function*(){let t=-1;try{t=e.href&&(yield this.book.resolveHref(e.href))?(yield this.book.resolveHref(e.href)).index:-1}catch(e){console.log(e)}return{label:e.label?e.label:t,href:e.href?e.href:"title"+t,index:t,subitems:e.subitems?yield this.getChapter(e.subitems):[]}}))))):yield Promise.all(this.book.sections.map(((e,t)=>f(this,void 0,void 0,(function*(){return{label:e.label?e.label:t,href:e.href?e.href:"title"+t,index:t,subitems:e.subitems?yield this.getChapter(e.subitems):[]}}))))),this.flattenChapters=this.flatChapter(this.chapterList),this.chapterList}))}getChapterDoc(){return f(this,void 0,void 0,(function*(){const e=this.flattenChapters.map((e=>e.index));return this.book.sections.map(((t,n)=>e.indexOf(n)>-1?{label:this.flattenChapters[e.indexOf(n)].label,href:this.flattenChapters[e.indexOf(n)].href,text:t}:{label:"",href:"",text:t}))}))}flatChapter(e){let t=[];for(let n=0;n0?(t.push(e[n]),t=t.concat(this.flatChapter(e[n].subitems))):t.push(e[n]);return t}getMetadata(){return new Promise(((e,t)=>f(this,void 0,void 0,(function*(){const n=this.book.metadata;try{const t=yield this.book.getCover();var r=new FileReader;r.readAsDataURL(t),r.onloadend=()=>{e({name:n.title,author:n.author?n.author[0].name:"",description:n.description,publisher:n.publisher,cover:r.result})}}catch(r){try{let t=n.author&&n.author[0]&&n.author[0].name?n.author[0].name:n.author&&n.author[0]?n.author[0]:n.author?n.author:"";e({name:n.title,author:t,description:n.description,publisher:n.publisher,cover:""})}catch(e){console.log(e),t(e)}}}))))}}const k=(e,t)=>[-1,...t,e.length].reduce((({xs:t,a:n},r)=>({xs:t?.concat([e.slice(n+1,r)])??[],a:r})),{}).xs,A=/\d/,I=/^epubcfi\((.*)\)$/,E=e=>e.replace(/[\^[\](),;=]/g,"^$&"),M=(e,t)=>{return n=([e])=>e===t,e.map(((e,t,r)=>n(e,t,r)?t:null)).filter((e=>null!=e));var n},B=e=>{const t=[];let n;for(const[r,i]of e){if("/"===r)t.push({index:i});else{const e=t[t.length-1];if(":"===r)e.offset=i;else if("~"===r)e.temporal=i;else if("@"===r)e.spatial=(e.spatial??[]).concat(i);else if(";s"===r)e.side=i;else if("["===r){if("/"!==n||!i){e.text=(e.text??[]).concat(i);continue}e.id=i}}n=r}return t},O=e=>k(e,M(e,"!")).map(B),D=e=>{const t=(e=>{const t=[];let n,r,i="";const o=e=>(t.push(e),n=null,i=""),s=e=>(i+=e,r=!1);for(const t of Array.from(e.trim()).concat(""))if("^"!==t||r){if("!"===n)o(["!"]);else if(","===n)o([","]);else if("/"===n||":"===n){if(A.test(t)){s(t);continue}o([n,parseInt(i)])}else if("~"===n){if(A.test(t)||"."===t){s(t);continue}o(["~",parseFloat(i)])}else if("@"===n){if(":"===t){o(["@",parseFloat(i)]),n="@";continue}if(A.test(t)||"."===t){s(t);continue}o(["@",parseFloat(i)])}else{if("["===n){";"!==t||r?","!==t||r?"]"!==t||r?s(t):o(["[",i]):(o(["[",i]),n="["):(o(["[",i]),n=";");continue}if(n?.startsWith(";")){"="!==t||r?";"!==t||r?"]"!==t||r?s(t):o([n,i]):(o([n,i]),n=";"):(n=`;${i}`,i="");continue}}"/"!==t&&":"!==t&&"~"!==t&&"@"!==t&&"["!==t&&"!"!==t&&","!==t||(n=t)}else r=!0;return t})((n=e,n.match(I)?.[1]??n));var n;const r=M(t,",");if(!r.length)return O(t);const[i,o,s]=k(t,r).map(O);return{parent:i,start:o,end:s}},N=({index:e,id:t,offset:n,temporal:r,spatial:i,text:o,side:s})=>{const a=s?`;s=${s}`:"";return`/${e}`+(t?`[${E(t)}${a}]`:"")+(null!=n&&e%2?`:${n}`:"")+(r?`~${r}`:"")+(i?`@${i.join(":")}`:"")+(o||!t&&s?"["+(o?.map(E)?.join(",")??"")+a+"]":"")},R=e=>e.parent?[e.parent,e.start,e.end].map(R).join(","):e.map((e=>e.map(N).join(""))).join("!"),P=e=>{return t=R(e),I.test(t)?t:`epubcfi(${t})`;var t},F=(e,t)=>{return"string"==typeof e?P(F(D(e),t)):e.parent?(n=e.parent,r=e[t?"end":"start"],n.slice(0,-1).concat([n[n.length-1].concat(r[0])]).concat(r.slice(1))):e;var n,r},_=({nodeType:e})=>3===e||4===e,H=({nodeType:e})=>1===e,U=e=>{const t=Array.from(e.childNodes).filter((e=>_(e)||H(e))).reduce(((e,t)=>{let n=e[e.length-1];return n?_(t)?Array.isArray(n)?n.push(t):_(n)?e[e.length-1]=[n,t]:e.push(t):H(n)?e.push(null,t):e.push(t):e.push(t),e}),[]);return H(t[0])&&t.unshift("first"),H(t[t.length-1])&&t.push("last"),t.unshift("before"),t.push("after"),t},j=(e,t)=>e?U(e)[t]:null,$=(e,t)=>{const{id:n}=t[t.length-1];if(n){const t=e.ownerDocument.getElementById(n);if(t)return{node:t,offset:0}}for(const{index:n}of t){const t=j(e,n);if("first"===t)return{node:e.firstChild??e};if("last"===t)return{node:e.lastChild??e};if("before"===t)return{node:e,before:!0};if("after"===t)return{node:e,after:!0};e=t}const{offset:r}=t[t.length-1];if(!Array.isArray(e))return{node:e,offset:r};let i=0;for(const t of e){const{length:e}=t.nodeValue;if(i+e>=r)return{node:t,offset:r-i};i+=e}},z=(e,t)=>{const{parentNode:n,id:r}=e,i=U(n),o=i.findIndex((t=>Array.isArray(t)?t.some((t=>t===e)):t===e)),s=i[o];if(Array.isArray(s)){let n=0;for(const r of s){if(r===e){n+=t;break}n+=r.nodeValue.length}t=n}const a={id:r,index:o,offset:t};return n!==e.ownerDocument.documentElement?z(n).concat(a):[a]},q=(e,t)=>$(e.documentElement,F(t)).node,W="urn:oasis:names:tc:opendocument:xmlns:container",X="http://www.w3.org/1999/xhtml",V="http://www.idpf.org/2007/opf",G="http://www.idpf.org/2007/ops",J="http://purl.org/dc/elements/1.1/",K="http://www.w3.org/2001/04/xmlenc#",Z="http://www.daisy.org/z3986/2005/ncx/",Y="http://www.w3.org/1999/xlink",Q="http://www.w3.org/ns/SMIL",ee={XML:"application/xml",NCX:"application/x-dtbncx+xml",XHTML:"application/xhtml+xml",HTML:"text/html",CSS:"text/css",SVG:"image/svg+xml",JS:/\/(x-)?(javascript|ecmascript)/},te=e=>e.toLowerCase().replace(/[-:](.)/g,((e,t)=>t.toUpperCase())),ne=(e,t,n)=>n?n=>n.getAttribute(e)?.split(/\s/)?.includes(t):"function"==typeof t?n=>t(n.getAttribute(e)):n=>n.getAttribute(e)===t,re=(...e)=>t=>t?Object.fromEntries(e.map((e=>[te(e),t.getAttribute(e)]))):null,ie=e=>{return t=e?.textContent,t?t.trim().replace(/\s{2,}/g," "):"";var t},oe=(e,t)=>{const n=e.lookupNamespaceURI(null)===t||e.lookupPrefix(t),r=n?(e,n)=>e=>e.namespaceURI===t&&e.localName===n:(e,t)=>e=>e.localName===t;return{$:(e,t)=>[...e.children].find(r(e,t)),$$:(e,t)=>[...e.children].filter(r(e,t)),$$$:n?(e,n)=>[...e.getElementsByTagNameNS(t,n)]:(e,n)=>[...e.getElementsByTagName(t,n)]}},se=(e,t)=>{try{if(t.includes(":"))return new URL(e,t);const n="whatever://whatever/";return decodeURI(new URL(e,n+t).href.replace(n,""))}catch(t){return console.warn(t),e}},ae=e=>/^(?!blob)\w+:/i.test(e),le=async(e,t,n)=>{const r=[];e.replace(t,((...e)=>(r.push(e),null)));const i=[];for(const e of r)i.push(await n(...e));return e.replace(t,(()=>i.shift()))},ce=e=>e.replace(/[-/\\^$*+?.()|[\]{}]/g,"\\$&"),he={attrs:["dir","xml:lang"]},de={name:"alternate-script",many:!0,...he,props:["file-as"]},ue={many:!0,...he,props:[{name:"role",many:!0,attrs:["scheme"]},"file-as",de]},fe=[{name:"title",many:!0,...he,props:["title-type","display-seq","file-as",de]},{name:"identifier",many:!0,props:[{name:"identifier-type",attrs:["scheme"]}]},{name:"language",many:!0},{name:"creator",...ue},{name:"contributor",...ue},{name:"publisher",...he,props:["file-as",de]},{name:"description",...he,props:[de]},{name:"rights",...he,props:[de]},{name:"date"},{name:"dcterms:modified",type:"meta"},{name:"subject",many:!0,...he,props:["term","authority",de]},{name:"belongs-to-collection",type:"meta",many:!0,...he,props:["collection-type","group-position","dcterms:identifier","file-as",de,{name:"belongs-to-collection",recursive:!0}]}],pe=(e,t=e=>e)=>{const{$:n,$$:r,$$$:i}=oe(e,X),o=e=>r=>{const i=n(r,"a")??n(r,"span"),o=n(r,"ol"),a=(e=>e?decodeURI(t(e)):null)(i?.getAttribute("href")),l={label:ie(i)||i?.getAttribute("title"),href:a,subitems:s(o)};return e&&(l.type=i?.getAttributeNS(G,"type")?.split(/\s/)),l},s=(e,t)=>e?r(e,"li").map(o(t)):null,a=(e,t)=>s(n(e,"ol"),t),l=i(e,"nav");let c=null,h=null,d=null,u=[];for(const e of l){const t=e.getAttributeNS(G,"type")?.split(/\s/)??[];t.includes("toc")?c??=a(e):t.includes("page-list")?h??=a(e):t.includes("landmarks")?d??=a(e,!0):u.push({label:ie(e.firstElementChild),type:t,list:a(e)})}return{toc:c,pageList:h,landmarks:d,others:u}},ge=(e,t=e=>e)=>{const{$:n,$$:r}=oe(e,Z),i=e=>{const o=n(e,"navLabel"),s=n(e,"content"),a=ie(o),l=(e=>e?decodeURI(t(e)):null)(s.getAttribute("src"));if("navPoint"===e.localName){const t=r(e,"navPoint");return{label:a,href:l,subitems:t.length?t.map(i):null}}return{label:a,href:l}},o=(e,t)=>r(e,t).map(i),s=(t,r)=>{const i=n(e.documentElement,t);return i?o(i,r):null};return{toc:s("navMap","navPoint"),pageList:s("pageList","pageTarget"),others:r(e.documentElement,"navList").map((e=>({label:ie(n(e,"navLabel")),list:o(e,"navTarget")})))}},me=e=>{if(!e)return;const t=e.split(":").map((e=>parseFloat(e)));if(3===t.length){const[e,n,r]=t;return 60*e*60+60*n+r}if(2===t.length){const[e,n]=t;return 60*e+n}const[n,r]=e.split(/(?=[^\d.])/);return parseFloat(n)*("h"===r?3600:"min"===r?60:"ms"===r?.001:1)},ye=/([0-9a-f]{8})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{12})/,be=e=>ie(e.getElementById(e.documentElement.getAttribute("unique-identifier"))??e.getElementsByTagNameNS(J,"identifier")[0]),we=async(e,t,n)=>{const r=new Uint8Array(await n.slice(0,t).arrayBuffer());t=Math.min(t,r.length);for(var i=0;i{const t=(new TextEncoder).encode(e),n=await globalThis.crypto.subtle.digest("SHA-1",t);return new Uint8Array(n)},xe=(e=ve)=>({"http://www.idpf.org/2008/embedding":{key:t=>e(be(t).replaceAll(/[\u0020\u0009\u000d\u000a]/g,"")),decode:(e,t)=>we(e,1040,t)},"http://ns.adobe.com/pdf/enc#RC":{key:e=>{const t=(e=>{for(const t of e.getElementsByTagNameNS(J,"identifier")){const[e]=ie(t).split(":").slice(-1);if(ye.test(e))return e}return""})(e).replaceAll("-","");return Uint8Array.from({length:16},((e,n)=>parseInt(t.slice(2*n,2*n+2),16)))},decode:(e,t)=>we(e,1024,t)}});class Ce{#e=new Map;#t=new Map;#n;constructor(e){this.#n=e}async init(e,t){if(!e)return;const n=Array.from(e.getElementsByTagNameNS(K,"EncryptedData"),(e=>({algorithm:e.getElementsByTagNameNS(K,"EncryptionMethod")[0]?.getAttribute("Algorithm"),uri:e.getElementsByTagNameNS(K,"CipherReference")[0]?.getAttribute("URI")})));for(const{algorithm:e,uri:r}of n){if(!this.#t.has(e)){const n=this.#n[e];if(!n){console.warn("Unknown encryption algorithm");continue}const r=await n.key(t);this.#t.set(e,(e=>n.decode(r,e)))}this.#e.set(r,e)}}getDecoder(e){return this.#t.get(this.#e.get(e))??(e=>e)}}class Se{constructor({opf:e,resolveHref:t}){this.opf=e;const{$:n,$$:r,$$$:i}=oe(e,V),o=n(e.documentElement,"manifest"),s=n(e.documentElement,"spine"),a=r(s,"itemref");this.manifest=r(o,"item").map(re("href","id","media-type","properties","media-overlay")).map((e=>(e.href=t(e.href),e.properties=e.properties?.split(/\s/),e))),this.spine=a.map(re("idref","id","linear","properties")).map((e=>(e.properties=e.properties?.split(/\s/),e))),this.pageProgressionDirection=s.getAttribute("page-progression-direction"),this.navPath=this.getItemByProperty("nav")?.href,this.ncxPath=(this.getItemByID(s.getAttribute("toc"))??this.manifest.find((e=>e.mediaType===ee.NCX)))?.href;const l=n(e.documentElement,"guide");l&&(this.guide=r(l,"reference").map(re("type","title","href")).map((({type:e,title:n,href:r})=>({label:n,type:e.split(/\s/),href:t(r)})))),this.cover=this.getItemByProperty("cover-image")??this.getItemByID(i(e,"meta").find(ne("name","cover"))?.getAttribute("content"))??this.getItemByHref(this.guide?.find((e=>e.type.includes("cover")))?.href),this.cfis=(e=>{const t=[],{parentNode:n}=e[0],r=z(n);for(const[i,o]of U(n).entries()){const n=e[t.length];o===n&&t.push(P([r.concat({id:n.id,index:i})]))}return t})(a)}getItemByID(e){return this.manifest.find((t=>t.id===e))}getItemByHref(e){return this.manifest.find((t=>t.href===e))}getItemByProperty(e){return this.manifest.find((t=>t.properties?.includes(e)))}resolveCFI(e){const t=D(e),n=(t.parent??t).shift();let r=q(this.opf,n);r&&"idref"!==r.nodeName&&(n.at(-1).id=null,r=q(this.opf,n));const i=r?.getAttribute("idref");return{index:this.spine.findIndex((e=>e.idref===i)),anchor:e=>((e,t)=>{const n=F(t),r=F(t,!0),i=e.documentElement,o=$(i,n[0]),s=$(i,r[0]),a=e.createRange();return o.before?a.setStartBefore(o.node):o.after?a.setStartAfter(o.node):a.setStart(o.node,o.offset),s.before?a.setEndBefore(s.node):s.after?a.setEndAfter(s.node):a.setEnd(s.node,s.offset),a})(e,t)}}}class Te{#r=new Map;#i=new Map;#o=new Map;allowScript=!1;constructor({loadText:e,loadBlob:t,resources:n}){this.loadText=e,this.loadBlob=t,this.manifest=n.manifest,this.assets=n.manifest}createURL(e,t,n,r){if(!t)return"";const i=URL.createObjectURL(new Blob([t],{type:n}));if(this.#r.set(e,i),this.#o.set(e,1),r){const t=this.#i.get(r);t?t.push(e):this.#i.set(r,[e])}return i}ref(e,t){const n=this.#i.get(t);return n?.includes(e)||(this.#o.set(e,this.#o.get(e)+1),n?n.push(e):this.#i.set(t,[e])),this.#r.get(e)}unref(e){if(!this.#o.has(e))return;const t=this.#o.get(e)-1;if(t<1){URL.revokeObjectURL(this.#r.get(e)),this.#r.delete(e),this.#o.delete(e);const t=this.#i.get(e);if(t)for(;t.length;)this.unref(t.pop());this.#i.delete(e)}else this.#o.set(e,t)}async loadItem(e,t=[]){if(!e)return null;const{href:n,mediaType:r}=e,i=ee.JS.test(e.mediaType);if(i&&!this.allowScript)return null;const o=t.at(-1);if(this.#r.has(n))return this.ref(n,o);return(i||[ee.XHTML,ee.HTML,ee.CSS,ee.SVG].includes(r))&&t.every((e=>e!==n))?this.loadReplaced(e,t):this.createURL(n,await this.loadBlob(n),r,o)}async loadHref(e,t,n=[]){if(ae(e))return e;const r=se(e,t);let i=this.manifest.find((e=>e.href===r));return i||(i={href:r,mediaType:""}),this.loadItem(i,n.concat(t))}async loadReplaced(e,t=[]){const{href:n,mediaType:r}=e,i=t.at(-1),o=await this.loadText(n);if(!o)return null;if([ee.XHTML,ee.HTML,ee.SVG].includes(r)){let s=(new DOMParser).parseFromString(o,r);if(r===ee.XHTML&&s.querySelector("parsererror")&&(console.warn(s.querySelector("parsererror").innerText),e.mediaType=ee.HTML,s=(new DOMParser).parseFromString(o,e.mediaType)),[ee.XHTML,ee.SVG].includes(e.mediaType)){let e=s.firstChild;for(;e instanceof ProcessingInstruction;){if(e.data){const r=await le(e.data,/(?:^|\s*)(href\s*=\s*['"])([^'"]*)(['"])/i,((e,r,i,o)=>this.loadHref(i,n,t).then((e=>`${r}${e}${o}`))));e.replaceWith(s.createProcessingInstruction(e.target,r))}e=e.nextSibling}}const a=async(e,r)=>e.setAttribute(r,await this.loadHref(e.getAttribute(r),n,t));for(const e of s.querySelectorAll("link[href]"))await a(e,"href");for(const e of s.querySelectorAll("[src]"))await a(e,"src");for(const e of s.querySelectorAll("[poster]"))await a(e,"poster");for(const e of s.querySelectorAll("object[data]"))await a(e,"data");for(const e of s.querySelectorAll("[*|href]:not([href]"))e.setAttributeNS(Y,"href",await this.loadHref(e.getAttributeNS(Y,"href"),n,t));for(const e of s.querySelectorAll("style"))e.textContent&&(e.textContent=await this.replaceCSS(e.textContent,n,t));for(const e of s.querySelectorAll("[style]"))e.setAttribute("style",await this.replaceCSS(e.getAttribute("style"),n,t));const l=(new XMLSerializer).serializeToString(s);return this.createURL(n,l,e.mediaType,i)}const s=r===ee.CSS?await this.replaceCSS(o,n,t):await this.replaceString(o,n,t);return this.createURL(n,s,r,i)}async replaceCSS(e,t,n=[]){const r=await le(e,/url\(\s*["']?([^'"\n]*?)\s*["']?\s*\)/gi,((e,r)=>this.loadHref(r,t,n).then((e=>`url("${e}")`)))),i=await le(r,/@import\s*["']([^"'\n]*?)["']/gi,((e,r)=>this.loadHref(r,t,n).then((e=>`@import "${e}"`)))),o=window?.innerWidth??800,s=window?.innerHeight??600;return i.replace(/-epub-/gi,"").replace(/(\d*\.?\d+)vw/gi,((e,t)=>parseFloat(t)*o/100+"px")).replace(/(\d*\.?\d+)vh/gi,((e,t)=>parseFloat(t)*s/100+"px")).replace(/page-break-(after|before|inside)/gi,((e,t)=>`-webkit-column-break-${t}`))}replaceString(e,t,n=[]){const r=new Map,i=this.assets.map((e=>{if(e.href===t)return;const n=((e,t)=>{if(!e)return t;const n=e.replace(/\/$/,"").split("/"),r=t.replace(/\/$/,"").split("/"),i=(n.length>r.length?n:r).findIndex(((e,t)=>n[t]!==r[t]));return i<0?"":Array(n.length-i).fill("..").concat(r.slice(i)).join("/")})((e=>e.slice(0,e.lastIndexOf("/")+1))(t),e.href),i=encodeURI(n),o="/"+e.href,s=encodeURI(o),a=new Set([n,i,o,s]);for(const t of a)r.set(t,e);return Array.from(a)})).flat().filter((e=>e));if(!i.length)return e;const o=new RegExp(i.map(ce).join("|"),"g");return le(e,o,(async e=>this.loadItem(r.get(e.replace(/^\//,"")),n.concat(t))))}unloadItem(e){this.unref(e?.href)}}const Le=e=>{for(const t of e){if("page-spread-left"===t||"rendition:page-spread-left"===t)return"left";if("page-spread-right"===t||"rendition:page-spread-right"===t)return"right";if("rendition:page-spread-center"===t)return"center"}};class ke{parser=new DOMParser;#s;constructor({loadText:e,loadBlob:t,getSize:n,sha1:r}){this.loadText=e,this.loadBlob=t,this.getSize=n,this.#s=new Ce(xe(r))}#a(e){return e&&e.includes("opf:scheme")&&(e=e.replaceAll("opf:scheme","scheme")),e?this.parser.parseFromString(e,ee.XML):null}async#l(e){return this.#a(await this.loadText(e))}async init(){const e=await this.#l("META-INF/container.xml");if(!e)throw new Error("Failed to load container file");const t=Array.from(e.getElementsByTagNameNS(W,"rootfile"),re("full-path","media-type")).filter((e=>"application/oebps-package+xml"===e.mediaType));if(!t.length)throw new Error("No package document defined in container");const n=t[0].fullPath,r=await this.#l(n);if(!r)throw new Error("Failed to load package document");const i=await this.#l("META-INF/encryption.xml");await this.#s.init(i,r),this.resources=new Se({opf:r,resolveHref:e=>se(e,n)});const o=new Te({loadText:this.loadText,loadBlob:e=>Promise.resolve(this.loadBlob(e)).then(this.#s.getDecoder(e)),resources:this.resources});this.sections=this.resources.spine.map(((e,t)=>{const{idref:n,linear:r,properties:i=[]}=e,s=this.resources.getItemByID(n);return s?{id:this.resources.getItemByID(n)?.href,load:()=>o.loadItem(s),unload:()=>o.unloadItem(s),createDocument:()=>this.loadDocument(s),size:this.getSize(s.href),cfi:this.resources.cfis[t],linear:r,pageSpread:Le(i),resolveHref:e=>se(e,s.href),loadMediaOverlay:()=>this.loadMediaOverlay(s)}:(console.warn(`Could not find item with ID "${n}" in manifest`),null)})).filter((e=>e));const{navPath:s,ncxPath:a}=this.resources;if(s)try{const e=e=>se(e,s),t=pe(await this.#l(s),e);this.toc=t.toc,this.pageList=t.pageList,this.landmarks=t.landmarks}catch(e){console.warn(e)}if((!this.toc||0===this.toc.length)&&a)try{const e=e=>se(e,a),t=ge(await this.#l(a),e);this.toc=t.toc,this.pageList=t.pageList}catch(e){console.warn(e)}this.landmarks??=this.resources.guide;const{metadata:l,rendition:c,media:h}=(e=>{const{$:t,$$:n}=oe(e,V),r=t(e.documentElement,"metadata"),i=Array.from(r.children),o=(e,t)=>{if(!t)return null;const{props:n=[],attrs:r=[]}=e,s=ie(t);if(!n.length&&!r.length)return s;const a=t.getAttribute("id"),l=a?i.filter(ne("refines","#"+a)):[];return Object.fromEntries([["value",s]].concat(n.map((t=>{const{many:n,recursive:r}=t,i="string"==typeof t?t:t.name,s=ne("property",i),a=r?e:t;return[te(i),n?l.filter(s).map((e=>o(a,e))):o(a,l.find(s))]}))).concat(r.map((e=>[te(e),t.getAttribute(e)]))))},s=i.filter(ne("refines",null)),a=e=>Object.fromEntries(n(r,"meta").filter(ne("property",(t=>t?.startsWith(e)))).map((t=>[t.getAttribute("property").replace(e,""),ie(t)])));return{metadata:Object.fromEntries(fe.map((e=>{const{type:t,name:n,many:r}=e,i="meta"===t?e=>e.namespaceURI===V&&e.getAttribute("property")===n:e=>e.namespaceURI===J&&e.localName===n;return[te(n),r?s.filter(i).map((t=>o(e,t))):o(e,s.find(i))]}))),rendition:a("rendition:"),media:a("media:")}})(r);this.rendition=c,this.media=h,h.duration=me(h.duration),this.dir=this.resources.pageProgressionDirection,this.rawMetadata=l;const d=l?.title?.[0];this.metadata={title:d?.value,sortAs:d?.fileAs,language:l?.language,identifier:be(r),description:l?.description?.value,publisher:l?.publisher?.value,published:l?.date,modified:l?.dctermsModified,subject:l?.subject?.filter((({value:e,code:t})=>e||t))?.map((({value:e,code:t,scheme:n})=>({name:e,code:t,scheme:n}))),rights:l?.rights?.value};const u={art:"artist",aut:"author",bkp:"producer",clr:"colorist",edt:"editor",ill:"illustrator",trl:"translator",pbl:"publisher"},f=e=>t=>{const n=[...new Set(t.role?.map((({value:t,scheme:n})=>(n&&"marc:relators"!==n?null:u[t])??e)))],r={name:t.value,sortAs:t.fileAs};return[n?.length?n:[e],r]};return l?.creator?.map(f("author"))?.concat(l?.contributor?.map?.(f("contributor")))?.forEach((([e,t])=>e.forEach((e=>{this.metadata[e]?this.metadata[e].push(t):this.metadata[e]=[t]})))),this}async loadDocument(e){const t=await this.loadText(e.href);return this.parser.parseFromString(t,e.mediaType)}async loadMediaOverlay(e){const t=e.mediaOverlay;if(!t)return null;const n=this.resources.getItemByID(t),r=((e,t=e=>e)=>{const{$:n,$$$:r}=oe(e,Q);return r(e,"par").map((e=>{const r=n(e,"text")?.getAttribute("src")?.split("#")?.[1],i=n(e,"audio");return i?{id:r,audio:{src:(o=i.getAttribute("src"),o?decodeURI(t(o)):null),clipBegin:me(i.getAttribute("clipBegin")),clipEnd:me(i.getAttribute("clipEnd"))}}:{id:r};var o}))})(await this.#l(n.href),(e=>se(e,n.href)));return r}resolveCFI(e){return this.resources.resolveCFI(e)}resolveHref(e){const[t,n]=e.split("#"),r=this.resources.getItemByHref(decodeURI(t));if(!r)return null;return{index:this.resources.spine.findIndex((({idref:e})=>e===r.id)),anchor:n?e=>((e,t)=>e.getElementById(t)??e.querySelector(`[name="${CSS.escape(t)}"]`))(e,n):()=>0}}splitTOCHref(e){return e?.split("#")??[]}getTOCFragment(e,t){return e.getElementById(t)??e.querySelector(`[name="${CSS.escape(t)}"]`)}isExternal(e){return ae(e)}async getCover(){const e=this.resources?.cover;return e?.href?new Blob([await this.loadBlob(e.href)],{type:e.mediaType}):null}async getCalibreBookmarks(){const e=await this.loadText("META-INF/calibre_bookmarks.txt"),t="encoding=json+base64:";if(e?.startsWith(t)){const t=atob(e.slice(21));return JSON.parse(t)}}}const Ae=(e,t=!1)=>{const n=(new DOMParser).parseFromString(t?je(e):e,"text/html");let r=Oe(n);0===r.length&&(r=qe(n));for(let e=0;e""};return a.sections=s.map((e=>({id:e.index,load:()=>{return t=e.index,f(void 0,void 0,void 0,(function*(){return URL.createObjectURL(new Blob([s[t].text],{type:"text/html"}))}));var t},unload:()=>{e.index}}))),a.toc=s.map((e=>({label:e.label,href:"title"+e.index}))).filter((e=>""!==e.label)),a.rendition={layout:"pre-paginated"},a.resolveHref=e=>({index:parseInt(e.substring(5,e.length))}),a.splitTOCHref=e=>[e,null],a.getTOCFragment=e=>e.documentElement,a};let Ie=["章","节","回","節","卷","部","輯","辑","話","集","话","篇"," "," "],Ee=[],Me=["CHAPTER","Chapter","序章","前言","声明","写在前面的话","后记","楔子","后序","尾声"],Be=[" "," ","、","·",".",":",":"];const Oe=e=>Array.from(e.querySelectorAll("h1,h2,h3,h4,h5,h6,title")),De=e=>e.trim().replace(/(\r\n|\n|\r|\t)/gm,"").substring(0,100).split("").filter((e=>"="!==e&&"-"!==e&&"_"!==e&&"+"!==e)).join(""),Ne=e=>e&&e.length<40&&!Re(e)&&(Pe(e)||e.startsWith("第")&&_e(e)||e.startsWith("卷")&&He(e)||e.indexOf("第")>-1&&e.lastIndexOf("第")<4&&_e(e.substr(e.indexOf("第")))||Fe(e)),Re=e=>Ee.filter((t=>e.indexOf(t)>-1)).length>0,Pe=t=>Me.filter((n=>t.startsWith(n)||t.startsWith(e.s2t(n))||t.startsWith(e.t2s(n)))).length>0,Fe=e=>Be.filter((t=>e.indexOf(t)>-1&&(/^[\u4e00\u4e8c\u4e09\u56db\u4e94\u516d\u4e03\u516b\u4e5d\u5341\u767e\u5343\u4e07\u842c\u96f6]+$/.test(e.substring(0,e.indexOf(t)))||/^\d+$/.test(e.substring(0,e.indexOf(t)))))).length>0,_e=e=>{let t=!1;for(let n=0;n!(!/^[\u4e00\u4e8c\u4e09\u56db\u4e94\u516d\u4e03\u516b\u4e5d\u5341\u767e\u5343\u4e07\u842c\u96f6]+$/.test(e.substring(1,e.indexOf(" ")))&&!/^\d+$/.test(e.substring(1,e.indexOf(" "))))||(!(!/^[\u4e00\u4e8c\u4e09\u56db\u4e94\u516d\u4e03\u516b\u4e5d\u5341\u767e\u5343\u4e07\u842c\u96f6]+$/.test(e.substring(1,e.indexOf(" ")))&&!/^\d+$/.test(e.substring(1,e.indexOf(" "))))||!(!/^[\u4e00\u4e8c\u4e09\u56db\u4e94\u516d\u4e03\u516b\u4e5d\u5341\u767e\u5343\u4e07\u842c\u96f6]+$/.test(e.substring(1))&&!/^\d+$/.test(e.substring(1)))),Ue=e=>{let t=[],n=e.split("
").filter((e=>""!==e.trim())),r=n.map((e=>$e(e)||ze(e)));return t=n.map(((e,t)=>({index:t,label:r[t],text:e,href:"title"+t}))),t},je=e=>{let t="",n=e.split("\n");for(let e of n)De(e)&&Ne(De(e))?t+=`

${De(e)}

`:t+=`

${e}

`;return t||`

Title

${e}

`},$e=e=>{const t=/]*>(.*?)<\/h[1-6]>/.exec(e);return t?t[1].replace(/</g,"<").replace(/>/g,">"):""},ze=e=>{const t=/]*>(.*?)<\/title>/.exec(e);return t?t[1].replace(/</g,"<").replace(/>/g,">"):""},qe=e=>{let t=e.getElementsByTagName("*"),n=Array.from(t).filter((e=>1===e.childNodes.length&&e.childNodes[0].nodeType===Node.TEXT_NODE&&Ne(De(e.textContent)))),r=[];for(let e=0;eArray.from(e.querySelectorAll("h1,h2,h3,h4,h5,h6,p,div,ul,dl,ol,pre,blockquote,address")),Ve=(e,t,n,r,i,o)=>f(void 0,void 0,void 0,(function*(){let s=Math.floor(e.clientWidth/12),a=s%2==0?s:s-1;const l=e.clientWidth;if("mimical"===t){let e=document.getElementById("book");e&&(e.style.display="block",n>0?o():n<0&&i(),console.log("first"),setTimeout((()=>{if(!e)return{};e.style.display="none"}),1e3))}n>0?r.body.scrollBy({top:0,left:-l-a,behavior:"sliding"===t?"smooth":"auto"}):n<0&&r.body.scrollBy({top:0,left:l+a,behavior:"sliding"===t?"smooth":"auto"})})),Ge=(e,n,r,i)=>{let o=t.findLastIndex(r,{href:n});return n&&t.findLastIndex(r,{href:n})>-1||(o=e),"prev"===i?Object.assign(Object.assign({},r[o-1]),{index:o-1}):Object.assign(Object.assign({},r[o+1]),{index:o+1})},Je=(e,t,n,r,i,o,s,a)=>f(void 0,void 0,void 0,(function*(){let t=parseInt(o.chapterDocIndex||"0"),l=o.chapterHref||"";if(0===t)return;let c=Ge(t,l,n,"prev");c&&(o.text="prevChapter",o.page="",yield Ze(c.index,c.label,c.href,n,e,r,i,o,s,a))})),Ke=(e,t,n,r)=>f(void 0,void 0,void 0,(function*(){let{width:i,height:o}=yield n[r].text.getDimension(),s="double"===t?2:1,a=Math.floor(e.clientWidth/12),l=a%2==0?a:a-1,c=(e.clientWidth-l)/s;"single"===t&&(c=e.clientWidth);let h=e.clientHeight,d=Math.min(c/i,h/o);return"scroll"===t&&(d=c/i),d})),Ze=(e,n,r,i,o,s,a,l,c,h)=>f(void 0,void 0,void 0,(function*(){if(c.body.innerHTML="",h.height="0px",c.body.scrollTo(0,0),n&&!e||i[e]&&i[e].label&&n&&n!==i[e].label&&-1===r.indexOf("#")){let r=t.findLastIndex(i,{label:n});-1!==r&&(e=r)}if((-1===e||e>i.length-1)&&(e=0),c.body.innerHTML=yield g(i[e].text,!1),"PDF"===a){let t=yield Ke(o,s,i,e);yield i[e].text.render(c,t)}yield Ye(c),l.chapterDocIndex&&i[l.chapterDocIndex].text&&i[l.chapterDocIndex].text.unload&&i[l.chapterDocIndex].text.unload(),l.chapterTitle=n,l.chapterHref=r,l.chapterDocIndex=e+"",l.percentage=e/i.length+"",l.text="",yield((e,t,n,r,i)=>f(void 0,void 0,void 0,(function*(){if(yield Promise.all(Array.from([...i.images,...i.querySelectorAll("image")]).map((e=>e.complete?Promise.resolve(0!==e.naturalHeight):new Promise((t=>{e.addEventListener("load",(()=>t(!0))),e.addEventListener("error",(()=>t(!1)))}))))).then((e=>{e.every((e=>e))?console.log("all images loaded successfully!!"):console.log("some images failed to load, all finished loading")})),console.log(1),yield S(e,t,n,i),"PDF"!==n&&x(i),"scroll"!==t){if(r.height=e.clientHeight+"px","double"===t){let t=Math.floor(e.clientWidth/12),n=t%2==0?t:t-1,r=(e.clientWidth+n)/2;if((i.body.scrollWidth-i.body.clientWidth)/r%2==1){let e=document.createElement("div");e.setAttribute("style","height: "+i.body.clientHeight+"px; display: inline-block; width: "+(r-n)+"px"),i.body.appendChild(e)}}}else if("PDF"===n){let e=i.querySelector(".koodoPDFLayer");if(!e)return;r.height=e.getBoundingClientRect().height+100+"px"}else r.height=i.body.scrollHeight+"px",r.height=i.body.scrollHeight+300+"px";console.log(2)})))(o,s,a,h,c),Qe(o,s,"","","","",c)})),Ye=e=>f(void 0,void 0,void 0,(function*(){let t=Array.from(e.getElementsByTagName("link"));for(let e=0;e{console.log("finished")}}let n=[];for(let e=0;e{r.addEventListener("load",e)})))}try{yield Promise.race([Promise.all(n),new Promise(((e,t)=>{setTimeout((()=>{t(new Error("Timeout"))}),1e3)}))])}catch(e){console.log(e)}})),Qe=(t,n,r,i,o,s,a)=>f(void 0,void 0,void 0,(function*(){let l=0,c=0,h=a.body;if(s&&"scroll"!==n){let e=Math.floor(t.clientWidth/12),n=e%2==0?e:e-1;c=((d=getComputedStyle(t).width,parseFloat(d.substring(0,d.length-2)))+n)*(parseInt(s)-1)}else if(r){let o=Xe(a.body).filter(((t,n)=>De(t.textContent)&&(De(t.textContent)===De(r)||De(t.textContent)===e.t2s(De(r))||De(t.textContent)===e.s2t(De(r)))&&(Math.abs(n-parseInt(i))<2||"search"===i||"ignore"===i||"next"===i)));if(0===o.length)return void console.log("failed");h=et(o[0],t,n),c=h?p(h.offsetLeft)-p(h.marginLeft||parseFloat(getComputedStyle(h).marginLeft)):"prevChapter"===r?a.body.scrollWidth:0,l=h?p(h.offsetTop)-p(h.marginTop||parseFloat(getComputedStyle(h).marginTop)):0,console.log(c,"left"),console.log(l,"top")}else if(o&&o.indexOf("#")>-1){let e=CSS.escape(o.split("#").reverse()[0]);if(!a.body.querySelector("#"+e))return;h=et(a.body.querySelector("#"+e)||a.body,t,n),c=h?p(h.offsetLeft)-p(h.marginLeft||parseFloat(getComputedStyle(h).marginLeft)):0,l=h?p(h.offsetTop)-p(h.marginTop||parseFloat(getComputedStyle(h).marginTop)):0}var d;"scroll"!==n?a.body.scrollTo(c,0):h.scrollIntoView()})),et=(e,t,n)=>{let r=Math.floor(t.clientWidth/12),i=r%2==0?r:r-1,o=p(e.offsetLeft)-p(e.marginLeft||parseFloat(getComputedStyle(e).marginLeft));return"scroll"===n||"scroll"!==n&&tt(parseInt(o+""),(t.clientWidth+i)/2)?e:e.parentElement?et(e.parentElement,t,n):e},tt=(e,t)=>{for(let n=e-10;n<=e+10;n++)if(n%t==0)return!0;return!1},nt=(e,t,n,r,i,o)=>f(void 0,void 0,void 0,(function*(){var s;if(We)return;let a=Xe(i.body),l=a.filter((n=>lt(e,n,t)&&(n.textContent||"").trim()));console.log(l,"visibleNode");let c=l[0];o&&(c=o);let h=0;console.log(c,"firstVisibleNode");for(let n=0;n{We=!1}),100)})),rt=(e,t,n)=>{let r=Math.floor(t.clientWidth/12),i=r%2==0?r:r-1;return Math.abs(e.offsetLeft-et(e,t,n).offsetLeft)>(t.clientWidth+i)/2},it=(e,n,r)=>{let i=r.chapterHref||"",o=i.lastIndexOf("#"),s=i.substring(0,o),a=i.substring(o+1);for(let i=0;i-1&&(r.chapterHref=e)}}},ot=(e,t,n,r,i,o,s,a)=>f(void 0,void 0,void 0,(function*(){let t=parseInt(o.chapterDocIndex||"0"),l=o.chapterHref||"";if(t>=n.length-1)return void(o.percentage="1");let c=Ge(t,l,n,"next");c&&(o.page="",yield Ze(c.index,c.label,c.href,n,e,r,i,o,s,a))})),st=(e,t,n)=>Xe(n.body).filter((e=>!at(e))).filter((n=>lt(e,n,t)&&(n.textContent||"").trim())).filter((e=>"img"!==e.textContent)).map((e=>e.textContent)),at=e=>{var t=e.children;let n=!1;var r=/^(address|section|blockquote|body|center|dir|div|dl|fieldset|form|h[1-6]|hr|isindex|menu|noframes|noscript|ol|p|pre|table|ul|dd|dt|frameset|li|tbody|td|tfoot|th|thead|tr|html)$/i;if(Array.from(t).filter((e=>r.test(e.nodeName))).length<3)return!1;for(var i=0;i{var r=!1,i=t.getBoundingClientRect();if("scroll"!==n&&t.textContent&&t.textContent.trim()){let t=i.left;r=t>-10&&t<=e.clientWidth}else if("scroll"===n&&t.textContent&&t.textContent.trim()){let t=i.top;r=t>=e.scrollTop&&t<=e.scrollTop+e.clientHeight}else if("scroll"!==n){let t=i.left;r=t>=0&&t<=e.clientWidth}return r};class ct{constructor(){this.callbacks={},this.callbacks.base={}}on(e,t){const n=this;if(void 0===e||""===e)return console.warn("wrong names"),!1;if(void 0===t)return console.warn("wrong callback"),!1;return this.resolveNames(e).forEach((function(e){const r=n.resolveName(e);n.callbacks[r.namespace]instanceof Object||(n.callbacks[r.namespace]={}),n.callbacks[r.namespace][r.value]instanceof Array||(n.callbacks[r.namespace][r.value]=[]),n.callbacks[r.namespace][r.value].push(t)})),this}off(e){const t=this;if(void 0===e||""===e)return console.warn("wrong name"),!1;return this.resolveNames(e).forEach((function(e){const n=t.resolveName(e);if("base"!==n.namespace&&""===n.value)delete t.callbacks[n.namespace];else if("base"===n.namespace)for(const e in t.callbacks)t.callbacks[e]instanceof Object&&t.callbacks[e][n.value]instanceof Array&&(delete t.callbacks[e][n.value],0===Object.keys(t.callbacks[e]).length&&delete t.callbacks[e]);else t.callbacks[n.namespace]instanceof Object&&t.callbacks[n.namespace][n.value]instanceof Array&&(delete t.callbacks[n.namespace][n.value],0===Object.keys(t.callbacks[n.namespace]).length&&delete t.callbacks[n.namespace])})),this}trigger(e,t=[]){if(void 0===e||""===e)return console.warn("wrong name"),!1;const n=this;const r=t instanceof Array?t:[];let i=this.resolveNames(e);i=this.resolveName(i[0]),setTimeout((()=>{if("base"===i.namespace)for(const e in n.callbacks){if(n.callbacks[e]instanceof Object&&n.callbacks[e][i.value]instanceof Array&&n.callbacks[e][i.value])n.callbacks[e][i.value].forEach((function(e){e.apply(n,r)}));else if(this.callbacks[i.namespace]instanceof Object&&n.callbacks[i.namespace][i.value]){if(""===i.value)return console.warn("wrong name"),this;n.callbacks[i.namespace][i.value].forEach((function(e){e.apply(n,r)}))}return null}}),100)}resolveNames(e){let t=e;return t=t.replace(/[^a-zA-Z0-9 ,/.]/g,""),t=t.replace(/[,/]+/g," "),t=t.split(" "),t}resolveName(e){const t={},n=e.split(".");return t.original=e,t.value=n[0],t.namespace="base",n.length>1&&""!==n[1]&&(t.namespace=n[1]),t}}const ht=Node.ELEMENT_NODE,dt=Node.TEXT_NODE,ut=Node.CDATA_SECTION_NODE;function ft(e,t,n){let r,i,o,s=0,a=0,l=!0;for(i=0;ithis.compare(e,t)))}static compare(e,t){let n=e.get(),r=t.get();if(e.isRange||t.isRange){if(e.isRange&&t.isRange){const e=this.comparePath(n.from,r.from);return e||this.comparePath(n.to,r.to)}return e.isRange&&(n=n.from),t.isRange&&(r=r.from),this.comparePath(n,r)}return this.comparePath(n,r)}static compareParts(e,t){const n=Math.max(e.length,t.length);let r,i,o,s;for(r=0;r=n)return"img"===a.tagName.toLowerCase()&&r?{node:a,offset:r}:{node:a,offset:0}}else{if(l+=1,l===n)return"img"===a.tagName.toLowerCase()&&r?{node:a,offset:r}:{node:a,offset:0};if(l>n)return o?{node:o,offset:this.trueLength(e,o.textContent)}:{node:t,offset:0}}o=a;break;case dt:case ut:if(0!==l&&l%2!=0||(l+=1),l===n){const t=this.trueLength(e,a.textContent);if(!(r>=t))return{node:a,offset:r};r-=t}o=a;break;default:continue}if(n>l){const n={relativeToNode:"after",offset:0};return n.node=o||t,this.isTextNode(n.node)&&(n.offset=this.trueLength(e,n.node.textContent.length)),n}}isTextNode(e){return!!e&&(e.nodeType===dt||e.nodeType===ut)}correctOffset(e,t,n,r){let i,o=t;if("string"==typeof r?i=this.decodeEntities(e,r):(r.pre=this.decodeEntities(e,r.pre),r.post=this.decodeEntities(e,r.post),i=r.pre+"."+r.post),!this.isTextNode(t))return{node:t,offset:0};for(;this.isTextNode(o.previousSibling);)o=o.previousSibling;const s=o;let a;const l=[];let c="",h=0;for(;this.isTextNode(o)&&(a=this.decodeEntities(e,o.textContent),l[h]=a.length,c+=a,o.nextSibling);)o=o.nextSibling,h++;const d=r.pre?r.pre.length:0,u=function(e,t,n){n=n||0;const r=[];let i,o=0;do{if(i=e.match(t),!i)break;r.push(i.index+n),o+=i.index+i.length,e=e.slice(i.index+i.length)}while(o=l[h];){if(f-=l[h],f<0)return{node:t,offset:n};const e=[];if(!o.nextSibling||h+1>=e.length)return{node:t,offset:n};h++,o=o.nextSibling}return{node:o,offset:f}}resolveNode(e,t,n,r){if(r=Object.assign({},r||{}),!n)throw new Error("Missing DOM argument");let i;if(0===e&&(i=n.querySelector("package")),!i)for(const e of n.childNodes)if(e.nodeType===ht){i=e;break}if(i=n,!i)throw new Error("Document incompatible with CFIs");let o,s,a=i,l=0;for(o=t.length-1;o>=0;o--)if(s=t[o],!r.ignoreIDs&&s.nodeID&&(a=n.getElementById(s.nodeID))){l=o+1;break}a||(a=i);let c={node:a,offset:0};for(o=l;othis.parts.length-2)throw new Error("index is out of bounds");const r=this.parts[e];if(!r)throw new Error("Missing CFI part for index: "+e);let i=this.resolveNode(e,r,t,n).node;const o=i.tagName.toLowerCase();if("itemref"===o&&"spine"===i.parentNode.tagName.toLowerCase()){const e=i.getAttribute("idref");if(!e)throw new Error("Referenced node had not 'idref' attribute");if(i=t.getElementById(e),!i)throw new Error("Specified node is missing from manifest");const n=i.getAttribute("href");if(!n)throw new Error("Manifest item is missing href attribute");return n}if("iframe"===o||"embed"===o){const e=i.getAttribute("src");if(!e)throw new Error(o+" element is missing 'src' attribute");return e}if("object"===o){const e=i.getAttribute("data");if(!e)throw new Error(o+" element is missing 'data' attribute");return e}if("image"===o||"use"===o){const e=i.getAttribute("xlink:href");if(!e)throw new Error(o+" element is missing 'xlink:href' attribute");return e}throw new Error("No URI found")}deepClone(e){return JSON.parse(JSON.stringify(e))}resolveLocation(e,t){const n=t.length-1,r=t[n];if(!r)throw new Error("Missing CFI part for index: "+n);const i=this.resolveNode(n,r,e),o=this.deepClone(r[r.length-1]);return delete o.nodeIndex,o.offset||delete i.offset,Object.assign(Object.assign({},o),i)}resolveLast(e,t){if(t=Object.assign({range:!1},t||{}),!this.isRange)return this.resolveLocation(e,this.parts);if(t.range){const t=e.createRange(),n=this.getFrom();"before"===n.relativeToNode?t.setStartBefore(n.node,n.offset):"after"===n.relativeToNode?t.setStartAfter(n.node,n.offset):t.setStart(n.node,n.offset);const r=this.getTo();return"before"===r.relativeToNode?t.setEndBefore(r.node,r.offset):"after"===r.relativeToNode?t.setEndAfter(r.node,r.offset):t.setEnd(r.node,r.offset),t}return{from:this.resolveLocation(e,this.getFrom()),to:this.resolveLocation(e,this.getTo()),isRange:!0}}resolve(e,t){return this.resolveLast(e,t)}}const yt=["color-0","color-1","color-2","color-3","line-0","line-1","line-2","line-3"],bt=["#FEF3CD","#FBFACC","#CEFACD","#CDE9FA"],wt=["#fac106","#ebe702","#0be603","#0493e6"],vt=["#FF0000","#000080","#0000FF","#2EFF2E"],xt=(e,t,r,i,o,s)=>{var a,l;n.init();let c=yt[t],h=s.contentWindow||(null===(a=s.contentDocument)||void 0===a?void 0:a.defaultView),d=e;d=[d],n.getSelection(s).restoreCharacterRanges(o,d);let u=o.getSelection();if(!u)return;let f=u.getRangeAt(0);for(var p=kt(f),g=0;g{let a=yt[t],l=s.querySelector(".noteLayer");var c=i.getViewport({scale:o});e.coords.forEach((e=>{var t=c.convertToViewportRectangle(e),i=document.createElement("div");null==i||i.setAttribute("style","position: absolute;"+(a.indexOf("color")>-1?"background-color: ":"border-bottom: ")+(a.indexOf("color")>-1?wt[a.split("-")[1]]:`2px solid ${vt[a.split("-")[1]]}`)+"; left:"+Math.min(t[0],t[2])+"px; top:"+Math.min(t[1],t[3])+"px;width:"+Math.abs(t[0]-t[2])+"px; height:"+Math.abs(t[1]-t[3])+"px; z-index: 1;opacity: "+(a.indexOf("color")>-1?.3:1)+";"),null==i||i.setAttribute("data-key",n),null==i||i.setAttribute("class","kookit-note"),null==i||i.addEventListener("click",(e=>{e&&e.target&&e.target.dataset&&e.target.dataset.key&&r(e)})),l.appendChild(i)}))},St=e=>{const t=e.querySelectorAll(".kookit-note");for(let e=0;e{const o=Lt(e.getClientRects());for(let e=0;e-1?"background-color: ":"border-bottom: ")+(t.indexOf("color")>-1?bt[t.split("-")[1]]+";opacity: 1":`2px solid ${vt[t.split("-")[1]]}`)+";left:"+(Math.min(l.left,l.x)+i.body.scrollLeft)+"px; top:"+(Math.min(l.top,l.y)+i.body.scrollTop)+"px;width:"+l.width+"px; height:"+l.height+"px; z-index:-1;"),s.setAttribute("class"," kookit-note"),s.setAttribute("data-key",n),i.body.appendChild(s);var a=document.createElement("span");null==a||a.setAttribute("style","position: absolute;left:"+(Math.min(l.left,l.x)+i.body.scrollLeft)+"px; top:"+(Math.min(l.top,l.y)+i.body.scrollTop)+"px;width:"+l.width+"px; height:"+l.height+"px; z-index:1;"),a.setAttribute("class"," kookit-note"),a.setAttribute("data-key",n),a.addEventListener("click",(e=>{e&&e.target&&e.target.dataset&&e.target.dataset.key&&r(e)})),a.ontouchend=e=>{e&&e.target&&e.target.dataset&&e.target.dataset.key&&r(e),e.preventDefault(),e.stopPropagation()},i.body.appendChild(a)}},Lt=e=>{let t=[];for(let n=0;n{var t=e.commonAncestorContainer,n=new Array(0),r=new Array(0);if(e.startContainer!==t)for(let r=e.startContainer;r!==t;r=r.parentNode)n.push(r);if(n.length>0)for(let t=0;t0)for(let t=0;t0&&o.length>0))return[e];var c=document.createRange();return c.setStartAfter(n[n.length-1]),c.setEndBefore(o[o.length-1]),r.push(c),r.concat(s)};const At=e=>{!function(e){let t=document.getElementById("book");t&&t.remove();const n=document.createElement("div");n.id="book";const r=document.createElement("canvas");r.id="pageflip-canvas";const i=document.createElement("div");i.id="pages";for(let t=0;t=0?u[l-1].dragging=!0:d.x>0&&l+1{l+1{l-1>=0&&(u[l-1].target=1,l=Math.max(l-1,0))}}}}function y(e){var t=1-Math.abs(e.progress),n=.5*o*(1-e.progress),i=o*e.progress+n,l=20*t,c=.5*o*Math.max(Math.min(1-e.progress,.5),0),d=.5*o*Math.max(Math.min(t,.5),0),u=.5*o*Math.max(Math.min(t,.5),0);e.page.style.width=Math.max(i,0)+"px",h.save(),h.translate(0+r/2,a+0),h.strokeStyle="rgba(0,0,0,"+.05*t+")",h.lineWidth=30*t,h.beginPath(),h.moveTo(i-n,.5*-l),h.lineTo(i-n,s+.5*l),h.stroke();var f=h.createLinearGradient(i,0,i+d,0);f.addColorStop(0,"rgba(0,0,0,"+.2*t+")"),f.addColorStop(.8,"rgba(0,0,0,0.0)"),h.fillStyle=f,h.beginPath(),h.moveTo(i,0),h.lineTo(i+d,0),h.lineTo(i+d,s),h.lineTo(i,s),h.fill();var p=h.createLinearGradient(i-n-u,0,i-n,0);p.addColorStop(0,"rgba(0,0,0,0.0)"),p.addColorStop(1,"rgba(0,0,0,"+.15*t+")"),h.fillStyle=p,h.beginPath(),h.moveTo(i-n-u,0),h.lineTo(i-n,0),h.lineTo(i-n,s),h.lineTo(i-n-u,s),h.fill();var g=h.createLinearGradient(i-c,0,i,0);g.addColorStop(.35,"#fafafa"),g.addColorStop(.73,"#eeeeee"),g.addColorStop(.9,"#fafafa"),g.addColorStop(1,"#e2e2e2"),h.fillStyle=g,h.strokeStyle="rgba(0,0,0,0.06)",h.lineWidth=.5,h.beginPath(),h.moveTo(i,0),h.lineTo(i,s),h.quadraticCurveTo(i,s+2*l,i-n,s+l),h.lineTo(i-n,-l),h.quadraticCurveTo(i,2*-l,i,0),h.fill(),h.stroke(),h.restore()}},It=(e,t)=>{void 0!==t.nextSibling?t.parentNode.insertBefore(e,t.nextSibling):t.parentNode.appendChild(e)},Et=e=>{for(var t=0;void 0!==e.childNodes[t];t++)if("#text"===e.childNodes[t].nodeName&&0!==e.childNodes[t].textContent.trim().length){var n=e.childNodes[t],r=0;e.childNodes[t].textContent.split(/(\s+|\S+)/).forEach((e=>{if(0===e.length)return;var t=e.trim().length;if(0===t){let t=document.createTextNode(e);return It(t,n),r++,void(n=t)}var i=Math.floor(t/2);0===i&&(i=1);const o=document.createElement("b");if(o.innerHTML=e.slice(0,i),It(o,n),r++,n=o,1===e.length)return;let s=document.createTextNode(e.slice(i));It(s,n),r++,n=s})),e.removeChild(e.childNodes[t]),t+=r-1}};var Mt={B:!0,META:!0,LINK:!0,SCRIPT:!0,STYLE:!0};const Bt=e=>{if(null!==e&&void 0!==e.body)for(var t=e.body.getElementsByTagName("*"),n=0;void 0!==t[n];n++)if(!Mt[t[n].nodeName]&&1===t[n].nodeType)if("IFRAME"===t[n].nodeName)Bt(t[n].contentDocument);else{if(0===t[n].childNodes.length)continue;Et(t[n])}};class Ot extends ct{constructor(t){super(),this.tsTransform=()=>{let t=this.getDocument();t&&("Simplified To Traditional"===this.convertChinese?t.querySelectorAll("h1,h2,h3,h4,h5,h6,p,div,ul,dl,ol,pre,blockquote,address").forEach((t=>{t.innerHTML=t.innerHTML.split("").map((t=>e.s2t(t))).join("")})):"Traditional To Simplified"===this.convertChinese&&t.querySelectorAll("h1,h2,h3,h4,h5,h6,p,div,ul,dl,ol,pre,blockquote,address").forEach((t=>{t.innerHTML=t.innerHTML.split("").map((t=>e.t2s(t))).join("")})))},this.bionicReadingProcess=()=>{let e=this.getDocument();e&&"yes"===this.isBionic&&Bt(e)},this.addPageAnimation=()=>{if("mimical"===this.animation){let e=this.getProgress();if(!e)return;const t=At(e.totalPage);t&&(this.flipToNextPage=t.flipToNextPage,this.flipToPrevPage=t.flipToPrevPage)}},this.mode=t.mode,this.animation=t.animation,this.format=t.format,this.convertChinese=t.convertChinese,this.isBionic=t.isBionic,this.chapterList=[],this.chapterDocList=[],this.flattenChapters=[],this.book="",this.element="",this.tempLocation={},this.flipToNextPage=()=>{},this.flipToPrevPage=()=>{}}getPageSize(){let e="double"===this.mode?2:1,t=Math.floor(this.element.clientWidth/12),n=t%2==0?t:t-1;return{width:this.element.clientWidth,height:this.element.clientHeight,left:this.element.offsetLeft,top:this.element.offsetTop,scrollTop:this.element.scrollTop,sectionWidth:(this.element.clientWidth-n)/e,gap:n}}resolveChapter(e){let t=e,n=-1;for(let e=0;e-1)return this.flattenChapters[n];{let r=e.split("#")[0];for(let e=0;e-1)return this.flattenChapters[n];for(let e=0;e-1?{label:"",href:"",index:n}:null}}flatChapter(e){let t=[];for(let n=0;n0?(t.push(e[n]),t=t.concat(this.flatChapter(e[n].subitems))):t.push(e[n]);return this.flattenChapters=t,t}getChapter(){return this.chapterList}getChapterDoc(){return this.chapterDocList}goToPercentage(e){return f(this,void 0,void 0,(function*(){if(this.flattenChapters.length>0){let t=1===e?this.flattenChapters.length-1:Math.floor(this.flattenChapters.length*e);yield this.goToChapter(this.flattenChapters[t].index.toString(),this.flattenChapters[t].href,this.flattenChapters[t].label)}}))}goToChapterIndex(e){return f(this,void 0,void 0,(function*(){this.flattenChapters.length>0&&(yield this.goToChapter(this.flattenChapters[e].index,this.flattenChapters[e].href,this.flattenChapters[e].label))}))}goToChapter(e,t,n){return f(this,void 0,void 0,(function*(){console.log(e,t,n);let r=this.getDocument(),i=this.getIframe();r&&i&&(yield Ze(parseInt(e),n,t,this.chapterDocList,this.element,this.mode,this.format,this.tempLocation,r,i),t&&t.indexOf("#")>-1&&(yield Qe(this.element,this.mode,"","",t,"",r)),yield this.record(),this.trigger("rendered"))}))}goToPosition(e){return f(this,void 0,void 0,(function*(){let t=this.getDocument(),n=this.getIframe();if(!t||!n)return;let r=JSON.parse(e);this.tempLocation={text:r.text,chapterTitle:r.chapterTitle,chapterDocIndex:r.chapterDocIndex,chapterHref:r.chapterHref,count:r.count,page:r.page};let{text:i,chapterTitle:o,chapterDocIndex:s,chapterHref:a,count:l,page:c,cfi:h}=r;if(yield Ze(parseInt(s),o,a,this.chapterDocList,this.element,this.mode,this.format,this.tempLocation,t,n),h){const e=new mt(h,{});let t=this.getDocument();if(!t)return;const{node:n,offset:r}=e.resolve(t,{});if(console.log(n,r),n){let e=null,t=n;for(;t;){const n=t;if(n.tagName&&"h1,h2,h3,h4,h5,h6,p,div,ul,dl,ol,pre,blockquote,address".indexOf(n.tagName.toLowerCase())>-1){e=n;break}t=t.parentNode}e&&(l="ignore",i=e.textContent)}}yield Qe(this.element,this.mode,i,l,"",c,t),yield this.record(),this.trigger("rendered")}))}getDocument(){let e=document.getElementById("page-area");if(!e)return null;let t=e.getElementsByTagName("iframe")[0];if(!t)return null;let n=t.contentDocument;return n||null}getIframe(){let e=document.getElementById("page-area");if(!e)return null;let t=e.getElementsByTagName("iframe")[0];return t||null}goToNode(e){return f(this,void 0,void 0,(function*(){let t=this.getDocument();if(!t)return;let n=et(e,this.element,this.mode),r=n?p(n.offsetLeft)-p(n.marginLeft||parseFloat(getComputedStyle(n).marginLeft)):0,i=n?p(n.offsetTop)-p(n.marginTop||parseFloat(getComputedStyle(n).marginTop)):0;"scroll"!==this.mode?t.body.scrollTo(r,0):this.element.scrollTo(0,i),yield this.record(),this.trigger("rendered")}))}removeContent(){this.element.innerHTML=""}prev(){return f(this,void 0,void 0,(function*(){this.trigger("page-changed");let e=this.getDocument(),t=this.getIframe();if(e&&t){if("scroll"===this.mode&&0===p(this.element.scrollTop)||"scroll"!==this.mode&&0===p(e.body.scrollLeft)){yield Je(this.element,this.flatChapter(this.chapterList),this.chapterDocList,this.mode,this.format,this.tempLocation,e,t),parseInt(this.tempLocation.chapterDocIndex||"-1")>-1&&e.body.scrollTo(e.body.scrollWidth,0),this.trigger("rendered")}else"scroll"===this.mode?this.element.scrollBy({left:0,top:-(this.element.clientHeight-50),behavior:"smooth"}):yield Ve(this.element,this.animation,1,e,this.flipToNextPage,this.flipToPrevPage);yield this.record()}}))}next(){return f(this,void 0,void 0,(function*(){this.trigger("page-changed");let e=this.getDocument(),t=this.getIframe();e&&t&&(Math.abs(e.body.scrollWidth-p(e.body.scrollLeft)-e.body.clientWidth)<10&&"scroll"!==this.mode||Math.abs(this.element.scrollHeight-p(this.element.scrollTop)-this.element.clientHeight)<10&&"scroll"===this.mode?(yield ot(this.element,this.flatChapter(this.chapterList),this.chapterDocList,this.mode,this.format,this.tempLocation,e,t),this.trigger("rendered")):"scroll"===this.mode?this.element.scrollBy({left:0,top:this.element.clientHeight-50,behavior:"smooth"}):yield Ve(this.element,this.animation,-1,e,this.flipToNextPage,this.flipToPrevPage),yield this.record())}))}prevChapter(){return f(this,void 0,void 0,(function*(){this.trigger("page-changed");let e=this.getDocument(),t=this.getIframe();e&&t&&(yield Je(this.element,this.flatChapter(this.chapterList),this.chapterDocList,this.mode,this.format,this.tempLocation,e,t),yield this.record(),this.trigger("rendered"))}))}nextChapter(){return f(this,void 0,void 0,(function*(){this.trigger("page-changed");let e=this.getDocument(),t=this.getIframe();e&&t&&(yield ot(this.element,this.flatChapter(this.chapterList),this.chapterDocList,this.mode,this.format,this.tempLocation,e,t),yield this.record(),this.trigger("rendered"))}))}visibleText(){let e=this.getDocument();return e?st(this.element,this.mode,e):""}audioText(){let e=this.getDocument();return e?((e,t,n)=>{let r=Xe(n.body).filter((e=>!at(e))).filter((e=>(e.textContent||"").trim())).filter((e=>"img"!==e.textContent)).map((e=>e.textContent)),i=0,o=st(e,t,n);if(o&&o.length>0){let e=o[0];i=r.indexOf(e)}return r.slice(i)})(this.element,this.mode,e):""}highlightNode(e,t){let n=this.getDocument();n&&((e,t,n)=>{let r=Xe(n.body).filter((n=>(n.getAttribute("style")===t&&n.setAttribute("style",""),(n.textContent||"").trim()&&n.textContent===e)));r.length>0&&r[0].setAttribute("style",t)})(e,t,n)}doSearch(e){return f(this,void 0,void 0,(function*(){return yield((e,n)=>f(void 0,void 0,void 0,(function*(){var r;let i=[];for(let t=0;t!at(e)));for(let o=0;o-1&&i.push({excerpt:(null===(r=s[o].textContent)||void 0===r?void 0:r.substring(a-100,a+100))||"",cfi:JSON.stringify({text:s[o].textContent,chapterTitle:n[t].label,chapterDocIndex:t,chapterHref:n[t].href,count:"search",percentage:t/n.length})})}}for(let e=0;esetTimeout(e,1e3))));let e=this.getDocument();e&&(yield nt(this.element,this.mode,this.flatChapter(this.chapterList),this.tempLocation,e,null))}))}getPosition(){return this.tempLocation}getNotePosition(){return f(this,void 0,void 0,(function*(){let e=this.getDocument();if(!e)return;let t=function(e){const t=e.getSelection();if(!t)return null;if(t.rangeCount>0)return t.getRangeAt(0).startContainer.parentElement;return null}(e);return t?(yield nt(this.element,this.mode,this.flatChapter(this.chapterList),this.tempLocation,e,t),this.tempLocation):void 0}))}setStyle(e){let t=this.getDocument();t&&t.body.setAttribute("style",e)}getHightlightCoords(e){return f(this,void 0,void 0,(function*(){n.init();let e=this.getDocument(),t=this.getIframe();if(e&&t)return n.getSelection(t).saveCharacterRanges(e.body)[0]}))}renderHighlighters(e,t){return f(this,void 0,void 0,(function*(){let n=this.getDocument(),r=this.getIframe();if(n&&r){St(n);for(let i=0;if(void 0,void 0,void 0,(function*(){let n=yield a.loadAsync(e);var r=n.file("toc.json");let i=[];r&&(i=JSON.parse(yield r.async("string")));var o=n.file("sections.json");let s=[];o&&(s=JSON.parse(yield o.async("string")));const l={getCover:()=>""};return l.sections=s.map(((e,t)=>({id:e.href,load:()=>(e=>f(void 0,void 0,void 0,(function*(){var t=n.file("chapters/"+e+".html");let r="";return t&&(r=yield t.async("string")),URL.createObjectURL(new Blob([r],{type:"text/html"}))})))(t),unload:()=>{},loadAsset:e=>(e=>f(void 0,void 0,void 0,(function*(){var t=n.file(e);let r;return t&&(r=yield t.async("arraybuffer")),URL.createObjectURL(new Blob([r],{type:Dt[e.split(".").reverse()[0]]}))})))(e)}))),l.toc=i.map((e=>({label:e.label,href:e.href,subitems:e.subitems}))),l.rendition={layout:"pre-paginated"},l.resolveHref=e=>({index:t.findLastIndex(s,{href:e})}),l.splitTOCHref=e=>[e,null],l.getTOCFragment=e=>e.documentElement,l})),Pt=e=>new Promise(((t,n)=>f(void 0,void 0,void 0,(function*(){let n=new L(e),r=yield n.getChapter(e.toc),i=yield n.getChapterDoc(),o=r,s=i.map((e=>({href:e.href,label:e.label}))),l=yield Promise.all(i.map((e=>f(void 0,void 0,void 0,(function*(){let t="";if(e.text.load){let n=yield fetch(yield e.text.load()).then((e=>e.blob()));t=yield n.text()}return t}))))),c=new a;c.file("toc.json",JSON.stringify(o)),c.file("sections.json",JSON.stringify(s));let h=[];for(let e=0;ee.blob()));r.file(t+"."+Nt[o.type],o);let s="imgs/"+e+"/"+t+"."+Nt[o.type];n[t].src=s,n[t].getAttribute("xlink:href")&&n[t].setAttribute("xlink:href",s)}catch(e){console.log(e)}}let r=Array.from(t.getElementsByTagName("link"));for(let t=0;te.blob()));i.file(t+"."+Nt[r.type],r),n.href="css/"+e+"/"+t+"."+Nt[r.type]}catch(e){console.log(e)}}h.push(t.documentElement.innerHTML)}let d=c.folder("chapters");if(d){for(let e=0;ef(void 0,void 0,void 0,(function*(){t(yield new Response(e).arrayBuffer())})))).catch((e=>{t("err")}))}}))));class Ft extends Ot{constructor(e,t,n){super({mode:t,format:"EPUB",animation:n}),this.epubBuffer=e}renderTo(e){return new Promise(((t,n)=>f(this,void 0,void 0,(function*(){this.element=e,this.book||(yield this.parse()),console.log(this.book,"this.book");let n=new L(this.book);this.chapterList=yield n.getChapter(this.book.toc),this.chapterDocList=yield n.getChapterDoc(),w(e);let r=this.getDocument();r&&(T(e,this.mode,r),t())}))))}parse(){return f(this,void 0,void 0,(function*(){let e=new Blob([this.epubBuffer]),t=new File([e],"book",{lastModified:(new Date).getTime(),type:e.type});try{const e=yield this.makeZipLoader(t);this.book=yield new ke(e).init()}catch(e){throw console.log(e),e}}))}preCache(){return f(this,void 0,void 0,(function*(){return this.book||(yield this.parse()),yield Pt(this.book)}))}makeZipLoader(e){return f(this,void 0,void 0,(function*(){let t;try{t=new r(new i(e))}catch(e){throw e}const n=yield t.getEntries(),a=new Map(n.map((e=>[e.filename,e]))),l=e=>(t,...n)=>a.has(t)?e(a.get(t),...n):null;return{entries:n,loadText:l((e=>e.getData(new o))),loadBlob:l(((e,t)=>new Promise(((n,r)=>{e.getData(new s(t)).then((e=>{n(e)})).catch((e=>{n(new Blob)}))})))),getSize:e=>{var t,n;return null!==(n=null===(t=a.get(e))||void 0===t?void 0:t.uncompressedSize)&&void 0!==n?n:0}}}))}getMetadata(){return f(this,void 0,void 0,(function*(){try{this.book||(yield this.parse()),console.log(this.book);let e=new L(this.book);return yield e.getMetadata()}catch(e){throw console.log(e),e}}))}}const _t=e=>{if(!e)return"";const t=document.createElement("textarea");return t.innerHTML=e,t.value},Ht={XML:"application/xml",XHTML:"application/xhtml+xml",HTML:"text/html",CSS:"text/css",SVG:"image/svg+xml"},Ut={name:[0,32,"string"],type:[60,4,"string"],creator:[64,4,"string"],numRecords:[76,2,"uint"]},jt={compression:[0,2,"uint"],numTextRecords:[8,2,"uint"],recordSize:[10,2,"uint"],encryption:[12,2,"uint"]},$t={magic:[16,4,"string"],length:[20,4,"uint"],type:[24,4,"uint"],encoding:[28,4,"uint"],uid:[32,4,"uint"],version:[36,4,"uint"],titleOffset:[84,4,"uint"],titleLength:[88,4,"uint"],localeRegion:[94,1,"uint"],localeLanguage:[95,1,"uint"],resourceStart:[108,4,"uint"],huffcdic:[112,4,"uint"],numHuffcdic:[116,4,"uint"],exthFlag:[128,4,"uint"],trailingFlags:[240,4,"uint"],indx:[244,4,"uint"]},zt={resourceStart:[108,4,"uint"],fdst:[192,4,"uint"],numFdst:[196,4,"uint"],frag:[248,4,"uint"],skel:[252,4,"uint"],guide:[260,4,"uint"]},qt={magic:[0,4,"string"],length:[4,4,"uint"],count:[8,4,"uint"]},Wt={magic:[0,4,"string"],length:[4,4,"uint"],type:[8,4,"uint"],idxt:[20,4,"uint"],numRecords:[24,4,"uint"],encoding:[28,4,"uint"],language:[32,4,"uint"],total:[36,4,"uint"],ordt:[40,4,"uint"],ligt:[44,4,"uint"],numLigt:[48,4,"uint"],numCncx:[52,4,"uint"]},Xt={magic:[0,4,"string"],length:[4,4,"uint"],numControlBytes:[8,4,"uint"]},Vt={magic:[0,4,"string"],offset1:[8,4,"uint"],offset2:[12,4,"uint"]},Gt={magic:[0,4,"string"],length:[4,4,"uint"],numEntries:[8,4,"uint"],codeLength:[12,4,"uint"]},Jt={magic:[0,4,"string"],numEntries:[8,4,"uint"]},Kt={flags:[8,4,"uint"],dataStart:[12,4,"uint"],keyLength:[16,4,"uint"],keyStart:[20,4,"uint"]},Zt={1252:"windows-1252",65001:"utf-8"},Yt={100:["creator","string",!0],101:["publisher"],103:["description"],104:["isbn"],105:["subject","string",!0],106:["date"],108:["contributor","string",!0],109:["rights"],110:["subjectCode","string",!0],112:["source","string",!0],113:["asin"],121:["boundary","uint"],122:["fixedLayout"],125:["numResources","uint"],126:["originalResolution"],127:["zeroGutter"],128:["zeroMargin"],129:["coverURI"],132:["regionMagnification"],201:["coverOffset","uint"],202:["thumbnailOffset","uint"],503:["title"],524:["language","string",!0],527:["pageProgressionDirection"]},Qt={1:["ar","ar-SA","ar-IQ","ar-EG","ar-LY","ar-DZ","ar-MA","ar-TN","ar-OM","ar-YE","ar-SY","ar-JO","ar-LB","ar-KW","ar-AE","ar-BH","ar-QA"],2:["bg"],3:["ca"],4:["zh","zh-TW","zh-CN","zh-HK","zh-SG"],5:["cs"],6:["da"],7:["de","de-DE","de-CH","de-AT","de-LU","de-LI"],8:["el"],9:["en","en-US","en-GB","en-AU","en-CA","en-NZ","en-IE","en-ZA","en-JM",null,"en-BZ","en-TT","en-ZW","en-PH"],10:["es","es-ES","es-MX",null,"es-GT","es-CR","es-PA","es-DO","es-VE","es-CO","es-PE","es-AR","es-EC","es-CL","es-UY","es-PY","es-BO","es-SV","es-HN","es-NI","es-PR"],11:["fi"],12:["fr","fr-FR","fr-BE","fr-CA","fr-CH","fr-LU","fr-MC"],13:["he"],14:["hu"],15:["is"],16:["it","it-IT","it-CH"],17:["ja"],18:["ko"],19:["nl","nl-NL","nl-BE"],20:["no","nb","nn"],21:["pl"],22:["pt","pt-BR","pt-PT"],23:["rm"],24:["ro"],25:["ru"],26:["hr",null,"sr"],27:["sk"],28:["sq"],29:["sv","sv-SE","sv-FI"],30:["th"],31:["tr"],32:["ur"],33:["id"],34:["uk"],35:["be"],36:["sl"],37:["et"],38:["lv"],39:["lt"],41:["fa"],42:["vi"],43:["hy"],44:["az"],45:["eu"],46:["hsb"],47:["mk"],48:["st"],49:["ts"],50:["tn"],52:["xh"],53:["zu"],54:["af"],55:["ka"],56:["fo"],57:["hi"],58:["mt"],59:["se"],62:["ms"],63:["kk"],65:["sw"],67:["uz",null,"uz-UZ"],68:["tt"],69:["bn"],70:["pa"],71:["gu"],72:["or"],73:["ta"],74:["te"],75:["kn"],76:["ml"],77:["as"],78:["mr"],79:["sa"],82:["cy","cy-GB"],83:["gl","gl-ES"],87:["kok"],97:["ne"],98:["fy"]},en=(e,t)=>{const n=new e.constructor(e.length+t.length);return n.set(e),n.set(t,e.length),n},tn=(e,t,n)=>{const r=new e.constructor(e.length+t.length+n.length);return r.set(e),r.set(t,e.length),r.set(n,e.length+t.length),r},nn=new TextDecoder,rn=e=>nn.decode(e),on=e=>{if(!e)return;const t=e.byteLength,n=4===t?"getUint32":2===t?"getUint16":"getUint8";return new DataView(e)[n](0)},sn=(e,t)=>Object.fromEntries(Array.from(Object.entries(e)).map((([e,[n,r,i]])=>[e,("string"===i?rn:on)(t.slice(n,n+r))]))),an=e=>new TextDecoder(Zt[e]),ln=(e,t=0)=>{let n=0,r=0;for(const i of e.subarray(t,t+4))if(n=n<<7|(127&i)>>>0,r++,128&i)break;return{value:n,length:r}},cn=e=>{let t=0;for(const n of e.subarray(-4))128&n&&(t=0),t=t<<7|127&n;return t},hn=e=>{let t=0;for(;e>0;e>>=1)1&~e||t++;return t},dn=e=>{let t=0;for(;!(1&e);)e>>=1,t++;return t},un=e=>{let t=[];for(let n=0;n>>3,s=3+(7&i);for(let e=0;e{const n=t+32,r=n>>3;let i=0n;for(let n=t>>3;n<=r;n++)i=i<<8n|BigInt(e[n]??0);return i>>8n-BigInt(7&n)&0xffffffffn},pn=async(e,t)=>{const n=await t(e),r=sn(Wt,n);if("INDX"!==r.magic)throw new Error("Invalid INDX record");const i=an(r.encoding),o=n.slice(r.length),s=sn(Xt,o);if("TAGX"!==s.magic)throw new Error("Invalid TAGX section");const a=(s.length-12)/4,l=Array.from({length:a},((e,t)=>new Uint8Array(o.slice(12+4*t,12+4*t+4)))),c={};let h=0;for(let n=0;n1){const{value:n,length:r}=ln(i,p);h.push([e,null,n,t]),p+=r}else h.push([e,1,null,t]);else h.push([e,a>>dn(n),null,t])}const g={};for(const[e,t,n,r]of h){const o=[];if(null!=t)for(let e=0;eon(n.slice(8*t,8*t+4)))).map(((e,t,n)=>[e,n[t+1]]))}loadRecord(e){const t=this.#h[e];if(!t)throw new RangeError("Record index out of bounds");return this.#c.slice(...t).arrayBuffer()}async loadMagic(e){const t=this.#h[e][0];return rn(await this.#c.slice(t,t+4).arrayBuffer())}}class mn extends gn{#d=0;#u;#f;#p;#g;#m;constructor({unzlib:e}){super(),this.unzlib=e}async open(e){await super.open(e),this.headers=this.#y(await super.loadRecord(0)),this.#u=this.headers.mobi.resourceStart;let t=this.headers.mobi.version>=8;if(!t){const e=this.headers.exth?.boundary;if(e<4294967295)try{this.headers=this.#y(await super.loadRecord(e)),this.#d=e,t=!0}catch(e){console.warn(e),console.warn("Failed to open KF8; falling back to MOBI")}}return await this.#b(),t?new kn(this).init():new wn(this).init()}#y(e){const t=sn(jt,e),n=sn($t,e);if("MOBI"!==n.magic)throw new Error("Missing MOBI header");const{titleOffset:r,titleLength:i,localeLanguage:o,localeRegion:s}=n;n.title=e.slice(r,r+i);const a=Qt[o];n.language=a?.[s>>2]??a?.[0];const l=64&n.exthFlag?((e,t)=>{const{magic:n,count:r}=sn(qt,e);if("EXTH"!==n)throw new Error("Invalid EXTH header");const i=an(t),o={};let s=12;for(let t=0;t=8?sn(zt,e):null}}async#b(){const{palmdoc:e,mobi:t}=this.headers;this.#f=an(t.encoding),this.#p=new TextEncoder;const{compression:n}=e;if(this.#g=1===n?e=>e:2===n?un:17480===n?await(async(e,t)=>{const n=await t(e.huffcdic),{magic:r,offset1:i,offset2:o}=sn(Vt,n);if("HUFF"!==r)throw new Error("Invalid HUFF record");const s=Array.from({length:256},((e,t)=>i+4*t)).map((e=>on(n.slice(e,e+4)))).map((e=>[128&e,31&e,e>>>8])),a=[null].concat(Array.from({length:32},((e,t)=>o+8*t)).map((e=>[on(n.slice(e,e+4)),on(n.slice(e+4,e+8))]))),l=[];for(let n=1;n{let t=new Uint8Array;const n=8*e.byteLength;for(let r=0;r>>24];if(!o){for(;i>>>32-hn)break;const u=d-(i>>>32-h);let[f,p]=l[u];p||(f=c(f),l[u]=[f,!0]),t=en(t,f)}return t};return c})(t,this.loadRecord.bind(this)):null,!this.#g)throw new Error("Unknown compression type");const{trailingFlags:r}=t,i=1&r,o=hn(r>>>1);this.#m=e=>{for(let t=0;tnew Uint8Array(e))).then(this.#m).then(this.#g)}async loadResource(e){const t=await super.loadRecord(this.#u+e),n=rn(t.slice(0,4));return"FONT"===n?(async(e,t)=>{const{flags:n,dataStart:r,keyLength:i,keyStart:o}=sn(Kt,e),s=new Uint8Array(e.slice(r));if(2&n){const t=16===i?1024:1040,n=new Uint8Array(e.slice(o,o+i)),r=Math.min(t,s.length);for(var a=0;a{const{table:n,cncx:r}=await pn(e,t),i=n.map((({tagMap:e},t)=>({index:t,offset:e[1]?.[0],size:e[2]?.[0],label:r[e[3]]??"",headingLevel:e[4]?.[0],pos:e[6],parent:e[21]?.[0],firstChild:e[22]?.[0],lastChild:e[23]?.[0]}))),o=e=>(null==e.firstChild||(e.children=i.filter((t=>t.parent===e.index)).map(o)),e);return i.filter((e=>0===e.headingLevel)).map(o)})(e,this.loadRecord.bind(this))}getMetadata(){const{mobi:e,exth:t}=this.headers;return{identifier:e.uid.toString(),title:_t(t?.title||this.decode(e.title)),author:t?.creator?.map(_t),publisher:_t(t?.publisher),language:t?.language??e.language,published:t?.date,description:_t(t?.description),subject:t?.subject?.map(_t),rights:_t(t?.rights)}}async getCover(){const{exth:e}=this.headers,t=e?.coverOffset<4294967295?e?.coverOffset:e?.thumbnailOffset<4294967295?e?.thumbnailOffset:null;if(null!=t){const e=await this.loadResource(t);return new Blob([e])}}}const yn=/<\s*(?:mbp:)?pagebreak[^>]*>/gi,bn=/<[^<>]+filepos=['"]{0,1}(\d+)[^<>]*>/gi;class wn{parser=new DOMParser;serializer=new XMLSerializer;#w=new Map;#v=new Map;#r=new Map;#x;#C=[];#S=Ht.HTML;constructor(e){this.mobi=e}async init(){let e=new Uint8Array;for(let t=0;tString.fromCharCode(e))).join("");this.#x=[0].concat(Array.from(t.matchAll(yn),(e=>e.index))).map(((e,n,r)=>t.slice(e,r[n+1]))).map((e=>Uint8Array.from(e,(e=>e.charCodeAt(0))))).map((e=>({book:this,raw:e}))).reduce(((e,t)=>{const n=e[e.length-1];return t.start=n?.end??0,t.end=t.start+t.raw.byteLength,e.concat(t)}),[]),this.sections=this.#x.map(((e,t)=>({id:t,load:()=>this.loadSection(e),createDocument:()=>this.createDocument(e),size:e.end-e.start})));try{this.landmarks=await this.getGuide();const e=this.landmarks.find((({type:e})=>e?.includes("toc")))?.href;if(e){const{index:t}=this.resolveHref(e),n=await this.sections[t].createDocument();let r,i=0,o=0;const s=new Map,a=new Map;this.toc=Array.from(n.querySelectorAll("a[filepos]")).reduce(((e,t)=>{const n=(e=>{let t=0;for(;e;){const n=e.parentElement;if(n){const e=n.tagName.toLowerCase();"p"===e?t+=1.5:"blockquote"===e&&(t+=2)}e=n}return t})(t),l={label:t.innerText?.trim(),href:`filepos:${t.getAttribute("filepos")}`},c=n>o?i+1:n===o?i:s.get(n)??Math.max(0,i-1);if(c>i)r?(r.subitems??=[],r.subitems.push(l),a.set(c,r)):e.push(l);else{const t=a.get(c);t?t.subitems.push(l):e.push(l)}return r=l,i=c,o=n,s.set(n,c),e}),[])}}catch(e){console.warn(e)}return this.#C=[...new Set(Array.from(t.matchAll(bn),(e=>e[1])))].map((e=>({filepos:e,number:Number(e)}))).sort(((e,t)=>e.number-t.number)),this.metadata=this.mobi.getMetadata(),this.getCover=this.mobi.getCover.bind(this.mobi),this}async getGuide(){const e=await this.createDocument(this.#x[0]);return Array.from(e.getElementsByTagName("reference"),(e=>({label:e.getAttribute("title"),type:e.getAttribute("type")?.split(/\s/),href:`filepos:${e.getAttribute("filepos")}`})))}async loadResource(e){if(this.#w.has(e))return this.#w.get(e);const t=await this.mobi.loadResource(e),n=URL.createObjectURL(new Blob([t]));return this.#w.set(e,n),n}async loadRecindex(e){return this.loadResource(Number(e)-1)}async replaceResources(e){for(const t of e.querySelectorAll("img[recindex]")){const e=t.getAttribute("recindex");try{t.src=await this.loadRecindex(e)}catch(t){console.warn(`Failed to load image ${e}`)}}for(const t of e.querySelectorAll("[mediarecindex]")){const e=t.getAttribute("mediarecindex"),n=t.getAttribute("recindex");try{t.src=await this.loadRecindex(e),n&&(t.poster=await this.loadRecindex(n))}catch(t){console.warn(`Failed to load media ${e}`)}}for(const t of e.querySelectorAll("[filepos]")){const e=t.getAttribute("filepos");t.href=`filepos:${e}`}}async loadText(e){if(this.#v.has(e))return this.#v.get(e);const{raw:t}=e,n=this.#C.filter((({number:t})=>t>=e.start&&t({...t,offset:t.number-e.start})));let r=t;n.length&&(r=t.subarray(0,n[0].offset),n.forEach((({filepos:e,offset:i},o)=>{const s=n[o+1],a=this.mobi.encode(``);r=tn(r,a,t.subarray(i,s?.offset))})));const i=this.mobi.decode(r).replaceAll(yn,"");return this.#v.set(e,i),i}async createDocument(e){const t=await this.loadText(e);return this.parser.parseFromString(t,this.#S)}async loadSection(e){if(this.#r.has(e))return this.#r.get(e);const t=await this.createDocument(e),n=t.createElement("style");t.head.append(n),n.append(t.createTextNode("blockquote {\n margin-block-start: 0;\n margin-block-end: 0;\n margin-inline-start: 1em;\n margin-inline-end: 0;\n }")),await this.replaceResources(t);const r=this.serializer.serializeToString(t),i=URL.createObjectURL(new Blob([r],{type:this.#S}));return this.#r.set(e,i),i}resolveHref(e){const t=e.match(/filepos:(.*)/)[1],n=Number(t);return{index:this.#x.findIndex((e=>e.end>n)),anchor:e=>e.getElementById(`filepos${t}`)}}splitTOCHref(e){const t=e.match(/filepos:(.*)/)[1],n=Number(t);return[this.#x.findIndex((e=>e.end>n)),`filepos${t}`]}getTOCFragment(e,t){return e.getElementById(t)}isExternal(e){return/^(?!blob|filepos)\w+:/i.test(e)}destroy(){for(const e of this.#w.values())URL.revokeObjectURL(e);for(const e of this.#r.values())URL.revokeObjectURL(e)}}const vn=/kindle:(flow|embed):(\w+)(?:\?mime=(\w+\/[-+.\w]+))?/,xn=/kindle:pos:fid:(\w+):off:(\w+)/,Cn=e=>{const[t,n]=e.match(xn).slice(1);return{fid:parseInt(t,32),off:parseInt(n,32)}},Sn=(e=0,t=0)=>`kindle:pos:fid:${e.toString(32).toUpperCase().padStart(4,"0")}:off:${t.toString(32).toUpperCase().padStart(10,"0")}`,Tn=e=>{const t=e.match(/\s(id|name|aid)\s*=\s*['"]([^'"]*)['"]/i);if(!t)return;const[,n,r]=t;return`[${n}="${CSS.escape(r)}"]`},Ln=e=>{for(const t of e){if("page-spread-left"===t||"rendition:page-spread-left"===t)return"left";if("page-spread-right"===t||"rendition:page-spread-right"===t)return"right";if("rendition:page-spread-center"===t)return"center"}};class kn{parser=new DOMParser;serializer=new XMLSerializer;#r=new Map;#T=new Map;#L=new Map;#k={};#x;#A;#I=new Uint8Array;#E=new Uint8Array;#M=-1;#B=-1;#S=Ht.XHTML;#O=new Map;constructor(e){this.mobi=e}async init(){const e=this.mobi.loadRecord.bind(this.mobi),{kf8:t}=this.mobi.headers;try{const n=await e(t.fdst),r=sn(Jt,n);if("FDST"!==r.magic)throw new Error("Missing FDST record");const i=Array.from({length:r.numEntries},((e,t)=>12+8*t)).map((e=>[on(n.slice(e,e+4)),on(n.slice(e+4,e+8))]));this.#k.fdstTable=i,this.#A=i[i.length-1][1]}catch{}const n=(await pn(t.skel,e)).table.map((({name:e,tagMap:t},n)=>({index:n,name:e,numFrag:t[1][0],offset:t[6][0],length:t[6][1]}))),r=await pn(t.frag,e),i=r.table.map((({name:e,tagMap:t})=>({insertOffset:parseInt(e),selector:r.cncx[t[2][0]],index:t[4][0],offset:t[6][0],length:t[6][1]})));this.#k.skelTable=n,this.#k.fragTable=i,this.#x=n.reduce(((e,t)=>{const n=e[e.length-1],r=n?.fragEnd??0,o=r+t.numFrag,s=i.slice(r,o),a=t.length+s.map((e=>e.length)).reduce(((e,t)=>e+t)),l=(n?.totalLength??0)+a;return e.concat({skel:t,frags:s,fragEnd:o,length:a,totalLength:l})}),[]);const o=await this.getResourcesByMagic(["RESC","PAGE"]),s=new Map;if(o.RESC){const e=await this.mobi.loadRecord(o.RESC),t=this.mobi.decode(e.slice(16)).replace(/\0/g,""),n=t.search(/\?>/),r=`${t.slice(n)}`,i=this.parser.parseFromString(r,Ht.XML);for(const e of i.querySelectorAll("spine > itemref")){const t=parseInt(e.getAttribute("skelid"));s.set(t,Ln(e.getAttribute("properties")?.split(" ")??[]))}}this.sections=this.#x.map(((e,t)=>e.frags.length?{id:t,load:()=>this.loadSection(e),createDocument:()=>this.createDocument(e),size:e.length,pageSpread:s.get(t)}:{linear:"no"}));try{const e=await this.mobi.getNCX(),t=({label:e,pos:n,children:r})=>{const[i,o]=n,s=Sn(i,o),a=this.#T.get(i);return a?a.push(o):this.#T.set(i,[o]),{label:_t(e),href:s,subitems:r?.map(t)}};this.toc=e?.map(t),this.landmarks=await this.getGuide()}catch(e){console.warn(e)}const{exth:a}=this.mobi.headers;return this.dir=a.pageProgressionDirection,this.rendition={layout:"true"===a.fixedLayout?"pre-paginated":"reflowable",viewport:Object.fromEntries(a.originalResolution?.split("x")?.slice(0,2)?.map(((e,t)=>[t?"height":"width",e]))??[])},this.metadata=this.mobi.getMetadata(),this.getCover=this.mobi.getCover.bind(this.mobi),this}async getResourcesByMagic(e){const t={},n=this.mobi.headers.kf8.resourceStart,r=this.mobi.pdb.numRecords;for(let i=n;ie===n));r&&(t[r]=i)}catch{}return t}async getGuide(){const e=this.mobi.headers.kf8.guide;if(e<4294967295){const t=this.mobi.loadRecord.bind(this.mobi),{table:n,cncx:r}=await pn(e,t);return n.map((({name:e,tagMap:t})=>({label:r[t[1][0]]??"",type:e?.split(/\s/),href:Sn(t[6]?.[0]??t[3]?.[0])})))}}async loadResourceBlob(e){const{resourceType:t,id:n,type:r}=(e=>{const[t,n,r]=e.match(vn).slice(1);return{resourceType:t,id:parseInt(n,32),type:r}})(e),i="flow"===t?await this.loadFlow(n):await this.mobi.loadResource(n-1),o=[Ht.XHTML,Ht.HTML,Ht.CSS,Ht.SVG].includes(r)?await this.replaceResources(this.mobi.decode(i)):i,s=r===Ht.SVG?this.parser.parseFromString(o,r):null;return[new Blob([o],{type:r}),s?.getElementsByTagNameNS("http://www.w3.org/2000/svg","image")?.length?s.documentElement:null]}async loadResource(e){if(this.#r.has(e))return this.#r.get(e);const[t,n]=await this.loadResourceBlob(e),r=n?e:URL.createObjectURL(t);return n&&this.#O.set(r,n),this.#r.set(e,r),r}replaceResources(e){return(async(e,t,n)=>{const r=[];e.replace(t,((...e)=>(r.push(e),null)));const i=[];for(const e of r)i.push(await n(...e));return e.replace(t,(()=>i.shift()))})(e,new RegExp(vn,"g"),this.loadResource.bind(this))}async loadRaw(e,t){const n=t-this.#I.length,r=null==this.#A?1/0:this.#A-this.#E.length-e;if(n<0||ne;){const e=this.mobi.headers.palmdoc.numTextRecords-1-++this.#B,t=await this.mobi.loadText(e);this.#E=en(t,this.#E)}const i=this.#A-this.#E.length;return this.#E.slice(e-i,t-i)}loadFlow(e){if(e<4294967295)return this.loadRaw(...this.#k.fdstTable[e])}async loadText(e){const{skel:t,frags:n,length:r}=e,i=await this.loadRaw(t.offset,t.offset+r);let o=i.slice(0,t.length);for(const e of n){const n=e.insertOffset-t.offset,r=t.length+e.offset,s=i.slice(r,r+e.length);o=tn(o.slice(0,n),s,o.slice(n));const a=this.#T.get(e.index);if(a)for(const t of a){const n=this.mobi.decode(s).slice(t),r=Tn(n);this.#D(e.index,t,r)}}return this.mobi.decode(o)}async createDocument(e){const t=await this.loadText(e);return this.parser.parseFromString(t,this.#S)}async loadSection(e){if(this.#r.has(e))return this.#r.get(e);const t=await this.loadText(e),n=await this.replaceResources(t);let r=this.parser.parseFromString(n,this.#S);r.querySelector("parsererror")&&(this.#S=Ht.HTML,r=this.parser.parseFromString(n,this.#S));for(const[e,t]of this.#O)for(const n of r.querySelectorAll(`img[src="${e}"]`))n.replaceWith(t);const i=URL.createObjectURL(new Blob([this.serializer.serializeToString(r)],{type:this.#S}));return this.#r.set(e,i),i}getIndexByFID(e){return this.#x.findIndex((t=>t.frags.some((t=>t.index===e))))}#D(e,t,n){const r=this.#L.get(e);if(r)r.set(t,n);else{const r=new Map;this.#L.set(e,r),r.set(t,n)}}async resolveHref(e){const{fid:t,off:n}=Cn(e),r=this.getIndexByFID(t);if(r<0)return;const i=this.#L.get(t)?.get(n);if(i)return{index:r,anchor:e=>e.querySelector(i)};const{skel:o,frags:s}=this.#x[r],a=s.find((e=>e.index===t)),l=o.offset+o.length+a.offset,c=await this.loadRaw(l,l+a.length),h=this.mobi.decode(c).slice(n),d=Tn(h);this.#D(t,n,d);return{index:r,anchor:e=>e.querySelector(d)}}splitTOCHref(e){const t=Cn(e);return[this.getIndexByFID(t.fid),t]}getTOCFragment(e,{fid:t,off:n}){const r=this.#L.get(t)?.get(n);return e.querySelector(r)}isExternal(e){return/^(?!blob|kindle)\w+:/i.test(e)}destroy(){for(const e of this.#r.values())URL.revokeObjectURL(e)}}class An extends Ot{constructor(e,t,n){super({mode:t,format:"MOBI",animation:n}),this.mobiBuffer=e}renderTo(e){return new Promise(((t,n)=>f(this,void 0,void 0,(function*(){this.element=e,this.book||(yield this.parse());let n=new L(this.book);this.chapterList=yield n.getChapter(this.book.toc),this.chapterDocList=yield n.getChapterDoc(),w(e);let r=this.getDocument();r&&(T(e,this.mode,r),t())}))))}parse(){return f(this,void 0,void 0,(function*(){try{let e=new Blob([this.mobiBuffer]),t=new File([e],"book",{lastModified:(new Date).getTime(),type:e.type});(yield(async e=>"BOOKMOBI"===rn(await e.slice(60,68).arrayBuffer()))(t))&&(this.book=yield new mn({unzlib:l}).open(t))}catch(e){throw console.log(e),e}}))}preCache(){return f(this,void 0,void 0,(function*(){return this.book||(yield this.parse()),yield Pt(this.book)}))}getMetadata(){return f(this,void 0,void 0,(function*(){try{this.book||(yield this.parse());let e=new L(this.book);return yield e.getMetadata()}catch(e){throw console.log(e),e}}))}}const In=e=>`./lib/pdfjs/${e}`,En=window.pdfjsLib,Mn=async e=>await(await fetch(e)).text(),Bn=async()=>await Mn(In("text_layer_builder.css")),On=async()=>await Mn(In("annotation_layer_builder.css")),Dn=async(e,t)=>{const n=e.getViewport({scale:1});if(t){const t=document.createElement("canvas");t.height=n.height,t.width=n.width;const r=t.getContext("2d");return await e.render({canvasContext:r,viewport:n}).promise,new Promise((e=>t.toBlob(e)))}return URL.createObjectURL(new Blob([`\n \n \n \n \n \n
\n
\n
\n
\n
\n
\n\n `],{type:"text/html"}))},Nn=e=>({label:e.title,href:e.dest?JSON.stringify(e.dest):null,subitems:e.items.length?e.items.map(Nn):null}),Rn=async e=>{const t=new En.PDFDataRangeTransport(e.size,[]);t.requestDataRange=(n,r)=>{e.slice(n,r).arrayBuffer().then((e=>{t.onDataRange(n,e)}))};const n=await En.getDocument({range:t,cMapUrl:In("cmaps/"),standardFontDataUrl:In("standard_fonts/"),isEvalSupported:!1}).promise,r={rendition:{layout:"pre-paginated"}},{metadata:i,info:o}=await n.getMetadata()??{};r.metadata={title:i?.get("dc:title")??o?.Title,author:i?.get("dc:creator")??o?.Author,contributor:i?.get("dc:contributor"),description:i?.get("dc:description")??o?.Subject,language:i?.get("dc:language"),publisher:i?.get("dc:publisher"),subject:i?.get("dc:subject"),identifier:i?.get("dc:identifier"),source:i?.get("dc:source"),rights:i?.get("dc:rights")};const s=await n.getOutline();r.toc=s?.map(Nn);const a=new Map;return r.sections=Array.from({length:n.numPages}).map(((e,t)=>({id:t,load:async()=>{const e=a.get(t);if(e)return e;const r=await Dn(await n.getPage(t+1));return console.log(r),a.set(t,r),r},unload:async()=>{let e=await n.getPage(t+1);console.log(e),e.cleanup()},render:async(e,r)=>await(async(e,t,n)=>{const r=n*devicePixelRatio;let i=t.querySelector(".koodoPDFLayer");i.style.transform=`scale(${1/devicePixelRatio})`,i.style.transformOrigin="top left",i.style.setProperty("--scale-factor",r);const o=e.getViewport({scale:r}),s=document.createElement("canvas");i.style.width=`${o.width}px`,i.style.height=`${o.height}px`,s.height=o.height,s.width=o.width;const a=s.getContext("2d");await e.render({canvasContext:a,viewport:o}).promise,t.querySelector("#canvas").replaceChildren(t.adoptNode(s)),i.style.overflow="hidden";const l=t.querySelector(".textLayer"),c=new En.TextLayer({textContentSource:await e.streamTextContent(),container:l,viewport:o});await c.render();for(const e of document.querySelectorAll(".hiddenCanvasElement"))Object.assign(e.style,{position:"absolute",top:"0",left:"0",width:"0",height:"0",display:"none"});const h=document.createElement("div");h.className="endOfContent",l.append(h),l.onpointerdown=()=>l.classList.add("selecting"),l.onpointerup=()=>l.classList.remove("selecting");const d=t.querySelector(".annotationLayer");await new En.AnnotationLayer({page:e,viewport:o,div:d}).render({annotations:await e.getAnnotations(),linkService:{goToDestination:()=>{},getDestinationHash:e=>JSON.stringify(e),addLinkAttributes:(e,t)=>e.href=t}})})(await n.getPage(t+1),e,r),size:1e3,getDimension:async()=>{let e=(await n.getPage(t+1)).getViewport({scale:1});return{width:e.width,height:e.height}},getPage:async()=>await n.getPage(t+1)}))),r.isExternal=e=>/^\w+:/i.test(e),r.resolveHref=async e=>{const t=JSON.parse(e),r="string"==typeof t?await n.getDestination(t):t;return{index:await n.getPageIndex(r[0])}},r.splitTOCHref=async e=>{const t=JSON.parse(e),r="string"==typeof t?await n.getDestination(t):t;return[await n.getPageIndex(r[0]),null]},r.getTOCFragment=e=>e.documentElement,r.getCover=async()=>Dn(await n.getPage(1),!0),r.destroy=()=>n.destroy(),r};class Pn extends Ot{constructor(e,t,n){super({mode:t,format:"PDF",animation:n}),this.pdfBuffer=e}renderTo(e){return new Promise(((t,n)=>f(this,void 0,void 0,(function*(){this.element=e,this.book||(yield this.parse());let n=new L(this.book);this.chapterList=yield n.getChapter(this.book.toc),this.chapterDocList=yield n.getChapterDoc(),w(e);let r=this.getDocument();r&&(T(e,this.mode,r),t())}))))}parse(){return f(this,void 0,void 0,(function*(){try{let e=new Blob([this.pdfBuffer]),t=new File([e],"book",{lastModified:(new Date).getTime(),type:e.type});(yield(async e=>{const t=new Uint8Array(await e.slice(0,5).arrayBuffer());return 37===t[0]&&80===t[1]&&68===t[2]&&70===t[3]&&45===t[4]})(t))&&(this.book=yield Rn(t))}catch(e){throw console.log(e),e}}))}preCache(){return f(this,void 0,void 0,(function*(){return this.book||(yield this.parse()),yield Pt(this.book)}))}getMetadata(){return f(this,void 0,void 0,(function*(){try{this.book||(yield this.parse());let e=new L(this.book);return yield e.getMetadata()}catch(e){throw console.log(e),e}}))}getHightlightCoords(e){return f(this,void 0,void 0,(function*(){let t=this.getDocument();if(!t)return;var n=t.getSelection().getRangeAt(0).getClientRects();let r=yield this.chapterDocList[e].text.getPage(),i=yield Ke(this.element,this.mode,this.chapterDocList,e);var o=r.getViewport({scale:i});let s=t.querySelector("canvas");var a=null==s?void 0:s.getClientRects()[0];let l=[];for(let e=0;en[e].left&&(l[l.length-1].left=n[e].left),l[l.length-1].right{throw new Error("File system is not available")};var jn={},$n={};Object.defineProperty($n,"__esModule",{value:!0}),$n.default=(e,t,n)=>({confidence:n,name:t.name(e),lang:t.language?t.language():void 0});var zn=Fn&&Fn.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(jn,"__esModule",{value:!0});const qn=zn($n);jn.default=class{name(){return"ASCII"}match(e){const t=e.rawInput;for(let n=0;n126)return(0,qn.default)(e,this,0)}return(0,qn.default)(e,this,100)}};var Wn={},Xn=Fn&&Fn.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(Wn,"__esModule",{value:!0});const Vn=Xn($n);Wn.default=class{name(){return"UTF-8"}match(e){let t,n=!1,r=0,i=0,o=0;const s=e.rawInput;e.rawLen>=3&&239==(255&s[0])&&187==(255&s[1])&&191==(255&s[2])&&(n=!0);for(let t=0;t5)break;o=0}for(;t++,!(t>=e.rawLen);){if(128!=(192&s[t])){i++;break}if(0==--o){r++;break}}}}if(t=0,n&&0==i)t=100;else if(n&&r>10*i)t=80;else if(r>3&&0==i)t=100;else if(r>0&&0==i)t=80;else if(0==r&&0==i)t=10;else{if(!(r>10*i))return null;t=25}return(0,Vn.default)(e,this,t)}};var Gn={},Jn=Fn&&Fn.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(Gn,"__esModule",{value:!0}),Gn.UTF_32LE=Gn.UTF_32BE=Gn.UTF_16LE=Gn.UTF_16BE=void 0;const Kn=Jn($n);Gn.UTF_16BE=class{name(){return"UTF-16BE"}match(e){const t=e.rawInput;return t.length>=2&&254==(255&t[0])&&!(255&~t[1])?(0,Kn.default)(e,this,100):null}};Gn.UTF_16LE=class{name(){return"UTF-16LE"}match(e){const t=e.rawInput;return t.length>=2&&!(255&~t[0])&&254==(255&t[1])?t.length>=4&&0==t[2]&&0==t[3]?null:(0,Kn.default)(e,this,100):null}};class Zn{name(){return"UTF-32"}getChar(e,t){return-1}match(e){let t=0,n=0,r=!1,i=0;const o=e.rawLen/4*4,s=e.rawInput;if(0==o)return null;65279==this.getChar(s,0)&&(r=!0);for(let e=0;e=1114111||r>=55296&&r<=57343?n+=1:t+=1}return r&&0==n?i=100:r&&t>10*n?i=80:t>3&&0==n?i=100:t>0&&0==n?i=80:t>10*n&&(i=25),0==i?null:(0,Kn.default)(e,this,i)}}Gn.UTF_32BE=class extends Zn{name(){return"UTF-32BE"}getChar(e,t){return(255&e[t+0])<<24|(255&e[t+1])<<16|(255&e[t+2])<<8|255&e[t+3]}};Gn.UTF_32LE=class extends Zn{name(){return"UTF-32LE"}getChar(e,t){return(255&e[t+3])<<24|(255&e[t+2])<<16|(255&e[t+1])<<8|255&e[t+0]}};var Yn={},Qn=Fn&&Fn.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(Yn,"__esModule",{value:!0}),Yn.gb_18030=Yn.euc_kr=Yn.euc_jp=Yn.big5=Yn.sjis=void 0;const er=Qn($n);function tr(e,t){const n=(e,t,r,i)=>{if(i>>1);return t>e[o]?n(e,t,o+1,i):t=e.rawLen)return this.done=!0,-1;return 255&e.rawInput[this.nextIndex++]}}class rr{constructor(){this.commonChars=[]}name(){return"mbcs"}match(e){let t=0,n=0,r=0,i=0,o=0;const s=new nr;e:{for(s.reset();this.nextChar(s,e);){if(i++,s.error)r++;else{const e=4294967295&s.charValue;e>255&&(t++,null!=this.commonChars&&tr(this.commonChars,e)>=0&&n++)}if(r>=2&&5*r>=t)break e}if(t<=10&&0==r)o=0==t&&i<10?0:10;else if(t<20*r)o=0;else if(null==this.commonChars)o=30+t-20*r,o>100&&(o=100);else{const e=90/Math.log(t/4);o=Math.floor(Math.log(n+1)*e+10),o=Math.min(o,100)}}return 0==o?null:(0,er.default)(e,this,o)}nextChar(e,t){return!0}}Yn.sjis=class extends rr{constructor(){super(...arguments),this.commonChars=[33088,33089,33090,33093,33115,33129,33130,33141,33142,33440,33442,33444,33449,33450,33451,33453,33455,33457,33459,33461,33463,33469,33470,33473,33476,33477,33478,33480,33481,33484,33485,33500,33504,33511,33512,33513,33514,33520,33521,33601,33603,33614,33615,33624,33630,33634,33639,33653,33654,33673,33674,33675,33677,33683,36502,37882,38314]}name(){return"Shift_JIS"}language(){return"ja"}nextChar(e,t){e.index=e.nextIndex,e.error=!1;const n=e.charValue=e.nextByte(t);if(n<0)return!1;if(n<=127||n>160&&n<=223)return!0;const r=e.nextByte(t);return!(r<0)&&(e.charValue=n<<8|r,r>=64&&r<=127||r>=128&&r<=255||(e.error=!0),!0)}};function ir(e,t){e.index=e.nextIndex,e.error=!1;let n=0,r=0,i=0;return n=e.charValue=e.nextByte(t),n<0?e.done=!0:n<=141||(r=e.nextByte(t),e.charValue=e.charValue<<8|r,n>=161&&n<=254?r<161&&(e.error=!0):142!=n?143==n&&(i=e.nextByte(t),e.charValue=e.charValue<<8|i,i<161&&(e.error=!0)):r<161&&(e.error=!0)),0==e.done}Yn.big5=class extends rr{constructor(){super(...arguments),this.commonChars=[41280,41281,41282,41283,41287,41289,41333,41334,42048,42054,42055,42056,42065,42068,42071,42084,42090,42092,42103,42147,42148,42151,42177,42190,42193,42207,42216,42237,42304,42312,42328,42345,42445,42471,42583,42593,42594,42600,42608,42664,42675,42681,42707,42715,42726,42738,42816,42833,42841,42970,43171,43173,43181,43217,43219,43236,43260,43456,43474,43507,43627,43706,43710,43724,43772,44103,44111,44208,44242,44377,44745,45024,45290,45423,45747,45764,45935,46156,46158,46412,46501,46525,46544,46552,46705,47085,47207,47428,47832,47940,48033,48593,49860,50105,50240,50271]}name(){return"Big5"}language(){return"zh"}nextChar(e,t){e.index=e.nextIndex,e.error=!1;const n=e.charValue=e.nextByte(t);if(n<0)return!1;if(n<=127||255==n)return!0;const r=e.nextByte(t);return!(r<0)&&(e.charValue=e.charValue<<8|r,(r<64||127==r||255==r)&&(e.error=!0),!0)}};Yn.euc_jp=class extends rr{constructor(){super(...arguments),this.commonChars=[41377,41378,41379,41382,41404,41418,41419,41430,41431,42146,42148,42150,42152,42154,42155,42156,42157,42159,42161,42163,42165,42167,42169,42171,42173,42175,42176,42177,42179,42180,42182,42183,42184,42185,42186,42187,42190,42191,42192,42206,42207,42209,42210,42212,42216,42217,42218,42219,42220,42223,42226,42227,42402,42403,42404,42406,42407,42410,42413,42415,42416,42419,42421,42423,42424,42425,42431,42435,42438,42439,42440,42441,42443,42448,42453,42454,42455,42462,42464,42465,42469,42473,42474,42475,42476,42477,42483,47273,47572,47854,48072,48880,49079,50410,50940,51133,51896,51955,52188,52689],this.nextChar=ir}name(){return"EUC-JP"}language(){return"ja"}};Yn.euc_kr=class extends rr{constructor(){super(...arguments),this.commonChars=[45217,45235,45253,45261,45268,45286,45293,45304,45306,45308,45496,45497,45511,45527,45538,45994,46011,46274,46287,46297,46315,46501,46517,46527,46535,46569,46835,47023,47042,47054,47270,47278,47286,47288,47291,47337,47531,47534,47564,47566,47613,47800,47822,47824,47857,48103,48115,48125,48301,48314,48338,48374,48570,48576,48579,48581,48838,48840,48863,48878,48888,48890,49057,49065,49088,49124,49131,49132,49144,49319,49327,49336,49338,49339,49341,49351,49356,49358,49359,49366,49370,49381,49403,49404,49572,49574,49590,49622,49631,49654,49656,50337,50637,50862,51151,51153,51154,51160,51173,51373],this.nextChar=ir}name(){return"EUC-KR"}language(){return"ko"}};Yn.gb_18030=class extends rr{constructor(){super(...arguments),this.commonChars=[41377,41378,41379,41380,41392,41393,41457,41459,41889,41900,41914,45480,45496,45502,45755,46025,46070,46323,46525,46532,46563,46767,46804,46816,47010,47016,47037,47062,47069,47284,47327,47350,47531,47561,47576,47610,47613,47821,48039,48086,48097,48122,48316,48347,48382,48588,48845,48861,49076,49094,49097,49332,49389,49611,49883,50119,50396,50410,50636,50935,51192,51371,51403,51413,51431,51663,51706,51889,51893,51911,51920,51926,51957,51965,52460,52728,52906,52932,52946,52965,53173,53186,53206,53442,53445,53456,53460,53671,53930,53938,53941,53947,53972,54211,54224,54269,54466,54490,54754,54992]}name(){return"GB18030"}language(){return"zh"}nextChar(e,t){e.index=e.nextIndex,e.error=!1;let n=0,r=0,i=0,o=0;e:if(n=e.charValue=e.nextByte(t),n<0)e.done=!0;else if(!(n<=128))if(r=e.nextByte(t),e.charValue=e.charValue<<8|r,n>=129&&n<=254){if(r>=64&&r<=126||r>=80&&r<=254)break e;if(r>=48&&r<=57&&(i=e.nextByte(t),i>=129&&i<=254&&(o=e.nextByte(t),o>=48&&o<=57))){e.charValue=e.charValue<<16|i<<8|o;break e}e.error=!0}else;return 0==e.done}};var or={},sr=Fn&&Fn.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(or,"__esModule",{value:!0}),or.KOI8_R=or.windows_1256=or.windows_1251=or.ISO_8859_9=or.ISO_8859_8=or.ISO_8859_7=or.ISO_8859_6=or.ISO_8859_5=or.ISO_8859_2=or.ISO_8859_1=void 0;const ar=sr($n);class lr{constructor(e,t){this.byteIndex=0,this.ngram=0,this.ngramCount=0,this.hitCount=0,this.spaceChar=32,this.ngramList=e,this.byteMap=t}search(e,t){let n=0;return e[n+32]<=t&&(n+=32),e[n+16]<=t&&(n+=16),e[n+8]<=t&&(n+=8),e[n+4]<=t&&(n+=4),e[n+2]<=t&&(n+=2),e[n+1]<=t&&(n+=1),e[n]>t&&(n-=1),n<0||e[n]!=t?-1:n}lookup(e){this.ngramCount+=1,this.search(this.ngramList,e)>=0&&(this.hitCount+=1)}addByte(e){this.ngram=(this.ngram<<8)+(255&e)&16777215,this.lookup(this.ngram)}nextByte(e){return this.byteIndex>=e.inputLen?-1:255&e.inputBytes[this.byteIndex++]}parse(e,t){let n,r=!1;for(this.spaceChar=t;(n=this.nextByte(e))>=0;){const e=this.byteMap[n];0!=e&&(e==this.spaceChar&&r||this.addByte(e),r=e==this.spaceChar)}this.addByte(this.spaceChar);const i=this.hitCount/this.ngramCount;return i>.33?98:Math.floor(300*i)}}class cr{constructor(e,t){this.fLang=e,this.fNGrams=t}}class hr{constructor(){this.spaceChar=32,this.nGramLang=void 0}ngrams(){return[]}byteMap(){return[]}name(e){return"sbcs"}language(){return this.nGramLang}match(e){this.nGramLang=void 0;const t=this.ngrams();if(n=t,Array.isArray(n)&&isFinite(n[0])){const n=new lr(t,this.byteMap()).parse(e,this.spaceChar);return n<=0?null:(0,ar.default)(e,this,n)}var n;let r=-1;for(let n=t.length-1;n>=0;n--){const i=t[n],o=new lr(i.fNGrams,this.byteMap()).parse(e,this.spaceChar);o>r&&(r=o,this.nGramLang=i.fLang)}return r<=0?null:(0,ar.default)(e,this,r)}}or.ISO_8859_1=class extends hr{byteMap(){return[32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,0,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,32,32,32,32,32,32,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,170,32,32,32,32,32,32,32,32,32,32,181,32,32,32,32,186,32,32,32,32,32,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,32,248,249,250,251,252,253,254,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,32,248,249,250,251,252,253,254,255]}ngrams(){return[new cr("da",[2122086,2122100,2122853,2123118,2123122,2123375,2123873,2124064,2125157,2125671,2126053,2126697,2126708,2126953,2127465,6383136,6385184,6385252,6386208,6386720,6579488,6579566,6579570,6579572,6627443,6644768,6644837,6647328,6647396,6648352,6648421,6648608,6648864,6713202,6776096,6776174,6776178,6907749,6908960,6909543,7038240,7039845,7103858,7104871,7105637,7169380,7234661,7234848,7235360,7235429,7300896,7302432,7303712,7398688,7479396,7479397,7479411,7496992,7566437,7610483,7628064,7628146,7629164,7759218]),new cr("de",[2122094,2122101,2122341,2122849,2122853,2122857,2123113,2123621,2123873,2124142,2125161,2126691,2126693,2127214,2127461,2127471,2127717,2128501,6448498,6514720,6514789,6514804,6578547,6579566,6579570,6580581,6627428,6627443,6646126,6646132,6647328,6648352,6648608,6776174,6841710,6845472,6906728,6907168,6909472,6909541,6911008,7104867,7105637,7217249,7217252,7217267,7234592,7234661,7234848,7235360,7235429,7238757,7479396,7496805,7497065,7562088,7566437,7610468,7628064,7628142,7628146,7695972,7695975,7759218]),new cr("en",[2122016,2122094,2122341,2122607,2123375,2123873,2123877,2124142,2125153,2125670,2125938,2126437,2126689,2126708,2126952,2126959,2127720,6383972,6384672,6385184,6385252,6386464,6386720,6386789,6386793,6561889,6561908,6627425,6627443,6627444,6644768,6647412,6648352,6648608,6713202,6840692,6841632,6841714,6906912,6909472,6909543,6909806,6910752,7217249,7217268,7234592,7235360,7238688,7300640,7302688,7303712,7496992,7500576,7544929,7544948,7561577,7566368,7610484,7628146,7628897,7628901,7629167,7630624,7631648]),new cr("es",[2122016,2122593,2122607,2122853,2123116,2123118,2123123,2124142,2124897,2124911,2125921,2125935,2125938,2126197,2126437,2126693,2127214,2128160,6365283,6365284,6365285,6365292,6365296,6382441,6382703,6384672,6386208,6386464,6515187,6516590,6579488,6579564,6582048,6627428,6627429,6627436,6646816,6647328,6647412,6648608,6648692,6907246,6943598,7102752,7106419,7217253,7238757,7282788,7282789,7302688,7303712,7303968,7364978,7435621,7495968,7497075,7544932,7544933,7544944,7562528,7628064,7630624,7693600,15953440]),new cr("fr",[2122101,2122607,2122849,2122853,2122869,2123118,2123124,2124897,2124901,2125921,2125935,2125938,2126197,2126693,2126703,2127214,2154528,6385268,6386793,6513952,6516590,6579488,6579571,6583584,6627425,6627427,6627428,6627429,6627436,6627440,6627443,6647328,6647412,6648352,6648608,6648864,6649202,6909806,6910752,6911008,7102752,7103776,7103859,7169390,7217252,7234848,7238432,7238688,7302688,7302772,7304562,7435621,7479404,7496992,7544929,7544932,7544933,7544940,7544944,7610468,7628064,7629167,7693600,7696928]),new cr("it",[2122092,2122600,2122607,2122853,2122857,2123040,2124140,2124142,2124897,2125925,2125938,2127214,6365283,6365284,6365296,6365299,6386799,6514789,6516590,6579564,6580512,6627425,6627427,6627428,6627433,6627436,6627440,6627443,6646816,6646892,6647412,6648352,6841632,6889569,6889571,6889572,6889587,6906144,6908960,6909472,6909806,7102752,7103776,7104800,7105633,7234848,7235872,7237408,7238757,7282785,7282788,7282793,7282803,7302688,7302757,7366002,7495968,7496992,7563552,7627040,7628064,7629088,7630624,8022383]),new cr("nl",[2122092,2122341,2122849,2122853,2122857,2123109,2123118,2123621,2123877,2124142,2125153,2125157,2125680,2126949,2127457,2127461,2127471,2127717,2128489,6381934,6381938,6385184,6385252,6386208,6386720,6514804,6579488,6579566,6579570,6627426,6627446,6645102,6645106,6647328,6648352,6648435,6648864,6776174,6841716,6907168,6909472,6909543,6910752,7217250,7217252,7217253,7217256,7217263,7217270,7234661,7235360,7302756,7303026,7303200,7303712,7562088,7566437,7610468,7628064,7628142,7628146,7758190,7759218,7761775]),new cr("no",[2122100,2122102,2122853,2123118,2123122,2123375,2123873,2124064,2125157,2125671,2126053,2126693,2126699,2126703,2126708,2126953,2127465,2155808,6385252,6386208,6386720,6579488,6579566,6579572,6627443,6644768,6647328,6647397,6648352,6648421,6648864,6648948,6713202,6776174,6908779,6908960,6909543,7038240,7039845,7103776,7105637,7169380,7169390,7217267,7234848,7235360,7235429,7237221,7300896,7302432,7303712,7398688,7479411,7496992,7565165,7566437,7610483,7628064,7628142,7628146,7629164,7631904,7631973,7759218]),new cr("pt",[2122016,2122607,2122849,2122853,2122863,2123040,2123123,2125153,2125423,2125600,2125921,2125935,2125938,2126197,2126437,2126693,2127213,6365281,6365283,6365284,6365296,6382693,6382703,6384672,6386208,6386273,6386464,6516589,6516590,6578464,6579488,6582048,6582131,6627425,6627428,6647072,6647412,6648608,6648692,6906144,6906721,7169390,7238757,7238767,7282785,7282787,7282788,7282789,7282800,7303968,7364978,7435621,7495968,7497075,7544929,7544932,7544933,7544944,7566433,7628064,7630624,7693600,14905120,15197039]),new cr("sv",[2122100,2122102,2122853,2123118,2123510,2123873,2124064,2124142,2124655,2125157,2125667,2126053,2126699,2126703,2126708,2126953,2127457,2127465,2155634,6382693,6385184,6385252,6386208,6386804,6514720,6579488,6579566,6579570,6579572,6644768,6647328,6648352,6648864,6747762,6776174,6909036,6909543,7037216,7105568,7169380,7217267,7233824,7234661,7235360,7235429,7235950,7299944,7302432,7302688,7398688,7479393,7479411,7495968,7564129,7565165,7610483,7627040,7628064,7628146,7629164,7631904,7758194,14971424,16151072])]}name(e){return e&&e.c1Bytes?"windows-1252":"ISO-8859-1"}};or.ISO_8859_2=class extends hr{byteMap(){return[32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,0,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,32,32,32,32,32,32,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,177,32,179,32,181,182,32,32,185,186,187,188,32,190,191,32,177,32,179,32,181,182,183,32,185,186,187,188,32,190,191,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,32,248,249,250,251,252,253,254,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,32,248,249,250,251,252,253,254,32]}ngrams(){return[new cr("cs",[2122016,2122361,2122863,2124389,2125409,2125413,2125600,2125668,2125935,2125938,2126072,2126447,2126693,2126703,2126708,2126959,2127392,2127481,2128481,6365296,6513952,6514720,6627440,6627443,6627446,6647072,6647533,6844192,6844260,6910836,6972704,7042149,7103776,7104800,7233824,7268640,7269408,7269664,7282800,7300206,7301737,7304052,7304480,7304801,7368548,7368554,7369327,7403621,7562528,7565173,7566433,7566441,7566446,7628146,7630573,7630624,7676016,12477728,14773997,15296623,15540336,15540339,15559968,16278884]),new cr("hu",[2122016,2122106,2122341,2123111,2123116,2123365,2123873,2123887,2124147,2124645,2124649,2124790,2124901,2125153,2125157,2125161,2125413,2126714,2126949,2156915,6365281,6365291,6365293,6365299,6384416,6385184,6388256,6447470,6448494,6645625,6646560,6646816,6646885,6647072,6647328,6648421,6648864,6648933,6648948,6781216,6844263,6909556,6910752,7020641,7075450,7169383,7170414,7217249,7233899,7234923,7234925,7238688,7300985,7544929,7567973,7567988,7568097,7596391,7610465,7631904,7659891,8021362,14773792,15299360]),new cr("pl",[2122618,2122863,2124064,2124389,2124655,2125153,2125161,2125409,2125417,2125668,2125935,2125938,2126697,2127648,2127721,2127737,2128416,2128481,6365296,6365303,6385257,6514720,6519397,6519417,6582048,6584937,6627440,6627443,6627447,6627450,6645615,6646304,6647072,6647401,6778656,6906144,6907168,6907242,7037216,7039264,7039333,7170405,7233824,7235937,7235941,7282800,7305057,7305065,7368556,7369313,7369327,7369338,7502437,7502457,7563754,7564137,7566433,7825765,7955304,7957792,8021280,8022373,8026400,15955744]),new cr("ro",[2122016,2122083,2122593,2122597,2122607,2122613,2122853,2122857,2124897,2125153,2125925,2125938,2126693,2126819,2127214,2144873,2158190,6365283,6365284,6386277,6386720,6386789,6386976,6513010,6516590,6518048,6546208,6579488,6627425,6627427,6627428,6627440,6627443,6644e3,6646048,6646885,6647412,6648692,6889569,6889571,6889572,6889584,6907168,6908192,6909472,7102752,7103776,7106418,7107945,7234848,7238770,7303712,7365998,7496992,7497057,7501088,7594784,7628064,7631477,7660320,7694624,7695392,12216608,15625760])]}name(e){return e&&e.c1Bytes?"windows-1250":"ISO-8859-2"}};or.ISO_8859_5=class extends hr{byteMap(){return[32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,0,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,32,32,32,32,32,32,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,241,242,243,244,245,246,247,248,249,250,251,252,32,254,255,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,32,241,242,243,244,245,246,247,248,249,250,251,252,32,254,255]}ngrams(){return[2150944,2151134,2151646,2152400,2152480,2153168,2153182,2153936,2153941,2154193,2154462,2154464,2154704,2154974,2154978,2155230,2156514,2158050,13688280,13689580,13884960,14015468,14015960,14016994,14017056,14164191,14210336,14211104,14216992,14407133,14407712,14413021,14536736,14538016,14538965,14538991,14540320,14540498,14557394,14557407,14557409,14602784,14602960,14603230,14604576,14605292,14605344,14606818,14671579,14672085,14672088,14672094,14733522,14734804,14803664,14803666,14803672,14806816,14865883,14868e3,14868192,14871584,15196894,15459616]}name(){return"ISO-8859-5"}language(){return"ru"}};or.ISO_8859_6=class extends hr{byteMap(){return[32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,0,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,32,32,32,32,32,32,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,32,32,32,32,32,224,225,226,227,228,229,230,231,232,233,234,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32]}ngrams(){return[2148324,2148326,2148551,2152932,2154986,2155748,2156006,2156743,13050055,13091104,13093408,13095200,13100064,13100227,13100231,13100232,13100234,13100236,13100237,13100239,13100243,13100249,13100258,13100261,13100264,13100266,13100320,13100576,13100746,13115591,13181127,13181153,13181156,13181157,13181160,13246663,13574343,13617440,13705415,13748512,13836487,14229703,14279913,14805536,14950599,14993696,15001888,15002144,15016135,15058720,15059232,15066656,15081671,15147207,15189792,15255524,15263264,15278279,15343815,15343845,15343848,15386912,15388960,15394336]}name(){return"ISO-8859-6"}language(){return"ar"}};or.ISO_8859_7=class extends hr{byteMap(){return[32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,0,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,32,32,32,32,32,32,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,161,162,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,220,32,221,222,223,32,252,32,253,254,192,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,32,243,244,245,246,247,248,249,250,251,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,32]}ngrams(){return[2154989,2154992,2155497,2155753,2156016,2156320,2157281,2157797,2158049,2158368,2158817,2158831,2158833,2159604,2159605,2159847,2159855,14672160,14754017,14754036,14805280,14806304,14807292,14807584,14936545,15067424,15069728,15147252,15199520,15200800,15278324,15327520,15330014,15331872,15393257,15393268,15525152,15540449,15540453,15540464,15589664,15725088,15725856,15790069,15790575,15793184,15868129,15868133,15868138,15868144,15868148,15983904,15984416,15987951,16048416,16048617,16050157,16050162,16050666,16052e3,16052213,16054765,16379168,16706848]}name(e){return e&&e.c1Bytes?"windows-1253":"ISO-8859-7"}language(){return"el"}};or.ISO_8859_8=class extends hr{byteMap(){return[32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,0,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,32,32,32,32,32,32,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,181,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,32,32,32,32,32]}ngrams(){return[new cr("he",[2154725,2154727,2154729,2154746,2154985,2154990,2155744,2155749,2155753,2155758,2155762,2155769,2155770,2157792,2157796,2158304,2159340,2161132,14744096,14950624,14950625,14950628,14950636,14950638,14950649,15001056,15065120,15068448,15068960,15071264,15071776,15278308,15328288,15328762,15329773,15330592,15331104,15333408,15333920,15474912,15474916,15523872,15524896,15540448,15540449,15540452,15540460,15540462,15540473,15655968,15671524,15787040,15788320,15788525,15920160,16261348,16312813,16378912,16392416,16392417,16392420,16392428,16392430,16392441]),new cr("he",[2154725,2154732,2155753,2155756,2155758,2155760,2157040,2157810,2157817,2158053,2158057,2158565,2158569,2160869,2160873,2161376,2161381,2161385,14688484,14688492,14688493,14688506,14738464,14738916,14740512,14741024,14754020,14754029,14754042,14950628,14950633,14950636,14950637,14950639,14950648,14950650,15002656,15065120,15066144,15196192,15327264,15327520,15328288,15474916,15474925,15474938,15528480,15530272,15591913,15591920,15591928,15605988,15605997,15606010,15655200,15655968,15918112,16326884,16326893,16326906,16376864,16441376,16442400,16442857])]}name(e){return e&&e.c1Bytes?"windows-1255":"ISO-8859-8"}language(){return"he"}};or.ISO_8859_9=class extends hr{byteMap(){return[32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,0,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,32,32,32,32,32,32,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,170,32,32,32,32,32,32,32,32,32,32,181,32,32,32,32,186,32,32,32,32,32,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,32,248,249,250,251,252,105,254,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,32,248,249,250,251,252,253,254,255]}ngrams(){return[2122337,2122345,2122357,2122849,2122853,2123621,2123873,2124140,2124641,2124655,2125153,2125676,2126689,2126945,2127461,2128225,6365282,6384416,6384737,6384993,6385184,6385405,6386208,6386273,6386429,6386685,6388065,6449522,6578464,6579488,6580512,6627426,6627435,6644841,6647328,6648352,6648425,6648681,6909029,6909472,6909545,6910496,7102830,7102834,7103776,7103858,7217249,7217250,7217259,7234657,7234661,7234848,7235872,7235950,7273760,7498094,7535982,7759136,7954720,7958386,16608800,16608868,16609021,16642301]}name(e){return e&&e.c1Bytes?"windows-1254":"ISO-8859-9"}language(){return"tr"}};or.windows_1251=class extends hr{byteMap(){return[32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,0,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,32,32,32,32,32,32,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,32,32,32,32,32,144,131,32,131,32,32,32,32,32,32,154,32,156,157,158,159,144,32,32,32,32,32,32,32,32,32,154,32,156,157,158,159,32,162,162,188,32,180,32,32,184,32,186,32,32,32,32,191,32,32,179,179,180,181,32,32,184,32,186,32,188,190,190,191,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255]}ngrams(){return[2155040,2155246,2155758,2156512,2156576,2157280,2157294,2158048,2158053,2158305,2158574,2158576,2158816,2159086,2159090,2159342,2160626,2162162,14740968,14742268,14937632,15068156,15068648,15069682,15069728,15212783,15263008,15263776,15269664,15459821,15460384,15465709,15589408,15590688,15591653,15591679,15592992,15593186,15605986,15605999,15606001,15655456,15655648,15655918,15657248,15657980,15658016,15659506,15724267,15724773,15724776,15724782,15786210,15787492,15856352,15856354,15856360,15859488,15918571,15920672,15920880,15924256,16249582,16512288]}name(){return"windows-1251"}language(){return"ru"}};or.windows_1256=class extends hr{byteMap(){return[32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,0,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,32,32,32,32,32,32,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,32,32,32,32,32,32,129,32,131,32,32,32,32,136,32,138,32,156,141,142,143,144,32,32,32,32,32,32,32,152,32,154,32,156,32,32,159,32,32,32,32,32,32,32,32,32,32,170,32,32,32,32,32,32,32,32,32,32,181,32,32,32,32,32,32,32,32,32,32,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,32,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,32,32,32,32,244,32,32,32,32,249,32,251,252,32,32,255]}ngrams(){return[2148321,2148324,2148551,2153185,2153965,2154977,2155492,2156231,13050055,13091104,13093408,13095200,13099296,13099459,13099463,13099464,13099466,13099468,13099469,13099471,13099475,13099482,13099486,13099491,13099494,13099501,13099808,13100064,13100234,13115591,13181127,13181149,13181153,13181155,13181158,13246663,13574343,13617440,13705415,13748512,13836487,14295239,14344684,14544160,14753991,14797088,14806048,14806304,14885063,14927648,14928160,14935072,14950599,15016135,15058720,15124449,15131680,15474887,15540423,15540451,15540454,15583520,15585568,15590432]}name(){return"windows-1256"}language(){return"ar"}};or.KOI8_R=class extends hr{byteMap(){return[32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,0,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,32,32,32,32,32,32,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,163,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,163,32,32,32,32,32,32,32,32,32,32,32,32,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223]}ngrams(){return[2147535,2148640,2149313,2149327,2150081,2150085,2150338,2150607,2150610,2151105,2151375,2151380,2151631,2152224,2152399,2153153,2153684,2154196,12701385,12702936,12963032,12963529,12964820,12964896,13094688,13181136,13223200,13224224,13226272,13419982,13420832,13424846,13549856,13550880,13552069,13552081,13553440,13553623,13574352,13574355,13574359,13617103,13617696,13618392,13618464,13620180,13621024,13621185,13684684,13685445,13685449,13685455,13812183,13813188,13881632,13882561,13882569,13882583,13944268,13946656,13946834,13948960,14272544,14603471]}name(){return"KOI8-R"}language(){return"ru"}};var dr={},ur=Fn&&Fn.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(dr,"__esModule",{value:!0}),dr.ISO_2022_CN=dr.ISO_2022_KR=dr.ISO_2022_JP=void 0;const fr=ur($n);class pr{constructor(){this.escapeSequences=[]}name(){return"ISO_2022"}match(e){let t,n,r,i,o=0,s=0,a=0;const l=e.inputBytes,c=e.inputLen;e:for(t=0;tnull!=e&&"object"==typeof e&&(isFinite(e.length)&&e.length>=0),function(e){var t=Fn&&Fn.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var i=Object.getOwnPropertyDescriptor(t,n);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,i)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),n=Fn&&Fn.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),r=Fn&&Fn.__importStar||function(e){if(e&&e.__esModule)return e;var r={};if(null!=e)for(var i in e)"default"!==i&&Object.prototype.hasOwnProperty.call(e,i)&&t(r,e,i);return n(r,e),r},i=Fn&&Fn.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(e,"__esModule",{value:!0}),e.detectFileSync=e.detectFile=e.analyse=e.detect=void 0;const o=i(Un),s=i(jn),a=i(Wn),l=r(Gn),c=r(Yn),h=r(or),d=r(dr),u=gr,f=[new a.default,new l.UTF_16BE,new l.UTF_16LE,new l.UTF_32BE,new l.UTF_32LE,new c.sjis,new c.big5,new c.euc_jp,new c.euc_kr,new c.gb_18030,new d.ISO_2022_JP,new d.ISO_2022_KR,new d.ISO_2022_CN,new h.ISO_8859_1,new h.ISO_8859_2,new h.ISO_8859_5,new h.ISO_8859_6,new h.ISO_8859_7,new h.ISO_8859_8,new h.ISO_8859_9,new h.windows_1251,new h.windows_1256,new h.KOI8_R,new s.default];e.detect=t=>{const n=(0,e.analyse)(t);return n.length>0?n[0].name:null};e.analyse=e=>{if(!(0,u.isByteArray)(e))throw new Error("Input must be a byte array, e.g. Buffer or Uint8Array");const t=[];for(let e=0;e<256;e++)t[e]=0;for(let n=e.length-1;n>=0;n--)t[255&e[n]]++;let n=!1;for(let e=128;e<=159;e+=1)if(0!==t[e]){n=!0;break}const r={byteStats:t,c1Bytes:n,rawInput:e,rawLen:e.length,inputBytes:e,inputLen:e.length},i=f.map((e=>e.match(r))).filter((e=>!!e)).sort(((e,t)=>t.confidence-e.confidence));return i};e.detectFile=(t,n={})=>new Promise(((r,i)=>{let s;const a=(0,o.default)(),l=(t,n)=>{s&&a.closeSync(s),t?i(t):r((0,e.detect)(n))};if(n&&n.sampleSize){s=a.openSync(t,"r");const e=Buffer.allocUnsafe(n.sampleSize);a.read(s,e,0,n.sampleSize,n.offset,(t=>{l(t,e)}))}else a.readFile(t,l)}));e.detectFileSync=(t,n={})=>{const r=(0,o.default)();if(n&&n.sampleSize){const i=r.openSync(t,"r"),o=Buffer.allocUnsafe(n.sampleSize);return r.readSync(i,o,0,n.sampleSize,n.offset),r.closeSync(i),(0,e.detect)(o)}return(0,e.detect)(r.readFileSync(t))},e.default={analyse:e.analyse,detect:e.detect,detectFileSync:e.detectFileSync,detectFile:e.detectFile}}(Hn);var mr=_n(Hn);class yr extends Ot{constructor(e,t,n,r){super({mode:t,format:"TXT",animation:n}),this.txtBuffer=e,this.charset=r}renderTo(e){return new Promise(((t,n)=>f(this,void 0,void 0,(function*(){this.element=e,this.book||(yield this.parse());let n=new L(this.book);this.chapterList=yield n.getChapter(this.book.toc),this.chapterDocList=yield n.getChapterDoc(),w(e);let r=this.getDocument();r&&(T(e,this.mode,r),t())}))))}parse(){return f(this,void 0,void 0,(function*(){try{const e=new TextDecoder(this.charset),t=new Uint8Array(this.txtBuffer);let n=e.decode(t);this.book=Ae(n,!0)}catch(e){throw console.log(e),e}}))}preCache(){return f(this,void 0,void 0,(function*(){return this.book||(yield this.parse()),yield Pt(this.book)}))}getMetadata(e){return f(this,void 0,void 0,(function*(){try{const t=new Uint8Array(e);let n=mr.detect(t);return this.charset=n||"utf8",{charset:n||"utf8"}}catch(e){throw console.log(e),e}}))}}const br=({entries:e,loadBlob:t,getSize:n},r)=>{const i=new Map,o=new Map,s=[".jpg",".jpeg",".png",".gif",".bmp",".webp",".svg"],a=e.map((e=>e.filename)).filter((e=>s.some((t=>e.endsWith(t))))).sort(),l={getCover:()=>t(a[0])};return l.metadata={title:r.name},l.sections=a.map((e=>({id:e,load:()=>(async e=>{if(i.has(e))return i.get(e);const n=URL.createObjectURL(await t(e)),r=URL.createObjectURL(new Blob([``],{type:"text/html"}));return o.set(e,[n,r]),i.set(e,r),r})(e),unload:()=>(e=>{o.get(e)?.forEach?.((e=>URL.revokeObjectURL(e))),o.delete(e),i.delete(e)})(e),size:n(e)}))),l.toc=a.map((e=>({label:e,href:e}))),l.rendition={layout:"pre-paginated"},l.resolveHref=e=>({index:l.sections.findIndex((t=>t.id===e))}),l.splitTOCHref=e=>[e,null],l.getTOCFragment=e=>e.documentElement,l};class wr extends Ot{constructor(e,t,n,r){super({mode:t,format:n,animation:r}),this.comicBuffer=e,this.mode=t,this.format=n,this.chapterList=[],this.chapterDocList=[],this.book="",this.element="",this.rpc}renderTo(e){return new Promise(((t,n)=>f(this,void 0,void 0,(function*(){if(this.element=e,w(e),!this.book)try{yield this.parse()}catch(e){console.log(e),n(e)}let r=new L(this.book);this.chapterList=yield r.getChapter(this.book.toc),this.chapterDocList=yield r.getChapterDoc();let i=this.getDocument();i&&(T(e,this.mode,i),t())}))))}parse(){return f(this,void 0,void 0,(function*(){try{let e=new Blob([this.comicBuffer]),t=new File([e],"book."+this.format.toLocaleLowerCase(),{lastModified:(new Date).getTime(),type:e.type});if("CBZ"===this.format){const e=yield this.makeZipLoader(t);this.book=br(e,t)}else if("CBT"===this.format){const e=yield this.makeTarLoader();this.book=br(e,t)}else if("CBR"===this.format){this.rpc=yield window.RPC.new("./lib/libunrar/worker.js",{loaded:function(){console.log("loaded")},progressShow:function(e,t,n){console.log(n)}}),yield new Promise((e=>setTimeout(e,200)));const e=yield this.makeRarLoader();this.book=br(e,t)}else if("CB7"===this.format){const e=yield this.make7zLoader();this.book=br(e,t)}}catch(e){throw console.log(e),e}}))}preCache(){return f(this,void 0,void 0,(function*(){return this.book||(yield this.parse()),yield Pt(this.book)}))}makeZipLoader(e){return f(this,void 0,void 0,(function*(){const t=new r(new i(e)),n=yield t.getEntries(),a=new Map(n.map((e=>[e.filename,e]))),l=e=>(t,...n)=>a.has(t)?e(a.get(t),...n):null;return{entries:n,loadText:l((e=>e.getData(new o))),loadBlob:l(((e,t)=>e.getData(new s(t)))),getSize:e=>{var t,n;return null!==(n=null===(t=a.get(e))||void 0===t?void 0:t.uncompressedSize)&&void 0!==n?n:0}}}))}makeTarLoader(){return f(this,void 0,void 0,(function*(){const e=yield c(this.comicBuffer),t=new Map(e.map((e=>[e.name,e]))),n=e=>(n,...r)=>t.has(n)?e(t.get(n),...r):null,r=n((e=>e.readAsString())),i=n(((e,t)=>e.blob));return{entries:e.map((e=>({filename:e.name}))),loadText:r,loadBlob:i,getSize:e=>{var n,r;return null!==(r=null===(n=t.get(e))||void 0===n?void 0:n.size)&&void 0!==r?r:0}}}))}makeRarLoader(){return f(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{var n=[this.comicBuffer],r=[{name:"book.rar",content:this.comicBuffer}];this.rpc.transferables=n,this.rpc.unrar(r,null,0).then((t=>{let n=this.getRarEntries(t.ls);const r=new Map(Object.values(n).map((e=>[e.fullFileName,e]))),i=e=>(t,...n)=>r.has(t)?e(r.get(t),...n):null,o=i((e=>e.fullFileName)),s=i(((e,t)=>new Blob([e.fileContent])));e({entries:Object.values(n).map((e=>({filename:e.fullFileName}))),loadText:o,loadBlob:s,getSize:e=>{var t,n;return null!==(n=null===(t=r.get(e))||void 0===t?void 0:t.fileSize)&&void 0!==n?n:0}})})).catch((e=>{t(e),console.log(e)}))}))}))}make7zLoader(){return f(this,void 0,void 0,(function*(){const e="./lib/7z-wasm/7zz.wasm";if(!window.wasmBinary){const t=yield fetch(e,{credentials:"same-origin"});if(!t.ok)throw"failed to load wasm binary file at '"+e+"'";window.wasmBinary=yield t.arrayBuffer()}const t=yield window.SevenZip({wasmBinary:window.wasmBinary}),n=new Uint8Array(this.comicBuffer),r="archive.cb7",i=t.FS.open(r,"w+");t.FS.write(i,n,0,n.length),t.FS.close(i),t.callMain(["x",r]);const o=t.FS,s=this.get7zEntries(o.lookupPath("/").node),a=new Map(s.map((e=>[e.name,e]))),l=e=>(t,...n)=>a.has(t)?e(a.get(t),...n):null,c=l((e=>e.name)),h=l(((e,t)=>new Blob([e.buffer])));return{entries:s.map((e=>({filename:e.name}))),loadText:c,loadBlob:h,getSize:e=>{var t,n;return null!==(n=null===(t=a.get(e))||void 0===t?void 0:t.packSize)&&void 0!==n?n:0}}}))}getRarEntries(e){const t=Object.keys(e);let n=[];for(let r=0;r"archive.cb7"!=e&&"dev"!=e&&"home"!=e&&"proc"!=e&&"tmp"!=e));let r=[];for(let e=0;ef(this,void 0,void 0,(function*(){try{this.book||(yield this.parse());const t=yield this.book.getCover();var n=new FileReader;n.readAsDataURL(t),n.onloadend=()=>{e({cover:n.result})}}catch(e){console.log(e),t(e)}}))))}))}}const vr=e=>e?.trim()?.replace(/\s{2,}/g," "),xr=e=>vr(e?.textContent),Cr={XLINK:"http://www.w3.org/1999/xlink",EPUB:"http://www.idpf.org/2007/ops"},Sr="application/xml",Tr="application/xhtml+xml",Lr={strong:["strong","self"],emphasis:["em","self"],style:["span","self"],a:"anchor",strikethrough:["s","self"],sub:["sub","self"],sup:["sup","self"],code:["code","self"],image:"image"},kr={epigraph:["blockquote"],subtitle:["h2",Lr],"text-author":["p",Lr],date:["p",Lr],stanza:"stanza"},Ar={title:["header",{p:["h1",Lr],"empty-line":["br"]}],epigraph:["blockquote","self"],image:"image",annotation:["aside"],section:["section","self"],p:["p",Lr],poem:["blockquote",kr],subtitle:["h2",Lr],cite:["blockquote","self"],"empty-line":["br"],table:["table",{tr:["tr",["align"]],th:["th",["colspan","rowspan","align","valign"]],td:["td",["colspan","rowspan","align","valign"]]}],"text-author":["p",Lr]};kr.epigraph.push(Ar);const Ir={image:"image",title:["section",{p:["h1",Lr],"empty-line":["br"]}],epigraph:["section",Ar],section:["section",Ar]},Er=e=>{const t=e.getAttributeNS(Cr.XLINK,"href"),[,n]=t.split("#"),r=e.getRootNode().getElementById(n);return r?`data:${r.getAttribute("content-type")};base64,${r.textContent}`:t};class Mr{constructor(e){this.fb2=e,this.doc=document.implementation.createDocument(Cr.XHTML,"html")}image(e){const t=this.doc.createElement("img");return t.alt=e.getAttribute("alt"),t.title=e.getAttribute("title"),t.setAttribute("src",Er(e)),t}anchor(e){const t=this.convert(e,{a:["a",Lr]});return t.setAttribute("href",e.getAttributeNS(Cr.XLINK,"href")),"note"===e.getAttribute("type")&&t.setAttributeNS(Cr.EPUB,"epub:type","noteref"),t}stanza(e){const t=this.convert(e,{stanza:["p",{title:["header",{p:["strong",Lr],"empty-line":["br"]}],subtitle:["p",Lr]}]});for(const n of e.children)"v"===n.nodeName&&(t.append(this.doc.createTextNode(n.textContent)),t.append(this.doc.createElement("br")));return t}convert(e,t){if(3===e.nodeType)return this.doc.createTextNode(e.textContent);if(4===e.nodeType)return this.doc.createCDATASection(e.textContent);if(8===e.nodeType)return this.doc.createComment(e.textContent);const n=t?.[e.nodeName];if(!n)return null;if("string"==typeof n)return this[n](e);const[r,i]=n,o=this.doc.createElement(r);if(e.id&&(o.id=e.id),o.classList.add(e.nodeName),Array.isArray(i))for(const t of i)o.setAttribute(t,e.getAttribute(t));const s="self"===i?t:Array.isArray(i)?null:i;let a=e.firstChild;for(;a;){const e=this.convert(a,s);e&&o.append(e),a=a.nextSibling}return o}}const Br=URL.createObjectURL(new Blob(['\n@namespace epub "http://www.idpf.org/2007/ops";\nbody > img, section > img {\n display: block;\n margin: auto;\n}\n.title {\n text-align: center;\n}\nbody > section > .title, body.notesBodyType > .title {\n margin: 3em 0;\n}\nbody.notesBodyType > section .title {\n text-align: left;\n margin: 1em 0;\n}\np {\n text-indent: 1em;\n margin: 0;\n}\n:not(p) + p, p:first-child {\n text-indent: 0;\n}\n.poem p {\n text-indent: 0;\n margin: 1em 0;\n}\n.text-author, .date {\n text-align: end;\n}\n.text-author:before {\n content: "—";\n}\ntable {\n border-collapse: collapse;\n}\ntd, th {\n padding: .25em;\n}\na[epub|type~="noteref"] {\n font-size: .75em;\n vertical-align: super;\n}\nbody:not(.notesBodyType) > .title, body:not(.notesBodyType) > .epigraph {\n margin: 3em 0;\n}\n'],{type:"text/css"})),Or="data-foliate-id",Dr=async e=>{const t={},n=await(async e=>{const t=await e.arrayBuffer(),n=new TextDecoder("utf-8").decode(t),r=new DOMParser,i=r.parseFromString(n,Sr),o=i.xmlEncoding||n.match(/^<\?xml\s+version\s*=\s*["']1.\d+"\s+encoding\s*=\s*["']([A-Za-z0-9._-]*)["']/)?.[1];if(o&&"utf-8"!==o.toLowerCase()){const e=new TextDecoder(o).decode(t);return r.parseFromString(e,Sr)}return i})(e),r=new Mr(n),i=e=>n.querySelector(e),o=e=>[...n.querySelectorAll(e)],s=e=>{const t=xr(e.querySelector("nickname"));if(t)return t;const n=xr(e.querySelector("first-name")),r=xr(e.querySelector("middle-name")),i=xr(e.querySelector("last-name"));return{name:[n,r,i].filter((e=>e)).join(" "),sortAs:i?[i,[n,r].filter((e=>e)).join(" ")].join(", "):null}},a=e=>e?.getAttribute("value")??xr(e),l=i("title-info annotation");t.metadata={title:xr(i("title-info book-title")),identifier:xr(i("document-info id")),language:xr(i("title-info lang")),author:o("title-info author").map(s),translator:o("title-info translator").map(s),producer:o("document-info author").map(s).concat(o("document-info program-used").map(xr)),publisher:xr(i("publish-info publisher")),published:a(i("title-info date")),modified:a(i("document-info date")),description:l?r.convert(l,{annotation:["div",Ar]}).innerHTML:null,subject:o("title-info genre").map(xr)},t.getCover=()=>fetch(Er(i("coverpage image"))).then((e=>e.blob()));const c=Array.from(n.querySelectorAll("body"),(e=>{const t=r.convert(e,{body:["body",Ir]});return[Array.from(t.children,(e=>{const t=[e,...e.querySelectorAll("[id]")].map((e=>e.id));return{el:e,ids:t}})),t]})),h=c[0][0].map((({el:e,ids:t})=>({ids:t,titles:Array.from(e.querySelectorAll(":scope > section > .title"),((e,t)=>(e.setAttribute(Or,t),{title:xr(e),index:t}))),el:e}))).concat(c.slice(1).map((([e,t])=>{const n=e.map((e=>e.ids)).flat();return t.classList.add("notesBodyType"),{ids:n,el:t,linear:"no"}}))).map((({ids:e,titles:t,el:n,linear:r})=>{const i=(o=n.outerHTML,`\n\n \n ${o}\n`);var o;const s=new Blob([i],{type:Tr}),a=URL.createObjectURL(s);return{ids:e,title:vr(n.querySelector(".title, .subtitle, p")?.textContent??(n.classList.contains("title")?n.textContent:"")),titles:t,load:()=>a,createDocument:()=>(new DOMParser).parseFromString(i,Tr),size:s.size-Array.from(n.querySelectorAll("[src]"),(e=>e.getAttribute("src")?.length??0)).reduce(((e,t)=>e+t),0),linear:r}})),d=new Map;return t.sections=h.map(((e,t)=>{const{ids:n,load:r,createDocument:i,size:o,linear:s}=e;for(const e of n)e&&d.set(e,t);return{id:t,load:r,createDocument:i,size:o,linear:s}})),t.toc=h.map((({title:e,titles:t},n)=>{const r=n.toString();return{label:e,href:r,subitems:t?.length?t.map((({title:e,index:t})=>({label:e,href:`${r}#${t}`}))):null}})).filter((e=>e)),t.resolveHref=e=>{const[t,n]=e.split("#");return t?{index:Number(t),anchor:e=>e.querySelector(`[${Or}="${n}"]`)}:{index:d.get(n),anchor:e=>e.getElementById(n)}},t.splitTOCHref=e=>e?.split("#")?.map((e=>Number(e)))??[],t.getTOCFragment=(e,t)=>e.querySelector(`[${Or}="${t}"]`),t};class Nr extends Ot{constructor(e,t,n){super({mode:t,format:"FB2",animation:n}),this.fb2Buffer=e}renderTo(e){return new Promise(((t,n)=>f(this,void 0,void 0,(function*(){this.element=e,this.book||(yield this.parse());let n=new L(this.book);this.chapterList=yield n.getChapter(this.book.toc),this.chapterDocList=yield n.getChapterDoc(),w(e);let r=this.getDocument();r&&(T(e,this.mode,r),t())}))))}parse(){return f(this,void 0,void 0,(function*(){try{let e=new Blob([this.fb2Buffer]);this.book=yield Dr(e)}catch(e){throw console.log(e),e}}))}preCache(){return f(this,void 0,void 0,(function*(){return this.book||(yield this.parse()),yield Pt(this.book)}))}getMetadata(){return f(this,void 0,void 0,(function*(){try{this.book||(yield this.parse());let e=new L(this.book);return yield e.getMetadata()}catch(e){throw console.log(e),e}}))}}class Rr extends Ot{constructor(e,t,n){super({mode:t,format:"CACHE",animation:n}),this.cacheBuffer=e}renderTo(e){return new Promise(((t,n)=>f(this,void 0,void 0,(function*(){this.element=e,this.book=yield Rt(this.cacheBuffer);let n=new L(this.book);this.chapterList=yield n.getChapter(this.book.toc),this.chapterDocList=yield n.getChapterDoc(),w(e);let r=this.getDocument();r&&(T(e,this.mode,r),t())}))))}}class Pr extends Ot{constructor(e,t,n){super({mode:t,format:"DOCX",animation:n}),this.docxBuffer=e}renderTo(e){return new Promise(((t,n)=>f(this,void 0,void 0,(function*(){this.element=e,this.book||(yield this.parse());let n=new L(this.book);this.chapterList=yield n.getChapter(this.book.toc),this.chapterDocList=yield n.getChapterDoc(),w(e);let r=this.getDocument();r&&(T(e,this.mode,r),t())}))))}parse(){return f(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{try{h.convertToHtml({arrayBuffer:this.docxBuffer}).then((t=>f(this,void 0,void 0,(function*(){this.book=Ae(t.value,!1),e()}))))}catch(e){console.log(e),t(e)}}))}))}preCache(){return f(this,void 0,void 0,(function*(){return this.book||(yield this.parse()),yield Pt(this.book)}))}}class Fr extends Ot{constructor(e,t,n){super({mode:t,format:"MD",animation:n}),this.mdBuffer=e}renderTo(e){return new Promise(((t,n)=>f(this,void 0,void 0,(function*(){this.element=e,this.book||(yield this.parse());let n=new L(this.book);this.chapterList=yield n.getChapter(this.book.toc),this.chapterDocList=yield n.getChapterDoc(),w(e);let r=this.getDocument();r&&(T(e,this.mode,r),t())}))))}parse(){return f(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{try{var n=new Blob([this.mdBuffer],{type:"text/plain"}),r=new FileReader;r.onload=t=>f(this,void 0,void 0,(function*(){var n;let r=yield d(null===(n=t.target)||void 0===n?void 0:n.result);this.book=Ae(r,!1),e()})),r.readAsText(n,"UTF-8")}catch(e){console.log(e),t(e)}}))}))}preCache(){return f(this,void 0,void 0,(function*(){return this.book||(yield this.parse()),yield Pt(this.book)}))}}class _r extends Ot{constructor(e,t,n,r){super({mode:t,format:n,animation:r}),this.htmlBuffer=e}renderTo(e){return new Promise(((t,n)=>f(this,void 0,void 0,(function*(){this.element=e,this.book||(yield this.parse());let n=new L(this.book);this.chapterList=yield n.getChapter(this.book.toc),this.chapterDocList=yield n.getChapterDoc(),w(e);let r=this.getDocument();r&&(T(e,this.mode,r),t())}))))}parse(){return f(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{try{var n=new Blob([this.htmlBuffer],{type:Dt[this.format.toLocaleLowerCase()]}),r=new FileReader;r.onload=t=>f(this,void 0,void 0,(function*(){var n;let r=null===(n=t.target)||void 0===n?void 0:n.result;"MHTML"===this.format&&(r=u.convert(r).window.document.documentElement.innerHTML),this.book=Ae(r,!1),e()})),r.readAsText(n,"UTF-8")}catch(e){console.log(e),t(e)}}))}))}preCache(){return f(this,void 0,void 0,(function*(){return this.book||(yield this.parse()),yield Pt(this.book)}))}}export{Rr as CacheRender,wr as ComicRender,Pr as DocxRender,Ft as EpubRender,Nr as Fb2Render,_r as HtmlRender,Fr as MdRender,An as MobiRender,Pn as PdfRender,yr as TxtRender}; diff --git a/src/components/dialogs/feedbackDialog/component.tsx b/src/components/dialogs/feedbackDialog/component.tsx index f18f2abb..d374ec30 100644 --- a/src/components/dialogs/feedbackDialog/component.tsx +++ b/src/components/dialogs/feedbackDialog/component.tsx @@ -72,7 +72,7 @@ class FeedbackDialog extends Component< this.setState({ isSending: false }); return; } - toast(this.props.t("Sending")); + toast.loading(this.props.t("Sending"), { id: "sending-id" }); let version = packageInfo.version; const os = window.require("os"); const system = os.platform() + " " + os.version(); @@ -96,7 +96,9 @@ class FeedbackDialog extends Component< this.setState({ isSending: false }); return; } - toast.success(this.props.t("Sending successful")); + toast.success(this.props.t("Sending successful"), { + id: "sending-id", + }); this.props.handleFeedbackDialog(false); }; handleJump = (url: string) => { @@ -171,43 +173,36 @@ class FeedbackDialog extends Component< : { marginTop: "30px" } } /> -
-
- Upload attachments -
-
- { - if (!event || !event.target || !event.target.files) { - toast.error("Empty files"); + + { + if (!event || !event.target || !event.target.files) { + toast.error("Empty files"); + } + let files: any = event.target.files; + let zip = new JSZip(); + for (let index = 0; index < files.length; index++) { + const file = files[index]; + var fileSize = file.size; + var fileSizeMB = fileSize / (1024 * 1024); + if (fileSizeMB > 20) { + toast.error(this.props.t("File size is larger than 20MB")); + event.target.value = ""; + break; + } else { + zip.file(file.name, file); } - let files: any = event.target.files; - let zip = new JSZip(); - for (let index = 0; index < files.length; index++) { - const file = files[index]; - var fileSize = file.size; - var fileSizeMB = fileSize / (1024 * 1024); - if (fileSizeMB > 20) { - toast.error( - this.props.t("File size is larger than 20MB") - ); - event.target.value = ""; - break; - } else { - zip.file(file.name, file); - } - } - zip.generateAsync({ type: "blob" }).then((content) => { - this.setState({ fileContent: content }); - }); - }} - /> -
+ } + zip.generateAsync({ type: "blob" }).then((content) => { + this.setState({ fileContent: content }); + }); + }} + />